ATLAS Offline Software
Loading...
Searching...
No Matches
StackElement.h
Go to the documentation of this file.
1// Dear emacs, this is -*- c++ -*-
2
3/*
4 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5*/
6
7// $Id$
8#ifndef EXPRESSIONEVALUATION_STACKELEMENT_H
9#define EXPRESSIONEVALUATION_STACKELEMENT_H
10
11// System include(s):
12#include <iosfwd>
13#include <vector>
14#include <string>
15#include <atomic>
16
17// Local include(s):
19
30namespace ExpressionParsing {
31
32 // Forward declaration(s):
33 class IProxyLoader;
34
51
53 friend std::ostream& operator<<( std::ostream& os,
54 const StackElement& el );
55
56 public:
65
68
72 StackElement( unsigned int val ) : m_type( SE_INT ), m_intVal(static_cast<unsigned int>(val)) {}
74 StackElement( int val ) : m_type( SE_INT ), m_intVal(val) {}
76 StackElement( double val ) : m_type( SE_DOUBLE ), m_doubleVal( val ) {}
78 StackElement( const std::vector< int >& val ) : m_type( SE_VECINT ), m_vecIntVal(val) {}
80 StackElement( const std::vector< double >& val ) : m_type( SE_VECDOUBLE ), m_vecDoubleVal( val ) {}
82 StackElement( std::vector< int >&& val ) : m_type( SE_VECINT ), m_vecIntVal(std::move(val)) {}
84 StackElement( std::vector< double >&& val ) : m_type( SE_VECDOUBLE ), m_vecDoubleVal( std::move(val) ) {}
86 StackElement( const std::string& val, IProxyLoader* proxyLoader ) : /*m_type( SE_UNK ), */m_varName( val ), m_proxyLoader( proxyLoader ) {}
87;
91
94
96 StackElement& operator=( int rhs );
98 StackElement& operator=( double rhs );
100 StackElement& operator=( const std::vector< int >& rhs );
102 StackElement& operator=( const std::vector< double >& rhs );
104 StackElement& operator=( std::vector< int >&& rhs );
106 StackElement& operator=( std::vector< double >&& rhs );
107
110
113
118
120
123
126 template< typename T >
127 StackElement& operator-=( const T& rhs );
129 template< typename T >
130 StackElement& operator-=( const std::vector< T >& rhs );
133 template< typename T >
134 StackElement& operator+=( const T& rhs );
136 template< typename T >
137 StackElement& operator+=( const std::vector< T >& rhs );
140 template< typename T >
141 StackElement& operator*=( const T& rhs );
143 template< typename T >
144 StackElement& operator*=( const std::vector< T >& rhs );
147 template< typename T >
148 StackElement& operator/=( const T& rhs );
150 template< typename T >
151 StackElement& operator/=( const std::vector< T >& rhs );
152
155 template< typename T >
156 StackElement operator-( const T& rhs );
159 template< typename T >
160 StackElement operator+( const T& rhs );
163 template< typename T >
164 StackElement operator*( const T& rhs );
167 template< typename T >
168 StackElement operator/( const T& rhs );
169
171
174
176 ElementType getType() const;
178 bool isScalar() const;
180 bool isVector() const;
182 bool isProxy() const;
183
184 const std::string& proxyVarName() const { return m_varName; }
185
187 int asInt() const;
189 bool asBool() const;
190
192 template< typename T >
193 T scalarValue() const;
195 template< typename T >
196 std::vector< T > vectorValue( std::size_t sizeIfScalar = 0 );
197
199
202
205 void makeInt();
208 void makeDouble();
210 void makeVector( std::size_t n );
211
215
218 private:
219 template <class T_CompHelper>
220 StackElement _comparisonOp(StackElement &other, T_CompHelper comp_helper);
221 public:
230
232
235
237 template< typename T >
238 StackElement _pow( const T& n );
277
279
280 private:
283
284 void makeVectorIfNecessary( const StackElement& other );
285 void makeVectorIfNecessary( const std::vector< int >& other );
286 void makeVectorIfNecessary( const std::vector< double >& other );
287
288 void makeDoubleIfNecessary( const StackElement& other );
289 void makeDoubleIfNecessary( int other );
290 void makeDoubleIfNecessary( double other );
291 void makeDoubleIfNecessary( const std::vector< int >& other );
292 void makeDoubleIfNecessary( const std::vector< double >& other );
293
294 void ensureCompatible( const StackElement& other ) const;
295 template< typename T >
296 void ensureCompatibleVectors( const T& other ) const;
297 template< typename T >
298 void ensureCompatibleVectors( const std::vector< T >& other ) const;
299
300 size_t size() const;
302
305
307 int m_intVal = 0;
309 double m_doubleVal = 0.;
311 std::vector< int > m_vecIntVal;
313 std::vector< double > m_vecDoubleVal;
314
316 std::string m_varName;
320 mutable std::atomic<IProxyLoader::VariableType> m_variableType = IProxyLoader::VT_UNK;
323 mutable std::atomic<bool> m_determinedVariableType = false;
324 mutable std::atomic<bool> m_moved = false;
325
326 }; // class StackElement
327
329 std::ostream& operator<<( std::ostream& os, const StackElement& el );
330
331} // namespace ExpressionParsing
332
335
336#endif // EXPRESSIONEVALUATION_STACKELEMENT_H
static Double_t a
Class describing a single element in a text expression.
std::string m_varName
The name/definition of the variable.
int asInt() const
Get the internal value of the object as an integer.
bool isVector() const
Check if the object describes a vector value.
IProxyLoader * m_proxyLoader
Loader for the described variable.
StackElement operator+(StackElement &rhs)
Operator adding a value to the object.
StackElement _atanh()
Function taking the arc tangent hyperbolic value of the object.
std::vector< double > m_vecDoubleVal
The value of the object represented as a vector of doubles.
std::vector< T > vectorValue(std::size_t sizeIfScalar=0)
Evaluate the value of the object into the requested vector type.
StackElement & operator-=(const T &rhs)
StackElement _cos()
Function taking the cosine value of the object.
StackElement _gt(StackElement &other)
StackElement _acosh()
Function taking the arc cosine hyperbolic value of the object.
void makeDouble()
Function constructing internal double values in case integer values were given to the object initiall...
StackElement(double val)
Constructor creating the object with a double value.
StackElement _comparisonOp(StackElement &other, T_CompHelper comp_helper)
StackElement operator!()
NOT operator.
StackElement(const StackElement &a)
bool isProxy() const
Check if the object takes its value from a StoreGate object.
StackElement _tan()
Function taking the tangent value of the object.
StackElement _lt(StackElement &other)
StackElement operator*(const T &rhs)
StackElement & operator=(int rhs)
Operator assigning an integer value to the object.
StackElement _asin()
Function taking the arc sinus value of the object.
StackElement operator-(const T &rhs)
StackElement _pow(const T &n)
Function raising the object's value to the n'th power.
bool asBool() const
Get the internal value of the object as a boolean.
StackElement & operator*=(StackElement &rhs)
Multiply the object by a scalar type.
StackElement & operator-=(const std::vector< T > &rhs)
Subtract a vector type from the object.
StackElement & operator+=(StackElement &rhs)
Add a scalar type to the object.
StackElement operator/(StackElement &rhs)
Operator dividing the object by a value.
StackElement & operator*=(const std::vector< T > &rhs)
Multiply the object by a vector type.
StackElement operator-(StackElement &rhs)
Operator subtracting a value from the object.
T scalarValue() const
Evaluate the value of the object into the requested scalar type.
StackElement _eq(StackElement &other)
bool isScalar() const
Check if the object describes a scalar value.
ElementType
Type of the data held by this object.
@ SE_UNK
The type is not known, or not applicable.
@ SE_INT
The type is an integer.
@ SE_DOUBLE
The type is a double.
@ SE_VECINT
The type is a vector of integers.
@ SE_VECDOUBLE
The type is a vector of doubles.
friend std::ostream & operator<<(std::ostream &os, const StackElement &el)
Declare the print operator as a friend of the class.
StackElement _asinh()
Function taking the arc sinus hyperbolic value of the object.
StackElement & operator-=(StackElement &rhs)
Subtract a scalar type from the object.
StackElement(unsigned int val)
Constructor creating the object with an unsigned integer value.
StackElement operator/(const T &rhs)
void makeVectorIfNecessary(const StackElement &other)
The macro is not needed anymore:
StackElement _neq(StackElement &other)
StackElement _abs()
Function taking the absolute value of the object.
StackElement _or(StackElement &other)
StackElement(int val)
Constructor creating the object with a signed integer value.
StackElement _and(StackElement &other)
StackElement & operator=(StackElement &&rhs)
StackElement & operator+=(const std::vector< T > &rhs)
Add a vector type to the object.
StackElement(const std::vector< int > &val)
Constructor creating the object with a vector of integers value.
StackElement(const std::vector< double > &val)
Constructor creating the object with a vector of doubles value.
StackElement _tanh()
Function taking the tangent hyperbolic value of the object.
StackElement _sqrt()
Function taking the square root of the object.
StackElement _sum()
Function calculating a sum value.
StackElement operator*(StackElement &rhs)
Operator multiplying the object by a value.
void ensureCompatibleVectors(const T &other) const
StackElement _cosh()
Function taking the cosine hyperbolic value of the object.
StackElement _atan()
Function taking the arc tangent value of the object.
ElementType m_type
The type of the variable held by the object.
StackElement & operator*=(const T &rhs)
StackElement _sin()
Function taking the sinus value of the object.
StackElement(StackElement &&a)
StackElement _acos()
Function taking the arc cosine value of the object.
StackElement _cbrt()
Function taking the cubic root of the object.
int m_intVal
The value of the object represented as an integer.
StackElement(std::vector< int > &&val)
Constructor creating the object with a vector of integers value.
StackElement valueFromProxy() const
Set the internal variables of the object based on the objects in SG.
StackElement _exp()
Function taking the natural exponent of the object.
StackElement operator-()
Inverse operator.
void makeVector(std::size_t n)
Function converting a possibly scalar value into a vector.
StackElement _count()
Function counting elements.
ElementType getType() const
Get the variable type of the object.
StackElement(const std::string &val, IProxyLoader *proxyLoader)
Constructor creating the object from a text expression.
StackElement _log()
Function taking the logarithm of the object.
StackElement & operator/=(StackElement &rhs)
Divide the object by a scalar type.
StackElement()
Default constructor.
StackElement _sinh()
Function taking the sinus hyperbolic value of the object.
void ensureCompatibleVectors(const std::vector< T > &other) const
void ensureCompatible(const StackElement &other) const
std::atomic< bool > m_determinedVariableType
Internal flag showing whether the type of the variable was already determined.
StackElement & operator/=(const std::vector< T > &rhs)
Divide the object by a vector type.
const std::string & proxyVarName() const
std::vector< int > m_vecIntVal
The value of the object represented as a vector of integers.
StackElement & operator+=(const T &rhs)
StackElement _gte(StackElement &other)
StackElement(std::vector< double > &&val)
Constructor creating the object with a vector of doubles value.
StackElement & operator/=(const T &rhs)
void makeInt()
Function constructing internal integer values in case double values were given to the object initiall...
double m_doubleVal
The value of the object represented as a double.
std::atomic< IProxyLoader::VariableType > m_variableType
Type of the variable provided by the proxy loader.
void makeDoubleIfNecessary(const StackElement &other)
StackElement _lte(StackElement &other)
StackElement operator+(const T &rhs)
Namespace holding all the expression evaluation code.
std::ostream & operator<<(std::ostream &os, const StackElement &el)
Declare an output operator for StackElement objects.
STL namespace.