Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
3.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1998
  6. //
  7. // File: domain.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. // domain.cpp
  12. //
  13. #include <basetsd.h>
  14. #include "domain.h"
  15. bool RANGELIM :: operator < ( const RANGELIM & rlim ) const
  16. {
  17. if ( first ^ rlim.first )
  18. {
  19. // One has a bound and the other doesn't.
  20. // If we do not have an bound and other does, we are "less"
  21. return true;
  22. }
  23. // Both either have or don't have bounds. Therefore,
  24. // we're "less" iff both have bounds and ours is less
  25. // than the other's.
  26. return first && second < rlim.second;
  27. }
  28. bool RANGELIM :: operator > ( const RANGELIM & rlim ) const
  29. {
  30. if ( first ^ rlim.first )
  31. {
  32. // One has a bound and the other doesn't.
  33. // If we have a bound and the other doesn't, it is "greater"
  34. return true;
  35. }
  36. // Both either have or don't have bounds. Therefore,
  37. // we're "greater" iff both have bounds and ours is greater
  38. // than the other's.
  39. return first && second > rlim.second;
  40. }
  41. bool RANGELIM :: operator == ( const RANGELIM & rlim ) const
  42. {
  43. return first == rlim.first
  44. && ( !first || (second == rlim.second) );
  45. }
  46. // Order two RANGEDEFs according to their lower bounds.
  47. bool RANGEDEF :: operator < ( const RANGEDEF & rdef ) const
  48. {
  49. if ( self == rdef )
  50. return false;
  51. // If the other doesn't have a lower bound, we're geq
  52. if ( ! rdef.BLbound() )
  53. return false;
  54. // If we don't have an upper bound, we're gtr
  55. if ( ! BUbound() )
  56. return false;
  57. // The other has a lower bound and we have an upper bound;
  58. // start by checking them.
  59. bool bResult = RUbound() <= rdef.RLbound();
  60. if ( BLbound() )
  61. {
  62. // Both have lower bounds; self must be < other
  63. bResult &= (RLbound() <= rdef.RLbound());
  64. }
  65. if ( rdef.BUbound() )
  66. {
  67. // Both have upper bounds; self must be < other
  68. bResult &= (RUbound() <= rdef.RUbound());
  69. }
  70. return bResult;
  71. }
  72. bool RANGEDEF :: operator == ( const RANGEDEF & rdef ) const
  73. {
  74. return RlimLower() == rdef.RlimLower()
  75. && RlimUpper() == rdef.RlimUpper();
  76. }
  77. bool RANGEDEF :: operator > ( const RANGEDEF & rdef ) const
  78. {
  79. return !(self < rdef);
  80. }
  81. bool RANGEDEF :: BValid () const
  82. {
  83. return RlimLower() < RlimUpper()
  84. || RlimLower() == RlimUpper();
  85. }
  86. bool RANGEDEF :: BOverlap ( const RANGEDEF & rdef ) const
  87. {
  88. if ( self == rdef )
  89. return true;
  90. bool bLess = self < rdef;
  91. if ( bLess )
  92. return RlimUpper() > rdef.RlimLower();
  93. return rdef.RlimUpper() > RlimLower();
  94. }
  95. SZC RDOMAIN :: SzcState ( REAL rValue ) const
  96. {
  97. RANGELIM rlim(true,rValue);
  98. for ( const_iterator itdm = begin();
  99. itdm != end();
  100. itdm++ )
  101. {
  102. const RANGEDEF & rdef = (*itdm);
  103. SZC szcState = rdef.ZsrName();
  104. if ( rdef.RlimLower() == rlim )
  105. return szcState;
  106. if ( rdef.RlimUpper() < rlim )
  107. break;
  108. if ( rdef.RlimLower() < rlim )
  109. return szcState;
  110. }
  111. return NULL;
  112. }
  113. // Return true if any of the RANGEDEFs overlap
  114. bool RDOMAIN :: BOverlap () const
  115. {
  116. for ( const_iterator itdm = begin();
  117. itdm != end();
  118. itdm++ )
  119. {
  120. const_iterator itdmNext = itdm;
  121. itdmNext++;
  122. if ( itdmNext == end() )
  123. continue;
  124. // Check sequence of the list
  125. assert( *itdm < *itdmNext );
  126. // If ubounds collide, it's an overlap
  127. if ( *itdm > *itdmNext )
  128. return true;
  129. }
  130. return false;
  131. }
  132. GOBJMBN * GOBJMBN_DOMAIN :: CloneNew (
  133. MODEL & modelSelf,
  134. MODEL & modelNew,
  135. GOBJMBN * pgobjNew )
  136. {
  137. GOBJMBN_DOMAIN * pgdom = NULL;
  138. if ( pgobjNew == NULL )
  139. {
  140. pgdom = new GOBJMBN_DOMAIN;
  141. }
  142. else
  143. {
  144. DynCastThrow( pgobjNew, pgdom );
  145. }
  146. ASSERT_THROW( GOBJMBN::CloneNew( modelSelf, modelNew, pgdom ),
  147. EC_INTERNAL_ERROR,
  148. "cloning failed to returned object pointer" );
  149. pgdom->_domain = _domain;
  150. return pgdom;
  151. }