The Current class keeps a static stack of objects of the templated class, which can be used anywhere by any class. More...
#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 reference to the currently chosen object. | |
T * | operator-> () const |
Return a pointer to the currently chosen object. | |
operator bool () const | |
Test for existance. | |
bool | operator! () const |
Test for existance. | |
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. | |
static T * | ptr () |
Pointer to the stack. | |
Private Member Functions | |
Current< T > & | operator= (const Current< T > &)=delete |
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. | |
The Current class keeps a static stack of objects of the templated class, which can be used anywhere by any class.
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();
.
|
inline |
|
inline |
|
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.
|
inline |
The destructor removing the object specified in the constructor from the stack.
Definition at line 70 of file Current.h.
References ThePEG::Current< T >::pushed, and ThePEG::Current< T >::theStack.
|
inlinestatic |
Return a reference to the currently chosen object.
Definition at line 86 of file Current.h.
References ThePEG::Current< T >::theStack.
|
inlinestatic |
Returns true if there is no currently chosen object.
Definition at line 79 of file Current.h.
References ThePEG::Current< T >::theStack.
|
inline |
Test for existance.
Definition at line 114 of file Current.h.
References ThePEG::Current< T >::ptr().
|
inline |
Test for existance.
Definition at line 121 of file Current.h.
References ThePEG::Current< T >::ptr().
|
inline |
Return a reference to the currently chosen object.
Definition at line 93 of file Current.h.
References ThePEG::Current< T >::theStack.
|
inline |
Return a pointer to the currently chosen object.
Definition at line 100 of file Current.h.
References ThePEG::Current< T >::theStack.
|
inlinestatic |
Pointer to the stack.
Definition at line 107 of file Current.h.
References ThePEG::Current< T >::theStack.
Referenced by ThePEG::Current< T >::operator bool(), and ThePEG::Current< T >::operator!().
|
private |
True if this object is responsible for pushing an object onto the stack.
Definition at line 136 of file Current.h.
Referenced by ThePEG::Current< T >::Current(), and ThePEG::Current< T >::~Current().
|
staticprivate |
The stack of objects requested.
Definition at line 130 of file Current.h.
Referenced by ThePEG::Current< T >::current(), ThePEG::Current< T >::Current(), ThePEG::Current< T >::isVoid(), ThePEG::Current< T >::operator*(), ThePEG::Current< T >::operator->(), ThePEG::Current< T >::ptr(), and ThePEG::Current< T >::~Current().