home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / thread / threads / cmdroutr.hpp next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  2.9 KB  |  64 lines

  1. #ifndef _CMDROUTR_
  2. #define _CMDROUTR_
  3. /***************************************************************
  4. * FILE NAME: cmdroutr.hpp                                      *
  5. *                                                              *
  6. * DESCRIPTION:                                                 *
  7. *   This file contains the declaration(s) of the class(es):    *
  8. *     CMdroutr - Template class that generates simple          *
  9. *                ICommandHandler derived classes to route      *
  10. *                command events to object member functions.    *
  11. *                                                              *
  12. * COPYRIGHT:                                                   *
  13. *   Licensed Materials - Property of Solution Frameworks       *
  14. *   Copyright (C) 1996, Solution Frameworks                    *
  15. *   All Rights Reserved                                        *
  16. ***************************************************************/
  17. #ifndef _ICMDHDR_
  18.   #include <icmdhdr.hpp>
  19. #endif
  20.  
  21. /*---------------------- CommandRouter -------------------------
  22. | Objects of classes generated from this template are used     |
  23. | to route command events to arbitrary member functions of     |
  24. | arbitrary objects.  The template argument is the name of     |
  25. | the class whose member function is to be invoked.            |
  26. |                                                              |
  27. | Usage:                                                       |
  28. |   struct MyClass {                                           |
  29. |     Boolean                                                  |
  30. |       function ( ICommandEvent &cmd );                       |
  31. |   };                                                         |
  32. |   ...                                                        |
  33. |   MyClass                                                    |
  34. |     myObject;                                                |
  35. |   ...                                                        |
  36. |   CommandRouter<MyClass>                                     |
  37. |     router( aWindow, myObject, MyClass::function );          |
  38. --------------------------------------------------------------*/
  39. template < class Handler >
  40. class CommandRouter : public ICommandHandler {
  41. public:
  42.   CommandRouter ( IWindow       &window,
  43.                   Handler       &handler,
  44.                   Boolean (Handler::*memberFn)(ICommandEvent&) )
  45.     : ICommandHandler(),
  46.       handler        ( handler ),
  47.       memberFn       ( memberFn ) {
  48.       this->handleEventsFor( &window );
  49.     }
  50. protected:
  51. virtual Boolean
  52.   command ( ICommandEvent &event ) {
  53.     return (handler.*memberFn)( event );
  54.   }
  55. private:
  56. Handler
  57.  &handler;
  58. Boolean (Handler::*memberFn)( ICommandEvent & );
  59. CommandRouter ( const CommandRouter<Handler>& );
  60. operator = ( const CommandRouter<Handler>& );
  61. }; // class CommandRouter
  62.  
  63. #endif // _CMDROUTR_
  64.