MAK Data Logger API Documentation for DIS
 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
DtFunctionSlot(SlotFunction function)
Definition: signalSlot.h:50
void(* DtSlotFunction)(const SignalType &)
Definition: signalSlot.h:124
virtual void operator()(const SignalType &)=0
Definition: signalSlot.h:121
bool operator==(DtSlot< SignalType > &slot2)
Definition: signalSlot.h:34
virtual void * id()
Ids necessary for comparison.
Definition: signalSlot.h:66
Definition: signalSlot.h:22
SlotFunction myFunction
Definition: signalSlot.h:72
Definition: signalSlot.h:81
MemberSlotId myId
Definition: signalSlot.h:116
void operator()(const SignalType &value)
Definition: signalSlot.h:141
DtValueSignal(SignalType &valueRef)
Definition: signalSlot.h:166
DtSlot< SignalType > SlotType
Definition: signalSlot.h:126
void setAndEmitOnNotEqual(const SignalType &newValue)
Definition: signalSlot.h:171
void(ClassType::* SlotMemberFunction)(const SignalType &)
Definition: signalSlot.h:80
void(* SlotFunction)(const SignalType &)
Definition: signalSlot.h:48
std::list< SlotTypeSP > SlotList
Definition: signalSlot.h:128
virtual void * id()=0
Ids necessary for comparison.
MemberSlotId(ClassType *objectValue, SlotMemberFunction memberFunctionValue)
Definition: signalSlot.h:83
virtual void * id()
Ids necessary for comparison.
Definition: signalSlot.h:110
void setAndEmitOnEqual(const SignalType &newValue)
Definition: signalSlot.h:180
void disconnect(SlotTypeSP slot)
Definition: signalSlot.h:135
virtual void operator()(const SignalType &value)
Definition: signalSlot.h:100
virtual ~DtMemberSlot()
Definition: signalSlot.h:96
DtMemberSlot(ClassType *obj, SlotMemberFunction memberFunction)
Definition: signalSlot.h:92
SlotList mySlots
Definition: signalSlot.h:159
virtual int idSize()
Definition: signalSlot.h:61
void connect(SlotTypeSP slot)
Definition: signalSlot.h:130
SignalType & myRef
Definition: signalSlot.h:201
virtual int idSize()=0
static bool compare(SlotTypeSP slot1, SlotTypeSP slot2)
Definition: signalSlot.h:154
virtual int idSize()
Definition: signalSlot.h:105
DtBoost::shared_ptr< SlotType > SlotTypeSP
Definition: signalSlot.h:127
void DtDisconnect(DtSignal< SignalType > &signal, void(*slot)(SignalType))
Definition: signalSlot.h:223
SlotMemberFunction memberFunction
Definition: signalSlot.h:89
ClassType * object
Definition: signalSlot.h:88
virtual ~DtSlot()
Definition: signalSlot.h:27
DtSlot()
Definition: signalSlot.h:26
virtual void operator()(const SignalType &value)
Call function.
Definition: signalSlot.h:56
void DtConnect(DtSignal< SignalType > &signal, void(*slot)(SignalType))
Definition: signalSlot.h:207
Definition: signalSlot.h:76
Definition: signalSlot.h:45
void setAndEmit(const SignalType &newValue)
Definition: signalSlot.h:193
Definition: signalSlot.h:163

Document ID: Generated on Mon Mar 22 15:30:17 EDT 2021 from SVN revision 226440
Copyright © 2021 MAK Technologies. All Rights Reserved (www.mak.com)