FunctionBind.h
Go to the documentation of this file.
1 /*
2  * File: FunctionBind.h
3  * Author: denis
4  *
5  * Macros to bind boost::function to a function inside the class
6  * Due to boost::bind being picky about the names of the functions (or maybe it's a compiler's problem),
7  * we are going to bind to functions that have a name with the 1 at the end
8  *
9  * Created on January 24, 2012, 2:40 PM
10  */
11 
12 #ifndef FUNCTIONBIND_H
13 #define FUNCTIONBIND_H
14 
15 /// Delegate (or function pointer)
16 #define DELEGATE(CLASS,FUNC,OUTPUT,...) OUTPUT (CLASS::*FUNC) (__VA_ARGS__)
17 #define DELEGATEV(CLASS,FUNC,OUTPUT) DELEGATE(CLASS,FUNC,OUTPUT,)
18 
19 // Delegates for standard functions: init, sizeofdata, print, readData, setBufferSource, resetBufferSource
20 // Have to intput the name of the delegate
21 #define Init_t(FUNC) DELEGATEV(RawDAQData, FUNC, void )
22 #define Sizeofdata_t(FUNC) DELEGATEV(RawDAQData, FUNC, uint32_t) const
23 #define Print_t(FUNC) DELEGATE(RawDAQData, FUNC, void , std::ostream&) const
24 #define ReadData_t(FUNC) DELEGATE(RawDAQData, FUNC, void* , const void* )
25 #define SetBufferSource_t(FUNC) DELEGATE(RawDAQData, FUNC, bool , const void* )
26 #define ResetBufferSource_t(FUNC) DELEGATEV(RawDAQData, FUNC, bool )
27 
28 // No input name
29 #define init_t Init_t()
30 #define sizeofdata_t Sizeofdata_t()
31 #define print_t Print_t()
32 #define readData_t ReadData_t()
33 #define setBufferSource_t SetBufferSource_t()
34 #define resetBufferSource_t ResetBufferSource_t()
35 
36 /// Macro to execute the function given a function pointer
37 #define EXECUTE_GENERAL_FUNCTION(FULLFUNCTIONNAME) (this->*FULLFUNCTIONNAME)
38 
39 // These macros are used in a deep copy of delegates
40 #define DEEPCOPY_FUNCTION(FUNC) _function_##FUNC(copyin._function_##FUNC)
41 #define DEEPCOPY_GET(FUNC) DEEPCOPY_FUNCTION(get##FUNC)
42 #define DEEPCOPY_IS(FUNC) DEEPCOPY_FUNCTION(is##FUNC)
43 #define DEEPCOPY_SET(FUNC) DEEPCOPY_FUNCTION(set##FUNC)
44 #define DEEPCOPY_GET_AND_SET(FUNC)\
45  DEEPCOPY_GET(FUNC)\
46  ,DEEPCOPY_SET(FUNC)
47 #define DEEPCOPY_IS_AND_SET(FUNC)\
48  DEEPCOPY_IS(FUNC)\
49  ,DEEPCOPY_SET(FUNC)
50 
51 // These methods are used for zeroing out delegates
52 #define ZEROOUT_FUNCTION(FUNC) _function_##FUNC(NULL)
53 #define ZEROOUT_GET(FUNC) ZEROOUT_FUNCTION(get##FUNC)
54 #define ZEROOUT_IS(FUNC) ZEROOUT_FUNCTION(is##FUNC)
55 #define ZEROOUT_SET(FUNC) ZEROOUT_FUNCTION(set##FUNC)
56 #define ZEROOUT_GET_AND_SET(FUNC)\
57  ZEROOUT_GET(FUNC)\
58  ,ZEROOUT_SET(FUNC)
59 #define ZEROOUT_IS_AND_SET(FUNC)\
60  ZEROOUT_IS(FUNC)\
61  ,ZEROOUT_SET(FUNC)
62 
63 
64 #endif /* FUNCTIONBIND_H */