OTSSegment.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #include "stdafx.h"
  2. #include "OTSSegment.h"
  3. namespace OTSDATA {
  4. // CDomain
  5. COTSSegment::COTSSegment()
  6. {
  7. Init();
  8. }
  9. // constructor
  10. COTSSegment::COTSSegment(long a_nHeight, long a_nStart, long a_nLength) // constructor
  11. {
  12. Init();
  13. m_nHeight = a_nHeight;
  14. m_nStart = a_nStart;
  15. m_nLength = a_nLength;
  16. }
  17. COTSSegment::COTSSegment(const COTSSegment& a_oSource) // copy constructor
  18. {
  19. // can't copy itself
  20. if (&a_oSource == this)
  21. {
  22. return;
  23. }
  24. // copy data over
  25. Duplicate(a_oSource);
  26. }
  27. COTSSegment::COTSSegment(COTSSegment* a_poSource) // copy constructor
  28. {
  29. // input check
  30. ASSERT(a_poSource);
  31. if (!a_poSource)
  32. {
  33. return;
  34. }
  35. // can't copy itself
  36. if (a_poSource == this)
  37. {
  38. return;
  39. }
  40. // copy data over
  41. Duplicate(*a_poSource);
  42. }
  43. COTSSegment& COTSSegment::operator=(const COTSSegment& a_oSource) // =operator
  44. {
  45. // cleanup
  46. Cleanup();
  47. // copy the class data over
  48. Duplicate(a_oSource);
  49. // return class
  50. return *this;
  51. }
  52. BOOL COTSSegment::operator==(const COTSSegment&a_oSource) // ==operator
  53. {
  54. return m_nHeight == a_oSource.m_nHeight && m_nStart == a_oSource.m_nStart && m_nLength == a_oSource.m_nLength;
  55. }
  56. COTSSegment::~COTSSegment() // destructor
  57. {
  58. Cleanup();
  59. }
  60. void COTSSegment::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
  61. {
  62. xmls::xLong xnHeight;
  63. xmls::xLong xnStart;
  64. xmls::xLong xnLength;
  65. xmls::Slo slo;
  66. slo.Register("Height", &xnHeight);
  67. slo.Register("Start", &xnStart);
  68. slo.Register("Length", &xnLength);
  69. if (isStoring)
  70. {
  71. xnHeight = m_nHeight;
  72. xnStart = m_nStart;
  73. xnLength = m_nLength;
  74. slo.Serialize(true, classDoc, rootNode);
  75. }
  76. else
  77. {
  78. slo.Serialize(false, classDoc, rootNode);
  79. m_nHeight = xnHeight.value();
  80. m_nStart = xnStart.value();
  81. m_nLength = xnLength.value();
  82. }
  83. }
  84. BOOL COTSSegment::UpDownConection(const COTSSegment &a_Segment)
  85. {
  86. if (abs((int)(a_Segment.m_nHeight - m_nHeight)) != 1)
  87. {
  88. return FALSE;
  89. }
  90. long myStart = m_nStart;
  91. long myEnd = m_nStart + m_nLength - 1;
  92. long yourStart = a_Segment.m_nStart;
  93. long yourEnd = a_Segment.m_nStart + a_Segment.m_nLength - 1;
  94. if (yourStart-myEnd > 1 || myStart-yourEnd >1 )
  95. {
  96. return FALSE;
  97. }
  98. return TRUE;
  99. }
  100. // cleanup
  101. void COTSSegment::Cleanup()
  102. {
  103. }
  104. // initialization
  105. void COTSSegment::Init()
  106. {
  107. // height
  108. m_nHeight = 0;
  109. // start
  110. m_nStart = 0;
  111. // length
  112. m_nLength = 0;
  113. }
  114. // duplication
  115. void COTSSegment::Duplicate(const COTSSegment& a_oSource)
  116. {
  117. // initialization
  118. // copy data over
  119. m_nHeight = a_oSource.m_nHeight;
  120. m_nStart = a_oSource.m_nStart;
  121. m_nLength = a_oSource.m_nLength;
  122. }
  123. }