| 1 | /* | 
|---|
| 2 | * synergy -- mouse and keyboard sharing utility | 
|---|
| 3 | * Copyright (C) 2004 Chris Schoeneman | 
|---|
| 4 | * | 
|---|
| 5 | * This package is free software; you can redistribute it and/or | 
|---|
| 6 | * modify it under the terms of the GNU General Public License | 
|---|
| 7 | * found in the file COPYING that should have accompanied this file. | 
|---|
| 8 | * | 
|---|
| 9 | * This package is distributed in the hope that it will be useful, | 
|---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 12 | * GNU General Public License for more details. | 
|---|
| 13 | */ | 
|---|
| 14 |  | 
|---|
| 15 | #ifndef CMETHODEVENTJOB_H | 
|---|
| 16 | #define CMETHODEVENTJOB_H | 
|---|
| 17 |  | 
|---|
| 18 | #include "IEventJob.h" | 
|---|
| 19 |  | 
|---|
| 20 | //! Use a member function as an event job | 
|---|
| 21 | /*! | 
|---|
| 22 | An event job class that invokes a member function. | 
|---|
| 23 | */ | 
|---|
| 24 | template <class T> | 
|---|
| 25 | class TMethodEventJob : public IEventJob { | 
|---|
| 26 | public: | 
|---|
| 27 | //! run(event) invokes \c object->method(event, arg) | 
|---|
| 28 | TMethodEventJob(T* object, | 
|---|
| 29 | void (T::*method)(const CEvent&, void*), | 
|---|
| 30 | void* arg = NULL); | 
|---|
| 31 | virtual ~TMethodEventJob(); | 
|---|
| 32 |  | 
|---|
| 33 | // IJob overrides | 
|---|
| 34 | virtual void            run(const CEvent&); | 
|---|
| 35 |  | 
|---|
| 36 | private: | 
|---|
| 37 | T*                                      m_object; | 
|---|
| 38 | void                            (T::*m_method)(const CEvent&, void*); | 
|---|
| 39 | void*                           m_arg; | 
|---|
| 40 | }; | 
|---|
| 41 |  | 
|---|
| 42 | template <class T> | 
|---|
| 43 | inline | 
|---|
| 44 | TMethodEventJob<T>::TMethodEventJob(T* object, | 
|---|
| 45 | void (T::*method)(const CEvent&, void*), void* arg) : | 
|---|
| 46 | m_object(object), | 
|---|
| 47 | m_method(method), | 
|---|
| 48 | m_arg(arg) | 
|---|
| 49 | { | 
|---|
| 50 | // do nothing | 
|---|
| 51 | } | 
|---|
| 52 |  | 
|---|
| 53 | template <class T> | 
|---|
| 54 | inline | 
|---|
| 55 | TMethodEventJob<T>::~TMethodEventJob() | 
|---|
| 56 | { | 
|---|
| 57 | // do nothing | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | template <class T> | 
|---|
| 61 | inline | 
|---|
| 62 | void | 
|---|
| 63 | TMethodEventJob<T>::run(const CEvent& event) | 
|---|
| 64 | { | 
|---|
| 65 | if (m_object != NULL) { | 
|---|
| 66 | (m_object->*m_method)(event, m_arg); | 
|---|
| 67 | } | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | #endif | 
|---|