ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/L1Menu/interface/l1menu/RegisterTriggerMacro.h
Revision: 1.2
Committed: Tue May 28 23:14:01 2013 UTC (11 years, 11 months ago) by grimes
Content type: text/plain
Branch: MAIN
Changes since 1.1: +21 -5 lines
Log Message:
Numerous changes

File Contents

# User Rev Content
1 grimes 1.1 #ifndef l1menu_RegisterTriggerMacro_h
2     #define l1menu_RegisterTriggerMacro_h
3    
4     #include "l1menu/TriggerTable.h"
5    
6 grimes 1.2 /* Macro that registers the ITrigger subclass named in the trigger table.
7     *
8     * This macro works by creating a new class called <triggername>Factory that calls TriggerTable::registerTrigger()
9     * in its constructor. It also has a static method that creates an instance of the ITrigger subclass, this is the
10     * function pointer that is supplied to the TriggerTable.
11     *
12     * A single instance of the <triggername>Factory is instantiated at global scope (within whatever namespace the
13     * macro was called in) so that the trigger will be registered before control passes to main, or whatever the user
14     * entry point is.
15     */
16     #define DEFINE_TRIGGER_FACTORY( NAME ) class NAME##Factory \
17 grimes 1.1 { \
18     public: \
19 grimes 1.2 NAME##Factory( void (*pFunction)()=NULL ) \
20 grimes 1.1 { \
21     NAME temporaryInstance; \
22 grimes 1.2 TriggerTable::instance().registerTrigger( temporaryInstance.name(), temporaryInstance.version(), (&this->createTrigger) ); \
23     if( pFunction ) (*pFunction)(); \
24 grimes 1.1 } \
25 grimes 1.2 static std::unique_ptr<l1menu::ITrigger> createTrigger() \
26 grimes 1.1 { \
27 grimes 1.2 return std::unique_ptr<l1menu::ITrigger>(new NAME); \
28 grimes 1.1 } \
29     }; \
30 grimes 1.2
31     #define REGISTER_TRIGGER( NAME ) DEFINE_TRIGGER_FACTORY( NAME ) \
32 grimes 1.1 NAME##Factory NAME##FactoryOnlyInstance;
33    
34 grimes 1.2 #define REGISTER_TRIGGER_AND_CUSTOMISE( NAME, CUSTOM_FUNCTION_POINTER ) DEFINE_TRIGGER_FACTORY( NAME ) \
35     NAME##Factory NAME##FactoryOnlyInstance( CUSTOM_FUNCTION_POINTER );
36    
37 grimes 1.1 #endif