#include "stdafx.h" #include "OTSSegment.h" namespace OTSDATA { // CDomain COTSSegment::COTSSegment() { Init(); } // constructor COTSSegment::COTSSegment(long a_nHeight, long a_nStart, long a_nLength) // constructor { Init(); m_nHeight = a_nHeight; m_nStart = a_nStart; m_nLength = a_nLength; } COTSSegment::COTSSegment(const COTSSegment& a_oSource) // copy constructor { // can't copy itself if (&a_oSource == this) { return; } // copy data over Duplicate(a_oSource); } COTSSegment::COTSSegment(COTSSegment* a_poSource) // copy constructor { // input check ASSERT(a_poSource); if (!a_poSource) { return; } // can't copy itself if (a_poSource == this) { return; } // copy data over Duplicate(*a_poSource); } COTSSegment& COTSSegment::operator=(const COTSSegment& a_oSource) // =operator { // cleanup Cleanup(); // copy the class data over Duplicate(a_oSource); // return class return *this; } BOOL COTSSegment::operator==(const COTSSegment&a_oSource) // ==operator { return m_nHeight == a_oSource.m_nHeight && m_nStart == a_oSource.m_nStart && m_nLength == a_oSource.m_nLength; } COTSSegment::~COTSSegment() // destructor { Cleanup(); } void COTSSegment::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode) { xmls::xLong xnHeight; xmls::xLong xnStart; xmls::xLong xnLength; xmls::Slo slo; slo.Register("Height", &xnHeight); slo.Register("Start", &xnStart); slo.Register("Length", &xnLength); if (isStoring) { xnHeight = m_nHeight; xnStart = m_nStart; xnLength = m_nLength; slo.Serialize(true, classDoc, rootNode); } else { slo.Serialize(false, classDoc, rootNode); m_nHeight = xnHeight.value(); m_nStart = xnStart.value(); m_nLength = xnLength.value(); } } BOOL COTSSegment::UpDownConection(const COTSSegment &a_Segment) { if (abs((int)(a_Segment.m_nHeight - m_nHeight)) != 1) { return FALSE; } long myStart = m_nStart; long myEnd = m_nStart + m_nLength - 1; long yourStart = a_Segment.m_nStart; long yourEnd = a_Segment.m_nStart + a_Segment.m_nLength - 1; if (yourStart-myEnd > 1 || myStart-yourEnd >1 ) { return FALSE; } return TRUE; } // cleanup void COTSSegment::Cleanup() { } // initialization void COTSSegment::Init() { // height m_nHeight = 0; // start m_nStart = 0; // length m_nLength = 0; } // duplication void COTSSegment::Duplicate(const COTSSegment& a_oSource) { // initialization // copy data over m_nHeight = a_oSource.m_nHeight; m_nStart = a_oSource.m_nStart; m_nLength = a_oSource.m_nLength; } }