123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- #include "stdafx.h"
- #include "Stage.h"
- namespace OTSDATA {
- // CStage
- //IMPLEMENT_SERIAL(CStage, CObject, 1)
- // constructor
- CStage::CStage()
- {
- // initialization
- Init();
- }
- // copy constructor
- CStage::CStage(const CStage& a_oSource)
- {
- // can't copy itself
- if (&a_oSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(a_oSource);
- }
- // copy constructor
- CStage::CStage(CStage* a_poSource)
- {
- // can't copy itself
- if (a_poSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(*a_poSource);
- }
- // =operator
- CStage& CStage::operator=(const CStage& a_oSource)
- {
- // cleanup
- Cleanup();
- // copy the class data over
- Duplicate(a_oSource);
- // return class
- return *this;
- }
- // ==operator
- BOOL CStage::operator==(const CStage& a_oSource)
- {
- // return FASLE, if the two holes list are in different size
- int nSize = (int)m_listHoles.size();
- if (nSize != (int)a_oSource.m_listHoles.size())
- {
- return FALSE;
- }
- // return FALSE if any of the pare holes are different
- for (int i = 0; i < nSize; ++i)
- {
- if (!(*(m_listHoles[i].get()) == *(a_oSource.m_listHoles[i].get())))
- {
- return FALSE;
- }
- }
- // members check
- return m_strName.Compare(a_oSource.m_strName) == 0 &&
- *(m_poBourary.get()) == *((a_oSource.m_poBourary).get()) &&
- *(m_poSTD.get()) == *((a_oSource.m_poSTD).get());
- }
- // destructor
- CStage::~CStage()
- {
- // cleanup
- Cleanup();
- }
- // CDomain functions
- // public
- //// serialization
- //void CStage::Serialize(CArchive& ar)
- //{
- // // store?
- // if (ar.IsStoring())
- // {
- // // store
- // ar << m_strName;
- // }
- // else
- // {
- // // load
- // ar >> m_strName;
- // }
- // // member classes serialization
- // m_poBourary->Serialize(ar);
- // m_poSTD->Serialize(ar);
- // // holes list serialization
- // if (ar.IsStoring())
- // {
- // // store
- // ar << (int)m_listHoles.size();
- // for (auto pHole : m_listHoles)
- // {
- // pHole->Serialize(ar);
- // }
- // }
- // else
- // {
- // // load
- // int nSize;
- // ar >> nSize;
- // for (int i = 0; i < nSize; ++i)
- // {
- // CHolePtr pHole = CHolePtr(new CHole());
- // pHole->Serialize(ar);
- // m_listHoles.push_back(pHole);
- // }
- // }
- // // base object serialization
- // CObject::Serialize(ar);
- //}
- // boundary
- void CStage::SetBoundary(CDomainPtr a_poBourary)
- {
- // input check
- ASSERT(a_poBourary);
- if (!a_poBourary)
- {
- return;
- }
- m_poBourary = CDomainPtr(new CDomain(a_poBourary.get()));
- }
- // std
- void CStage::SetSTD(CDomainPtr a_poSTD)
- {
- // input check
- ASSERT(a_poSTD);
- if (!a_poSTD)
- {
- return;
- }
- m_poSTD = CDomainPtr(new CDomain(a_poSTD.get()));
- }
- // holes list
- void CStage::SetHoleList(CHolesList& a_listHoles, BOOL a_bClear /* = TRUE*/)
- {
- // clear holes list if necessary
- if (a_bClear)
- {
- m_listHoles.clear();
- }
- // copy the list
- for (auto pHole : a_listHoles)
- {
- CHolePtr pHoleNew = CHolePtr(new CHole(*pHole.get()));
- m_listHoles.push_back(pHoleNew);
- }
- }
- // sample holes list
- CHolePtr CStage::GetHoleByIndex(int a_nIndex)
- {
- if (a_nIndex < 0 || a_nIndex >= (int)m_listHoles.size())
- {
- // invalid index
- return nullptr;
- }
- return m_listHoles[a_nIndex];
- }
- CHolePtr CStage::GetHoleByName(CString a_strHoleName)
- {
- a_strHoleName.Trim();
- if (a_strHoleName.IsEmpty())
- {
- // invalid hole name
- return nullptr;
- }
- auto itr = std::find_if(m_listHoles.begin(), m_listHoles.end(), [a_strHoleName](CHolePtr p) { return p->GetName().CompareNoCase(a_strHoleName) == 0; });
- if (itr == m_listHoles.end())
- {
- // didn't find the hole
- return nullptr;
- }
- // return the hole
- return *itr;
- }
- void CStage::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
- {
- xmls::xString xnstrName;
- xmls::Collection<CHole> xHolelist;
- xmls::Slo slo;
- slo.Register("strName", &xnstrName);
- slo.Register("boundary", m_poBourary.get());
- slo.Register("std", m_poSTD.get());
- slo.Register("Holes", &xHolelist);
- if (isStoring)
- {
- xnstrName = m_strName;
- xHolelist.Clear();
- for (unsigned int i = 0; i < m_listHoles.size(); i++)
- {
- xHolelist.addItem(m_listHoles[i].get());
- }
- slo.Serialize(true, classDoc, rootNode);
- }
- else
- {
- slo.Serialize(false, classDoc, rootNode);
- m_strName = xnstrName.value().c_str();
- m_listHoles.clear();
- for (unsigned int i = 0; i < xHolelist.size(); i++)
- {
- m_listHoles.push_back(CHolePtr(xHolelist.getItem(i)));
- }
- }
- }
- // protected
- // cleanup
- void CStage::Cleanup()
- {
- // need to do nothing at the moment
- }
- // initialization
- void CStage::Init()
- {
- // initialization
- m_strName = _T("");
- m_poBourary = CDomainPtr(new CDomain());
- m_poSTD = CDomainPtr(new CDomain());
- m_listHoles.clear();
- }
- // duplication
- void CStage::Duplicate(const CStage& a_oSource)
- {
- Init();
- // copy data over
- m_strName = a_oSource.m_strName;
- m_poBourary = CDomainPtr(new CDomain(*(a_oSource.m_poBourary.get())));
- m_poSTD = CDomainPtr(new CDomain(*(a_oSource.m_poSTD.get())));
- for (auto pHole : a_oSource.m_listHoles)
- {
- CHolePtr pHoleNew = CHolePtr(new CHole(pHole.get()));
- m_listHoles.push_back(pHoleNew);
- }
- //xnstrName = a_oSource.m_strName;
- }
- }
|