The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
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
20namespace 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:
77 PositionalPropertyValueException( const Position& position, const std::string& message )
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
90 static PositionalPropertyValueException CouldNotFindUnit( const Position& position, const std::string& name ) {
91 return PositionalPropertyValueException( position, "Could not find unit '" + name + "'." );
92 }
93
95
96 private:
98 };
99 } // namespace Parsers
100} // namespace Gaudi
static PositionalPropertyValueException CouldNotFindUnit(const Position &position, const std::string &name)
PositionalPropertyValueException(const Position &position, const std::string &message)
static PositionalPropertyValueException CouldNotFind(const Position &position, const std::string &name)
static PositionalPropertyValueException CouldNotFindProperty(const Position &position, const std::string &name)
static PropertyValueException WrongRValue()
static PropertyValueException WrongLValue()
PropertyValueException(const std::string &message)
const std::string & String() const
const VectorOfStrings & Vector() const
const MapOfStrings & Map() const
PropertyValue(Value value, const Position &position, bool is_reference=false)
std::vector< std::string > VectorOfStrings
VectorOfStrings & Vector()
std::map< std::string, std::string, std::less<> > MapOfStrings
std::variant< std::string, VectorOfStrings, MapOfStrings > Value
const PropertyValue operator+(const PropertyValue &right)
PropertyValue & operator+=(const PropertyValue &right)
const PropertyValue operator-(const PropertyValue &right)
PropertyValue(Value value, bool is_reference=false)
PropertyValue & operator-=(const PropertyValue &right)
const Position & position() const
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
STL namespace.