InclutionSTDData.cpp 5.7 KB

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