VR-Forces 4.10 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
noArgumentCallbackList.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2006 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
10 #pragma once
11 
13 
14 #include <set>
15 #include <boost/shared_ptr.hpp>
16 #include <boost/function.hpp>
17 
18 #include <tbb/spin_mutex.h>
19 
30 
31 template <typename T_CallbackFunctionType>
33 {
34  DtCallbackFunctionInfo(T_CallbackFunctionType func, void* usr = 0)
35  : callback(func)
36  , usrData(usr)
37  , deletedFlag(new bool(false))
38  {
39  }
40 
42  : callback(orig.callback)
43  , deletedFlag(orig.deletedFlag)
44  , usrData(orig.usrData)
45  {
46  }
47 
49  {
50  callback = rhs.callback;
52  usrData = rhs.usrData;
53 
54  return *this;
55  }
56 
57  bool operator<(const DtCallbackFunctionInfo& rhs) const
58  {
59  return callback < rhs.callback || (!(rhs.callback < callback) && usrData < rhs.usrData);
60  }
61 
62  bool operator>(const DtCallbackFunctionInfo& rhs) const
63  {
64  return (rhs < *this);
65  }
66 
67  bool operator==(const DtCallbackFunctionInfo& rhs) const
68  {
69  return ((callback == rhs.callback) &&
70  (userData == rhs.userData));
71  }
72 
73  bool operator!=(const DtCallbackFunctionInfo& rhs) const
74  {
75  return !(*this == rhs);
76  }
77 
78  void setIsDeleted(bool b) { *deletedFlag = b; };
79  bool isDeleted() const { return *deletedFlag; };
80 
81  const T_CallbackFunctionType& getCallback() const { return callback; };
82  void* userData() const { return usrData; };
83 
84 protected:
85  boost::shared_ptr<bool> deletedFlag;
86  T_CallbackFunctionType callback;
87  void* usrData;
88 };
89 
90 template <typename T_CallbackArg>
92 {
93 public:
95  typedef void (*DtCallbackFunctionType)(T_CallbackArg, void*);
96 
99 
102  explicit DtCallbackList(const DtCallbackList& orig);
103 
108  bool addCallback(DtCallbackFunctionType fcn, void* usrData);
112  bool removeCallback(DtCallbackFunctionType fcn, void* usrData);
113 
116  void invokeCallbacks(T_CallbackArg arg);
117 
119  void removeAll();
120 
122  {
125 
126  return *this;
127  }
128 
129 protected:
130  struct DtCallbackInfoType : public DtCallbackFunctionInfo<DtCallbackFunctionType>
131  {
134  {
135  }
136  };
137 
138  typedef std::set<DtCallbackInfoType> DtCallbackListType;
139 
140  mutable tbb::spin_mutex myMutex;
141 
143  unsigned myCallbackCount;
144 };
145 
153 {
154 public:
156  typedef void (*DtCallbackFunctionType)(void*);
157 
160 
164 
169  bool addCallback(DtCallbackFunctionType fcn, void* usrData);
173  bool removeCallback(DtCallbackFunctionType fcn, void* usrData);
174 
177  void invokeCallbacks();
178 
180  void removeAll();
181 
182 protected:
183  struct DtCallbackInfoType : public DtCallbackFunctionInfo<DtCallbackFunctionType>
184  {
185  DtCallbackInfoType(DtCallbackFunctionType callback, void* userData)
186  : DtCallbackFunctionInfo(callback, userData)
187  {
188  }
189  };
190 
191  typedef std::set<DtCallbackInfoType> DtCallbackListType;
192 
193  mutable tbb::spin_mutex myMutex;
194 
196  unsigned myCallbackCount;
197 
198 private:
199  DtNoArgumentCallbackList& operator=(const DtNoArgumentCallbackList& orig);
200 };
201 
202 template <typename Callback>
204 
211 {
212 public:
215 
220  bool disconnect()
221  {
222  if (myDisconnectFunction)
223  {
224  bool value = myDisconnectFunction();
225  myDisconnectFunction = DisconnectFunctionType();
226  return value;
227  }
228 
229  return false;
230  }
231 
232 private:
233  template <typename Callback>
234  friend class DtCallbackListT;
235 
236  typedef boost::function<bool()> DisconnectFunctionType;
237 
239  : myDisconnectFunction(func) { }
240 
242 };
243 
254 template <typename Callback>
255 class DtCallbackListT
256 {
257 public:
260 
266  DtCallbackConnection addCallback(const Callback& callback, bool* addedFirst = 0);
267 
273  void removeCallback(const Callback& callback, bool* removedLast = 0);
274 
281  void removeCallback(const boost::function<bool(const Callback&)>& removePredicate, bool* removedLast = 0);
282 
284  void removeAll();
285 
288 
289  void invokeCallbacks();
290 
291  template <typename T1>
292  void invokeCallbacks(const T1&);
293 
294  template <typename T1, typename T2>
295  void invokeCallbacks(const T1&, const T2&);
296 
297  template <typename T1, typename T2, typename T3>
298  void invokeCallbacks(const T1&, const T2&, const T3&);
300 
301 protected:
302  struct DtCallbackInfoType : public DtCallbackFunctionInfo<Callback>
303  {
305  : DtCallbackFunctionInfo<Callback>(callback)
306  {
307  }
308  };
309 
310  bool disconnect(const DtCallbackInfoType&);
311 
312  mutable tbb::spin_mutex myMutex;
313 
314  typename DtCallbackInfoType::List myCallbackList;
315  unsigned myCallbackCount;
316 
317 private:
320 };
321 
322 
323 #define callbackList_inl_
324 #include "readerWriter/noArgumentCallbackList.inl"
325 #undef callbackList_inl_
326 
void removeAll()
Removes all callbacks that have been registered.
bool isDeleted() const
Definition: noArgumentCallbackList.h:79
DtCallbackConnection addCallback(const Callback &callback, bool *addedFirst=0)
Adds a new callback to the list.
#define DT_DLL_readerWriter
This file is used to determine how to build Disable inconsistent dll linkage warning Visual Studio 6...
Definition: readerWriterDefines.h:34
bool operator<(const DtCallbackFunctionInfo &rhs) const
Definition: noArgumentCallbackList.h:57
DtCallbackList()
Default constructor.
unsigned myCallbackCount
Definition: noArgumentCallbackList.h:143
void invokeCallbacks(T_CallbackArg arg)
Invokes all the callbacks currently on the callback list.
bool operator>(const DtCallbackFunctionInfo &rhs) const
Definition: noArgumentCallbackList.h:62
std::set< DtCallbackInfoType > DtCallbackListType
Definition: noArgumentCallbackList.h:138
void setIsDeleted(bool b)
Definition: noArgumentCallbackList.h:78
void removeAll()
Removes all callbacks that have been registered.
void * usrData
Definition: noArgumentCallbackList.h:87
DtCallbackList; DtNoArgumentCallbackList.
Definition: noArgumentCallbackList.h:32
tbb::spin_mutex myMutex
Definition: noArgumentCallbackList.h:312
Represents the connection of a specific callback to a DtCallbackListT.
Definition: noArgumentCallbackList.h:210
DtCallbackInfoType(DtCallbackFunctionType callback, void *userData)
Definition: noArgumentCallbackList.h:185
bool disconnect()
Disconnect the connection.
Definition: noArgumentCallbackList.h:220
bool operator==(const DtCallbackFunctionInfo &rhs) const
Definition: noArgumentCallbackList.h:67
T_CallbackFunctionType callback
Definition: noArgumentCallbackList.h:86
bool disconnect(const DtCallbackInfoType &)
Definition: noArgumentCallbackList.h:302
tbb::spin_mutex myMutex
Definition: noArgumentCallbackList.h:193
bool removeCallback(DtCallbackFunctionType fcn, void *usrData)
Removes the specified callback from the list.
DtCallbackList & operator=(const DtCallbackList &orig)
Definition: noArgumentCallbackList.h:121
DtCallbackConnection()
Default constructor.
Definition: noArgumentCallbackList.h:214
DtCallbackListT & operator=(const DtCallbackListT &)
DtCallbackFunctionInfo & operator=(const DtCallbackFunctionInfo &rhs)
Definition: noArgumentCallbackList.h:48
unsigned myCallbackCount
Definition: noArgumentCallbackList.h:196
tbb::spin_mutex myMutex
Definition: noArgumentCallbackList.h:140
bool addCallback(DtCallbackFunctionType fcn, void *usrData)
Adds a new callback to the list.
DtCallbackFunctionInfo(T_CallbackFunctionType func, void *usr=0)
Definition: noArgumentCallbackList.h:34
This is a templated class which manages a list of callbacks.
Definition: noArgumentCallbackList.h:203
DtCallbackInfoType(const Callback &callback)
Definition: noArgumentCallbackList.h:304
unsigned myCallbackCount
Definition: noArgumentCallbackList.h:315
DtCallbackConnection(const DisconnectFunctionType &func)
Definition: noArgumentCallbackList.h:238
This class works just as DtCalllbackTable, but manages callbacks that have no arguments, and therefore don&#39;t fit in the template defined by DtCallbackList.
Definition: noArgumentCallbackList.h:152
boost::function< bool()> DisconnectFunctionType
Definition: noArgumentCallbackList.h:236
Definition: noArgumentCallbackList.h:91
DisconnectFunctionType myDisconnectFunction
Definition: noArgumentCallbackList.h:241
Definition: noArgumentCallbackList.h:130
void removeCallback(const Callback &callback, bool *removedLast=0)
Removes the specified callback from the list if it exists.
DtCallbackFunctionInfo(const DtCallbackFunctionInfo &orig)
Definition: noArgumentCallbackList.h:41
bool operator!=(const DtCallbackFunctionInfo &rhs) const
Definition: noArgumentCallbackList.h:73
std::set< DtCallbackInfoType > DtCallbackListType
Definition: noArgumentCallbackList.h:191
void * userData() const
Definition: noArgumentCallbackList.h:82
const T_CallbackFunctionType & getCallback() const
Definition: noArgumentCallbackList.h:81
DtCallbackInfoType(DtCallbackFunctionType callback, void *userData=0)
Definition: noArgumentCallbackList.h:132
boost::shared_ptr< bool > deletedFlag
Definition: noArgumentCallbackList.h:82
DtCallbackInfoType::List myCallbackList
Definition: noArgumentCallbackList.h:314
DtCallbackListT()
Default constructor.
Definition: noArgumentCallbackList.h:259
DtCallbackListType myCallbackList
Definition: noArgumentCallbackList.h:142
void invokeCallbacks()
Invokes all the callbacks currently on the callback list.
Definition: noArgumentCallbackList.h:183
DtCallbackListType myCallbackList
Definition: noArgumentCallbackList.h:195

Document ID: Generated on Tue Sep 21 17:42:52 EDT 2021 from SVN revision 234861
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)