The Gaudi Framework  master (37c0b60a)
PropertyValue.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef JOBOPTIONSVC_PROPERTY_VALUE_H_
12 #define JOBOPTIONSVC_PROPERTY_VALUE_H_
13 // ============================================================================
14 // Includes:
15 // ============================================================================
16 // STD & STL:
17 // ============================================================================
18 #include <map>
19 #include <stdexcept>
20 #include <string>
21 #include <variant>
22 #include <vector>
23 // ============================================================================
24 #include "Position.h"
25 // ============================================================================
26 namespace Gaudi {
27  namespace Parsers {
28  // ============================================================================
29  class PropertyValue final {
30  // ----------------------------------------------------------------------------
31  public:
34  using Value = std::variant<std::string, VectorOfStrings, MapOfStrings>;
35 
36  // ----------------------------------------------------------------------------
37  explicit PropertyValue( Value value, bool is_reference = false )
38  : value_( std::move( value ) ), is_reference_( is_reference ) {}
39  PropertyValue( Value value, const Position& position, bool is_reference = false )
40  : value_( std::move( value ) ), position_( position ), is_reference_( is_reference ) {}
41  // ----------------------------------------------------------------------------
42  const Position& position() const { return position_; }
43  // ----------------------------------------------------------------------------
44  std::string& String() { return std::get<std::string>( value_ ); }
45  const std::string& String() const { return std::get<std::string>( value_ ); }
46 
47  VectorOfStrings& Vector() { return std::get<VectorOfStrings>( value_ ); }
48  const VectorOfStrings& Vector() const { return std::get<VectorOfStrings>( value_ ); }
49 
50  MapOfStrings& Map() { return std::get<MapOfStrings>( value_ ); }
51  const MapOfStrings& Map() const { return std::get<MapOfStrings>( value_ ); }
52  // ----------------------------------------------------------------------------
53  std::string ToString() const;
54  bool HasPosition() const { return position_.Exists(); }
55  bool IsSimple() const;
56  bool IsVector() const;
57  bool IsMap() const;
58  bool IsReference() const { return is_reference_; };
59  // ----------------------------------------------------------------------------
60  // Operators:
61  // ----------------------------------------------------------------------------
62 
63  PropertyValue& operator+=( const PropertyValue& right );
64  const PropertyValue operator+( const PropertyValue& right );
65  PropertyValue& operator-=( const PropertyValue& right );
66  const PropertyValue operator-( const PropertyValue& right );
67  // bool operator == (const PropertyValue& right) const;
68  private:
72  // ----------------------------------------------------------------------------
73  }; // class PropertyValue
74  // ============================================================================
76  public:
79  return PropertyValueException( "Cannot apply +=/-= operation to left value." );
80  }
81 
83  return PropertyValueException( "Cannot apply +=/-= operation to right value." );
84  }
85  };
86 
88  public:
91  const Position& position() const { return position_; }
92 
94  return PositionalPropertyValueException( position, "Could not find property " + name + "." );
95  }
96 
98  const std::string& name ) {
99  return PositionalPropertyValueException( position, "Could not find property '" + name + "'." );
100  }
101 
103  return PositionalPropertyValueException( position, "Could not find unit '" + name + "'." );
104  }
105 
107 
108  private:
110  };
111  // ============================================================================
112  } // namespace Parsers
113 } // namespace Gaudi
114 // ============================================================================
115 #endif // JOBOPTIONSVC_PROPERTY_VALUE_H_
Gaudi::Parsers::PropertyValue::operator-=
PropertyValue & operator-=(const PropertyValue &right)
Definition: PropertyValue.cpp:51
precedence.message
message
Definition: precedence.py:19
std::string
STL class.
Gaudi::Parsers::PropertyValue::operator-
const PropertyValue operator-(const PropertyValue &right)
Definition: PropertyValue.cpp:69
Gaudi::Parsers::PropertyValue::Map
MapOfStrings & Map()
Definition: PropertyValue.h:50
Gaudi::Parsers::PropertyValue::ToString
std::string ToString() const
Definition: PropertyValue.cpp:73
Gaudi::Parsers::PropertyValue::HasPosition
bool HasPosition() const
Definition: PropertyValue.h:54
std::vector< std::string >
Gaudi::Parsers::PropertyValueException::PropertyValueException
PropertyValueException(const std::string &message)
Definition: PropertyValue.h:77
Gaudi::Parsers::PositionalPropertyValueException::~PositionalPropertyValueException
virtual ~PositionalPropertyValueException()
Definition: PropertyValue.h:106
Gaudi::Parsers::Position::Exists
bool Exists() const
Definition: Position.h:33
Gaudi::Parsers::PositionalPropertyValueException::CouldNotFind
static PositionalPropertyValueException CouldNotFind(const Position &position, const std::string &name)
Definition: PropertyValue.h:93
Gaudi::Parsers::PropertyValueException
Definition: PropertyValue.h:75
Gaudi::Parsers::PropertyValue
Definition: PropertyValue.h:29
Gaudi::Parsers::PropertyValueException::WrongRValue
static PropertyValueException WrongRValue()
Definition: PropertyValue.h:82
Gaudi::Parsers::PropertyValue::String
std::string & String()
Definition: PropertyValue.h:44
Gaudi::Parsers::PropertyValue::Map
const MapOfStrings & Map() const
Definition: PropertyValue.h:51
Gaudi::Parsers::PositionalPropertyValueException::CouldNotFindUnit
static PositionalPropertyValueException CouldNotFindUnit(const Position &position, const std::string &name)
Definition: PropertyValue.h:102
Gaudi::Parsers::PropertyValue::value_
Value value_
Definition: PropertyValue.h:69
Gaudi::Parsers::PropertyValue::IsVector
bool IsVector() const
Definition: PropertyValue.cpp:29
Gaudi::Parsers::Position
Definition: Position.h:23
Gaudi::Parsers::PropertyValue::Vector
const VectorOfStrings & Vector() const
Definition: PropertyValue.h:48
Gaudi::Parsers::PropertyValue::position_
Position position_
Definition: PropertyValue.h:70
Gaudi::Parsers::PositionalPropertyValueException::CouldNotFindProperty
static PositionalPropertyValueException CouldNotFindProperty(const Position &position, const std::string &name)
Definition: PropertyValue.h:97
Gaudi::Parsers::PropertyValue::PropertyValue
PropertyValue(Value value, const Position &position, bool is_reference=false)
Definition: PropertyValue.h:39
std::runtime_error
STL class.
std::map< std::string, std::string, std::less<> >
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
Position.h
Gaudi::Parsers::PropertyValue::IsMap
bool IsMap() const
Definition: PropertyValue.cpp:31
Gaudi::Parsers::PropertyValue::operator+=
PropertyValue & operator+=(const PropertyValue &right)
Definition: PropertyValue.cpp:33
Gaudi::Parsers::PropertyValue::IsReference
bool IsReference() const
Definition: PropertyValue.h:58
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
Gaudi::Parsers::PropertyValue::position
const Position & position() const
Definition: PropertyValue.h:42
std
STL namespace.
Gaudi::Parsers::PropertyValueException::WrongLValue
static PropertyValueException WrongLValue()
Definition: PropertyValue.h:78
Gaudi::Parsers::PositionalPropertyValueException
Definition: PropertyValue.h:87
Gaudi::Parsers::PropertyValue::IsSimple
bool IsSimple() const
Definition: PropertyValue.cpp:27
Gaudi::Parsers::PositionalPropertyValueException::position_
Position position_
Definition: PropertyValue.h:109
Gaudi::Parsers::PropertyValue::is_reference_
bool is_reference_
Definition: PropertyValue.h:71
Gaudi::Parsers::PropertyValue::operator+
const PropertyValue operator+(const PropertyValue &right)
Definition: PropertyValue.cpp:47
Gaudi::Parsers::PropertyValue::Vector
VectorOfStrings & Vector()
Definition: PropertyValue.h:47
Gaudi::Parsers::PropertyValue::Value
std::variant< std::string, VectorOfStrings, MapOfStrings > Value
Definition: PropertyValue.h:34
Gaudi::Parsers::PositionalPropertyValueException::position
const Position & position() const
Definition: PropertyValue.h:91
Gaudi::Parsers::PropertyValue::String
const std::string & String() const
Definition: PropertyValue.h:45
Gaudi::Parsers::PropertyValue::PropertyValue
PropertyValue(Value value, bool is_reference=false)
Definition: PropertyValue.h:37
Gaudi::Parsers::PositionalPropertyValueException::PositionalPropertyValueException
PositionalPropertyValueException(const Position &position, const std::string &message)
Definition: PropertyValue.h:89