#include <Current.h>
Public Member Functions | |
Current () | |
Default constructor does nothing. | |
Current (const Current< T > &) | |
Copy-constructor does nothing. | |
Current (T *t) | |
Construct a new object specifying a new object, o, to be used during this objects lifetime. | |
~Current () | |
The destructor removing the object specified in the constructor from the stack. | |
T * | operator-> () const |
Return a pointer to the currently chosen object. | |
Static Public Member Functions | |
static bool | isVoid () |
Returns true if there is no currently chosen object. | |
static T & | current () |
Return a reference to the currently chosen object. | |
Private Member Functions | |
Current< T > & | operator= (const Current< T > &) |
Private and non-existent assignment operator. | |
Private Attributes | |
bool | pushed |
True if this object is responsible for pushing an object onto the stack. | |
Static Private Attributes | |
static vector< T * > | theStack |
The stack of objects requested. |
When an object is active it adds itself to the stack which can be used by any other object through the static functions of the Current class. If someone needs to use an alternative object a new Current object can be constructed with a pointer to the desired object as argument and that object will the be used by the static Current functions until the Current object is destructed.
Default-contructed objects of the Current class can be used as a pointer to the currently chosen object on the stack.
The typical use case for this class is a handler class which uses a number of objects which do not have a reference back to the handler, but still need to acces some member functions. In a member function the handler class will construct a Current object: Current<Handler> current(this);
in any following function called in this member function, any object can then access the handlers methods as Current<Handler>()->memfun();
.
Definition at line 39 of file Current.h.
ThePEG::Current< T >::Current | ( | T * | t | ) | [inline] |
Construct a new object specifying a new object, o, to be used during this objects lifetime.
The object must not be deleted until the Current object us destroyed.
Definition at line 59 of file Current.h.
References ThePEG::Current< T >::pushed, and ThePEG::Current< T >::theStack.