| Line |  | 
|---|
| 1 | /* | 
|---|
| 2 | * synergy -- mouse and keyboard sharing utility | 
|---|
| 3 | * Copyright (C) 2002 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 CMETHODJOB_H | 
|---|
| 16 | #define CMETHODJOB_H | 
|---|
| 17 |  | 
|---|
| 18 | #include "IJob.h" | 
|---|
| 19 |  | 
|---|
| 20 | //! Use a function as a job | 
|---|
| 21 | /*! | 
|---|
| 22 | A job class that invokes a member function. | 
|---|
| 23 | */ | 
|---|
| 24 | template <class T> | 
|---|
| 25 | class TMethodJob : public IJob { | 
|---|
| 26 | public: | 
|---|
| 27 | //! run() invokes \c object->method(arg) | 
|---|
| 28 | TMethodJob(T* object, void (T::*method)(void*), void* arg = NULL); | 
|---|
| 29 | virtual ~TMethodJob(); | 
|---|
| 30 |  | 
|---|
| 31 | // IJob overrides | 
|---|
| 32 | virtual void            run(); | 
|---|
| 33 |  | 
|---|
| 34 | private: | 
|---|
| 35 | T*                                      m_object; | 
|---|
| 36 | void                            (T::*m_method)(void*); | 
|---|
| 37 | void*                           m_arg; | 
|---|
| 38 | }; | 
|---|
| 39 |  | 
|---|
| 40 | template <class T> | 
|---|
| 41 | inline | 
|---|
| 42 | TMethodJob<T>::TMethodJob(T* object, void (T::*method)(void*), void* arg) : | 
|---|
| 43 | m_object(object), | 
|---|
| 44 | m_method(method), | 
|---|
| 45 | m_arg(arg) | 
|---|
| 46 | { | 
|---|
| 47 | // do nothing | 
|---|
| 48 | } | 
|---|
| 49 |  | 
|---|
| 50 | template <class T> | 
|---|
| 51 | inline | 
|---|
| 52 | TMethodJob<T>::~TMethodJob() | 
|---|
| 53 | { | 
|---|
| 54 | // do nothing | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 | template <class T> | 
|---|
| 58 | inline | 
|---|
| 59 | void | 
|---|
| 60 | TMethodJob<T>::run() | 
|---|
| 61 | { | 
|---|
| 62 | if (m_object != NULL) { | 
|---|
| 63 | (m_object->*m_method)(m_arg); | 
|---|
| 64 | } | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 | #endif | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.