ElementRange.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // ElementRange.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. //#include "OTSData.h"
  5. #include "ElementRange.h"
  6. namespace OTSDATA {
  7. // CElementRange
  8. // constructor
  9. CElementRange::CElementRange()
  10. {
  11. // initialization
  12. Init();
  13. }
  14. // copy constructor
  15. CElementRange::CElementRange(const CElementRange& a_oSource)
  16. {
  17. // can't copy itself
  18. if (&a_oSource == this)
  19. {
  20. return;
  21. }
  22. // copy data over
  23. Duplicate(a_oSource);
  24. }
  25. // copy constructor
  26. CElementRange::CElementRange(CElementRange* a_poSource)
  27. {
  28. // input check
  29. ASSERT(a_poSource);
  30. if (!a_poSource)
  31. {
  32. return;
  33. }
  34. // can't copy itself
  35. if (a_poSource == this)
  36. {
  37. return;
  38. }
  39. // copy data over
  40. Duplicate(*a_poSource);
  41. }
  42. // =operator
  43. CElementRange& CElementRange::operator=(const CElementRange& a_oSource)
  44. {
  45. // cleanup
  46. Cleanup();
  47. // copy the class data over
  48. Duplicate(a_oSource);
  49. // return class
  50. return *this;
  51. }
  52. // ==operator
  53. BOOL CElementRange::operator==(const CElementRange& a_oSource)
  54. {
  55. return *(m_poElement.get()) == *(a_oSource.m_poElement.get()) && *(m_poRange.get()) == *(a_oSource.m_poRange.get());
  56. }
  57. // destructor
  58. CElementRange::~CElementRange()
  59. {
  60. // cleanup
  61. Cleanup();
  62. }
  63. // CElementRange member functions
  64. // public
  65. // serialization
  66. void CElementRange::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
  67. {
  68. xmls::Slo slo;
  69. slo.Register("Element", m_poElement.get());
  70. slo.Register("Range", m_poRange.get());
  71. if (isStoring)
  72. {
  73. slo.Serialize(true, classDoc, rootNode);
  74. }
  75. else
  76. {
  77. slo.Serialize(false, classDoc, rootNode);
  78. }
  79. }
  80. // element
  81. void CElementRange::SetElement(CElementPtr a_poElement)
  82. {
  83. ASSERT(a_poElement);
  84. if(!a_poElement)
  85. {
  86. m_poElement = CElementPtr(new CElement());
  87. }
  88. else
  89. {
  90. m_poElement = a_poElement;
  91. }
  92. }
  93. // % x 100 range
  94. void CElementRange::SetRange(CIntRangePtr a_poRange)
  95. {
  96. ASSERT(a_poRange);
  97. if(!a_poRange)
  98. {
  99. m_poRange = CIntRangePtr(new CIntRange());
  100. }
  101. else
  102. {
  103. m_poRange = a_poRange;
  104. }
  105. }
  106. // protected
  107. // cleanup
  108. void CElementRange::Cleanup()
  109. {
  110. // need to do nothing at the moment
  111. }
  112. // initialization
  113. void CElementRange::Init()
  114. {
  115. // initialization
  116. m_poElement = CElementPtr(new CElement());
  117. m_poRange = CIntRangePtr(new CIntRange());
  118. }
  119. // duplication
  120. void CElementRange::Duplicate(const CElementRange& a_oSource)
  121. {
  122. // initialization
  123. Init();
  124. // copy data over
  125. m_poElement = CElementPtr(a_oSource.m_poElement);
  126. m_poRange = CIntRangePtr(a_oSource.m_poRange);
  127. }
  128. }