#include "stdafx.h" #include "OTSFeature.h" namespace OTSDATA { // COTSFeature // constructor COTSFeature::COTSFeature() // constructor { Init(); } COTSFeature::COTSFeature(const COTSFeature& a_oSource) // copy constructor { // can't copy itself if (&a_oSource == this) { return; } // copy data over Duplicate(a_oSource); } COTSFeature::COTSFeature(COTSFeature* a_poSource) // copy constructor { // can't copy itself if (a_poSource == this) { return; } // copy data over Duplicate(*a_poSource); } COTSFeature& COTSFeature::operator=(const COTSFeature& a_oSource) // =operator { // cleanup Cleanup(); // copy the class data over Duplicate(a_oSource); // return class return *this; } BOOL COTSFeature::operator==(const COTSFeature& a_oSource) // ==operator { // return FASLE, if the two segments list are in different size int nSize = (int)m_listSegments.size(); if (nSize != (int)a_oSource.m_listSegments.size()) { return FALSE; } // return FALSE if any of the segments are different for (int i = 0; i < nSize; ++i) { if (!(*(m_listSegments[i].get()) == *(a_oSource.m_listSegments[i].get()))) { return FALSE; } } // members check return TRUE; } COTSFeature::~COTSFeature() // destructor { Cleanup(); } void COTSFeature::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode) { xmls::Collection xSegmentlist; xmls::Slo slo; slo.Register("Segmentlist", &xSegmentlist); if (isStoring) { xSegmentlist.Clear(); for (unsigned int i = 0; i < m_listSegments.size(); i++) { xSegmentlist.addItem(m_listSegments[i].get()); } slo.Serialize(true, classDoc, rootNode); } else { slo.Serialize(false, classDoc, rootNode); m_listSegments.clear(); for (unsigned int i = 0; i < xSegmentlist.size(); i++) { m_listSegments.push_back(COTSSegmentPtr(xSegmentlist.getItem(i))); } } } // segments list void COTSFeature::SetSegmentsList(COTSSegmentsList& a_plistSegment, BOOL a_bClear) { // clear holes list if necessary if (a_bClear) { m_listSegments.clear(); } // copy the list for (auto pSegment : a_plistSegment) { //COTSSegmentPtr pSegmentNew = COTSSegmentPtr(new COTSSegment(pSegment.get())); m_listSegments.push_back(pSegment); } } COTSSegmentPtr COTSFeature::GetSegmentByIndex(int a_nIndex) { if (a_nIndex < 0 || a_nIndex >= (int)m_listSegments.size()) { // invalid index return nullptr; } return m_listSegments[a_nIndex]; } // cleanup void COTSFeature::Cleanup() { m_listSegments.clear(); } // initialization void COTSFeature::Init() { // initialization m_listSegments.clear(); } // duplication void COTSFeature::Duplicate(const COTSFeature& a_oSource) { // initialization Init(); // copy data over for (auto pSegments : a_oSource.m_listSegments) { COTSSegmentPtr pSegmentNew = COTSSegmentPtr(new COTSSegment(*pSegments.get())); m_listSegments.push_back(pSegmentNew); } } }