#include <BLUserCode.hh>
See the section in the User's Guide titled "User Code for various commands".
This is used as follows: a G4beamline command that needs to call user-supplied code will have a name, and it will expect all user-supplied code to arrange so getType() returns that name. The G4beamline author will write a class BLUserXXX that is derived from BLUserCode and implements getType() with the correct value -- so users should NOT override this function. Usually this class declaration will be put into this file. BLUserXXX will also define some additional virtual function(s) for the user to implement, appropriate to the function to be performed. The user must implement these functions and getName(). There's one other requirement: the user class must call registerUserCode() at the end of its default constructor, and must define a static instance of the class using that constructor -- this provides linkage into G4beamline so that the underlying command can find and call the user code.
The user code should be compiled into a shared object, using the g4blmake command. The G4beamline input file should use the "load" command to load the shared object BEFORE any command references the user class. NOTE: the "load" command uses the filename built by g4blmake; the other command(s) use the getName() implemented by the user class. Multiple instances of user code can be put into a single .cc file (or multiple .cc files linked into one shared object); they must each have a unique getName() return value.
NOTE: this class will interface between shared objects, so no inline function can reference any static data member. This does NOT apply to user-supplied derived classes that necessarily reside in a single shared object.
Public Member Functions | |
BLUserCode () | |
Constructor. | |
virtual | ~BLUserCode () |
Destructor. | |
void | registerUserCode () |
registerUserCode() -- register this instance with the BLManager so other commands can find it. Note that every final derived class must call this at the end of its default constructor, and must define a static object using that constructor. | |
virtual const char * | getType ()=0 |
Name of the type -- MUST be overridden in derived classes that define an interface to user code from a G4beamline command. | |
virtual const char * | getName ()=0 |
Name of the instance -- MUST be overridden in user-supplied derived classes. | |
Static Private Attributes | |
static std::vector< BLUserCode * > * | list |
void BLUserCode::registerUserCode | ( | ) |
registerUserCode() -- register this instance with the BLManager so other commands can find it. Note that every final derived class must call this at the end of its default constructor, and must define a static object using that constructor.
References BLManager::getObject(), and BLManager::registerUserCode().
00025 { 00026 BLManager::getObject()->registerUserCode(this); 00027 }
virtual const char* BLUserCode::getType | ( | ) | [pure virtual] |
Name of the type -- MUST be overridden in derived classes that define an interface to user code from a G4beamline command.
Implemented in BLUserTrackFilter.
virtual const char* BLUserCode::getName | ( | ) | [pure virtual] |
Name of the instance -- MUST be overridden in user-supplied derived classes.
Implemented in BLUserTrackFilter.
std::vector<BLUserCode*>* BLUserCode::list [static, private] |