ATLAS Offline Software
Loading...
Searching...
No Matches
PropertyWrapper.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8
9#ifndef ASG_TOOLS__PROPERTY_WRAPPER_H
10#define ASG_TOOLS__PROPERTY_WRAPPER_H
11
12
13#ifndef XAOD_STANDALONE
14
15#include <GaudiKernel/PropertyHolder.h>
16
17#else
18
20#include <iosfwd>
21#include <string>
22#include <utility>
23
24namespace Gaudi
25{
36
37 template<typename T> class Property final
38 {
39 public:
40 template<typename T2>
41 Property (T2 *owner, const std::string& name, const T& value,
42 const std::string& title = "");
43
44 public:
45 template<typename T2>
46 Property (T2 *owner, const std::string& name, T&& value,
47 const std::string& title = "");
48
49 public:
50 operator const T& () const noexcept;
51 const T& value () const noexcept {return m_value;}
52
53 public:
54 template<typename T2>
55 Property<T>& operator = (T2&& that);
56
57 public:
58 template<typename T2>
59 decltype(auto) operator + (T2&& that) const;
60
61 public:
62 decltype(auto) empty () const {return m_value.empty();}
63 decltype(auto) size () const {return m_value.size();};
64 decltype(auto) begin () const {return m_value.begin();}
65 decltype(auto) end () const {return m_value.end();}
66 template<typename T2> decltype(auto) operator [] (const T2& index) const {
67 return m_value[index];}
68
69 // the property we created. this is used for debugging output and
70 // includes the name for that reason. it is maybe a bit hacky, but
71 // it allows us to give proper printout (with proper meaning it
72 // matches Athena).
73 public:
74 auto *getProperty () const {return m_property;}
75
76 private:
77 T m_value;
78
79 private:
80 const PropertyMgr::PropMap_t::value_type *m_property = nullptr;
81 };
82
83
84
87
88 template<typename T> template<typename T2>
89 Property<T> ::
90 Property (T2 *owner, const std::string& name, const T& value,
91 const std::string& title)
92 : m_value (value)
93 {
94 owner->declareProperty (name, m_value, title);
95 if (auto iter = owner->getPropertyMgr()->getProperties().find(name);
96 iter != owner->getPropertyMgr()->getProperties().end())
97 m_property = &*iter;
98 else
99 throw std::logic_error ("PropertyWrapper::Property - property not found");
100 }
101
102
103
104 template<typename T> template<typename T2>
106 Property (T2 *owner, const std::string& name, T&& value,
107 const std::string& title)
108 : m_value (std::move (value))
109 {
110 owner->declareProperty (name, m_value, title);
111 if (auto iter = owner->getPropertyMgr()->getProperties().find(name);
112 iter != owner->getPropertyMgr()->getProperties().end())
113 m_property = &*iter;
114 else
115 throw std::logic_error ("PropertyWrapper::Property - property not found");
116 }
117
118
119
120 template<typename T>
121 Property<T> ::
122 operator const T& () const noexcept
123 {
124 return m_value;
125 }
126
127
128
129 template<typename T> template<typename T2>
131 operator = (T2&& that)
132 {
133 m_value = std::forward<T2>(that);
134 return *this;
135 }
136
137
138
139 template<typename T> template<typename T2>
140 decltype(auto) Property<T> ::
141 operator + (T2&& that) const
142 {
143 return m_value + std::forward<T2>(that);
144 }
145
146
147
148 template<typename T1,typename T2>
149 decltype(auto) operator + (T1&& lh, const Property<T2>& rh)
150 {
151 return std::forward<T1>(lh) + rh.value();
152 }
153
154
155
156 template<typename T,typename T2>
157 bool operator == (const Property<T>& lhs, const T2& rhs)
158 {
159 return lhs.value() == rhs;
160 }
161
162
163
164 template<typename T,typename T2>
165 bool operator != (const Property<T>& lhs, const T2& rhs)
166 {
167 return lhs.value() != rhs;
168 }
169
170
171
172 template<typename T>
173 std::ostream& operator << (std::ostream& str, const Property<T>& property)
174 {
175 std::string propertyString;
176 if (property.getProperty()->second->getString (propertyString).isFailure())
177 throw std::runtime_error ("PropertyWrapper::operator << - no string conversion available");
178 return str << "'" << property.getProperty()->first << "': " << propertyString;
179 }
180}
181
182#endif
183
184#endif
bool operator!=(const DataVector< T > &a, const DataVector< T > &b)
Based on operator==.
bool operator==(const DataVector< T > &a, const DataVector< T > &b)
Vector equality comparison.
std::ostream & operator<<(std::ostream &lhs, const TestGaudiProperty &rhs)
static const Attributes_t empty
Support class for PropertyMgr.
Definition Property.h:23
str index
Definition DeMoScan.py:362
=============================================================================
unsigned long long T
T getProperty(const asg::IAsgTool *interface_tool, const std::string &prop_name)
STL namespace.