ScummVM API documentation
te_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 TETRAEDGE_TE_TE_CALLBACK_H
23 #define TETRAEDGE_TE_TE_CALLBACK_H
24 
25 //#include "common/callback.h"
26 
27 namespace Tetraedge {
28 
30 public:
31  virtual ~TeICallback0Param() {}
32  virtual bool operator()() = 0;
33  virtual bool call() = 0;
34  virtual float priority() const = 0;
35  virtual bool equals(const TeICallback0Param *other) const = 0;
36 };
37 
42 template<class T> class TeCallback0Param : public TeICallback0Param {
43 public:
44  typedef bool(T::*TMethod)();
45 protected:
46  T *_object;
47  TMethod _method;
48  float _priority;
49 public:
50  TeCallback0Param(T *object, TMethod method, float priority_ = 0.0f): _object(object), _method(method), _priority(priority_) {}
51  virtual ~TeCallback0Param() {}
52  bool operator()() override { return (_object->*_method)(); }
53  bool call() override { return (_object->*_method)(); }
54 
55  virtual float priority() const override { return _priority; }
56 
57  bool equals(const TeICallback0Param *other) const override {
58  const TeCallback0Param<T> *o = dynamic_cast<const TeCallback0Param<T> *>(other);
59  return o && _object == o->_object && _method == o->_method;
60  }
61  //virtual void setPriority()
62 };
63 
64 template<class T> class TeICallback1Param {
65 public:
66  virtual ~TeICallback1Param() {}
67  virtual bool operator()(T data) = 0;
68  virtual bool call(T data) = 0;
69  virtual float &priority() = 0;
70  virtual bool equals(const TeICallback1Param *other) const = 0;
71 };
72 
73 
74 template<class T, typename S> class TeCallback1Param : public TeICallback1Param<S> {
75 public:
76  typedef bool(T::*TMethod)(S);
77 protected:
78  T *_object;
79  TMethod _method;
80  float _priority;
81 public:
82  TeCallback1Param(T *object, TMethod method, float priority_ = 0.0f): _object(object), _method(method), _priority(priority_) {}
83  virtual ~TeCallback1Param() {}
84  bool operator()(S data) override { return (_object->*_method)(data); }
85  bool call(S data) override { return (_object->*_method)(data); }
86 
87  virtual float &priority() override { return _priority; }
88 
89  bool equals(const TeICallback1Param<S> *other) const override {
90  const TeCallback1Param<T, S> *o = dynamic_cast<const TeCallback1Param<T, S> *>(other);
91  return o && _object == o->_object && _method == o->_method;
92  }
93  //virtual void setPriority()
94 };
95 
96 
97 template<class S, class T> class TeICallback2Param {
98 public:
99  virtual ~TeICallback2Param() {}
100  virtual bool operator()(S data1, T data2) = 0;
101  virtual bool call(S data1, T data2) = 0;
102  virtual float &priority() = 0;
103  virtual bool equals(const TeICallback2Param *other) const = 0;
104 };
105 
106 
107 template<class C, class S, typename T> class TeCallback2Param : public TeICallback2Param<S, T> {
108 public:
109  typedef bool(C::*TMethod)(S, T);
110 protected:
111  C *_object;
112  TMethod _method;
113  float _priority;
114 public:
115  TeCallback2Param(C *object, TMethod method, float priority_ = 0.0f): _object(object), _method(method), _priority(priority_) {}
116  virtual ~TeCallback2Param() {}
117  bool operator()(S data1, T data2) override { return (_object->*_method)(data1, data2); }
118  bool call(S data1, T data2) override { return (_object->*_method)(data1, data2); }
119 
120  virtual float &priority() override { return _priority; }
121 
122  bool equals(const TeICallback2Param<S, T> *other) const override {
123  const TeCallback2Param<C, S, T> *o = dynamic_cast<const TeCallback2Param<C, S, T> *>(other);
124  return o && _object == o->_object && _method == o->_method;
125  }
126  //virtual void setPriority()
127 };
128 
129 
130 
131 } // end namespace Tetraedge
132 
133 #endif // TETRAEDGE_TE_TE_CALLBACK_H
Definition: detection.h:27
Definition: te_callback.h:29
Definition: te_callback.h:107
Definition: te_callback.h:97
Definition: te_callback.h:74
Definition: te_callback.h:42
Definition: te_callback.h:64