thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
ThePEG::Current< T > Class Template Reference

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.
 

Detailed Description

template<typename T>
class ThePEG::Current< T >

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();.

Definition at line 39 of file Current.h.

Constructor & Destructor Documentation

◆ Current() [1/3]

template<typename T >
ThePEG::Current< T >::Current ( )
inline

Default constructor does nothing.

Definition at line 46 of file Current.h.

◆ Current() [2/3]

template<typename T >
ThePEG::Current< T >::Current ( const Current< T > &  )
inline

Copy-constructor does nothing.

Definition at line 51 of file Current.h.

◆ Current() [3/3]

template<typename T >
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.

◆ ~Current()

template<typename T >
ThePEG::Current< T >::~Current ( )
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.

Member Function Documentation

◆ current()

template<typename T >
static T & ThePEG::Current< T >::current ( )
inlinestatic

Return a reference to the currently chosen object.

Definition at line 86 of file Current.h.

References ThePEG::Current< T >::theStack.

◆ isVoid()

template<typename T >
static bool ThePEG::Current< T >::isVoid ( )
inlinestatic

Returns true if there is no currently chosen object.

Definition at line 79 of file Current.h.

References ThePEG::Current< T >::theStack.

◆ operator bool()

template<typename T >
ThePEG::Current< T >::operator bool ( ) const
inline

Test for existance.

Definition at line 114 of file Current.h.

References ThePEG::Current< T >::ptr().

◆ operator!()

template<typename T >
bool ThePEG::Current< T >::operator! ( ) const
inline

Test for existance.

Definition at line 121 of file Current.h.

References ThePEG::Current< T >::ptr().

◆ operator*()

template<typename T >
T & ThePEG::Current< T >::operator* ( ) const
inline

Return a reference to the currently chosen object.

Definition at line 93 of file Current.h.

References ThePEG::Current< T >::theStack.

◆ operator->()

template<typename T >
T * ThePEG::Current< T >::operator-> ( ) const
inline

Return a pointer to the currently chosen object.

Definition at line 100 of file Current.h.

References ThePEG::Current< T >::theStack.

◆ ptr()

template<typename T >
static T * ThePEG::Current< T >::ptr ( )
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!().

Member Data Documentation

◆ pushed

template<typename T >
bool ThePEG::Current< T >::pushed
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().

◆ theStack

template<typename T >
std::vector< T * > ThePEG::Current< T >::theStack
staticprivate

The documentation for this class was generated from the following file: