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.

221 lines
4.5 KiB

  1. #ifndef _CLI_HXX_
  2. #define _CLI_HXX_
  3. template <class TXLargeInteger, class TSubType, class TQuadType>
  4. // Either LARGE_INTEGER/LONG/LONGLONG or ULARGE_INTEGER/ULONG/ULONGLONG
  5. class TXLargeIntegerWrapper
  6. {
  7. public:
  8. TXLargeIntegerWrapper()
  9. {
  10. QuadPart = 0;
  11. }
  12. TXLargeIntegerWrapper( const TXLargeIntegerWrapper &xliWrapper )
  13. {
  14. QuadPart = xliWrapper.QuadPart;
  15. }
  16. TXLargeIntegerWrapper( const TXLargeInteger xli )
  17. {
  18. QuadPart = xli.QuadPart;
  19. }
  20. TXLargeIntegerWrapper( const int i )
  21. {
  22. QuadPart = i;
  23. }
  24. TXLargeIntegerWrapper( const ULONG ul )
  25. {
  26. LowPart = ul;
  27. HighPart = 0;
  28. }
  29. TXLargeIntegerWrapper( const UINT ui )
  30. {
  31. LowPart = ui;
  32. HighPart = 0;
  33. }
  34. TXLargeIntegerWrapper( const LONG l )
  35. {
  36. QuadPart = static_cast<TSubType>(l); // Sign-extend
  37. }
  38. TXLargeIntegerWrapper( const TQuadType q )
  39. {
  40. QuadPart = q;
  41. }
  42. public:
  43. TXLargeIntegerWrapper &operator=( const TXLargeIntegerWrapper xli )
  44. {
  45. QuadPart = xli.QuadPart;
  46. return(*this);
  47. }
  48. public:
  49. BOOL operator==( const TXLargeIntegerWrapper xli ) const
  50. {
  51. return( QuadPart == xli.QuadPart );
  52. }
  53. BOOL operator!=( const TXLargeIntegerWrapper xli ) const
  54. {
  55. return( QuadPart != xli.QuadPart );
  56. }
  57. BOOL operator<( const TXLargeIntegerWrapper xli ) const
  58. {
  59. return( QuadPart < xli.QuadPart );
  60. }
  61. BOOL operator<=( const TXLargeIntegerWrapper xli ) const
  62. {
  63. return( QuadPart <= xli.QuadPart );
  64. }
  65. BOOL operator>( const TXLargeIntegerWrapper xli ) const
  66. {
  67. return( QuadPart > xli.QuadPart );
  68. }
  69. BOOL operator>=( TXLargeIntegerWrapper xli ) const
  70. {
  71. return( QuadPart >= xli.QuadPart );
  72. }
  73. TXLargeIntegerWrapper operator-() const
  74. {
  75. TXLargeIntegerWrapper ret;
  76. ret.QuadPart = -QuadPart;
  77. return( ret );
  78. }
  79. public:
  80. TXLargeIntegerWrapper operator+( TXLargeIntegerWrapper xli )
  81. {
  82. TXLargeIntegerWrapper ret;
  83. ret.QuadPart = QuadPart + xli.QuadPart;
  84. return(ret);
  85. }
  86. TXLargeIntegerWrapper& operator+=( TXLargeIntegerWrapper xli )
  87. {
  88. QuadPart += xli.QuadPart;
  89. return(*this);
  90. }
  91. TXLargeIntegerWrapper& operator++( ) // prefix
  92. {
  93. ++QuadPart;
  94. return(*this);
  95. }
  96. TXLargeIntegerWrapper operator++(int) // postfix
  97. {
  98. TQuadType QuadPartReturn = QuadPart++;
  99. return(QuadPartReturn);
  100. }
  101. TXLargeIntegerWrapper operator-( TXLargeIntegerWrapper xli )
  102. {
  103. TXLargeIntegerWrapper ret;
  104. ret.QuadPart = QuadPart - xli.QuadPart;
  105. return(ret);
  106. }
  107. TXLargeIntegerWrapper& operator-=( TXLargeIntegerWrapper xli )
  108. {
  109. QuadPart -= xli.QuadPart;
  110. return(*this);
  111. }
  112. TXLargeIntegerWrapper& operator--( ) // prefix
  113. {
  114. --QuadPart;
  115. return(*this);
  116. }
  117. TXLargeIntegerWrapper operator--(int) // postfix
  118. {
  119. TQuadType QuadPartReturn = QuadPart--;
  120. return(QuadPartReturn);
  121. }
  122. public:
  123. TXLargeIntegerWrapper& operator*( TXLargeIntegerWrapper xli )
  124. {
  125. TXLargeIntegerWrapper ret;
  126. ret.QuadPart = QuadPart * xli.QuadPart;
  127. return(ret);
  128. }
  129. TXLargeIntegerWrapper& operator*=( TXLargeIntegerWrapper xli )
  130. {
  131. QuadPart *= xli.QuadPart;
  132. return( *this );
  133. }
  134. public:
  135. TXLargeInteger* operator&()
  136. {
  137. return( reinterpret_cast<TXLargeInteger*>(this) );
  138. }
  139. public:
  140. operator ULARGE_INTEGER() const
  141. {
  142. ULARGE_INTEGER uli;
  143. uli.HighPart = HighPart;
  144. uli.LowPart = LowPart;
  145. return( uli );
  146. }
  147. operator LARGE_INTEGER() const
  148. {
  149. LARGE_INTEGER li;
  150. li.HighPart = HighPart;
  151. li.LowPart = LowPart;
  152. return( li );
  153. }
  154. public:
  155. typedef DWORD typeLowPart;
  156. typedef TSubType typeHighPart;
  157. typedef TQuadType typeQuadPart;
  158. typedef TXLargeInteger typeWholePart;
  159. union
  160. {
  161. struct
  162. {
  163. typeLowPart LowPart;
  164. typeHighPart HighPart;
  165. };
  166. typeQuadPart QuadPart;
  167. };
  168. };
  169. typedef TXLargeIntegerWrapper<LARGE_INTEGER, LONG, LONGLONG> CLargeInteger;
  170. typedef TXLargeIntegerWrapper<ULARGE_INTEGER, ULONG, ULONGLONG> CULargeInteger;
  171. #endif // #ifndef _CLI_HXX_