InclutionSTDData.cpp 5.6 KB

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