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.

184 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. vs_time.hxx
  5. Abstract:
  6. Classes for encapsulating time structures
  7. Author:
  8. Adi Oltean [AOltean] 15-Oct-1998
  9. Revision History:
  10. At creation I added a class for encapsulating the FILETIME struct.
  11. --*/
  12. #ifndef _H_VSS_TIME
  13. #define _H_VSS_TIME
  14. ////////////////////////////////////////////////////////////////////////
  15. // Standard foo for file name aliasing. This code block must be after
  16. // all includes of VSS header files.
  17. //
  18. #ifdef VSS_FILE_ALIAS
  19. #undef VSS_FILE_ALIAS
  20. #endif
  21. #define VSS_FILE_ALIAS "INCTIMEH"
  22. //
  23. ////////////////////////////////////////////////////////////////////////
  24. class CVsFileTime
  25. {
  26. // Constructors/destructors
  27. public:
  28. CVsFileTime ( DWORD dwMillisecOffset = 0 )
  29. {
  30. if (dwMillisecOffset == INFINITE)
  31. SetInfinite();
  32. else
  33. {
  34. GetSystemTime();
  35. (*this) += dwMillisecOffset;
  36. }
  37. }
  38. CVsFileTime ( FILETIME ftWhen )
  39. {
  40. m_ftTime = ftWhen;
  41. }
  42. CVsFileTime ( const CVsFileTime& ftWhen )
  43. {
  44. m_ftTime = ftWhen.m_ftTime;
  45. }
  46. // Attributes
  47. public:
  48. operator LARGE_INTEGER () const
  49. {
  50. LARGE_INTEGER lnTime;
  51. lnTime.LowPart = m_ftTime.dwLowDateTime;
  52. lnTime.HighPart = m_ftTime.dwHighDateTime;
  53. return lnTime;
  54. }
  55. operator LONGLONG () const
  56. {
  57. LARGE_INTEGER lnTime;
  58. lnTime.LowPart = m_ftTime.dwLowDateTime;
  59. lnTime.HighPart = m_ftTime.dwHighDateTime;
  60. return lnTime.QuadPart;
  61. }
  62. operator FILETIME () const
  63. {
  64. return m_ftTime;
  65. }
  66. bool operator < ( const CVsFileTime& ftWith ) const
  67. {
  68. return ( CompareFileTime( &m_ftTime, &ftWith.m_ftTime ) == -1L );
  69. }
  70. bool operator == ( const CVsFileTime& ftWith ) const
  71. {
  72. return ( CompareFileTime( &m_ftTime, &ftWith.m_ftTime ) == 0L );
  73. }
  74. bool operator > ( const CVsFileTime& ftWith ) const
  75. {
  76. return ( CompareFileTime( &m_ftTime, &ftWith.m_ftTime ) == 1L );
  77. }
  78. bool operator <= ( const CVsFileTime& ftWith ) const
  79. {
  80. return ( CompareFileTime( &m_ftTime, &ftWith.m_ftTime ) != 1L );
  81. }
  82. bool operator != ( const CVsFileTime& ftWith ) const
  83. {
  84. return ( CompareFileTime( &m_ftTime, &ftWith.m_ftTime ) != 0L );
  85. }
  86. bool operator >= ( const CVsFileTime& ftWith ) const
  87. {
  88. return ( CompareFileTime( &m_ftTime, &ftWith.m_ftTime ) != -1L );
  89. }
  90. BOOL IsExpired() const
  91. {
  92. return (*this < CVsFileTime() );
  93. }
  94. BOOL IsInfinite() const
  95. {
  96. return (m_ftTime.dwLowDateTime == INFINITE)&&
  97. (m_ftTime.dwHighDateTime == INFINITE);
  98. }
  99. // Operations
  100. public:
  101. CVsFileTime& GetSystemTime()
  102. {
  103. // WARNING! Different calls may return the same result!
  104. GetSystemTimeAsFileTime( &m_ftTime );
  105. return *this;
  106. }
  107. CVsFileTime& operator = ( const CVsFileTime& ftValue )
  108. {
  109. m_ftTime = ftValue.m_ftTime;
  110. return *this;
  111. }
  112. CVsFileTime& operator += ( DWORD dwMilliseconds )
  113. {
  114. if (dwMilliseconds == INFINITE)
  115. SetInfinite();
  116. else
  117. {
  118. ULARGE_INTEGER ulnTime;
  119. ulnTime.LowPart = m_ftTime.dwLowDateTime;
  120. ulnTime.HighPart = m_ftTime.dwHighDateTime;
  121. ulnTime.QuadPart += dwMilliseconds * 10000 ;
  122. m_ftTime.dwLowDateTime = ulnTime.LowPart;
  123. m_ftTime.dwHighDateTime = ulnTime.HighPart;
  124. }
  125. return *this;
  126. }
  127. void SetInfinite()
  128. {
  129. m_ftTime.dwLowDateTime = INFINITE;
  130. m_ftTime.dwHighDateTime = INFINITE;
  131. }
  132. #ifdef _DEBUG
  133. void Dump()
  134. {
  135. BsDebugTraceAlways( 0, DEBUG_TRACE_BS_LIB,
  136. ( L"CVsFileTime::Dump() reports stored time = 0x%08x:0x%08x",
  137. m_ftTime.dwHighDateTime,
  138. m_ftTime.dwLowDateTime
  139. ) );
  140. }
  141. #endif // _DEBUG
  142. // Implementation
  143. private:
  144. FILETIME m_ftTime;
  145. };
  146. #endif // _H_VSS_TIME