123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- #include "stdafx.h"
- #include "DoubleRange.h"
- //#include "OTSData.h"
- // CIntRange
- namespace OTSDATA
- {
- // constructor
- CDoubleRange::CDoubleRange()
- {
- // initialization
- Init();
- }
- CDoubleRange::CDoubleRange(double a_dStart, double a_dEnd)
- {
- // initialization
- Init();
- m_dStart = min(a_dStart, a_dEnd);
- m_dEnd = max(a_dStart, a_dEnd);
- }
- // copy constructor
- CDoubleRange::CDoubleRange(const CDoubleRange& a_oSource)
- {
- // can't copy itself
- if (&a_oSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(a_oSource);
- }
- // copy constructor
- CDoubleRange::CDoubleRange(CDoubleRange* 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
- CDoubleRange& CDoubleRange::operator=(const CDoubleRange& a_oSource)
- {
- // cleanup
- Cleanup();
- // copy the class data over
- Duplicate(a_oSource);
- // return class
- return *this;
- }
- // ==operator
- BOOL CDoubleRange::operator==(const CDoubleRange& a_oSource)
- {
- // return test result
- return m_dStart == a_oSource.m_dStart && m_dEnd == a_oSource.m_dEnd;
- }
- // detractor
- CDoubleRange::~CDoubleRange()
- {
- Cleanup();
- }
- // CDoulbeRange member functions
- // serialization
- // data in range
- BOOL CDoubleRange::DataInRange(double a_dData)
- {
- return a_dData >= m_dStart && a_dData <= m_dEnd;
- }
- // start
- void CDoubleRange::SetStart(double a_dStart)
- {
- m_dStart = a_dStart;
- //Normalise();
- }
- // end
- void CDoubleRange::SetEnd(double a_dEnd)
- {
- m_dEnd = a_dEnd;
- //Normalise();
- }
- void CDoubleRange::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
- {
- xmls::xDouble xStart;
- xmls::xDouble xEnd;
- xmls::Slo slo;
- slo.Register("start", &xStart);
- slo.Register("end", &xEnd);
- if (isStoring)
- {
- xStart = m_dStart;
- xEnd = m_dEnd;
- slo.Serialize(true, classDoc, rootNode);
- }
- else
- {
- slo.Serialize(false, classDoc, rootNode);
- m_dStart = xStart.value();
- m_dEnd = xEnd.value();
- }
- }
- // cleanup
- void CDoubleRange::Cleanup()
- {
- // nothing needs to be done at the moment
- }
- // initialization
- void CDoubleRange::Init()
- {
- m_dStart = 0;
- m_dEnd = 0;
- }
- // duplication
- void CDoubleRange::Duplicate(const CDoubleRange& a_oSource)
- {
- // initialization
- Init();
- // copy data over
- m_dStart = a_oSource.m_dStart;
- m_dEnd = a_oSource.m_dEnd;
- }
- // normalize
- void CDoubleRange::Normalise()
- {
- CDoubleRange oRange = *this;
- m_dEnd = max(oRange.m_dStart, oRange.m_dEnd);
- m_dStart = min(oRange.m_dStart, oRange.m_dEnd);
- }
- }
|