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

  1. #ifndef _IOBSERVR_
  2. #define _IOBSERVR_
  3. /*******************************************************************************
  4. * FILE NAME: iobservr.hpp                                                      *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the classes:                                                *
  8. *     IObserver                                                                *
  9. *     IObserverConnectionTo                                                    *
  10. *                                                                              *
  11. * COPYRIGHT:                                                                   *
  12. *   IBM Open Class Library                                                     *
  13. *   (C) Copyright International Business Machines Corporation 1992, 1996       *
  14. *   Licensed Material - Program-Property of IBM - All Rights Reserved.         *
  15. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  16. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  17. *                                                                              *
  18. *******************************************************************************/
  19. #include <ivbase.hpp>
  20. #include <ievtdata.hpp>
  21.  
  22. #pragma pack(4)
  23.  
  24. class INotificationEvent;
  25. class INotifier;
  26. class IObserverData;
  27.  
  28. class IObserver : public IVBase {
  29. typedef IVBase
  30.   Inherited;
  31. public:
  32. /*------------------------------- Constructors -------------------------------*/
  33. virtual
  34.  ~IObserver ( );
  35.  
  36. /*---------------------------- Notifier Attachment ---------------------------*/
  37. virtual IObserver
  38.  &handleNotificationsFor       ( INotifier&        notifier,
  39.                                  const IEventData& userData = IEventData() ),
  40.  &stopHandlingNotificationsFor ( INotifier&        notifier );
  41.  
  42.  
  43. protected:
  44. /*----------------------------- Event Dispatching ----------------------------*/
  45. virtual IObserver
  46.  &dispatchNotificationEvent  ( const INotificationEvent& event )=0;
  47.  
  48. /*------------------------------- Constructors -------------------------------*/
  49.   IObserver ( );
  50.  
  51. private:
  52. /*--------------------------------- Private ----------------------------------*/
  53. friend class INotifier;
  54. friend class IObserverList;
  55.  
  56. IObserverData
  57.  *fObserverData;
  58. }; // IObserver
  59.  
  60. #pragma info(nocpy)
  61.  
  62. template <class ATarget>
  63. class IObserverConnectionTo : public IObserver {
  64. typedef IObserver
  65.   Inherited;
  66. public:
  67. /*----------------------------- Type Definitions -----------------------------*/
  68. typedef void (ATarget::* MemberFunction)( const INotificationEvent& );
  69.  
  70. /*------------------------------- Constructors -------------------------------*/
  71.   IObserverConnectionTo ( ATarget&       target,
  72.                           MemberFunction memberFunction );
  73. virtual
  74.  ~IObserverConnectionTo ( );
  75.  
  76. protected:
  77. /*----------------------------- Event Dispatching ----------------------------*/
  78. virtual IObserverConnectionTo<ATarget>
  79.  &dispatchNotificationEvent ( const INotificationEvent& event);
  80.  
  81. private:
  82. /*--------------------------------- Private ----------------------------------*/
  83. ATarget
  84.  &fTarget;
  85. MemberFunction
  86.   fConnectedMember;
  87. };  // IObserverConnectionTo
  88.  
  89. template<class ATarget>
  90. inline
  91. IObserverConnectionTo<ATarget>::IObserverConnectionTo( ATarget& target,
  92.                                                        MemberFunction memberFunction )
  93. : fTarget(target), fConnectedMember(memberFunction)
  94. {
  95. }
  96.  
  97. #ifndef __TEMPINC__
  98.   #include <iobservr.c>
  99. #endif
  100.  
  101. #pragma info(restore)
  102.  
  103. #pragma pack()
  104.  
  105. #endif /* _IOBSERVR_ */
  106.