Hot Door CORE  0.7.0
Adobe® Illustrator® Plug-in Library
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 
59 namespace hdi
60 {
61  namespace core
62  {
67  class Callback
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::auto_ptr<Callback> CallbackAP;
107 
108 
109 
115  template <class hdiTargetType>
116  class __Callback : public Callback
117  {
118  private:
122  typedef hdiTargetType TargetType;
123 
127  typedef void (TargetType::*ActionType)(void);
128 
132  typedef void (TargetType::*ConstActionType)(void) const;
133 
137  TargetType* __target;
138 
142  ActionType __action;
143 
147  ConstActionType __constAction;
148 
149 
150  public:
162  explicit __Callback(TargetType* target_, ActionType action_) :
163  Callback(),
164  __target(target_),
165  __action(action_),
166  __constAction(NULL)
167  {
168 // #if defined(HDI_CORE_DEBUG)
169 // assert(target_ != NULL);
170 // assert(action_ != NULL);
171 // #endif
172  }
173 
174  explicit __Callback(TargetType* target_, ConstActionType action_) :
175  Callback(),
176  __target(target_),
177  __action(NULL),
178  __constAction(action_)
179  {
180 // #if defined(HDI_CORE_DEBUG)
181 // assert(target_ != NULL);
182 // assert(action_ != NULL);
183 // #endif
184  }
185 
196  Callback(),
197  __target(cb_.__target),
198  __action(cb_.__action),
199  __constAction(cb_.__constAction)
200  {
201  // no-op
202  }
203 
209  virtual ~__Callback()
210  {
211  // no-op
212  }
213 
225  virtual __Callback<TargetType>* clone() const
226  {
227  return new __Callback<TargetType>(*this);
228  }
229 
236  virtual void execute() const
237  {
238  if(!this->__target)
239  return;
240 
241  if(this->__action)
242  {
243  (this->__target->*this->__action)();
244  }
245  else if(this->__constAction)
246  {
247  (this->__target->*this->__constAction)();
248  }
249  }
250 
251 
252  private:
258  __Callback() : Callback(), __target(NULL), __action(NULL), __constAction(NULL)
259  {
260  // no-op
261  }
262  };
263 
267  class __Dummy
268  {
269  public:
275  void nothing();
276 
277 
278  private:
284  __Dummy();
285 
291  __Dummy(const __Dummy&);
292 
298  ~__Dummy();
299 
305  __Dummy& operator=(const __Dummy&);
306  };
307  }
308 }
309 
310 #endif
311 // __HDI_CORE_CALLBACK__
virtual Callback * clone() const =0
Pure virtual callback cloning method, so __Callback objects can be stored as Callback*.
virtual ~Callback()
Callback destructor, no-op at this time.
Definition: hdicoreCallback.h:85
virtual void execute() const
Executes the callback.
Definition: hdicoreCallback.h:236
virtual ~__Callback()
__Callback destructor; no-op at this time
Definition: hdicoreCallback.h:209
void nothing()
__Dummy no-op
__Callback(TargetType *target_, ActionType action_)
__Callback constructor
Definition: hdicoreCallback.h:162
virtual __Callback< TargetType > * clone() const
Convenience method to clone a __Callback object.
Definition: hdicoreCallback.h:225
Base class for templated __Callback class.
Definition: hdicoreCallback.h:67
Header file for a wide variety of necessary typedefs, enums, and forwards declarations.
Definition: hdicoreaiArray.h:12
Callback()
Callback constructor, no-op at this time.
Definition: hdicoreCallback.h:100
Just a simple "dummy" class to allow for creation of "empty" callbacks.
Definition: hdicoreCallback.h:267
virtual void execute() const =0
Pure virtual callback execution method, so __Callback objects can be stored as Callback*.
__Callback(const __Callback< TargetType > &cb_)
__Callback copy constructor
Definition: hdicoreCallback.h:195
Class to describe a target object and a method of it, to be called at a later time.
Definition: hdicoreCallback.h:116