| The Gaudi Framework v32r1 (f65d50dc)

CArrayAsProperty.h
Go to the documentation of this file.
1 #ifndef NO_C_ARRAY_AS_PROPERTY_WARNING
2 # warning deprecated header (will be removed in Gaudi v29r0), think about using std::array<T,N> instead of T[N]
3 #endif
4 #ifndef GAUDIKERNEL_CARRAYASPROPERTY_H
5 # define GAUDIKERNEL_CARRAYASPROPERTY_H
6 # include "GaudiKernel/Property.h"
7
8 namespace Gaudi {
9 template <class TYPE, size_t N, class VERIFIER, class HANDLERS>
10 class Property<TYPE[N], VERIFIER, HANDLERS> : public Details::PropertyBase {
11 public:
12 // ==========================================================================
14 using StorageType = TYPE ( & )[N];
15 using ValueType = typename std::remove_reference<StorageType>::type;
16 using VerifierType = VERIFIER;
17 using HandlersType = HANDLERS;
18
19 private:
21 StorageType m_value;
22 VerifierType m_verifier;
23 HandlersType m_handlers;
26 template <class T>
27 static inline constexpr bool is_this_type_v = std::is_same_v<Property, typename std::remove_reference_t<T>>;
28 template <class T>
29 using not_copying = std::enable_if<!is_this_type_v<T>>;
31 public:
32 // ==========================================================================
34 inline Property( std::string name, StorageType value, std::string doc = "" )
35 : PropertyBase( typeid( ValueType ), std::move( name ), std::move( doc ) ), m_value( value ) {
36 m_verifier( m_value );
37 }
38
39 using PropertyBase::declareReadHandler;
40 using PropertyBase::declareUpdateHandler;
41
43 PropertyBase& declareReadHandler( std::function<void( PropertyBase& )> fun ) override {
44 m_handlers.setReadHandler( std::move( fun ) );
45 return *this;
46 }
48 PropertyBase& declareUpdateHandler( std::function<void( PropertyBase& )> fun ) override {
49 m_handlers.setUpdateHandler( std::move( fun ) );
50 return *this;
51 }
52
54 const std::function<void( PropertyBase& )> readCallBack() const override { return m_handlers.getReadHandler(); }
56 const std::function<void( PropertyBase& )> updateCallBack() const override { return m_handlers.getUpdateHandler(); }
57
59 bool useUpdateHandler() override {
60 m_handlers.useUpdateHandler( *this );
61 return true;
62 }
63
65 operator const ValueType&() const {
66 m_handlers.useReadHandler( *this );
67 return m_value;
68 }
69 // /// Automatic conversion to value (reference).
70 // operator ValueType& () {
71 // useReadHandler();
72 // return m_value;
73 // }
74
76 Property& operator=( const ValueType& v ) {
77 m_verifier( v );
78 for ( size_t i = 0; i != N; ++i ) { m_value[i] = v[i]; }
79 m_handlers.useUpdateHandler( *this );
80 return *this;
81 }
82
84 // Property(const Property& other):
85 // PropertyBase(other), value(other.m_value) {}
86
88 const VerifierType& verifier() const { return m_verifier; }
90 VerifierType& verifier() { return m_verifier; }
91
94 const ValueType& value() const { return *this; }
95 ValueType& value() { return const_cast<ValueType&>( (const ValueType&)*this ); }
96 bool setValue( const ValueType& v ) {
97 *this = v;
98 return true;
99 }
100 bool set( const ValueType& v ) {
101 *this = v;
102 return true;
103 }
104 PropertyBase* clone() const override { return new Property( *this ); }
106
110 inline size_t size() const { return N; }
111 inline bool empty() const { return false; }
112 template <class T = const ValueType>
113 inline decltype( std::declval<T>()[typename T::key_type{}] ) operator[]( const typename T::key_type& key ) const {
114 return value()[key];
115 }
116 template <class T = ValueType>
117 inline decltype( std::declval<T>()[typename T::key_type{}] ) operator[]( const typename T::key_type& key ) {
118 return value()[key];
119 }
121 // ==========================================================================
122 public:
124 bool assign( const PropertyBase& source ) override {
125 // Is the property of "the same" type?
126 const Property* p = dynamic_cast<const Property*>( &source );
127 if ( p ) {
128 *this = p->value();
129 } else {
130 this->fromString( source.toString() ).ignore();
131 }
132 return true;
133 }
135 bool load( PropertyBase& dest ) const override {
136 // delegate to the 'opposite' method
137 return dest.assign( *this );
138 }
140 StatusCode fromString( const std::string& source ) override {
141 ValueType tmp;
142 if ( Parsers::parse( tmp, source ).isSuccess() ) {
143 *this = tmp;
144 } else {
145 throw std::invalid_argument( "cannot parse '" + source + "' to " + this->type() );
146 }
147 return StatusCode::SUCCESS;
148 }
150 std::string toString() const override {
151 m_handlers.useReadHandler( *this );
152 return Utils::toString( m_value );
153 }
155 void toStream( std::ostream& out ) const override {
156 m_handlers.useReadHandler( *this );
157 Utils::toStream( m_value, out );
158 }
159 };
160 template <class TYPE, size_t N, class VERIFIER, class HANDLERS>
161 class Property<TYPE ( & )[N], VERIFIER, HANDLERS> : public Property<TYPE[N], VERIFIER, HANDLERS> {
162 public:
163 using Property<TYPE[N], VERIFIER, HANDLERS>::Property;
164 };
165 } // namespace Gaudi
166 #endif
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::value
const ValueType & value() const
Backward compatibility.
Definition: CArrayAsProperty.h:94
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::fromString
StatusCode fromString(const std::string &source) override
string -> value
Definition: CArrayAsProperty.h:140
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::toString
std::string toString() const override
value -> string
Definition: CArrayAsProperty.h:150
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::VerifierType
VERIFIER VerifierType
Definition: CArrayAsProperty.h:16
Gaudi::Utils::toStream
std::ostream & toStream(ITERATOR first, ITERATOR last, std::ostream &s, const std::string &open, const std::string &close, const std::string &delim)
the helper function to print the sequence
Definition: ToStream.h:284
Gaudi::Property::is_this_type_v
static constexpr bool is_this_type_v
helper typedefs for SFINAE
Definition: Property.h:370
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::useUpdateHandler
bool useUpdateHandler() override
manual trigger for callback for update
Definition: CArrayAsProperty.h:59
std::function
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::toStream
void toStream(std::ostream &out) const override
value -> stream
Definition: CArrayAsProperty.h:155
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::HandlersType
HANDLERS HandlersType
Definition: CArrayAsProperty.h:17
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::m_value
StorageType m_value
Storage.
Definition: CArrayAsProperty.h:21
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:334
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std
STL namespace.
Gaudi::Parsers::parse
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
Definition: DODBasicMapper.cpp:11
Gaudi::Property::m_handlers
HandlersType m_handlers
Definition: Property.h:366
Gaudi::Property::m_value
StorageType m_value
Storage.
Definition: Property.h:364
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::readCallBack
const std::function< void(PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
Definition: CArrayAsProperty.h:54
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::updateCallBack
const std::function< void(PropertyBase &)> updateCallBack() const override
get a reference to the updateCallBack
Definition: CArrayAsProperty.h:56
Gaudi::Details::PropertyBase::name
const std::string name() const
property name
Definition: Property.h:36
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::ValueType
typename std::remove_reference< StorageType >::type ValueType
Definition: CArrayAsProperty.h:15
Gaudi::Details::PropertyBase::PropertyBase
PropertyBase(const std::type_info &type, std::string name="", std::string doc="")
constructor from the property name and the type
Definition: Property.h:111
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::value
ValueType & value()
Definition: CArrayAsProperty.h:95
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::StorageType
TYPE(&)[N] StorageType
Hosted type.
Definition: CArrayAsProperty.h:14
std::enable_if
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::declareUpdateHandler
PropertyBase & declareUpdateHandler(std::function< void(PropertyBase &)> fun) override
set new callback for update
Definition: CArrayAsProperty.h:48
Gaudi::Property::Property
Property()
Construct an anonymous property with default constructed value.
Definition: Property.h:444
std::string
STL class.
IOTest.N
int N
Definition: IOTest.py:99
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::size
size_t size() const
Definition: CArrayAsProperty.h:110
gaudirun.dest
dest
Definition: gaudirun.py:201
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Gaudi::Property::value
const ValueType & value() const
Backward compatibility (.
Definition: Property.h:526
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::set
bool set(const ValueType &v)
Definition: CArrayAsProperty.h:100
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
std::move
T move(T... args)
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::empty
bool empty() const
Definition: CArrayAsProperty.h:111
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::verifier
const VerifierType & verifier() const
Copy constructor.
Definition: CArrayAsProperty.h:88
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::clone
PropertyBase * clone() const override
clones the current property
Definition: CArrayAsProperty.h:104
Gaudi::Details::PropertyBase::type
std::string type() const
property type
Definition: Property.h:42
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::assign
bool assign(const PropertyBase &source) override
get the value from another property
Definition: CArrayAsProperty.h:124
Property.h
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::Property
Property(std::string name, StorageType value, std::string doc="")
the constructor with property name, value and documentation.
Definition: CArrayAsProperty.h:34
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::setValue
bool setValue(const ValueType &v)
Definition: CArrayAsProperty.h:96
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::m_handlers
HandlersType m_handlers
Definition: CArrayAsProperty.h:23
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::declareReadHandler
PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun) override
set new callback for reading
Definition: CArrayAsProperty.h:43
std::remove_reference
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::m_verifier
VerifierType m_verifier
Definition: CArrayAsProperty.h:22
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::load
bool load(PropertyBase &dest) const override
set value to another property
Definition: CArrayAsProperty.h:135
std::ostream
STL class.
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::operator=
Property & operator=(const ValueType &v)
Assignment from value.
Definition: CArrayAsProperty.h:76
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
Gaudi::Property::m_verifier
VerifierType m_verifier
Definition: Property.h:365
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::verifier
VerifierType & verifier()
Accessor to verifier.
Definition: CArrayAsProperty.h:90
std::invalid_argument
STL class.
Gaudi::Property::fromString
StatusCode fromString(const std::string &source) override
string -> value
Definition: Property.h:676