The Gaudi Framework  v29r0 (ff2e7097)
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 <vector>
12 // ============================================================================
13 #include <boost/variant.hpp>
14 // ============================================================================
15 #include "Position.h"
16 // ============================================================================
17 namespace Gaudi
18 {
19  namespace Parsers
20  {
21  // ============================================================================
22  class PropertyValue final
23  {
24  // ----------------------------------------------------------------------------
25  public:
26  typedef boost::variant<std::string, std::vector<std::string>, std::map<std::string, std::string>> Value;
29 
30  // ----------------------------------------------------------------------------
31  explicit PropertyValue( Value value, bool is_reference = false )
32  : value_( std::move( value ) ), is_reference_( is_reference )
33  {
34  }
35  PropertyValue( Value value, const Position& position, bool is_reference = false )
36  : value_( std::move( value ) ), position_( position ), is_reference_( is_reference )
37  {
38  }
39  // ----------------------------------------------------------------------------
40  const Position& position() const { return position_; }
41  // ----------------------------------------------------------------------------
42  std::string& String() { return boost::get<std::string>( value_ ); }
43  const std::string& String() const { return boost::get<std::string>( value_ ); }
44 
45  VectorOfStrings& Vector() { return boost::get<VectorOfStrings>( value_ ); }
46  const VectorOfStrings& Vector() const { return boost::get<VectorOfStrings>( value_ ); }
47 
48  MapOfStrings& Map() { return boost::get<MapOfStrings>( value_ ); }
49  const MapOfStrings& Map() const { return boost::get<MapOfStrings>( value_ ); }
50  // ----------------------------------------------------------------------------
51  std::string ToString() const;
52  bool HasPosition() const { return position_.Exists(); }
53  bool IsSimple() const;
54  bool IsVector() const;
55  bool IsMap() const;
56  bool IsReference() const { return is_reference_; };
57  // ----------------------------------------------------------------------------
58  // Operators:
59  // ----------------------------------------------------------------------------
60 
61  PropertyValue& operator+=( const PropertyValue& right );
62  const PropertyValue operator+( const PropertyValue& right );
63  PropertyValue& operator-=( const PropertyValue& right );
64  const PropertyValue operator-( const PropertyValue& right );
65  // bool operator == (const PropertyValue& right) const;
66  private:
67  Value value_;
70  // ----------------------------------------------------------------------------
71  }; // class PropertyValue
72  // ============================================================================
74  {
75  public:
76  PropertyValueException( const std::string& message ) : std::runtime_error( message ) {}
78  {
79  return PropertyValueException( "Cannot apply +=/-= operation to left value." );
80  }
81 
83  {
84  return PropertyValueException( "Cannot apply +=/-= operation to right value." );
85  }
86  };
87 
89  {
90  public:
92  : std::runtime_error( message ), position_( position )
93  {
94  }
95  const Position& position() const { return position_; }
96 
98  {
99  return PositionalPropertyValueException( position, "Could not find property " + name + "." );
100  }
101 
103  {
104  return PositionalPropertyValueException( position, "Could not find property '" + name + "'." );
105  }
106 
108  {
109  return PositionalPropertyValueException( position, "Could not find unit '" + name + "'." );
110  }
111 
113 
114  private:
116  };
117  // ============================================================================
118  } /* Gaudi */
119 } /* Parsers */
120 // ============================================================================
121 #endif // JOBOPTIONSVC_PROPERTY_VALUE_H_
const PropertyValue operator-(const PropertyValue &right)
std::vector< std::string > VectorOfStrings
Definition: PropertyValue.h:27
std::map< std::string, std::string > MapOfStrings
Definition: PropertyValue.h:28
const std::string & String() const
Definition: PropertyValue.h:43
PropertyValue(Value value, bool is_reference=false)
Definition: PropertyValue.h:31
static PositionalPropertyValueException CouldNotFind(const Position &position, const std::string &name)
Definition: PropertyValue.h:97
STL namespace.
const MapOfStrings & Map() const
Definition: PropertyValue.h:49
PositionalPropertyValueException(const Position &position, const std::string &message)
Definition: PropertyValue.h:91
static PositionalPropertyValueException CouldNotFindUnit(const Position &position, const std::string &name)
STL class.
const VectorOfStrings & Vector() const
Definition: PropertyValue.h:46
PropertyValueException(const std::string &message)
Definition: PropertyValue.h:76
PropertyValue(Value value, const Position &position, bool is_reference=false)
Definition: PropertyValue.h:35
static PropertyValueException WrongRValue()
Definition: PropertyValue.h:82
const Position & position() const
Definition: PropertyValue.h:40
boost::variant< std::string, std::vector< std::string >, std::map< std::string, std::string > > Value
Definition: PropertyValue.h:26
VectorOfStrings & Vector()
Definition: PropertyValue.h:45
PropertyValue & operator+=(const PropertyValue &right)
static PositionalPropertyValueException CouldNotFindProperty(const Position &position, const std::string &name)
const PropertyValue operator+(const PropertyValue &right)
PropertyValue & operator-=(const PropertyValue &right)
std::string ToString() const
bool Exists() const
Definition: Position.h:28
static PropertyValueException WrongLValue()
Definition: PropertyValue.h:77
Helper functions to set/get the application return code.
Definition: __init__.py:1