OTSFeature.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #include "stdafx.h"
  2. #include "OTSFeature.h"
  3. namespace OTSDATA {
  4. // COTSFeature
  5. // constructor
  6. COTSFeature::COTSFeature() // constructor
  7. {
  8. Init();
  9. }
  10. COTSFeature::COTSFeature(const COTSFeature& a_oSource) // copy constructor
  11. {
  12. // can't copy itself
  13. if (&a_oSource == this)
  14. {
  15. return;
  16. }
  17. // copy data over
  18. Duplicate(a_oSource);
  19. }
  20. COTSFeature::COTSFeature(COTSFeature* a_poSource) // copy constructor
  21. {
  22. // can't copy itself
  23. if (a_poSource == this)
  24. {
  25. return;
  26. }
  27. // copy data over
  28. Duplicate(*a_poSource);
  29. }
  30. COTSFeature& COTSFeature::operator=(const COTSFeature& a_oSource) // =operator
  31. {
  32. // cleanup
  33. Cleanup();
  34. // copy the class data over
  35. Duplicate(a_oSource);
  36. // return class
  37. return *this;
  38. }
  39. BOOL COTSFeature::operator==(const COTSFeature& a_oSource) // ==operator
  40. {
  41. // return FASLE, if the two segments list are in different size
  42. int nSize = (int)m_listSegments.size();
  43. if (nSize != (int)a_oSource.m_listSegments.size())
  44. {
  45. return FALSE;
  46. }
  47. // return FALSE if any of the segments are different
  48. for (int i = 0; i < nSize; ++i)
  49. {
  50. if (!(*(m_listSegments[i].get()) == *(a_oSource.m_listSegments[i].get())))
  51. {
  52. return FALSE;
  53. }
  54. }
  55. // members check
  56. return TRUE;
  57. }
  58. COTSFeature::~COTSFeature() // destructor
  59. {
  60. Cleanup();
  61. }
  62. void COTSFeature::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
  63. {
  64. xmls::Collection<COTSSegment> xSegmentlist;
  65. xmls::Slo slo;
  66. slo.Register("Segmentlist", &xSegmentlist);
  67. if (isStoring)
  68. {
  69. xSegmentlist.Clear();
  70. for (unsigned int i = 0; i < m_listSegments.size(); i++)
  71. {
  72. xSegmentlist.addItem(m_listSegments[i].get());
  73. }
  74. slo.Serialize(true, classDoc, rootNode);
  75. }
  76. else
  77. {
  78. slo.Serialize(false, classDoc, rootNode);
  79. m_listSegments.clear();
  80. for (unsigned int i = 0; i < xSegmentlist.size(); i++)
  81. {
  82. m_listSegments.push_back(COTSSegmentPtr(xSegmentlist.getItem(i)));
  83. }
  84. }
  85. }
  86. // segments list
  87. void COTSFeature::SetSegmentsList(COTSSegmentsList& a_plistSegment, BOOL a_bClear)
  88. {
  89. // clear holes list if necessary
  90. if (a_bClear)
  91. {
  92. m_listSegments.clear();
  93. }
  94. // copy the list
  95. for (auto pSegment : a_plistSegment)
  96. {
  97. //COTSSegmentPtr pSegmentNew = COTSSegmentPtr(new COTSSegment(pSegment.get()));
  98. m_listSegments.push_back(pSegment);
  99. }
  100. }
  101. COTSSegmentPtr COTSFeature::GetSegmentByIndex(int a_nIndex)
  102. {
  103. if (a_nIndex < 0 || a_nIndex >= (int)m_listSegments.size())
  104. {
  105. // invalid index
  106. return nullptr;
  107. }
  108. return m_listSegments[a_nIndex];
  109. }
  110. // cleanup
  111. void COTSFeature::Cleanup()
  112. {
  113. m_listSegments.clear();
  114. }
  115. // initialization
  116. void COTSFeature::Init()
  117. {
  118. // initialization
  119. m_listSegments.clear();
  120. }
  121. // duplication
  122. void COTSFeature::Duplicate(const COTSFeature& a_oSource)
  123. {
  124. // initialization
  125. Init();
  126. // copy data over
  127. for (auto pSegments : a_oSource.m_listSegments)
  128. {
  129. COTSSegmentPtr pSegmentNew = COTSSegmentPtr(new COTSSegment(*pSegments.get()));
  130. m_listSegments.push_back(pSegmentNew);
  131. }
  132. }
  133. }