// IntRange.cpp : implementation file // #include "stdafx.h" //#include "OTSData.h" #include "IntRange.h" // CIntRange namespace OTSDATA { // constructor CIntRange::CIntRange() { // initialization Init(); } CIntRange::CIntRange(long a_nStart, long a_nEnd) { // initialization Init(); m_nStart = min(a_nStart, a_nEnd); m_nEnd = max(a_nStart, a_nEnd); } // copy constructor CIntRange::CIntRange(const CIntRange& a_oSource) { // can't copy itself if (&a_oSource == this) { return; } // copy data over Duplicate(a_oSource); } // copy constructor CIntRange::CIntRange(CIntRange* 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 CIntRange& CIntRange::operator=(const CIntRange& a_oSource) { // cleanup Cleanup(); // copy the class data over Duplicate(a_oSource); // return class return *this; } // ==operator BOOL CIntRange::operator==(const CIntRange& a_oSource) { // return test result return m_nStart == a_oSource.m_nStart && m_nEnd == a_oSource.m_nEnd; } // detractor CIntRange::~CIntRange() { Cleanup(); } // CIntRange member functions // serialization // data in range BOOL CIntRange::DataInRange(long a_nData) { return a_nData >= m_nStart && a_nData <= m_nEnd; } // start void CIntRange::SetStart(long a_nStart) { m_nStart = a_nStart; //Normalise(); } // end void CIntRange::SetEnd(long a_nEnd) { m_nEnd = a_nEnd; //Normalise(); } void CIntRange::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode) { xmls::xInt xStart; xmls::xInt xEnd; xmls::Slo slo; slo.Register("start", &xStart); slo.Register("end", &xEnd); if (isStoring) { xStart = m_nStart; xEnd = m_nEnd; slo.Serialize(true, classDoc, rootNode); } else { slo.Serialize(false, classDoc, rootNode); m_nStart = xStart.value(); m_nEnd = xEnd.value(); } } // cleanup void CIntRange::Cleanup() { // nothing needs to be done at the moment } // initialization void CIntRange::Init() { m_nStart = 0; m_nEnd = 0; } // duplication void CIntRange::Duplicate(const CIntRange& a_oSource) { // initialization Init(); // copy data over m_nStart = a_oSource.m_nStart; m_nEnd = a_oSource.m_nEnd; } // normalize void CIntRange::Normalise() { int s = m_nStart; int e = m_nEnd; m_nEnd = max(s, e); m_nStart = min(s, e); } }