gusimplewhiteboard
WBFunctor.h
Go to the documentation of this file.
1/* MiPAL 2010
2Author: Tyrone Trevorrow, Carl Lusty, and Rene Hexel
3Purpose: Provides a more generic mechanism for function callbacks.
4 Feel free to extend this to support any function's parameter lists.
5 Change Log:
6 21/1/2013 - Extended to add simple wb compatability, Carl.
7*/
8
9#ifndef WB_W_B_FUNCTOR_H
10#define WB_W_B_FUNCTOR_H
11
12#ifdef bool
13#undef bool
14#endif
15
16#ifdef true
17#undef true
18#undef false
19#endif
20
21#pragma clang diagnostic push
22#pragma clang diagnostic ignored "-Wweak-vtables"
23#pragma clang diagnostic ignored "-Wpadded"
24
25#include <string>
26#include <gu_util.h>
27
28#include "WBMsg.h"
29#include "guwhiteboardtypelist_generated.h" //for type enum
30#include "gusimplewhiteboard.h" //for gu_simple_message
31
32#define WB_BIND( f ) createWBFunctor(this, &f)
33#define WB_TYPE_BIND( t, f ) createWBFunctor(this, &f, t)
34
41{
42public:
48 virtual void call(std::string s, WBMsg* m) = 0; //old wbmsg format for callbacks
49
54 virtual void call(gu_simple_message* m) = 0; //new simple_message callbacks
55
61 virtual void call(guWhiteboard::wb_types t, gu_simple_message* m) = 0; //new simple_message callbacks (with type overwrite for subscribe to all special type)
62
65
67 virtual uint16_t get_event_count() = 0;
68
73 virtual void set_event_count(uint16_t e) = 0;
74
76 virtual bool is_simple_wb_version() = 0;
77
79 virtual ~WBFunctorBase(){}
80};
81
87template <typename C>
89{
90public:
94 WBFunctor(C* obj, void (C::*pFunc) (std::string, WBMsg*)):
95 fObject(obj), fFunction(pFunc), simple_wb_version(false) { }
96
101 fObject(obj), s_fFunction(pFunc), type_enum(t), event_count(0), simple_wb_version(true) { }
102
108 void call(std::string s, WBMsg* m) OVERRIDE
109 {
110 (fObject->*fFunction)(s,m);
111 }
112
117 void call(gu_simple_message* m) OVERRIDE
118 {
120 }
121
128 {
129 (fObject->*s_fFunction)(t, m);
130 }
131
133 guWhiteboard::wb_types type() OVERRIDE { return type_enum; }
134
136 uint16_t get_event_count() OVERRIDE { return event_count; }
137
142 void set_event_count(uint16_t e) OVERRIDE { event_count = e; }
143
145 bool is_simple_wb_version() OVERRIDE { return simple_wb_version; }
146
148 typedef void (C::*s_func) (guWhiteboard::wb_types, gu_simple_message*); //simple wb implementation
149
152
153protected:
155 typedef void (C::*func) (std::string, WBMsg*);
159 uint16_t event_count;
161};
162
163template <typename C>
164WBFunctorBase* createWBFunctor(C *obj, void (C::*f) (std::string, WBMsg*))
165{
166 return new WBFunctor<C>(obj, f);
167}
168template <typename C>
170{
171 return new WBFunctor<C>(obj, f, t);
172}
173
174
175
176#pragma clang diagnostic pop
177
179
180#endif //WB_W_B_FUNCTOR_H
WBFunctorBase * createWBFunctor(C *obj, void(C::*f)(std::string, WBMsg *))
Definition: WBFunctor.h:164
Base class for WBFunctor.
Definition: WBFunctor.h:41
virtual void call(guWhiteboard::wb_types t, gu_simple_message *m)=0
Call method for the 'simple' whiteboard aka 'typed whiteboard' callbacks that passes data around in a...
virtual void call(std::string s, WBMsg *m)=0
Call method for the OLD whiteboard callbacks that used WBMsg - Deprecated.
virtual ~WBFunctorBase()
destructor
Definition: WBFunctor.h:79
virtual guWhiteboard::wb_types type()=0
getter for the WB type
virtual uint16_t get_event_count()=0
getter for the WB event counter
virtual void set_event_count(uint16_t e)=0
setter for the WB event counter
virtual void call(gu_simple_message *m)=0
Call method for the 'simple' whiteboard aka 'typed whiteboard' callbacks that passes data around in a...
virtual bool is_simple_wb_version()=0
is this being used by the 'simple whiteboard' or the OLD whiteboard (which is now Deprecated)
WBFunctor callback manager class.
Definition: WBFunctor.h:89
uint16_t event_count
the event counter
Definition: WBFunctor.h:159
void(C::* s_func)(guWhiteboard::wb_types, gu_simple_message *)
function prototype for the new 'simple whiteboard' callbacks
Definition: WBFunctor.h:148
WBFunctor(C *obj, void(C::*pFunc)(guWhiteboard::wb_types, gu_simple_message *), guWhiteboard::wb_types t)
WBFunctor Constructor.
Definition: WBFunctor.h:100
uint16_t get_event_count() OVERRIDE
getter for the WB event counter
Definition: WBFunctor.h:136
void(C::* func)(std::string, WBMsg *)
OLD function prototype (which is now Deprecated)
Definition: WBFunctor.h:155
bool simple_wb_version
flag, is this a 'simple' whiteboard usage of WBFunctor
Definition: WBFunctor.h:160
s_func get_s_func_ptr()
getter
Definition: WBFunctor.h:151
func fFunction
OLD function object.
Definition: WBFunctor.h:156
C * fObject
ptr to call containing the callback method
Definition: WBFunctor.h:154
bool is_simple_wb_version() OVERRIDE
is this being used by the 'simple whiteboard' or the OLD whiteboard (which is now Deprecated)
Definition: WBFunctor.h:145
WBFunctor(C *obj, void(C::*pFunc)(std::string, WBMsg *))
WBFunctor Constructor.
Definition: WBFunctor.h:94
void set_event_count(uint16_t e) OVERRIDE
setter for the WB event counter
Definition: WBFunctor.h:142
guWhiteboard::wb_types type() OVERRIDE
getter for the WB type
Definition: WBFunctor.h:133
guWhiteboard::wb_types type_enum
'simple' whiteboard types
Definition: WBFunctor.h:158
void call(guWhiteboard::wb_types t, gu_simple_message *m) OVERRIDE
Call method for the 'simple' whiteboard aka 'typed whiteboard' callbacks that passes data around in a...
Definition: WBFunctor.h:127
void call(gu_simple_message *m) OVERRIDE
Call method for the 'simple' whiteboard aka 'typed whiteboard' callbacks that passes data around in a...
Definition: WBFunctor.h:117
s_func s_fFunction
'simple' function object
Definition: WBFunctor.h:157
void call(std::string s, WBMsg *m) OVERRIDE
Call method for the OLD whiteboard callbacks that used WBMsg - Deprecated.
Definition: WBFunctor.h:108
Old WB class for storing shared data.
Definition: WBMsg.h:86
typedef::wb_types wb_types
union type that is used to store data in shared memory