InclutionSTDData.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. 
  2. #include "stdafx.h"
  3. #include "InclutionSTDData.h"
  4. #include <algorithm>
  5. namespace OTSClassifyEngine {
  6. // constructor
  7. CInclutionSTDData::CInclutionSTDData()
  8. {
  9. // initialization
  10. Init();
  11. }
  12. // copy constructor
  13. CInclutionSTDData::CInclutionSTDData(const CInclutionSTDData& a_oSource)
  14. {
  15. // can't copy itself
  16. if (&a_oSource == this)
  17. {
  18. return;
  19. }
  20. // copy data over
  21. Duplicate(a_oSource);
  22. }
  23. // copy constructor
  24. CInclutionSTDData::CInclutionSTDData(CInclutionSTDData* a_poSource)
  25. {
  26. // input check
  27. ASSERT(a_poSource);
  28. if (!a_poSource)
  29. {
  30. return;
  31. }
  32. // can't copy itself
  33. if (a_poSource == this)
  34. {
  35. return;
  36. }
  37. // copy data over
  38. Duplicate(*a_poSource);
  39. }
  40. // =operator
  41. CInclutionSTDData& CInclutionSTDData::operator=(const CInclutionSTDData& a_oSource)
  42. {
  43. // cleanup
  44. Cleanup();
  45. // copy the class data over
  46. Duplicate(a_oSource);
  47. // return class
  48. return *this;
  49. }
  50. // ==operator
  51. BOOL CInclutionSTDData::operator==(const CInclutionSTDData& a_oSource)
  52. {
  53. // elements list
  54. int nSize = (int)m_listElements.size();
  55. if (nSize != (int)a_oSource.m_listElements.size())
  56. {
  57. return FALSE;
  58. }
  59. for (unsigned int i = 0; i < nSize; ++i)
  60. {
  61. if (!(*(m_listElements[i].get()) == *(a_oSource.m_listElements[i].get())))
  62. {
  63. return FALSE;
  64. }
  65. }
  66. // element rangers list
  67. nSize = (int)m_listSTDItems.size();
  68. if (nSize != (int)a_oSource.m_listSTDItems.size())
  69. {
  70. return FALSE;
  71. }
  72. for (unsigned int i = 0; i < nSize; ++i)
  73. {
  74. if (!(*(m_listSTDItems[i].get()) == *(a_oSource.m_listSTDItems[i].get())))
  75. {
  76. return FALSE;
  77. }
  78. }
  79. // members
  80. return m_strVersion.Compare(a_oSource.m_strVersion) == 0 && m_strName.Compare(a_oSource.m_strName) == 0;
  81. }
  82. // destructor
  83. CInclutionSTDData::~CInclutionSTDData()
  84. {
  85. // cleanup
  86. Cleanup();
  87. }
  88. // CPartSTDData member functions
  89. // public
  90. // serialization
  91. // elements list
  92. void CInclutionSTDData::SetElementsList(CElementsList& a_listElements, BOOL a_bClear)
  93. {
  94. // clear elements list if necessary
  95. if (a_bClear)
  96. {
  97. m_listElements.clear();
  98. }
  99. // copy elements list
  100. for (auto poElement : a_listElements)
  101. {
  102. //CElementPtr poElementNew(new CElement(poElement.get()));
  103. CElementPtr poElementNew(poElement.get());
  104. m_listElements.push_back(poElementNew);
  105. }
  106. }
  107. // std items list
  108. void CInclutionSTDData::SetSTDItemsList(CSTDItemsList& a_listSTDItems, BOOL a_bClear)
  109. {
  110. m_listSTDItems = a_listSTDItems;
  111. }
  112. CSTDItemPtr CInclutionSTDData::GetSTDItemById(int a_nId)
  113. {
  114. // std item
  115. CSTDItemPtr poSDTItem = nullptr;
  116. // get std items list
  117. auto itr = std::find_if(m_listSTDItems.begin(), m_listSTDItems.end(), [a_nId](CSTDItemPtr& poSTDItemPtr) { return poSTDItemPtr->GetSTDId() == a_nId; });
  118. if (itr != m_listSTDItems.end())
  119. {
  120. // found the std item
  121. poSDTItem = *itr;
  122. }
  123. // return std item
  124. return poSDTItem;
  125. }
  126. void CInclutionSTDData::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
  127. {
  128. xmls::xInt xFileMark;
  129. xmls::xString xstrVersion;
  130. xmls::xString xstrName;
  131. xmls::Collection<CElement> xElementslist;
  132. xmls::Collection<CSTDItem> xSTDItemslist;
  133. xmls::Slo slo;
  134. slo.Register("FileMark", &xFileMark);
  135. slo.Register("Version", &xstrVersion);
  136. slo.Register("libName", &xstrName);
  137. slo.Register("Elementslist", &xElementslist);
  138. slo.Register("STDItemslist", &xSTDItemslist);
  139. if (isStoring)
  140. {
  141. xFileMark = PART_STD_FILE_MARK;
  142. xstrVersion = m_strVersion;
  143. xstrName = m_strName;
  144. xElementslist.Clear();
  145. for (unsigned int i = 0; i < m_listElements.size(); i++)
  146. {
  147. xElementslist.addItem(m_listElements[i].get());
  148. }
  149. xSTDItemslist.Clear();
  150. for (unsigned int i = 0; i < m_listSTDItems.size(); i++)
  151. {
  152. xSTDItemslist.addItem(m_listSTDItems[i].get());
  153. }
  154. int nSTDId = (int)OTS_ID_SCOPE::USER_DEFINED_MIN;
  155. for (auto poSTDItem : m_listSTDItems)
  156. {
  157. //poSTDItem->Serialize(ar);
  158. int STDId = poSTDItem->GetSTDId();
  159. if (STDId < (int)OTS_ID_SCOPE::SYS_DEFINED_MIN)
  160. {
  161. poSTDItem->SetSTDId(nSTDId);
  162. ++nSTDId;
  163. }
  164. }
  165. slo.Serialize(true, classDoc, rootNode);
  166. }
  167. else
  168. {
  169. slo.Serialize(false, classDoc, rootNode);
  170. m_strVersion = xstrVersion.value().c_str();
  171. m_strName = xstrName.value().c_str();
  172. m_listElements.clear();
  173. for ( int i = 0; i < xElementslist.size(); i++)
  174. {
  175. m_listElements.push_back(CElementPtr(xElementslist.getItem(i)));
  176. }
  177. m_listSTDItems.clear();
  178. for ( int i = 0; i < xSTDItemslist.size(); i++)
  179. {
  180. m_listSTDItems.push_back(CSTDItemPtr(xSTDItemslist.getItem(i)));
  181. }
  182. int nIdInit = (int)OTS_ID_SCOPE::USER_DEFINED_MIN;
  183. for (auto s:m_listSTDItems)
  184. {
  185. //if PARTCLE value is NOT_IDENTIFIED Set STDID is Identifying
  186. if (s->GetSTDId() == (int)OTS_PARTICLE_BASIC_CLASSIFY::NOT_IDENTIFIED)
  187. {
  188. s->SetSTDId(nIdInit);
  189. ++nIdInit;
  190. }
  191. }
  192. }
  193. }
  194. // protected
  195. // cleanup
  196. void CInclutionSTDData::Cleanup()
  197. {
  198. // need to do nothing at the moment
  199. }
  200. // initialization
  201. void CInclutionSTDData::Init()
  202. {
  203. // initialization
  204. m_strVersion = _T("1.1.1");
  205. m_strName = _T("");
  206. m_listElements.clear();
  207. m_listSTDItems.clear();
  208. }
  209. // duplication
  210. void CInclutionSTDData::Duplicate(const CInclutionSTDData& a_oSource)
  211. {
  212. // initialization
  213. Init();
  214. // copy data over
  215. m_strVersion = a_oSource.m_strVersion;
  216. m_strName = a_oSource.m_strName;
  217. for (auto poElement : a_oSource.m_listElements)
  218. {
  219. CElementPtr poElementNew(new CElement(*(poElement.get())));
  220. m_listElements.push_back(poElementNew);
  221. }
  222. for (auto poSTDItem : a_oSource.m_listSTDItems)
  223. {
  224. CSTDItemPtr poSTDItemNew(new CSTDItem(*(poSTDItem.get())));
  225. m_listSTDItems.push_back(poSTDItemNew);
  226. }
  227. }
  228. }