ScummVM API documentation
callback.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef COMMON_CALLBACK_H
23 #define COMMON_CALLBACK_H
24 
25 namespace Common {
26 
49 template<typename S = void *> class BaseCallback {
50 public:
51  BaseCallback() {}
52  virtual ~BaseCallback() {}
53  virtual void operator()(S data) = 0;
54 };
55 
63 template<typename T> class GlobalFunctionCallback: public BaseCallback<T> {
64  typedef void(*GlobalFunction)(T result);
65  GlobalFunction _callback;
66 
67 public:
68  GlobalFunctionCallback(GlobalFunction cb): _callback(cb) {}
69  virtual ~GlobalFunctionCallback() {}
70  virtual void operator()(T data) {
71  if (_callback) _callback(data);
72  }
73 };
74 
91 template<class T, typename S = void *> class Callback: public BaseCallback<S> {
92 protected:
93  typedef void(T::*TMethod)(S);
94  T *_object;
95  TMethod _method;
96 public:
97  Callback(T *object, TMethod method): _object(object), _method(method) {}
98  virtual ~Callback() {}
99  void operator()(S data) { (_object->*_method)(data); }
100 };
101 
133 template<class T, typename OS, typename S = void *> class CallbackBridge: public BaseCallback<S> {
134  typedef void(T::*TCallbackMethod)(BaseCallback<OS> *, S);
135  T *_object;
136  TCallbackMethod _method;
137  BaseCallback<OS> *_outerCallback;
138 public:
139  CallbackBridge(T *object, TCallbackMethod method, BaseCallback<OS> *outerCallback):
140  _object(object), _method(method), _outerCallback(outerCallback) {}
141  virtual ~CallbackBridge() {}
142  void operator()(S data) { (_object->*_method)(_outerCallback, data); }
143 };
144 
147 } // End of namespace Common
148 
149 #endif
Definition: callback.h:63
Definition: callback.h:91
Definition: callback.h:133
virtual void operator()(S data)=0
virtual void operator()(T data)
Definition: callback.h:70
Definition: algorithm.h:29
Definition: callback.h:49
void operator()(S data)
Definition: callback.h:142
void operator()(S data)
Definition: callback.h:99