Hot Door CORE 0.8.2
Adobe® Illustrator® Plug-in Library
Loading...
Searching...
No Matches
hdicoreCallback.h
Go to the documentation of this file.
1
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
78 virtual Callback* clone() const = 0;
79
85 virtual ~Callback()
86 {
87 // no-op
88 }
89
90
91 protected:
101 {
102 // no-op
103 }
104 };
105
106 typedef std::unique_ptr<Callback> CallbackUP;
107 typedef std::shared_ptr<Callback> CallbackSP;
108 typedef std::weak_ptr<Callback> CallbackWP;
109
110
111
117 template <class hdiTargetType>
118 class __Callback : public Callback
119 {
120 private:
124 typedef hdiTargetType TargetType;
125
129 typedef void (TargetType::*ActionType)(void);
130
134 typedef void (TargetType::*ConstActionType)(void) const;
135
139 TargetType* __target;
140
144 ActionType __action;
145
149 ConstActionType __constAction;
150
151
152 public:
164 explicit __Callback(TargetType* target_, ActionType action_) :
165 Callback(),
166 __target(target_),
167 __action(action_),
168 __constAction(NULL)
169 {
170// #if defined(HDI_CORE_DEBUG)
171// assert(target_ != NULL);
172// assert(action_ != NULL);
173// #endif
174 }
175
176 explicit __Callback(TargetType* target_, ConstActionType action_) :
177 Callback(),
178 __target(target_),
179 __action(NULL),
180 __constAction(action_)
181 {
182// #if defined(HDI_CORE_DEBUG)
183// assert(target_ != NULL);
184// assert(action_ != NULL);
185// #endif
186 }
187
198 Callback(),
199 __target(cb_.__target),
200 __action(cb_.__action),
201 __constAction(cb_.__constAction)
202 {
203 // no-op
204 }
205
211 virtual ~__Callback()
212 {
213 // no-op
214 }
215
228 {
229 return new __Callback<TargetType>(*this);
230 }
231
238 virtual void execute() const
239 {
240 if(!this->__target)
241 return;
242
243 if(this->__action)
244 {
245 (this->__target->*this->__action)();
246 }
247 else if(this->__constAction)
248 {
249 (this->__target->*this->__constAction)();
250 }
251 }
252
253
254 private:
260 __Callback() : Callback(), __target(NULL), __action(NULL), __constAction(NULL)
261 {
262 // no-op
263 }
264 };
265
270 {
271 public:
277 void nothing();
278
279
280 private:
286 __Dummy();
287
293 __Dummy(const __Dummy&);
294
300 ~__Dummy();
301
307 __Dummy& operator=(const __Dummy&);
308 };
309 }
310}
311
312#endif
313// __HDI_CORE_CALLBACK__
Class to describe a target object and a method of it, to be called at a later time.
Definition: hdicoreCallback.h:119
virtual void execute() const
Executes the callback.
Definition: hdicoreCallback.h:238
virtual __Callback< TargetType > * clone() const
Convenience method to clone a __Callback object.
Definition: hdicoreCallback.h:227
__Callback(const __Callback< TargetType > &cb_)
__Callback copy constructor
Definition: hdicoreCallback.h:197
virtual ~__Callback()
__Callback destructor; no-op at this time
Definition: hdicoreCallback.h:211
__Callback(TargetType *target_, ActionType action_)
__Callback constructor
Definition: hdicoreCallback.h:164
Just a simple "dummy" class to allow for creation of "empty" callbacks.
Definition: hdicoreCallback.h:270
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:85
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:100
Header file for a wide variety of necessary typedefs, enums, and forwards declarations.