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
25namespace Common {
26
49template<typename S = void *> class BaseCallback {
50public:
51 BaseCallback() {}
52 virtual ~BaseCallback() {}
53 virtual void operator()(S data) = 0;
54};
55
63template<typename T> class GlobalFunctionCallback: public BaseCallback<T> {
64 typedef void(*GlobalFunction)(T result);
65 GlobalFunction _callback;
66
67public:
68 GlobalFunctionCallback(GlobalFunction cb): _callback(cb) {}
69 virtual ~GlobalFunctionCallback() {}
70 virtual void operator()(T data) {
71 if (_callback) _callback(data);
72 }
73};
74
91template<class T, typename S = void *> class Callback: public BaseCallback<S> {
92protected:
93 typedef void(T::*TMethod)(S);
94 T *_object;
95 TMethod _method;
96public:
97 Callback(T *object, TMethod method): _object(object), _method(method) {}
98 virtual ~Callback() {}
99 void operator()(S data) override { (_object->*_method)(data); }
100};
101
133template<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;
138public:
139 CallbackBridge(T *object, TCallbackMethod method, BaseCallback<OS> *outerCallback):
140 _object(object), _method(method), _outerCallback(outerCallback) {}
141 virtual ~CallbackBridge() {}
142 void operator()(S data) override { (_object->*_method)(_outerCallback, data); }
143};
144
147} // End of namespace Common
148
149#endif
Definition: callback.h:49
virtual void operator()(S data)=0
Definition: callback.h:133
void operator()(S data) override
Definition: callback.h:142
Definition: callback.h:91
void operator()(S data) override
Definition: callback.h:99
Definition: callback.h:63
virtual void operator()(T data)
Definition: callback.h:70
Definition: algorithm.h:29