home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / classinc.pak / TIMER.H < prev    next >
C/C++ Source or Header  |  1997-07-23  |  2KB  |  87 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  TIMER.H                                                               */
  4. /*                                                                        */
  5. /*  Copyright (c) 1991, 1994 Borland International                        */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( CLASSLIB_TIMER_H )
  11. #define CLASSLIB_TIMER_H
  12.  
  13. #if !defined( __DOS__ ) && !defined( BUILDBIDSTIMER )
  14. #error class TTimer only available under DOS
  15. #endif
  16.  
  17. #if !defined( CLASSLIB_DEFS_H )
  18. #include <classlib/defs.h>
  19. #endif
  20.  
  21. #pragma option -Vo-
  22. #if defined( BI_CLASSLIB_NO_po )
  23. #pragma option -po-
  24. #endif
  25.  
  26. class TTimer
  27. {
  28.  
  29. public:
  30.  
  31.     TTimer();
  32.  
  33.     void Start();
  34.     void Stop();
  35.     void Reset();
  36.  
  37.     int Status();
  38.     double Time();
  39.  
  40.     static double Resolution();
  41.  
  42. private:
  43.  
  44.     static unsigned Adjust;
  45.     static unsigned Calibrate();
  46.     int Running;
  47.  
  48.     struct TIME
  49.         {
  50.         unsigned long DosCount;
  51.         unsigned TimerCount;
  52.         };
  53.  
  54.     TIME StartTime;
  55.  
  56.     double Time_;
  57.  
  58. };
  59.  
  60. #if defined( BI_OLDNAMES )
  61. #define Timer TTimer
  62. #endif
  63.  
  64. inline int TTimer::Status()
  65. {
  66.     return Running;
  67. }
  68.  
  69. inline double TTimer::Time()
  70. {
  71.     return Time_/1.E6;
  72. }
  73.  
  74. inline double TTimer::Resolution()
  75. {
  76.     return 839/1.E9;
  77. }
  78.  
  79. #if defined( BI_CLASSLIB_NO_po )
  80. #pragma option -po.
  81. #endif
  82.  
  83. #pragma option -Vo.
  84.  
  85. #endif  // CLASSLIB_TIMER_H
  86.  
  87.