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.

223 lines
5.4 KiB

  1. #ifndef _FILETIME_H_
  2. #define _FILETIME_H_
  3. //**************************************************************************
  4. // NOTE: This file is duplicated in urlmon and webcheck. If you make
  5. // changes please sync them!
  6. //**************************************************************************
  7. #define MAKEINT64(lo, hi) ((__int64)(((DWORD)(lo)) | ((__int64)((DWORD)(hi))) << 32))
  8. #ifndef LODWORD
  9. #define LODWORD(i) ((DWORD)(i))
  10. #endif
  11. #ifndef HIDWORD
  12. #define HIDWORD(i) ((DWORD)(((__int64)(i) >> 32) & 0xFFFFFFFF))
  13. #endif
  14. // This is Monday, January 1, 1601 at 12:00:00 am
  15. #define MIN_FILETIME 0i64
  16. // This is Thursday, September 14, 30828 at 2:48:05 am
  17. #define MAX_FILETIME 0x7FFFFFFFFFFFFFFFi64
  18. // For clarity since FILETIME is expressed as 100-nanosecond intervals
  19. #define ONE_SECOND_IN_FILETIME 10000000i64
  20. #define ONE_MSEC_IN_FILEITME 10000i64
  21. #define ONE_MINUTE_IN_FILETIME (ONE_SECOND_IN_FILETIME * 60i64)
  22. struct CFileTime : public FILETIME
  23. {
  24. // Constructors
  25. CFileTime() { *this = 0; }
  26. CFileTime(const FILETIME& f) { *this = f; }
  27. CFileTime(const CFileTime& f) { *this = f; }
  28. CFileTime(__int64 i) { *this = i; }
  29. // Assignment operators
  30. inline CFileTime& operator = (const FILETIME& f)
  31. {
  32. dwLowDateTime = f.dwLowDateTime;
  33. dwHighDateTime = f.dwHighDateTime;
  34. return *this;
  35. }
  36. inline CFileTime& operator = (const CFileTime& f)
  37. {
  38. dwLowDateTime = f.dwLowDateTime;
  39. dwHighDateTime = f.dwHighDateTime;
  40. return *this;
  41. }
  42. inline CFileTime& operator = (__int64 i)
  43. {
  44. dwLowDateTime = LODWORD(i);
  45. dwHighDateTime = HIDWORD(i);
  46. return *this;
  47. }
  48. // Comparison operators
  49. inline BOOL operator == (__int64 i)
  50. {
  51. return MAKEINT64(dwLowDateTime, dwHighDateTime) == i;
  52. }
  53. inline BOOL operator > (__int64 i)
  54. {
  55. return MAKEINT64(dwLowDateTime, dwHighDateTime) > i;
  56. }
  57. inline BOOL operator < (__int64 i)
  58. {
  59. return MAKEINT64(dwLowDateTime, dwHighDateTime) < i;
  60. }
  61. inline BOOL operator != (__int64 i)
  62. {
  63. return !(*this == i);
  64. }
  65. inline BOOL operator >= (__int64 i)
  66. {
  67. return !(*this < i);
  68. }
  69. inline BOOL operator <= (__int64 i)
  70. {
  71. return !(*this > i);
  72. }
  73. inline BOOL operator == (const FILETIME& f)
  74. {
  75. return *this == MAKEINT64(f.dwLowDateTime, f.dwHighDateTime);
  76. }
  77. inline BOOL operator > (const FILETIME& f)
  78. {
  79. return *this > MAKEINT64(f.dwLowDateTime, f.dwHighDateTime);
  80. }
  81. inline BOOL operator < (const FILETIME& f)
  82. {
  83. return *this < MAKEINT64(f.dwLowDateTime, f.dwHighDateTime);
  84. }
  85. inline BOOL operator != (const FILETIME& f)
  86. {
  87. return !(*this == f);
  88. }
  89. inline BOOL operator >= (const FILETIME& f)
  90. {
  91. return !(*this < f);
  92. }
  93. inline BOOL operator <= (const FILETIME& f)
  94. {
  95. return !(*this > f);
  96. }
  97. // Arithemetic operators
  98. inline CFileTime operator + (__int64 i)
  99. {
  100. return CFileTime(MAKEINT64(dwLowDateTime, dwHighDateTime) + i);
  101. }
  102. inline CFileTime operator += (__int64 i)
  103. {
  104. *this = *this + i;
  105. return *this;
  106. }
  107. inline CFileTime operator - (__int64 i)
  108. {
  109. return CFileTime(MAKEINT64(dwLowDateTime, dwHighDateTime) - i);
  110. }
  111. inline CFileTime operator -= (__int64 i)
  112. {
  113. *this = *this - i;
  114. return *this;
  115. }
  116. inline CFileTime operator * (__int64 i)
  117. {
  118. return CFileTime(MAKEINT64(dwLowDateTime, dwHighDateTime) * i);
  119. }
  120. inline CFileTime operator *= (__int64 i)
  121. {
  122. *this = *this * i;
  123. return *this;
  124. }
  125. inline CFileTime operator / (__int64 i)
  126. {
  127. return CFileTime(MAKEINT64(dwLowDateTime, dwHighDateTime) / i);
  128. }
  129. inline CFileTime operator /= (__int64 i)
  130. {
  131. *this = *this / i;
  132. return *this;
  133. }
  134. inline CFileTime operator + (const FILETIME& f)
  135. {
  136. return *this + MAKEINT64(f.dwLowDateTime, f.dwHighDateTime);
  137. }
  138. inline CFileTime operator += (const FILETIME& f)
  139. {
  140. *this = *this + f;
  141. return *this;
  142. }
  143. inline CFileTime operator - (const FILETIME& f)
  144. {
  145. return *this - MAKEINT64(f.dwLowDateTime, f.dwHighDateTime);
  146. }
  147. inline CFileTime operator -= (const FILETIME& f)
  148. {
  149. *this = *this - f;
  150. return *this;
  151. }
  152. inline CFileTime operator * (const FILETIME& f)
  153. {
  154. return *this * MAKEINT64(f.dwLowDateTime, f.dwHighDateTime);
  155. }
  156. inline CFileTime operator *= (const FILETIME& f)
  157. {
  158. *this = *this * f;
  159. return *this;
  160. }
  161. inline CFileTime operator / (const FILETIME& f)
  162. {
  163. return *this / MAKEINT64(f.dwLowDateTime, f.dwHighDateTime);
  164. }
  165. inline CFileTime operator /= (const FILETIME& f)
  166. {
  167. *this = *this / f;
  168. return *this;
  169. }
  170. };
  171. //
  172. // Conversions
  173. // NOTE: We can't do want operator __int64() since what causes to many
  174. // ambiguous situations that the compiler just can't handle.
  175. //
  176. inline __int64 FileTimeToInt64(const FILETIME& f)
  177. {
  178. return MAKEINT64(f.dwLowDateTime, f.dwHighDateTime);
  179. }
  180. #endif