MAK Data Logger API Documentation for HLA
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
signalSlot.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 1992-2010 VT MAK
3 ** All rights reserved.
4 ******************************************************************************/
5 
10 
11 
12 #ifndef signalSlot_H_
13 #define signalSlot_H_
14 
15 #include <vlutil/vlSmartPointers.h>
16 #include <list>
17 
18 namespace MAKLogger
19 {
20 
21 template <typename SignalType>
22 class DtSlot
23 {
24 public:
25 
26  DtSlot(){}
27  virtual ~DtSlot(){}
28 
29  virtual void operator()(const SignalType&) = 0;
31  virtual void* id() = 0;
32  virtual int idSize() = 0;
33 
35  {
37  if(this->idSize() != slot2.idSize()) return false;
39  return memcmp(this->id(),slot2.id(),this->idSize()) == 0;
40  }
41 
42 };
43 
44 template <typename SignalType>
45 class DtFunctionSlot : public DtSlot<SignalType>
46 {
47 public:
48  typedef void (*SlotFunction)(const SignalType&);
49 
51  myFunction(function)
52  {
53  }
54 
56  virtual void operator()(const SignalType& value)
57  {
58  myFunction(value);
59  }
60 
61  virtual int idSize()
62  {
63  return sizeof(myFunction);
64  }
65 
66  virtual void* id()
67  {
68  return &myFunction;
69  }
70 
71 protected:
73 };
74 
75 template <typename ClassType,typename SignalType>
76 class DtMemberSlot : public DtSlot<SignalType>
77 {
78 public:
79 
80  typedef void (ClassType::*SlotMemberFunction)(const SignalType&);
81  struct MemberSlotId
82  {
83  MemberSlotId(ClassType* objectValue, SlotMemberFunction memberFunctionValue)
84  : object(objectValue)
85  , memberFunction(memberFunctionValue)
86  {
87  }
88  ClassType* object;
90  };
91 
92  DtMemberSlot(ClassType* obj,SlotMemberFunction memberFunction)
93  : myId(obj, memberFunction)
94  {}
95 
96  virtual ~DtMemberSlot()
97  {
98  }
99 
100  virtual void operator()(const SignalType& value)
101  {
102  (myId.object->*myId.memberFunction)(value);
103  }
104 
105  virtual int idSize()
106  {
107  return sizeof(myId);
108  }
109 
110  virtual void* id()
111  {
112  return &myId;
113  }
114 
115 protected:
117 };
118 
119 
120 template <typename SignalType>
121 class DtSignal
122 {
123 public:
124  typedef void (*DtSlotFunction)(const SignalType&);
125 
127  typedef DtBoost::shared_ptr<SlotType> SlotTypeSP;
128  typedef std::list<SlotTypeSP> SlotList;
129 
130  void connect(SlotTypeSP slot)
131  {
132  mySlots.push_back(slot);
133  }
134 
136  {
137  typename SlotList::iterator newEnd = std::remove_if(mySlots.begin(),mySlots.end(), std::bind2nd(std::ptr_fun(compare),slot));
138  mySlots.erase(newEnd, mySlots.end());
139  }
140 
141  void operator()(const SignalType& value)
142  {
143  typename SlotList::iterator func = mySlots.begin();
144  typename SlotList::iterator end = mySlots.end();
145  for(;func != end;++func)
146  {
147  SlotTypeSP& s = *func;
148  s->operator()(value);
149  }
150  }
151 
152 protected:
153 
154  static bool compare(SlotTypeSP slot1,SlotTypeSP slot2)
155  {
156  return *(slot1.get()) == *(slot2.get());
157  }
158 
160 };
161 
162 template <typename SignalType>
163 class DtValueSignal : public DtSignal<SignalType>
164 {
165 public:
166  DtValueSignal(SignalType& valueRef) :
167  myRef(valueRef)
168  {
169  }
170 
171  void setAndEmitOnNotEqual(const SignalType& newValue)
172  {
173  if(newValue != myRef)
174  {
175  myRef = newValue;
176  (*this)(myRef);
177  }
178  }
179 
180  void setAndEmitOnEqual(const SignalType& newValue)
181  {
182  if(newValue == myRef)
183  {
184  myRef = newValue;
185  (*this)(myRef);
186  }
187  else
188  {
189  myRef = newValue;
190  }
191  }
192 
193  void setAndEmit(const SignalType& newValue)
194  {
195  myRef = newValue;
196  (*this)(myRef);
197  }
198 
199 
200 protected:
201  SignalType& myRef;
202 };
203 
204 
205 
206 template<typename SignalType>
207 void DtConnect(DtSignal<SignalType>& signal,void (*slot)(SignalType))
208 {
210 }
211 
212 template <typename ClassType,typename SignalType>
213 void DtConnect(DtSignal<SignalType>& signal,ClassType* member,void (ClassType::*slot)(const SignalType&))
214 {
215 #ifdef __solaris__
217 #else
219 #endif
220 }
221 
222 template<typename SignalType>
223 void DtDisconnect(DtSignal<SignalType>& signal,void (*slot)(SignalType) )
224 {
226 }
227 
228 template <typename ClassType,typename SignalType>
229 void DtDisconnect(DtSignal<SignalType>& signal,ClassType* member,void (ClassType::*slot)(const SignalType&) )
230 {
232 }
233 
234 }
235 
236 #endif

Document ID: Generated on Tue Aug 1 09:00:26 EDT 2017 from SVN revision 179128
Copyright © 2017 VT MÄK. All Rights Reserved (www.mak.com)