The Gaudi Framework  v33r0 (d5ea422b)
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:
32  typedef std::variant<std::string, std::vector<std::string>, std::map<std::string, std::string>> Value;
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:
77  PropertyValueException( const std::string& message ) : std::runtime_error( message ) {}
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:
90  : std::runtime_error( message ), position_( position ) {}
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_
const PropertyValue operator-(const PropertyValue &right)
std::vector< std::string > VectorOfStrings
Definition: PropertyValue.h:33
std::map< std::string, std::string > MapOfStrings
Definition: PropertyValue.h:34
const VectorOfStrings & Vector() const
Definition: PropertyValue.h:48
PropertyValue(Value value, bool is_reference=false)
Definition: PropertyValue.h:37
static PositionalPropertyValueException CouldNotFind(const Position &position, const std::string &name)
Definition: PropertyValue.h:93
STL namespace.
std::string ToString() const
PositionalPropertyValueException(const Position &position, const std::string &message)
Definition: PropertyValue.h:89
static PositionalPropertyValueException CouldNotFindUnit(const Position &position, const std::string &name)
STL class.
PropertyValueException(const std::string &message)
Definition: PropertyValue.h:77
bool Exists() const
Definition: Position.h:33
std::variant< std::string, std::vector< std::string >, std::map< std::string, std::string > > Value
Definition: PropertyValue.h:32
PropertyValue(Value value, const Position &position, bool is_reference=false)
Definition: PropertyValue.h:39
static PropertyValueException WrongRValue()
Definition: PropertyValue.h:82
VectorOfStrings & Vector()
Definition: PropertyValue.h:47
PropertyValue & operator+=(const PropertyValue &right)
static PositionalPropertyValueException CouldNotFindProperty(const Position &position, const std::string &name)
Definition: PropertyValue.h:97
const PropertyValue operator+(const PropertyValue &right)
PropertyValue & operator-=(const PropertyValue &right)
const std::string & String() const
Definition: PropertyValue.h:45
const Position & position() const
Definition: PropertyValue.h:42
static PropertyValueException WrongLValue()
Definition: PropertyValue.h:78
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
const MapOfStrings & Map() const
Definition: PropertyValue.h:51