123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #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<COTSSegment> 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);
- }
- }
- }
|