13 #ifndef FFA_SWITCH_BOARD_H
14 #define FFA_SWITCH_BOARD_H
16 #if defined(win32) || defined(win64)
17 #pragma warning(disable:4503)
146 using SwbMap = std::map<FFaSwitchBoardConnector*,IntMap>;
159 #define FFASWB_TEMPLATE1 template < class P1Type >
160 #define FFASWB_ADDED_TEMPLATE_ARGS1 , class P1Type
161 #define FFASWB_TYPE_LIST1 < P1Type >
162 #define FFASWB_ADDED_TYPE_LIST1 , P1Type
164 #define FFASWB_ARGUMENT_LIST1 P1Type p1
165 #define FFASWB_ADDED_FUNCTION_ARGS1 , P1Type p1
167 #define FFASWB_PARAM_LIST1 p1
171 #define FFASWB_TEMPLATE2 template < class P1Type, class P2Type >
172 #define FFASWB_ADDED_TEMPLATE_ARGS2 , class P1Type, class P2Type
173 #define FFASWB_TYPE_LIST2 < P1Type, P2Type >
174 #define FFASWB_ADDED_TYPE_LIST2 , P1Type, P2Type
176 #define FFASWB_ARGUMENT_LIST2 P1Type p1, P2Type p2
177 #define FFASWB_ADDED_FUNCTION_ARGS2 , P1Type p1, P2Type p2
179 #define FFASWB_PARAM_LIST2 p1, p2
183 #define FFASWB_TEMPLATE3 template < class P1Type, class P2Type, class P3Type >
184 #define FFASWB_ADDED_TEMPLATE_ARGS3 , class P1Type, class P2Type, class P3Type
185 #define FFASWB_TYPE_LIST3 < P1Type, P2Type, P3Type >
186 #define FFASWB_ADDED_TYPE_LIST3 , P1Type, P2Type, P3Type
188 #define FFASWB_ARGUMENT_LIST3 P1Type p1, P2Type p2, P3Type p3
189 #define FFASWB_ADDED_FUNCTION_ARGS3 , P1Type p1, P2Type p2, P3Type p3
191 #define FFASWB_PARAM_LIST3 p1, p2, p3
195 #define FFASWB_TEMPLATE4 template < class P1Type, class P2Type, class P3Type, class P4Type >
196 #define FFASWB_ADDED_TEMPLATE_ARGS4 , class P1Type, class P2Type, class P3Type, class P4Type
197 #define FFASWB_TYPE_LIST4 < P1Type, P2Type, P3Type, P4Type >
198 #define FFASWB_ADDED_TYPE_LIST4 , P1Type, P2Type, P3Type, P4Type
200 #define FFASWB_ARGUMENT_LIST4 P1Type p1, P2Type p2, P3Type p3, P4Type p4
201 #define FFASWB_ADDED_FUNCTION_ARGS4 , P1Type p1, P2Type p2, P3Type p3, P4Type p4
203 #define FFASWB_PARAM_LIST4 p1, p2, p3, p4
210 #define FFASWB_MAKE_SLOTBASE_TEMPLATE(nr, templateDef, argumentList, typeList) \
213 class FFaSlotBase##nr : public FFaSlotBase \
216 FFaSlotBase##nr () { myTypeID = getClassTypeID(); } \
217 virtual ~FFaSlotBase##nr () {} \
218 virtual void invoke(argumentList) = 0; \
219 static unsigned int getClassTypeID() \
221 static unsigned int ourClassTypeID = ++uniqueTypeId; \
222 return ourClassTypeID; \
236 #define FFASWB_MAKE_SLOT_TEMPLATE(nr, addedTemplateArgs, argumentList, parameterList, typeList) \
238 template<class T addedTemplateArgs> \
239 class FFaSlot##nr : public FFaSlotBase##nr typeList \
241 typedef void (T::*methodType)(argumentList); \
244 FFaSlot##nr (T* obj, methodType method) \
247 myMethodPt = method; \
248 myObject->addSlot(this); \
251 virtual ~FFaSlot##nr () \
253 myObject->removeSlot(this); \
256 virtual void invoke(argumentList) \
258 (this->myObject->*this->myMethodPt)(parameterList); \
261 virtual bool operator==(FFaSlotBase& otherSlot) \
263 return ((FFaSwitchBoardConnector*)this->myObject == otherSlot.getObject() && \
264 (anyMethodType)this->myMethodPt == otherSlot.getMethod()); \
267 virtual FFaSwitchBoardConnector* getObject() { return myObject; } \
268 virtual anyMethodType getMethod() { return (anyMethodType)myMethodPt; } \
269 virtual anyFunctionType getFunction() { return (anyFunctionType)NULL; } \
270 virtual bool isStaticSlot() const { return false; } \
274 methodType myMethodPt; \
287 #define FFASWB_MAKE_STATIC_SLOT_TEMPLATE(nr, templateDef, argumentList, parameterList, typeList) \
290 class FFaStaticSlot##nr : public FFaSlotBase##nr typeList \
292 typedef void (*functionType)(argumentList); \
295 FFaStaticSlot##nr (functionType func) { myFunctionPt = func; } \
296 virtual ~FFaStaticSlot##nr () {} \
298 virtual void invoke(argumentList) { (this->myFunctionPt)(parameterList); } \
300 virtual bool operator==(FFaSlotBase& otherSlot) \
302 if (otherSlot.isStaticSlot()) \
303 return (anyFunctionType)myFunctionPt == otherSlot.getFunction(); \
308 virtual FFaSwitchBoardConnector* getObject() { return NULL; } \
309 virtual anyMethodType getMethod() { return (anyMethodType)NULL; } \
310 virtual anyFunctionType getFunction() { return (anyFunctionType)myFunctionPt; } \
311 virtual bool isStaticSlot() const { return true; } \
314 functionType myFunctionPt; \
332 #define FFASWB_MAKE_EMIT_FUNCTION_TEMPLATE(nr, templateDef, addedArgumentList, parameterList, typeList) \
334 templateDef void FFaSwitchBoardCall(FFaSwitchBoardConnector* sender, int subject addedArgumentList) \
336 unsigned int typeID = FFaSlotBase##nr typeList::getClassTypeID(); \
337 FFaSlotList& ffSlot = FFaSwitchBoard::getSlots(sender,subject,typeID); \
338 FFaSlotList::iterator it = ffSlot.end(); \
339 while ((it = FFaSwitchBoard::nextValidSlot(it,ffSlot,sender,subject)) != ffSlot.end()) \
340 static_cast<FFaSlotBase##nr typeList*>(it->slotPt)->invoke(parameterList); \
352 #define FFASWB_MAKE_SIMPLE_CONNECT_FUNCTION_TEMPLATE(nr, addedTemplateArgs, argumentList, addedTypeList) \
354 template<class RecieverType addedTemplateArgs> \
355 void FFaSwitchBoardConnect(FFaSwitchBoardConnector* sender, int subject, RecieverType* receiver, \
356 void (RecieverType::*method)(argumentList)) \
358 FFaSwitchBoard::connect(sender, subject, new FFaSlot##nr <RecieverType addedTypeList>(receiver,method)); \
370 #define FFASWB_MAKE_SIMPLE_DISCONNECT_FUNCTION_TEMPLATE(nr, addedTemplateArgs, argumentList, addedTypeList) \
372 template<class RecieverType addedTemplateArgs> \
373 void FFaSwitchBoardDisConnect(FFaSwitchBoardConnector* sender, int subject, RecieverType* receiver, \
374 void (RecieverType::*method)(argumentList)) \
376 FFaSwitchBoard::disConnect(sender, subject, new FFaSlot##nr <RecieverType addedTypeList>(receiver,method)); \
391 #define FFaSlot0S(ownerType, method) new FFaStaticSlot0 (&ownerType::method)
393 #define FFaSlot1S(ownerType, method, P1Type) new FFaStaticSlot1<P1Type> (&ownerType::method)
395 #define FFaSlot2S(ownerType, method, P1Type, P2Type) new FFaStaticSlot2<P1Type, P2Type> (&ownerType::method)
397 #define FFaSlot3S(ownerType, method, P1Type, P2Type, P3Type) new FFaStaticSlot3<P1Type, P2Type, P3Type> (&ownerType::method)
399 #define FFaSlot4S(ownerType, method, P1Type, P2Type, P3Type, P4Type) new FFaStaticSlot4<P1Type, P2Type, P3Type, P4Type> (&ownerType::method)
402 #define FFaSlot0M(ownerType, owner, method) new FFaSlot0<ownerType> (owner,&ownerType::method)
404 #define FFaSlot1M(ownerType, owner, method, P1Type) new FFaSlot1<ownerType, P1Type> (owner,&ownerType::method)
406 #define FFaSlot2M(ownerType, owner, method, P1Type, P2Type) new FFaSlot2<ownerType, P1Type, P2Type> (owner,&ownerType::method)
408 #define FFaSlot3M(ownerType, owner, method, P1Type, P2Type, P3Type) new FFaSlot3<ownerType, P1Type, P2Type, P3Type> (owner,&ownerType::method)
410 #define FFaSlot4M(ownerType, owner, method, P1Type, P2Type, P3Type, P4Type) new FFaSlot4<ownerType, P1Type, P2Type, P3Type, P4Type> (owner,&ownerType::method)
void(* anyFunctionType)(...)
Callback function pointer.
Definition: FFaSwitchBoard.H:42
std::list< FFaSlotBasePt > FFaSlotList
Slot container.
Definition: FFaSwitchBoard.H:37
#define FFASWB_MAKE_SLOT_TEMPLATE(nr, addedTemplateArgs, argumentList, parameterList, typeList)
Macro that defines the different slotN templates.
Definition: FFaSwitchBoard.H:236
#define FFASWB_MAKE_SIMPLE_DISCONNECT_FUNCTION_TEMPLATE(nr, addedTemplateArgs, argumentList, addedTypeList)
Macro that defines the disconnect function templates.
Definition: FFaSwitchBoard.H:370
#define FFASWB_MAKE_SIMPLE_CONNECT_FUNCTION_TEMPLATE(nr, addedTemplateArgs, argumentList, addedTypeList)
Macro that defines the connect function templates.
Definition: FFaSwitchBoard.H:352
#define FFASWB_MAKE_EMIT_FUNCTION_TEMPLATE(nr, templateDef, addedArgumentList, parameterList, typeList)
Function to call all the slots connected to a signal.
Definition: FFaSwitchBoard.H:332
#define FFASWB_MAKE_STATIC_SLOT_TEMPLATE(nr, templateDef, argumentList, parameterList, typeList)
Macro that defines the different static slotN templates.
Definition: FFaSwitchBoard.H:287
void(FFaSwitchBoardConnector::* anyMethodType)(...)
Callback function pointer.
Definition: FFaSwitchBoard.H:40
#define FFASWB_MAKE_SLOTBASE_TEMPLATE(nr, templateDef, argumentList, typeList)
Macro that defines the different slotBaseN templates.
Definition: FFaSwitchBoard.H:210
The most basic slot class.
Definition: FFaSwitchBoard.H:117
bool addConnection(FFaSwitchBoardConnector *sender, int subject)
Definition: FFaSwitchBoard.C:336
SwbMap mySwitchBoardLookups
sender --> (subject,count)
Definition: FFaSwitchBoard.H:148
static int uniqueTypeId
Running counter to ensure unique Ids.
Definition: FFaSwitchBoard.H:141
bool removeConnection(FFaSwitchBoardConnector *sender, int subject)
Definition: FFaSwitchBoard.C:353
virtual ~FFaSlotBase()
The destructor removes this from the switchboard.
Definition: FFaSwitchBoard.C:323
virtual FFaSwitchBoardConnector * getObject()=0
virtual bool isStaticSlot() const =0
virtual anyMethodType getMethod()=0
unsigned int myTypeID
Class type Id of this slot.
Definition: FFaSwitchBoard.H:140
unsigned int getTypeID() const
Returns the myTypeID of this slot.
Definition: FFaSwitchBoard.H:127
bool IAmDeletingMe
Set to true during destruction.
Definition: FFaSwitchBoard.H:149
std::map< int, int > IntMap
Definition: FFaSwitchBoard.H:144
FFaSlotBase()
Default constructor.
Definition: FFaSwitchBoard.H:120
std::map< FFaSwitchBoardConnector *, IntMap > SwbMap
Convenience type alias, switchboard connection mapping.
Definition: FFaSwitchBoard.H:146
virtual bool operator==(FFaSlotBase &otherSlot)=0
Equality operator.
virtual anyFunctionType getFunction()=0
Base class for every class that want to send or recieve.
Definition: FFaSwitchBoard.H:83
std::set< FFaSlotBase * > mySlots
The slot container for this object.
Definition: FFaSwitchBoard.H:108
void setLabel(const char *s)
Definition: FFaSwitchBoard.H:105
const char * label
Label used for debug output.
Definition: FFaSwitchBoard.H:110
const char * getLabel() const
Definition: FFaSwitchBoard.H:104
void removeSlot(FFaSlotBase *slot)
Removes slot from mySlots.
Definition: FFaSwitchBoard.H:91
virtual ~FFaSwitchBoardConnector()
The destructor cleans up mySlots.
Definition: FFaSwitchBoard.C:310
FFaSwitchBoardConnector(const char *s=NULL)
Default constructor.
Definition: FFaSwitchBoard.C:300
bool IAmDeletingMe
Set to true during destruction.
Definition: FFaSwitchBoard.H:109
void addSlot(FFaSlotBase *slot)
Adds slot to mySlots.
Definition: FFaSwitchBoard.H:98
Static switchboard that holds the connection information.
Definition: FFaSwitchBoard.H:48
void disConnect(FFaSwitchBoardConnector *sender, int subject, FFaSlotBase *slot)
Removes slot from the switchboard.
Definition: FFaSwitchBoard.C:89
void removeSlotReference(FFaSwitchBoardConnector *sender, int subject, FFaSlotBase *slot)
Used by FFaSlotBase only.
Definition: FFaSwitchBoard.C:198
void removeInstance()
Cleans up the heap-allocated switchboard container.
Definition: FFaSwitchBoard.C:70
FFaSlotList::iterator nextValidSlot(FFaSlotList::iterator it, FFaSlotList &slots, FFaSwitchBoardConnector *sender, int subject)
Used internally by the switchboard mechanism classes.
Definition: FFaSwitchBoard.C:238
void removeAllOwnerConnections(FFaSwitchBoardConnector *owner)
Removes all slots connected to owener.
Definition: FFaSwitchBoard.C:149
FFaSlotList & getSlots(FFaSwitchBoardConnector *sender, int subject, unsigned int typeID)
Used internally in switchboard mechanism classes.
Definition: FFaSwitchBoard.C:214
void removeAllSenderConnections(FFaSwitchBoardConnector *sender)
Used by FFaSwitchBoardConnector only.
Definition: FFaSwitchBoard.C:112
void connect(FFaSwitchBoardConnector *sender, int subject, FFaSlotBase *slot)
Adds a new slot to the switchboard.
Definition: FFaSwitchBoard.C:77
A slot pointer with reference counting.
Definition: FFaSwitchBoard.H:31
short int refCount
Number of references to this slot.
Definition: FFaSwitchBoard.H:33
FFaSlotBase * slotPt
Pointer to the actial slot.
Definition: FFaSwitchBoard.H:32