home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_12 / 9n12057a < prev    next >
Text File  |  1991-10-17  |  2KB  |  77 lines

  1. /*
  2. REPRATE.HPP
  3.  
  4. Header file for periodic event class definitions.
  5. Paul A. Cornelius, August 1991
  6. */
  7.  
  8. #ifndef REPRATE_HPP
  9. #define REPRATE_HPP
  10.  
  11. typedef void (*CALL_ME)();      // user function type
  12. const unsigned TICKS_PER_SECOND=1024;
  13.  
  14. #ifndef DLIST_HPP
  15.     #include <dlist.hpp>
  16. #endif
  17.  
  18. class RepRate
  19. {
  20. friend class RepRateList;
  21. private:
  22.     CALL_ME func;
  23.     long tick_interval; 
  24.         // ticks between calls to CALL_ME
  25.     long count_now;
  26.     void HandleTick();
  27. public:
  28.     RepRate(double Hz,CALL_ME);
  29.     ~RepRate()                          {}
  30.     double ChangeRepRate(double Hz);        
  31.         // returns actual rep rate
  32.     void ChangeFunction(CALL_ME p)      {func = p;}
  33.     double GetRepRate()                 
  34.         // returns actual rep rate
  35.     {
  36.         return double(TICKS_PER_SECOND) / 
  37.          double(tick_interval);
  38.     }
  39. };
  40.  
  41. // The next class supports a list of RepRate objects.
  42. // An instance is declared globally as TimerList.  
  43. // There can be only a single RepRateList per program; 
  44. // attempting to instantiate a second one will
  45. // cause an assertion failure.
  46. declare(zGDList,RepRate);
  47. class RepRateList
  48. {
  49. friend void handle_tick();
  50.     static int On;
  51.     int TimerOn;
  52.     int Error;
  53.     zGDList(RepRate) Replist;
  54.     void TurnOnTimer();
  55.     void TurnOffTimer();
  56.     void HandleTick();
  57. public:
  58.     RepRateList();          
  59.         // Clock does not turn on until first RepRate 
  60.         // object is linked in
  61.     ~RepRateList();         // Turns off the clock
  62.  
  63.     void Linkin(RepRate*);  
  64.         // Attaches the object to the list, starts 
  65.         // clock if not already going
  66.     void Linkout(RepRate*); 
  67.         // Removes object from list, stops clock if
  68.         // it is the last one
  69.     int GetError()          {return Error;}     
  70.         // 1 linked list error
  71. };
  72.  
  73. extern RepRateList TimerList;
  74.  
  75. #endif
  76.  
  77.