DoubleRange.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #include "stdafx.h"
  2. #include "DoubleRange.h"
  3. //#include "OTSData.h"
  4. // CIntRange
  5. namespace OTSDATA
  6. {
  7. // constructor
  8. CDoubleRange::CDoubleRange()
  9. {
  10. // initialization
  11. Init();
  12. }
  13. CDoubleRange::CDoubleRange(double a_dStart, double a_dEnd)
  14. {
  15. // initialization
  16. Init();
  17. m_dStart = min(a_dStart, a_dEnd);
  18. m_dEnd = max(a_dStart, a_dEnd);
  19. }
  20. // copy constructor
  21. CDoubleRange::CDoubleRange(const CDoubleRange& a_oSource)
  22. {
  23. // can't copy itself
  24. if (&a_oSource == this)
  25. {
  26. return;
  27. }
  28. // copy data over
  29. Duplicate(a_oSource);
  30. }
  31. // copy constructor
  32. CDoubleRange::CDoubleRange(CDoubleRange* a_poSource)
  33. {
  34. // input check
  35. ASSERT(a_poSource);
  36. if (!a_poSource)
  37. {
  38. return;
  39. }
  40. // can't copy itself
  41. if (a_poSource == this)
  42. {
  43. return;
  44. }
  45. // copy data over
  46. Duplicate(*a_poSource);
  47. }
  48. // =operator
  49. CDoubleRange& CDoubleRange::operator=(const CDoubleRange& a_oSource)
  50. {
  51. // cleanup
  52. Cleanup();
  53. // copy the class data over
  54. Duplicate(a_oSource);
  55. // return class
  56. return *this;
  57. }
  58. // ==operator
  59. BOOL CDoubleRange::operator==(const CDoubleRange& a_oSource)
  60. {
  61. // return test result
  62. return m_dStart == a_oSource.m_dStart && m_dEnd == a_oSource.m_dEnd;
  63. }
  64. // detractor
  65. CDoubleRange::~CDoubleRange()
  66. {
  67. Cleanup();
  68. }
  69. // CDoulbeRange member functions
  70. // serialization
  71. // data in range
  72. BOOL CDoubleRange::DataInRange(double a_dData)
  73. {
  74. return a_dData >= m_dStart && a_dData <= m_dEnd;
  75. }
  76. // start
  77. void CDoubleRange::SetStart(double a_dStart)
  78. {
  79. m_dStart = a_dStart;
  80. //Normalise();
  81. }
  82. // end
  83. void CDoubleRange::SetEnd(double a_dEnd)
  84. {
  85. m_dEnd = a_dEnd;
  86. //Normalise();
  87. }
  88. void CDoubleRange::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
  89. {
  90. xmls::xDouble xStart;
  91. xmls::xDouble xEnd;
  92. xmls::Slo slo;
  93. slo.Register("start", &xStart);
  94. slo.Register("end", &xEnd);
  95. if (isStoring)
  96. {
  97. xStart = m_dStart;
  98. xEnd = m_dEnd;
  99. slo.Serialize(true, classDoc, rootNode);
  100. }
  101. else
  102. {
  103. slo.Serialize(false, classDoc, rootNode);
  104. m_dStart = xStart.value();
  105. m_dEnd = xEnd.value();
  106. }
  107. }
  108. // cleanup
  109. void CDoubleRange::Cleanup()
  110. {
  111. // nothing needs to be done at the moment
  112. }
  113. // initialization
  114. void CDoubleRange::Init()
  115. {
  116. m_dStart = 0;
  117. m_dEnd = 0;
  118. }
  119. // duplication
  120. void CDoubleRange::Duplicate(const CDoubleRange& a_oSource)
  121. {
  122. // initialization
  123. Init();
  124. // copy data over
  125. m_dStart = a_oSource.m_dStart;
  126. m_dEnd = a_oSource.m_dEnd;
  127. }
  128. // normalize
  129. void CDoubleRange::Normalise()
  130. {
  131. CDoubleRange oRange = *this;
  132. m_dEnd = max(oRange.m_dStart, oRange.m_dEnd);
  133. m_dStart = min(oRange.m_dStart, oRange.m_dEnd);
  134. }
  135. }