123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #include "snap7_buf.h"
- #include <string>
- #include <string.h>
- Snap7_buf::Snap7_buf()
- {
- m_id = 0;
- m_start_index = 0;
- m_size = 0;
- mp_buf_obverse = nullptr;
- mp_buf_reverse = nullptr;
- m_communication_mode = NO_COMMUNICATION;
- }
- Snap7_buf::Snap7_buf(const Snap7_buf& other)
- {
- m_id = other.m_id;
- m_start_index = other.m_start_index;
- m_communication_mode = other.m_communication_mode;
- if ( other.m_size > 0 && other.mp_buf_obverse != nullptr && other.mp_buf_reverse != nullptr)
- {
- mp_buf_obverse = (void*)malloc(other.m_size);
- memcpy(mp_buf_obverse, other.mp_buf_obverse, other.m_size);
- mp_buf_reverse = (void*)malloc(other.m_size);
- memcpy(mp_buf_reverse, other.mp_buf_reverse, other.m_size);
- m_size = other.m_size;
- }
- }
- Snap7_buf& Snap7_buf::operator =(const Snap7_buf& other)
- {
- m_id = other.m_id;
- m_start_index = other.m_start_index;
- m_communication_mode = other.m_communication_mode;
- if ( other.m_size > 0 && other.mp_buf_obverse != nullptr && other.mp_buf_reverse != nullptr)
- {
- mp_buf_obverse = (void*)malloc(other.m_size);
- memcpy(mp_buf_obverse, other.mp_buf_obverse, other.m_size);
- mp_buf_reverse = (void*)malloc(other.m_size);
- memcpy(mp_buf_reverse, other.mp_buf_reverse, other.m_size);
- m_size = other.m_size;
- }
- }
- Snap7_buf::~Snap7_buf()
- {
- if ( mp_buf_obverse )
- {
- free(mp_buf_obverse);
- mp_buf_obverse = NULL;
- }
- if ( mp_buf_reverse )
- {
- free(mp_buf_reverse);
- mp_buf_reverse = NULL;
- }
- }
- Snap7_buf::Snap7_buf(int id, int start_index, int size, Communication_mode communication_mode)
- {
- m_id = id;
- m_start_index = start_index;
- m_communication_mode = communication_mode;
- if ( size > 0)
- {
- mp_buf_obverse = (void*)malloc(size);
- memset(mp_buf_obverse, 0, size);
- mp_buf_reverse = (void*)malloc(size);
- memset(mp_buf_reverse, 0, size);
- m_size = size;
- }
- }
- Snap7_buf::Snap7_buf(int id, int start_index, int size, void* p_buf_obverse, void* p_buf_reverse, Communication_mode communication_mode)
- {
- m_id = id;
- m_start_index = start_index;
- m_communication_mode = communication_mode;
- if ( size > 0 && p_buf_obverse != nullptr && p_buf_reverse != nullptr)
- {
- mp_buf_obverse = (void*)malloc(size);
- memcpy(mp_buf_obverse, p_buf_obverse, size);
- mp_buf_reverse = (void*)malloc(size);
- memcpy(mp_buf_reverse, p_buf_reverse, size);
- m_size = size;
- }
- }
- int Snap7_buf::get_id()
- {
- return m_id;
- }
- int Snap7_buf::get_start_index()
- {
- return m_start_index;
- }
- int Snap7_buf::get_size()
- {
- return m_size;
- }
- void* Snap7_buf::get_buf_obverse()
- {
- return mp_buf_obverse;
- }
- void* Snap7_buf::get_buf_reverse()
- {
- return mp_buf_reverse;
- }
- Snap7_buf::Communication_mode Snap7_buf::get_communication_mode()
- {
- return m_communication_mode;
- }
- void Snap7_buf::set_communication_mode(Communication_mode communication_mode)
- {
- m_communication_mode = communication_mode;
- }
|