home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / itimer.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  6.3 KB  |  210 lines

  1. #ifndef _ITIMER_
  2. #define _ITIMER_
  3.  
  4. /*******************************************************************************
  5. * FILE NAME: itimer.hpp                                                        *
  6. *                                                                              *
  7. * DESCRIPTION:                                                                 *
  8. *   Declaration of the classes:                                                *
  9. *     ITimer                                                                   *
  10. *     ITimer::Cursor                                                           *
  11. *     ITimerFn                                                                 *
  12. *     ITimerMemberFn                                                           *
  13. *     ITimerMemberFn0                                                          *
  14. *                                                                              *
  15. * COPYRIGHT:                                                                   *
  16. *   IBM Open Class Library                                                     *
  17. *   (C) Copyright International Business Machines Corporation 1992, 1996       *
  18. *   Licensed Material - Program-Property of IBM - All Rights Reserved.         *
  19. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  20. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  21. *                                                                              *
  22. *******************************************************************************/
  23. #include <ivbase.hpp>
  24. #include <irefcnt.hpp>
  25.  
  26. class IString;
  27. class ITimerData;
  28.  
  29. #pragma pack(4)
  30.  
  31. class ITimerFn : public IRefCounted {
  32. typedef IRefCounted
  33.   Inherited;
  34. public:
  35. /*------------------------------- Constructors -------------------------------*/
  36.   ITimerFn ( );
  37.  
  38. virtual
  39.   ~ITimerFn ( );
  40.  
  41. /*---------------------------- Timer Expiration ------------------------------*/
  42. virtual void
  43.   timerExpired ( unsigned long timerId ) = 0;
  44.  
  45. private:
  46. /*----------------------------- Hidden Members -------------------------------*/
  47.   ITimerFn      ( const ITimerFn& function );
  48. ITimerFn
  49.   &operator=    ( const ITimerFn& function );
  50.  
  51. }; // class ITimerFn
  52.  
  53.  
  54. template < class T >
  55. class ITimerMemberFn : public ITimerFn {
  56. typedef ITimerFn
  57.   Inherited;
  58. public:
  59. /*------------------------------- Constructors -------------------------------*/
  60. ITimerMemberFn ( T &object,
  61.                  void ( T::*memberFunction )(unsigned long) )
  62.   : fMemberFunction( memberFunction ), fObject( object )
  63.   {
  64.   }
  65.  
  66. /*---------------------------- Timer Expiration ------------------------------*/
  67. virtual void
  68.   timerExpired ( unsigned long timerId )
  69.   {
  70.   (fObject.*fMemberFunction)(timerId);
  71.   }
  72.  
  73. private:
  74. /*----------------------------- Hidden Members -------------------------------*/
  75.   ITimerMemberFn  ( const ITimerMemberFn<T>& timerFunction );
  76. ITimerMemberFn<T>
  77.   &operator=      ( const ITimerMemberFn<T>& timerFunction );
  78.  
  79. /*--------------------------------- Private ----------------------------------*/
  80. T
  81.   &fObject;
  82. void (T::
  83.   *fMemberFunction)(unsigned long);
  84. }; // ITimerMemberFn
  85.  
  86.  
  87. template < class T >
  88. class ITimerMemberFn0 : public ITimerFn {
  89. typedef ITimerFn
  90.   Inherited;
  91. public:
  92. /*------------------------------- Constructors -------------------------------*/
  93. ITimerMemberFn0 ( T &object,
  94.                   void ( T::*memberFunction )() )
  95.   : fMemberFunction( memberFunction ), fObject( object )
  96.   {
  97.   }
  98.  
  99. /*---------------------------- Timer Expiration ------------------------------*/
  100. virtual void
  101.   timerExpired ( unsigned long timerId )
  102.   {
  103.   (fObject.*fMemberFunction)();
  104.   }
  105.  
  106. private:
  107. /*----------------------------- Hidden Members -------------------------------*/
  108.   ITimerMemberFn0 ( const ITimerMemberFn0<T>& timerFunction );
  109. ITimerMemberFn0<T>
  110.  &operator=       ( const ITimerMemberFn0<T>& timerFunction );
  111.  
  112. /*--------------------------------- Private ----------------------------------*/
  113. T
  114.   &fObject;
  115. void (T::
  116.   *fMemberFunction)();
  117. }; // ITimerMemberFn0
  118.  
  119.  
  120. class ITimer : public IVBase {
  121. typedef IVBase
  122.   Inherited;
  123. public:
  124.  
  125. /*------------------------------- Constructors -------------------------------*/
  126.   ITimer            ( );
  127.   ITimer            ( const IReference<ITimerFn>& timerFunction,
  128.                       unsigned long timerInterval = 1000 );
  129.   ITimer            ( unsigned long timerIdentifier );
  130.   ITimer            ( const ITimer& timer );
  131.   ITimer &operator= ( const ITimer& timer );
  132.  
  133. virtual
  134.   ~ITimer ( );
  135.  
  136. /*--------------------------- Starting and Stopping --------------------------*/
  137. virtual ITimer
  138.   &start   ( const IReference<ITimerFn>& timerFunction ),
  139.   &start   ( const IReference<ITimerFn>& timerFunction,
  140.              unsigned long               timerInterval );
  141.  
  142. virtual ITimer
  143.   &stop    ( );
  144.  
  145. Boolean
  146.   isStarted ( ) const;
  147.  
  148. /*-----------------------------Timer Information -----------------------------*/
  149. unsigned long
  150.   id ( ) const;
  151.  
  152. /*-------------------------------- Diagnostics -------------------------------*/
  153. virtual IString
  154.   asString    ( ) const,
  155.   asDebugInfo ( ) const;
  156.  
  157. /*--------------------------- Expiration Interval ----------------------------*/
  158. unsigned long
  159.   interval ( ) const;
  160.  
  161. virtual ITimer
  162.  &setInterval ( unsigned long aInterval = 1000 );
  163.  
  164.  
  165. class Cursor : public IVBase {
  166. typedef IVBase
  167.   Inherited;
  168. public:
  169. /*------------------------------- Constructors -------------------------------*/
  170.   Cursor ( );
  171. virtual
  172.  ~Cursor ( );
  173.  
  174. /*------------------------------ Timer Iteration -----------------------------*/
  175. virtual Boolean
  176.   setToFirst ( ),
  177.   setToNext  ( ),
  178.   isValid    ( ) const;
  179.  
  180. virtual void
  181.   invalidate ( );
  182.  
  183. private:
  184. /*--------------------------------- Private ----------------------------------*/
  185. friend ITimer;
  186. unsigned long
  187.   fIndex;
  188. }; // class ITimer::Cursor
  189.  
  190. /*-------------------------- Retrieving Objects ------------------------------*/
  191. static ITimer
  192.   timerAt ( const Cursor& cursor );
  193.  
  194. /*------------------------------- Comparison ---------------------------------*/
  195. Boolean
  196.   operator == ( const ITimer timer );
  197.  
  198. private:
  199. /*--------------------------------- Private ----------------------------------*/
  200. unsigned long
  201.   fIndex;
  202.  
  203. ITimerData
  204.  *fTimerData;
  205. }; // ITimer
  206.  
  207. #pragma pack()
  208.  
  209. #endif /* _ITIMER_ */
  210.