| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 | // IntRange.cpp : implementation file//#include "stdafx.h"//#include "OTSData.h"#include "IntRange.h"// CIntRangenamespace 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()	{		m_nEnd = max(m_nStart, m_nEnd);		m_nStart = min(m_nStart, m_nEnd);	}}
 |