The Gaudi Framework  v32r2 (46d42edc)
PropertyValue.h
Go to the documentation of this file.
1 #ifndef JOBOPTIONSVC_PROPERTY_VALUE_H_
2 #define JOBOPTIONSVC_PROPERTY_VALUE_H_
3 // ============================================================================
4 // Includes:
5 // ============================================================================
6 // STD & STL:
7 // ============================================================================
8 #include <map>
9 #include <stdexcept>
10 #include <string>
11 #include <variant>
12 #include <vector>
13 // ============================================================================
14 #include "Position.h"
15 // ============================================================================
16 namespace Gaudi {
17  namespace Parsers {
18  // ============================================================================
19  class PropertyValue final {
20  // ----------------------------------------------------------------------------
21  public:
22  typedef std::variant<std::string, std::vector<std::string>, std::map<std::string, std::string>> Value;
25 
26  // ----------------------------------------------------------------------------
27  explicit PropertyValue( Value value, bool is_reference = false )
28  : value_( std::move( value ) ), is_reference_( is_reference ) {}
29  PropertyValue( Value value, const Position& position, bool is_reference = false )
30  : value_( std::move( value ) ), position_( position ), is_reference_( is_reference ) {}
31  // ----------------------------------------------------------------------------
32  const Position& position() const { return position_; }
33  // ----------------------------------------------------------------------------
34  std::string& String() { return std::get<std::string>( value_ ); }
35  const std::string& String() const { return std::get<std::string>( value_ ); }
36 
37  VectorOfStrings& Vector() { return std::get<VectorOfStrings>( value_ ); }
38  const VectorOfStrings& Vector() const { return std::get<VectorOfStrings>( value_ ); }
39 
40  MapOfStrings& Map() { return std::get<MapOfStrings>( value_ ); }
41  const MapOfStrings& Map() const { return std::get<MapOfStrings>( value_ ); }
42  // ----------------------------------------------------------------------------
43  std::string ToString() const;
44  bool HasPosition() const { return position_.Exists(); }
45  bool IsSimple() const;
46  bool IsVector() const;
47  bool IsMap() const;
48  bool IsReference() const { return is_reference_; };
49  // ----------------------------------------------------------------------------
50  // Operators:
51  // ----------------------------------------------------------------------------
52 
53  PropertyValue& operator+=( const PropertyValue& right );
54  const PropertyValue operator+( const PropertyValue& right );
55  PropertyValue& operator-=( const PropertyValue& right );
56  const PropertyValue operator-( const PropertyValue& right );
57  // bool operator == (const PropertyValue& right) const;
58  private:
62  // ----------------------------------------------------------------------------
63  }; // class PropertyValue
64  // ============================================================================
66  public:
67  PropertyValueException( const std::string& message ) : std::runtime_error( message ) {}
69  return PropertyValueException( "Cannot apply +=/-= operation to left value." );
70  }
71 
73  return PropertyValueException( "Cannot apply +=/-= operation to right value." );
74  }
75  };
76 
78  public:
80  : std::runtime_error( message ), position_( position ) {}
81  const Position& position() const { return position_; }
82 
84  return PositionalPropertyValueException( position, "Could not find property " + name + "." );
85  }
86 
88  const std::string& name ) {
89  return PositionalPropertyValueException( position, "Could not find property '" + name + "'." );
90  }
91 
93  return PositionalPropertyValueException( position, "Could not find unit '" + name + "'." );
94  }
95 
96  virtual ~PositionalPropertyValueException() throw() {}
97 
98  private:
100  };
101  // ============================================================================
102  } // namespace Parsers
103 } // namespace Gaudi
104 // ============================================================================
105 #endif // JOBOPTIONSVC_PROPERTY_VALUE_H_
const PropertyValue operator-(const PropertyValue &right)
std::vector< std::string > VectorOfStrings
Definition: PropertyValue.h:23
std::map< std::string, std::string > MapOfStrings
Definition: PropertyValue.h:24
const VectorOfStrings & Vector() const
Definition: PropertyValue.h:38
PropertyValue(Value value, bool is_reference=false)
Definition: PropertyValue.h:27
static PositionalPropertyValueException CouldNotFind(const Position &position, const std::string &name)
Definition: PropertyValue.h:83
STL namespace.
std::string ToString() const
PositionalPropertyValueException(const Position &position, const std::string &message)
Definition: PropertyValue.h:79
static PositionalPropertyValueException CouldNotFindUnit(const Position &position, const std::string &name)
Definition: PropertyValue.h:92
STL class.
PropertyValueException(const std::string &message)
Definition: PropertyValue.h:67
bool Exists() const
Definition: Position.h:23
std::variant< std::string, std::vector< std::string >, std::map< std::string, std::string > > Value
Definition: PropertyValue.h:22
PropertyValue(Value value, const Position &position, bool is_reference=false)
Definition: PropertyValue.h:29
static PropertyValueException WrongRValue()
Definition: PropertyValue.h:72
VectorOfStrings & Vector()
Definition: PropertyValue.h:37
PropertyValue & operator+=(const PropertyValue &right)
static PositionalPropertyValueException CouldNotFindProperty(const Position &position, const std::string &name)
Definition: PropertyValue.h:87
const PropertyValue operator+(const PropertyValue &right)
PropertyValue & operator-=(const PropertyValue &right)
const std::string & String() const
Definition: PropertyValue.h:35
const Position & position() const
Definition: PropertyValue.h:32
static PropertyValueException WrongLValue()
Definition: PropertyValue.h:68
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
const MapOfStrings & Map() const
Definition: PropertyValue.h:41