thepeg
is hosted by
Hepforge
,
IPPP Durham
ThePEG
2.3.0
Utilities
Current.h
1
// -*- C++ -*-
2
//
3
// Current.h is a part of ThePEG - Toolkit for HEP Event Generation
4
// Copyright (C) 1999-2019 Leif Lonnblad
5
//
6
// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8
//
9
#ifndef ThePEG_Current_H
10
#define ThePEG_Current_H
11
// This is the declaration of the Current class.
12
13
namespace
ThePEG
{
14
38
template
<
typename
T>
39
class
Current
{
40
41
public
:
42
46
Current
() :
pushed
(false) {}
47
51
Current
(
const
Current<T>
&)
52
:
pushed
(false) {}
53
59
Current
(T * t) :
pushed
(false) {
60
if
( t ) {
61
theStack
.push_back(t);
62
pushed
=
true
;
63
}
64
}
65
70
~Current
() {
71
if
(
pushed
)
theStack
.pop_back();
72
}
73
74
public
:
75
79
static
bool
isVoid
() {
80
return
theStack
.empty() || !(
theStack
.back());
81
}
82
86
static
T &
current
() {
87
return
*
theStack
.back();
88
}
89
93
T &
operator*
()
const
{
94
return
*
theStack
.back();
95
}
96
100
T *
operator->
()
const
{
101
return
theStack
.back();
102
}
103
107
static
T *
ptr
() {
108
return
theStack
.back();
109
}
110
114
operator
bool()
const
{
115
return
ptr
();
116
}
117
121
bool
operator!
()
const
{
122
return
!
ptr
();
123
}
124
125
private
:
126
130
static
vector<T *>
theStack
;
131
136
bool
pushed
;
137
138
private
:
139
143
Current<T>
&
operator=
(
const
Current<T>
&) =
delete
;
144
145
};
146
147
template
<
typename
T>
148
std::vector<T *>
ThePEG::Current<T>::theStack
;
149
150
}
151
152
#endif
/* ThePEG_Current_H */
ThePEG::Current
The Current class keeps a static stack of objects of the templated class, which can be used anywhere ...
Definition:
Current.h:39
ThePEG::Current::operator*
T & operator*() const
Return a reference to the currently chosen object.
Definition:
Current.h:93
ThePEG::Current::~Current
~Current()
The destructor removing the object specified in the constructor from the stack.
Definition:
Current.h:70
ThePEG::Current::theStack
static vector< T * > theStack
The stack of objects requested.
Definition:
Current.h:130
ThePEG::Current::isVoid
static bool isVoid()
Returns true if there is no currently chosen object.
Definition:
Current.h:79
ThePEG::Current::current
static T & current()
Return a reference to the currently chosen object.
Definition:
Current.h:86
ThePEG::Current::operator=
Current< T > & operator=(const Current< T > &)=delete
Private and non-existent assignment operator.
ThePEG::Current::pushed
bool pushed
True if this object is responsible for pushing an object onto the stack.
Definition:
Current.h:136
ThePEG::Current::operator!
bool operator!() const
Test for existance.
Definition:
Current.h:121
ThePEG::Current::Current
Current(T *t)
Construct a new object specifying a new object, o, to be used during this objects lifetime.
Definition:
Current.h:59
ThePEG::Current::Current
Current()
Default constructor does nothing.
Definition:
Current.h:46
ThePEG::Current::ptr
static T * ptr()
Pointer to the stack.
Definition:
Current.h:107
ThePEG::Current::Current
Current(const Current< T > &)
Copy-constructor does nothing.
Definition:
Current.h:51
ThePEG::Current::operator->
T * operator->() const
Return a pointer to the currently chosen object.
Definition:
Current.h:100
ThePEG
This is the main namespace within which all identifiers in ThePEG are declared.
Definition:
FactoryBase.h:28
Generated on Thu Jun 20 2024 14:47:02 for ThePEG by
1.9.6