WbemTime.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:6k
源码类别:

模拟服务器

开发平台:

C/C++

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved 
  4. //
  5. //  wbemtime.h
  6. //
  7. //  Purpose: declares the WBEMTime and WBEMTimeSpan objects which are 
  8. //  similar to the MFC CTime and CTimeSpan objects.  The WBEM versions
  9. //  are capable of storing down to the nsec and also have functions for
  10. //  Creating from and getting BSTRs.
  11. //
  12. //  Note; The current implementation of WBEMTime does not support dates 
  13. //  before 1601;
  14. //
  15. //***************************************************************************
  16. #if _MSC_VER > 1000
  17. #pragma once
  18. #endif
  19. #ifndef WBEMTIME_HEADERFILE_IS_INCLUDED
  20. #define WBEMTIME_HEADERFILE_IS_INCLUDED
  21. #define INVALID_TIME 0xffffffffffffffff
  22. #include <polarity.h>
  23. #include <time.h>
  24. #pragma warning( disable : 4290 ) // Ignore 'C++ Exception Specification ignored'
  25. #include <ProvExce.h>
  26. ///////////////////////////////////////////////////////////////////////////
  27. // WBEMTimeSpan - This class holds time span values. 
  28. class POLARITY WBEMTimeSpan 
  29. {
  30. private:
  31.     ULONGLONG m_Time;
  32.     friend class WBEMTime;
  33. public:
  34.     WBEMTimeSpan ()                                             { m_Time = INVALID_TIME ; }
  35.     WBEMTimeSpan ( const BSTR bstrDMTFFormat )                  { *this = bstrDMTFFormat ; }
  36.     WBEMTimeSpan ( 
  37.         int iDays , 
  38.         int iHours , 
  39.         int iMinutes ,  
  40.         int iSeconds , 
  41.         int iMSec=0 , 
  42.         int iUSec=0, 
  43.         int iNSec=0 
  44.     ) ;
  45.     WBEMTimeSpan operator+ (const WBEMTimeSpan &uAdd ) const ;
  46.     const WBEMTimeSpan &operator+= ( const WBEMTimeSpan &uAdd ) ;
  47.     WBEMTimeSpan operator- (const WBEMTimeSpan &uSub ) const ;
  48.     const WBEMTimeSpan &operator-= ( const WBEMTimeSpan &uSub ) ;
  49.     const WBEMTimeSpan &operator= ( const BSTR pDMTFFormat ) ; 
  50.     BOOL operator== ( const WBEMTimeSpan &a ) const             { return m_Time == a.m_Time ; }
  51.     BOOL operator!= ( const WBEMTimeSpan &a ) const             { return m_Time != a.m_Time ; }
  52.     BOOL operator<  ( const WBEMTimeSpan &a ) const             { return m_Time < a.m_Time ; }
  53.     BOOL operator<= ( const WBEMTimeSpan &a ) const             { return m_Time <= a.m_Time ; }
  54.     BOOL operator>  ( const WBEMTimeSpan &a ) const             { return m_Time > a.m_Time ; }
  55.     BOOL operator>= ( const WBEMTimeSpan &a ) const             { return m_Time >= a.m_Time ; }
  56.     BSTR GetBSTR ( void ) const throw ( CHeap_Exception ) ;
  57.     bool IsOk () const                                          { return m_Time != INVALID_TIME ? true : false; }
  58.     ULONGLONG GetTime () const                                  { return m_Time ; }
  59.     void Clear ( void )                                         { m_Time = INVALID_TIME ; }
  60.     
  61.     // These are all deprecated
  62.     WBEMTimeSpan ( const FILETIME &ft ) ;
  63.     WBEMTimeSpan ( const time_t & t ) ;
  64.     const WBEMTimeSpan &operator= ( const FILETIME &ft ) ;
  65.     const WBEMTimeSpan &operator= ( const time_t &t ) ;
  66.     BOOL Gettime_t ( time_t *ptime_t ) const ;
  67.     BOOL GetFILETIME ( FILETIME *pst ) const ;
  68. };
  69. ///////////////////////////////////////////////////////////////////////////
  70. // WBEMTime - This class holds time values. 
  71. class POLARITY WBEMTime 
  72. {
  73. public:
  74.     WBEMTime ()                                                 { m_uTime = INVALID_TIME ; }
  75.     WBEMTime ( const BSTR bstrDMTFFormat )                      { *this = bstrDMTFFormat ; }
  76.     WBEMTime ( const SYSTEMTIME &st )                           { *this = st ; }
  77.     WBEMTime ( const FILETIME &ft )                             { *this = ft ; }
  78.     WBEMTime ( const struct tm &tmin )                          { *this = tmin ; }
  79.     WBEMTime ( const time_t &t )                                { *this = t ; }
  80.     WBEMTime        operator+ ( const WBEMTimeSpan &uAdd ) const ;
  81.     const WBEMTime &operator+=( const WBEMTimeSpan &ts ) ;
  82.     WBEMTimeSpan    operator- ( const WBEMTime &sub ) ;
  83.     WBEMTime        operator- ( const WBEMTimeSpan &sub ) const;
  84.     const WBEMTime &operator-=( const WBEMTimeSpan &sub );
  85.     const WBEMTime &operator= ( const BSTR bstrDMTFFormat ) ; 
  86.     const WBEMTime &operator= ( const SYSTEMTIME &st ) ;
  87.     const WBEMTime &operator= ( const FILETIME &ft ) ;
  88.     const WBEMTime &operator= ( const struct tm &tmin ) ;
  89.     const WBEMTime &operator= ( const time_t & t) ;
  90.     BOOL operator== ( const WBEMTime &a ) const                 { return m_uTime == a.m_uTime ; }
  91.     BOOL operator!= ( const WBEMTime &a ) const                 { return m_uTime != a.m_uTime ; }
  92.     BOOL operator<  ( const WBEMTime &a ) const                 { return m_uTime < a.m_uTime ; }
  93.     BOOL operator<= ( const WBEMTime &a ) const                 { return m_uTime <= a.m_uTime ; }
  94.     BOOL operator>  ( const WBEMTime &a ) const                 { return m_uTime > a.m_uTime ; }
  95.     BOOL operator>= ( const WBEMTime &a ) const                 { return m_uTime >= a.m_uTime ; }
  96.     BSTR GetBSTR ( void ) const throw ( CHeap_Exception ) ;
  97.     BOOL GetStructtm (struct tm *ptm ) const;
  98.     BOOL Gettime_t ( time_t *ptime_t ) const;
  99.     BOOL GetSYSTEMTIME ( SYSTEMTIME *pst ) const;
  100.     BOOL GetFILETIME ( FILETIME *pst ) const;
  101.     BOOL SetDMTF ( const BSTR wszText ) ;
  102.     BSTR GetDMTF ( BOOL bLocal = FALSE ) const throw ( CHeap_Exception ) ;
  103.     BSTR GetDMTFNonNtfs(void) const ;
  104.     void Clear ( void )                                         { m_uTime = INVALID_TIME ; }
  105.     bool IsOk () const                                          { return m_uTime != INVALID_TIME ? true : false; }
  106.     ULONGLONG GetTime () const                                  { return m_uTime ; }
  107.     static LONG WINAPI GetLocalOffsetForDate(const struct tm *tmin);
  108.     static LONG WINAPI GetLocalOffsetForDate(const SYSTEMTIME *pst);
  109.     static LONG WINAPI GetLocalOffsetForDate(const FILETIME *pft);
  110.     static LONG WINAPI GetLocalOffsetForDate(const time_t &t);
  111. private:
  112.     ULONGLONG m_uTime;
  113. };
  114. #endif