home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / mac / SiteBldr / AMOVIE / SDK / _SETUP / COMMON.Z / reftime.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-15  |  2.9 KB  |  118 lines

  1. //==========================================================================;
  2. //
  3. //  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. //  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. //  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. //  PURPOSE.
  7. //
  8. //  Copyright (c) 1992 - 1996  Microsoft Corporation.  All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------;
  11.  
  12. //
  13. // CRefTime
  14. //
  15. // Manage reference times.
  16. // Shares same data layout as REFERENCE_TIME, but adds some (nonvirtual)
  17. // functions providing simple comparison, conversion and arithmetic.
  18. //
  19. // A reference time (at the moment) is a unit of seconds represented in
  20. // 100ns units as is used in the Win32 FILETIME structure. BUT the time
  21. // a REFERENCE_TIME represents is NOT the time elapsed since 1/1/1601 it
  22. // will either be stream time or reference time depending upon context
  23. //
  24. // This class provides simple arithmetic operations on reference times
  25. //
  26. // keep non-virtual otherwise the data layout will not be the same as
  27. // REFERENCE_TIME
  28.  
  29.  
  30. // -----
  31. // note that you are safe to cast a CRefTime* to a REFERENCE_TIME*, but
  32. // you will need to do so explicitly
  33. // -----
  34.  
  35.  
  36. #ifndef __REFTIME__
  37. #define __REFTIME__
  38.  
  39.  
  40. const LONGLONG MILLISECONDS = (1000);            // 10 ^ 3
  41. const LONGLONG NANOSECONDS = (1000000000);       // 10 ^ 9
  42. const LONGLONG UNITS = (NANOSECONDS / 100);      // 10 ^ 7
  43.  
  44. /*  Unfortunately an inline function here generates a call to __allmul
  45.     - even for constants!
  46. */
  47. #define MILLISECONDS_TO_100NS_UNITS(lMs) \
  48.     Int32x32To64((lMs), (UNITS / MILLISECONDS))
  49.  
  50. class CRefTime
  51. {
  52. public:
  53.  
  54.     // *MUST* be the only data member so that this class is exactly
  55.     // equivalent to a REFERENCE_TIME.
  56.     // Also, must be *no virtual functions*
  57.  
  58.     REFERENCE_TIME m_time;
  59.  
  60.     inline CRefTime()
  61.     {
  62.         // default to 0 time
  63.         m_time = 0;
  64.     };
  65.  
  66.     inline CRefTime(LONG msecs)
  67.     {
  68.         m_time = MILLISECONDS_TO_100NS_UNITS(msecs);
  69.     };
  70.  
  71.     inline CRefTime(REFERENCE_TIME rt)
  72.     {
  73.         m_time = rt;
  74.     };
  75.  
  76.     inline operator REFERENCE_TIME() const
  77.     {
  78.         return m_time;
  79.     };
  80.  
  81.     inline CRefTime& operator=(const CRefTime& rt)
  82.     {
  83.         m_time = rt.m_time;
  84.         return *this;
  85.     };
  86.  
  87.     inline CRefTime& operator=(const LONGLONG ll)
  88.     {
  89.         m_time = ll;
  90.         return *this;
  91.     };
  92.  
  93.     inline CRefTime& operator+=(const CRefTime& rt)
  94.     {
  95.         return (*this = *this + rt);
  96.     };
  97.  
  98.     inline CRefTime& operator-=(const CRefTime& rt)
  99.     {
  100.         return (*this = *this - rt);
  101.     };
  102.  
  103.     inline LONG Millisecs(void)
  104.     {
  105.         return (LONG)(m_time / (UNITS / MILLISECONDS));
  106.     };
  107.  
  108.     inline LONGLONG GetUnits(void)
  109.     {
  110.         return m_time;
  111.     };
  112. };
  113.  
  114. const CRefTime TimeZero = LONGLONG(0);
  115.  
  116. #endif /* __REFTIME__ */
  117.  
  118.