Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  namespace Parsers {
19  // ============================================================================
20  class PropertyValue final {
21  // ----------------------------------------------------------------------------
22  public:
23  typedef boost::variant<std::string, std::vector<std::string>, std::map<std::string, std::string>> Value;
26 
27  // ----------------------------------------------------------------------------
28  explicit PropertyValue( Value value, bool is_reference = false )
29  : value_( std::move( value ) ), is_reference_( is_reference ) {}
30  PropertyValue( Value value, const Position& position, bool is_reference = false )
31  : value_( std::move( value ) ), position_( position ), is_reference_( is_reference ) {}
32  // ----------------------------------------------------------------------------
33  const Position& position() const { return position_; }
34  // ----------------------------------------------------------------------------
35  std::string& String() { return boost::get<std::string>( value_ ); }
36  const std::string& String() const { return boost::get<std::string>( value_ ); }
37 
38  VectorOfStrings& Vector() { return boost::get<VectorOfStrings>( value_ ); }
39  const VectorOfStrings& Vector() const { return boost::get<VectorOfStrings>( value_ ); }
40 
41  MapOfStrings& Map() { return boost::get<MapOfStrings>( value_ ); }
42  const MapOfStrings& Map() const { return boost::get<MapOfStrings>( value_ ); }
43  // ----------------------------------------------------------------------------
44  std::string ToString() const;
45  bool HasPosition() const { return position_.Exists(); }
46  bool IsSimple() const;
47  bool IsVector() const;
48  bool IsMap() const;
49  bool IsReference() const { return is_reference_; };
50  // ----------------------------------------------------------------------------
51  // Operators:
52  // ----------------------------------------------------------------------------
53 
54  PropertyValue& operator+=( const PropertyValue& right );
55  const PropertyValue operator+( const PropertyValue& right );
56  PropertyValue& operator-=( const PropertyValue& right );
57  const PropertyValue operator-( const PropertyValue& right );
58  // bool operator == (const PropertyValue& right) const;
59  private:
60  Value value_;
63  // ----------------------------------------------------------------------------
64  }; // class PropertyValue
65  // ============================================================================
67  public:
68  PropertyValueException( const std::string& message ) : std::runtime_error( message ) {}
70  return PropertyValueException( "Cannot apply +=/-= operation to left value." );
71  }
72 
74  return PropertyValueException( "Cannot apply +=/-= operation to right value." );
75  }
76  };
77 
79  public:
81  : std::runtime_error( message ), position_( position ) {}
82  const Position& position() const { return position_; }
83 
85  return PositionalPropertyValueException( position, "Could not find property " + name + "." );
86  }
87 
89  const std::string& name ) {
90  return PositionalPropertyValueException( position, "Could not find property '" + name + "'." );
91  }
92 
94  return PositionalPropertyValueException( position, "Could not find unit '" + name + "'." );
95  }
96 
97  virtual ~PositionalPropertyValueException() throw() {}
98 
99  private:
101  };
102  // ============================================================================
103  } // namespace Parsers
104 } // namespace Gaudi
105 // ============================================================================
106 #endif // JOBOPTIONSVC_PROPERTY_VALUE_H_
const PropertyValue operator-(const PropertyValue &right)
std::vector< std::string > VectorOfStrings
Definition: PropertyValue.h:24
std::map< std::string, std::string > MapOfStrings
Definition: PropertyValue.h:25
const std::string & String() const
Definition: PropertyValue.h:36
PropertyValue(Value value, bool is_reference=false)
Definition: PropertyValue.h:28
static PositionalPropertyValueException CouldNotFind(const Position &position, const std::string &name)
Definition: PropertyValue.h:84
STL namespace.
const MapOfStrings & Map() const
Definition: PropertyValue.h:42
PositionalPropertyValueException(const Position &position, const std::string &message)
Definition: PropertyValue.h:80
static PositionalPropertyValueException CouldNotFindUnit(const Position &position, const std::string &name)
Definition: PropertyValue.h:93
STL class.
const VectorOfStrings & Vector() const
Definition: PropertyValue.h:39
PropertyValueException(const std::string &message)
Definition: PropertyValue.h:68
PropertyValue(Value value, const Position &position, bool is_reference=false)
Definition: PropertyValue.h:30
static PropertyValueException WrongRValue()
Definition: PropertyValue.h:73
const Position & position() const
Definition: PropertyValue.h:33
boost::variant< std::string, std::vector< std::string >, std::map< std::string, std::string > > Value
Definition: PropertyValue.h:23
VectorOfStrings & Vector()
Definition: PropertyValue.h:38
PropertyValue & operator+=(const PropertyValue &right)
static PositionalPropertyValueException CouldNotFindProperty(const Position &position, const std::string &name)
Definition: PropertyValue.h:88
const PropertyValue operator+(const PropertyValue &right)
PropertyValue & operator-=(const PropertyValue &right)
std::string ToString() const
bool Exists() const
Definition: Position.h:23
static PropertyValueException WrongLValue()
Definition: PropertyValue.h:69
Helper functions to set/get the application return code.
Definition: __init__.py:1