VR-Forces 4.7 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 <list>
15 #include <boost/shared_ptr.hpp>
16 #include <boost/function.hpp>
17 
18 #include <tbb/spin_mutex.h>
19 
30 template <typename T_CallbackArg>
32 {
33 public:
35  typedef void (*DtCallbackFunctionType)(T_CallbackArg, void*);
36 
39 
42  explicit DtCallbackList(const DtCallbackList& orig);
43 
48  bool addCallback(DtCallbackFunctionType fcn, void* usrData);
52  bool removeCallback(DtCallbackFunctionType fcn, void* usrData);
53 
56  void invokeCallbacks(T_CallbackArg arg);
57 
59  void removeAll();
60 
61 protected:
63  {
65  void* userData;
67 
69  };
70 
71  typedef std::list< boost::shared_ptr<DtCallbackInfoType> > DtCallbackListType;
72 
73  mutable tbb::spin_mutex myMutex;
74 
76  unsigned myCallbackCount;
77 
78 private:
80 };
81 
89 {
90 public:
92  typedef void (*DtCallbackFunctionType)(void*);
93 
96 
100 
105  bool addCallback(DtCallbackFunctionType fcn, void* usrData);
109  bool removeCallback(DtCallbackFunctionType fcn, void* usrData);
110 
113  void invokeCallbacks();
114 
116  void removeAll();
117 
118 protected:
120  {
121  DtCallbackFunctionType callback;
122  void* userData;
124 
125  DtCallbackInfoType(DtCallbackFunctionType callback, void* userData);
126  };
127 
128  typedef std::list< boost::shared_ptr<DtCallbackInfoType> > DtCallbackListType;
129 
130  mutable tbb::spin_mutex myMutex;
131 
133  unsigned myCallbackCount;
134 
135 private:
136  DtNoArgumentCallbackList& operator=(const DtNoArgumentCallbackList& orig);
137 };
138 
139 template <typename Callback>
140 class DtCallbackListT;
141 
148 {
149 public:
152 
157  bool disconnect()
158  {
159  if (myDisconnectFunction)
160  {
161  bool value = myDisconnectFunction();
162  myDisconnectFunction = DisconnectFunctionType();
163  return value;
164  }
165 
166  return false;
167  }
168 
169 private:
170  template <typename Callback>
171  friend class DtCallbackListT;
172 
173  typedef boost::function<bool()> DisconnectFunctionType;
174 
176  : myDisconnectFunction(func) { }
177 
179 };
180 
191 template <typename Callback>
193 {
194 public:
197 
203  DtCallbackConnection addCallback(const Callback& callback, bool* addedFirst = 0);
204 
210  void removeCallback(const Callback& callback, bool* removedLast = 0);
211 
218  void removeCallback(const boost::function<bool(const Callback&)>& removePredicate, bool* removedLast = 0);
219 
221  void removeAll();
222 
225 
226  void invokeCallbacks();
227 
228  template <typename T1>
229  void invokeCallbacks(const T1&);
230 
231  template <typename T1, typename T2>
232  void invokeCallbacks(const T1&, const T2&);
233 
234  template <typename T1, typename T2, typename T3>
235  void invokeCallbacks(const T1&, const T2&, const T3&);
237 
238 protected:
240  {
241  typedef boost::shared_ptr<DtCallbackInfoType> Ptr;
242  typedef boost::weak_ptr<DtCallbackInfoType> WPtr;
243  typedef std::list<Ptr> List;
244 
245  Callback callback;
247 
248  typename List::iterator iterator;
249 
250  DtCallbackInfoType(const Callback& callback)
251  : callback(callback), deletedFlag(false) { }
252 
253  Callback& getCallback() { return callback; }
254  };
255 
256  bool disconnect(const typename DtCallbackInfoType::WPtr&);
257 
258  mutable tbb::spin_mutex myMutex;
259 
261  unsigned myCallbackCount;
262 
263 private:
266 };
267 
268 
269 #define callbackList_inl_
270 #include "readerWriter/noArgumentCallbackList.inl"
271 #undef callbackList_inl_
272 

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)