Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PropertyValue.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 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 #pragma once
12 
13 #include "Position.h"
14 #include <map>
15 #include <stdexcept>
16 #include <string>
17 #include <variant>
18 #include <vector>
19 
20 namespace Gaudi {
21  namespace Parsers {
22  class PropertyValue final {
23  public:
24  using VectorOfStrings = std::vector<std::string>;
25  using MapOfStrings = std::map<std::string, std::string, std::less<>>;
26  using Value = std::variant<std::string, VectorOfStrings, MapOfStrings>;
27 
28  // ----------------------------------------------------------------------------
29  explicit PropertyValue( Value value, bool is_reference = false )
30  : value_( std::move( value ) ), is_reference_( is_reference ) {}
31  PropertyValue( Value value, const Position& position, bool is_reference = false )
32  : value_( std::move( value ) ), position_( position ), is_reference_( is_reference ) {}
33  // ----------------------------------------------------------------------------
34  const Position& position() const { return position_; }
35  // ----------------------------------------------------------------------------
36  std::string& String() { return std::get<std::string>( value_ ); }
37  const std::string& String() const { return std::get<std::string>( value_ ); }
38 
39  VectorOfStrings& Vector() { return std::get<VectorOfStrings>( value_ ); }
40  const VectorOfStrings& Vector() const { return std::get<VectorOfStrings>( value_ ); }
41 
42  MapOfStrings& Map() { return std::get<MapOfStrings>( value_ ); }
43  const MapOfStrings& Map() const { return std::get<MapOfStrings>( value_ ); }
44 
45  std::string ToString() const;
46  bool HasPosition() const { return position_.Exists(); }
47  bool IsSimple() const;
48  bool IsVector() const;
49  bool IsMap() const;
50  bool IsReference() const { return is_reference_; };
51 
52  PropertyValue& operator+=( const PropertyValue& right );
53  const PropertyValue operator+( const PropertyValue& right );
54  PropertyValue& operator-=( const PropertyValue& right );
55  const PropertyValue operator-( const PropertyValue& right );
56 
57  private:
61  };
62 
63  class PropertyValueException : public std::runtime_error {
64  public:
65  PropertyValueException( const std::string& message ) : std::runtime_error( message ) {}
67  return PropertyValueException( "Cannot apply +=/-= operation to left value." );
68  }
69 
71  return PropertyValueException( "Cannot apply +=/-= operation to right value." );
72  }
73  };
74 
75  class PositionalPropertyValueException : public std::runtime_error {
76  public:
78  : std::runtime_error( message ), position_( position ) {}
79  const Position& position() const { return position_; }
80 
81  static PositionalPropertyValueException CouldNotFind( const Position& position, const std::string& name ) {
82  return PositionalPropertyValueException( position, "Could not find property " + name + "." );
83  }
84 
86  const std::string& name ) {
87  return PositionalPropertyValueException( position, "Could not find property '" + name + "'." );
88  }
89 
91  return PositionalPropertyValueException( position, "Could not find unit '" + name + "'." );
92  }
93 
94  virtual ~PositionalPropertyValueException() throw() {}
95 
96  private:
98  };
99  } // namespace Parsers
100 } // namespace Gaudi
Gaudi::Parsers::PropertyValue::operator-=
PropertyValue & operator-=(const PropertyValue &right)
Definition: PropertyValue.cpp:39
precedence.message
message
Definition: precedence.py:19
Gaudi::Parsers::PropertyValue::operator-
const PropertyValue operator-(const PropertyValue &right)
Definition: PropertyValue.cpp:56
Gaudi::Parsers::PropertyValue::Map
MapOfStrings & Map()
Definition: PropertyValue.h:42
GaudiPartProp.decorators.std
std
Definition: decorators.py:32
Gaudi::Parsers::PropertyValue::ToString
std::string ToString() const
Definition: PropertyValue.cpp:60
Gaudi::Parsers::PropertyValue::HasPosition
bool HasPosition() const
Definition: PropertyValue.h:46
Gaudi::Parsers::PropertyValueException::PropertyValueException
PropertyValueException(const std::string &message)
Definition: PropertyValue.h:65
Gaudi::Parsers::PositionalPropertyValueException::~PositionalPropertyValueException
virtual ~PositionalPropertyValueException()
Definition: PropertyValue.h:94
Gaudi::Parsers::Position::Exists
bool Exists() const
Definition: Position.h:27
Gaudi::Parsers::PositionalPropertyValueException::CouldNotFind
static PositionalPropertyValueException CouldNotFind(const Position &position, const std::string &name)
Definition: PropertyValue.h:81
Gaudi::Parsers::PropertyValue::VectorOfStrings
std::vector< std::string > VectorOfStrings
Definition: PropertyValue.h:24
Gaudi::Parsers::PropertyValueException
Definition: PropertyValue.h:63
Gaudi::Parsers::PropertyValue
Definition: PropertyValue.h:22
Gaudi::Parsers::PropertyValueException::WrongRValue
static PropertyValueException WrongRValue()
Definition: PropertyValue.h:70
Gaudi::Parsers::PropertyValue::String
std::string & String()
Definition: PropertyValue.h:36
Gaudi::Parsers::PropertyValue::Map
const MapOfStrings & Map() const
Definition: PropertyValue.h:43
Gaudi::Parsers::PositionalPropertyValueException::CouldNotFindUnit
static PositionalPropertyValueException CouldNotFindUnit(const Position &position, const std::string &name)
Definition: PropertyValue.h:90
Gaudi::Parsers::PropertyValue::value_
Value value_
Definition: PropertyValue.h:58
Gaudi::Parsers::PropertyValue::IsVector
bool IsVector() const
Definition: PropertyValue.cpp:19
Gaudi::Parsers::Position
Definition: Position.h:17
Gaudi::Parsers::PropertyValue::Vector
const VectorOfStrings & Vector() const
Definition: PropertyValue.h:40
Gaudi::Parsers::PropertyValue::MapOfStrings
std::map< std::string, std::string, std::less<> > MapOfStrings
Definition: PropertyValue.h:25
Gaudi::Parsers::PropertyValue::position_
Position position_
Definition: PropertyValue.h:59
Gaudi::Parsers::PositionalPropertyValueException::CouldNotFindProperty
static PositionalPropertyValueException CouldNotFindProperty(const Position &position, const std::string &name)
Definition: PropertyValue.h:85
Gaudi::Parsers::PropertyValue::PropertyValue
PropertyValue(Value value, const Position &position, bool is_reference=false)
Definition: PropertyValue.h:31
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:20
Gaudi::Parsers::PropertyValue::operator+=
PropertyValue & operator+=(const PropertyValue &right)
Definition: PropertyValue.cpp:21
Gaudi::Parsers::PropertyValue::IsReference
bool IsReference() const
Definition: PropertyValue.h:50
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
Gaudi::Parsers::PropertyValue::position
const Position & position() const
Definition: PropertyValue.h:34
Gaudi::Parsers::PropertyValueException::WrongLValue
static PropertyValueException WrongLValue()
Definition: PropertyValue.h:66
Gaudi::Parsers::PositionalPropertyValueException
Definition: PropertyValue.h:75
Gaudi::Parsers::PropertyValue::IsSimple
bool IsSimple() const
Definition: PropertyValue.cpp:18
Gaudi::Parsers::PositionalPropertyValueException::position_
Position position_
Definition: PropertyValue.h:97
Gaudi::Parsers::PropertyValue::is_reference_
bool is_reference_
Definition: PropertyValue.h:60
Gaudi::Parsers::PropertyValue::operator+
const PropertyValue operator+(const PropertyValue &right)
Definition: PropertyValue.cpp:35
Gaudi::Parsers::PropertyValue::Vector
VectorOfStrings & Vector()
Definition: PropertyValue.h:39
Gaudi::Parsers::PropertyValue::Value
std::variant< std::string, VectorOfStrings, MapOfStrings > Value
Definition: PropertyValue.h:26
Gaudi::Parsers::PositionalPropertyValueException::position
const Position & position() const
Definition: PropertyValue.h:79
Gaudi::Parsers::PropertyValue::String
const std::string & String() const
Definition: PropertyValue.h:37
Gaudi::Parsers::PropertyValue::PropertyValue
PropertyValue(Value value, bool is_reference=false)
Definition: PropertyValue.h:29
Gaudi::Parsers::PositionalPropertyValueException::PositionalPropertyValueException
PositionalPropertyValueException(const Position &position, const std::string &message)
Definition: PropertyValue.h:77