// PartSTDData.cpp : implementation file // #include "stdafx.h" //#include "OTSDataResource.h" #include "InclutionSTDData.h" #include namespace OTSClassifyEngine { // constructor CInclutionSTDData::CInclutionSTDData() { // initialization Init(); } // copy constructor CInclutionSTDData::CInclutionSTDData(const CInclutionSTDData& a_oSource) { // can't copy itself if (&a_oSource == this) { return; } // copy data over Duplicate(a_oSource); } // copy constructor CInclutionSTDData::CInclutionSTDData(CInclutionSTDData* a_poSource) { // input check ASSERT(a_poSource); if (!a_poSource) { return; } // can't copy itself if (a_poSource == this) { return; } // copy data over Duplicate(*a_poSource); } // =operator CInclutionSTDData& CInclutionSTDData::operator=(const CInclutionSTDData& a_oSource) { // cleanup Cleanup(); // copy the class data over Duplicate(a_oSource); // return class return *this; } // ==operator BOOL CInclutionSTDData::operator==(const CInclutionSTDData& a_oSource) { // elements list int nSize = (int)m_listElements.size(); if (nSize != (int)a_oSource.m_listElements.size()) { return FALSE; } for (unsigned int i = 0; i < nSize; ++i) { if (!(*(m_listElements[i].get()) == *(a_oSource.m_listElements[i].get()))) { return FALSE; } } // element rangers list nSize = (int)m_listSTDItems.size(); if (nSize != (int)a_oSource.m_listSTDItems.size()) { return FALSE; } for (unsigned int i = 0; i < nSize; ++i) { if (!(*(m_listSTDItems[i].get()) == *(a_oSource.m_listSTDItems[i].get()))) { return FALSE; } } // members return m_strVersion.Compare(a_oSource.m_strVersion) == 0 && m_strName.Compare(a_oSource.m_strName) == 0; } // destructor CInclutionSTDData::~CInclutionSTDData() { // cleanup Cleanup(); } // CPartSTDData member functions // public // serialization // elements list void CInclutionSTDData::SetElementsList(CElementsList& a_listElements, BOOL a_bClear) { // clear elements list if necessary if (a_bClear) { m_listElements.clear(); } // copy elements list for (auto poElement : a_listElements) { //CElementPtr poElementNew(new CElement(poElement.get())); CElementPtr poElementNew(poElement.get()); m_listElements.push_back(poElementNew); } } // std items list void CInclutionSTDData::SetSTDItemsList(CSTDItemsList& a_listSTDItems, BOOL a_bClear) { m_listSTDItems = a_listSTDItems; } CSTDItemPtr CInclutionSTDData::GetSTDItemById(int a_nId) { // std item CSTDItemPtr poSDTItem = nullptr; // get std items list auto itr = std::find_if(m_listSTDItems.begin(), m_listSTDItems.end(), [a_nId](CSTDItemPtr& poSTDItemPtr) { return poSTDItemPtr->GetSTDId() == a_nId; }); if (itr != m_listSTDItems.end()) { // found the std item poSDTItem = *itr; } // return std item return poSDTItem; } void CInclutionSTDData::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode) { xmls::xInt xFileMark; xmls::xString xstrVersion; xmls::xString xstrName; xmls::Collection xElementslist; xmls::Collection xSTDItemslist; xmls::Slo slo; slo.Register("FileMark", &xFileMark); slo.Register("Version", &xstrVersion); slo.Register("libName", &xstrName); slo.Register("Elementslist", &xElementslist); slo.Register("STDItemslist", &xSTDItemslist); if (isStoring) { xFileMark = PART_STD_FILE_MARK; xstrVersion = m_strVersion; xstrName = m_strName; xElementslist.Clear(); for (unsigned int i = 0; i < m_listElements.size(); i++) { xElementslist.addItem(m_listElements[i].get()); } xSTDItemslist.Clear(); for (unsigned int i = 0; i < m_listSTDItems.size(); i++) { xSTDItemslist.addItem(m_listSTDItems[i].get()); } int nSTDId = (int)OTS_ID_SCOPE::USER_DEFINED_MIN; for (auto poSTDItem : m_listSTDItems) { //poSTDItem->Serialize(ar); int STDId = poSTDItem->GetSTDId(); if (STDId < (int)OTS_ID_SCOPE::SYS_DEFINED_MIN) { poSTDItem->SetSTDId(nSTDId); ++nSTDId; } } slo.Serialize(true, classDoc, rootNode); } else { slo.Serialize(false, classDoc, rootNode); m_strVersion = xstrVersion.value().c_str(); m_strName = xstrName.value().c_str(); m_listElements.clear(); for ( int i = 0; i < xElementslist.size(); i++) { m_listElements.push_back(CElementPtr(xElementslist.getItem(i))); } m_listSTDItems.clear(); for ( int i = 0; i < xSTDItemslist.size(); i++) { m_listSTDItems.push_back(CSTDItemPtr(xSTDItemslist.getItem(i))); } int nIdInit = (int)OTS_ID_SCOPE::USER_DEFINED_MIN; for (auto s:m_listSTDItems) { //if PARTCLE value is NOT_IDENTIFIED Set STDID is Identifying if (s->GetSTDId() == (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED) { s->SetSTDId(nIdInit); ++nIdInit; } } } } // protected // cleanup void CInclutionSTDData::Cleanup() { // need to do nothing at the moment } // initialization void CInclutionSTDData::Init() { // initialization m_strVersion = _T("1.1.1"); m_strName = _T(""); m_listElements.clear(); m_listSTDItems.clear(); } // duplication void CInclutionSTDData::Duplicate(const CInclutionSTDData& a_oSource) { // initialization Init(); // copy data over m_strVersion = a_oSource.m_strVersion; m_strName = a_oSource.m_strName; for (auto poElement : a_oSource.m_listElements) { CElementPtr poElementNew(new CElement(*(poElement.get()))); m_listElements.push_back(poElementNew); } for (auto poSTDItem : a_oSource.m_listSTDItems) { CSTDItemPtr poSTDItemNew(new CSTDItem(*(poSTDItem.get()))); m_listSTDItems.push_back(poSTDItemNew); } } }