Hot Door CORE 0.8.4
Adobe® Illustrator® Plug-in Library
Loading...
Searching...
No Matches
hdicoreCallback.h
Go to the documentation of this file.
1
6
7#ifndef __HDI_CORE_CALLBACK__
8#define __HDI_CORE_CALLBACK__
9
10#include <assert.h>
11
12#include "hdicoreTypes.h"
13
30#define HDI_CORE_CALLBACK_T(__HDI_C__) hdi::core::__Callback<__HDI_C__>
31
49#define HDI_CORE_CALLBACK(__HDI_C__, __HDI_O__, __HDI_M__) \
50 hdi::core::__Callback<__HDI_C__>(__HDI_O__, &__HDI_C__::__HDI_M__)
51
57#define HDI_CORE_CALLBACK_NONE HDI_CORE_CALLBACK(hdi::core::__Dummy, NULL, nothing)
58
59namespace hdi
60{
61 namespace core
62 {
68 {
69 public:
73 virtual void execute() const = 0;
74
80 virtual Callback* clone() const = 0;
81
87 virtual ~Callback()
88 {
89 // no-op
90 }
91
92
93 protected:
103 {
104 // no-op
105 }
106 };
107
108 typedef std::unique_ptr<Callback> CallbackUP;
109 typedef std::shared_ptr<Callback> CallbackSP;
110 typedef std::weak_ptr<Callback> CallbackWP;
111
112
113
119 template <class hdiTargetType>
120 class __Callback : public Callback
121 {
122 private:
126 typedef hdiTargetType TargetType;
127
131 typedef void (TargetType::*ActionType)(void);
132
136 typedef void (TargetType::*ConstActionType)(void) const;
137
141 TargetType* __target;
142
146 ActionType __action;
147
151 ConstActionType __constAction;
152
153
154 public:
166 explicit __Callback(TargetType* target_, ActionType action_) :
167 Callback(),
168 __target(target_),
169 __action(action_),
170 __constAction(NULL)
171 {
172// #if defined(HDI_CORE_DEBUG)
173// assert(target_ != NULL);
174// assert(action_ != NULL);
175// #endif
176 }
177
178 explicit __Callback(TargetType* target_, ConstActionType action_) :
179 Callback(),
180 __target(target_),
181 __action(NULL),
182 __constAction(action_)
183 {
184// #if defined(HDI_CORE_DEBUG)
185// assert(target_ != NULL);
186// assert(action_ != NULL);
187// #endif
188 }
189
200 Callback(),
201 __target(cb_.__target),
202 __action(cb_.__action),
203 __constAction(cb_.__constAction)
204 {
205 // no-op
206 }
207
213 virtual ~__Callback()
214 {
215 // no-op
216 }
217
230 {
231 return new __Callback<TargetType>(*this);
232 }
233
240 virtual void execute() const
241 {
242 if(!this->__target)
243 return;
244
245 if(this->__action)
246 {
247 (this->__target->*this->__action)();
248 }
249 else if(this->__constAction)
250 {
251 (this->__target->*this->__constAction)();
252 }
253 }
254
255
256 private:
262 __Callback() : Callback(), __target(NULL), __action(NULL), __constAction(NULL)
263 {
264 // no-op
265 }
266 };
267
271 class __Dummy
272 {
273 public:
279 void nothing();
280
281
282 private:
288 __Dummy();
289
295 __Dummy(const __Dummy&);
296
302 ~__Dummy();
303
309 __Dummy& operator=(const __Dummy&);
310 };
311 }
312}
313
314#endif
315// __HDI_CORE_CALLBACK__
Class to describe a target object and a method of it, to be called at a later time.
Definition hdicoreCallback.h:121
virtual void execute() const
Executes the callback.
Definition hdicoreCallback.h:240
virtual __Callback< TargetType > * clone() const
Convenience method to clone a __Callback object.
Definition hdicoreCallback.h:229
__Callback(const __Callback< TargetType > &cb_)
__Callback copy constructor
Definition hdicoreCallback.h:199
virtual ~__Callback()
__Callback destructor; no-op at this time
Definition hdicoreCallback.h:213
__Callback(TargetType *target_, ActionType action_)
__Callback constructor
Definition hdicoreCallback.h:166
void nothing()
__Dummy no-op
Base class for templated __Callback class.
Definition hdicoreCallback.h:68
virtual void execute() const =0
Pure virtual callback execution method, so __Callback objects can be stored as Callback*.
virtual ~Callback()
Callback destructor, no-op at this time.
Definition hdicoreCallback.h:87
virtual Callback * clone() const =0
Pure virtual callback cloning method, so __Callback objects can be stored as Callback*.
Callback()
Callback constructor, no-op at this time.
Definition hdicoreCallback.h:102
Header file for a wide variety of necessary typedefs, enums, and forwards declarations.