| The Gaudi Framework v28r2-patches (bc4ad17a)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 {
10 template <class TYPE, size_t N, class VERIFIER, class HANDLERS>
11 class Property<TYPE [N], VERIFIER, HANDLERS> : public Details::PropertyBase
12 {
13 public:
14 // ==========================================================================
16 using StorageType = TYPE ( & )[N];
17 using ValueType = typename std::remove_reference<StorageType>::type;
18 using VerifierType = VERIFIER;
19 using HandlersType = HANDLERS;
20
21 private:
23 StorageType m_value;
24 VerifierType m_verifier;
25 HandlersType m_handlers;
28 template <class T>
29 using is_this_type = std::is_same<Property, typename std::remove_reference<T>::type>;
30 template <class T>
31 using not_copying = std::enable_if<!is_this_type<T>::value>;
33 public:
34 // ==========================================================================
36 inline Property( std::string name, StorageType value, std::string doc = "" )
37 : PropertyBase( typeid( ValueType ), std::move( name ), std::move( doc ) ), m_value( value )
38 {
39 m_verifier( m_value );
40 }
41
42 using PropertyBase::declareReadHandler;
43 using PropertyBase::declareUpdateHandler;
44
46 PropertyBase& declareReadHandler( std::function<void( PropertyBase& )> fun ) override
47 {
48 m_handlers.setReadHandler( std::move( fun ) );
49 return *this;
50 }
52 PropertyBase& declareUpdateHandler( std::function<void( PropertyBase& )> fun ) override
53 {
54 m_handlers.setUpdateHandler( std::move( fun ) );
55 return *this;
56 }
57
59 const std::function<void( PropertyBase& )> readCallBack() const override { return m_handlers.getReadHandler(); }
61 const std::function<void( PropertyBase& )> updateCallBack() const override { return m_handlers.getUpdateHandler(); }
62
64 bool useUpdateHandler() override
65 {
66 m_handlers.useUpdateHandler( *this );
67 return true;
68 }
69
71 operator const ValueType&() const
72 {
73 m_handlers.useReadHandler( *this );
74 return m_value;
75 }
76 // /// Automatic conversion to value (reference).
77 // operator ValueType& () {
78 // useReadHandler();
79 // return m_value;
80 // }
81
83 Property& operator=( const ValueType& v )
84 {
85 m_verifier( v );
86 for ( size_t i = 0; i != N; ++i ) {
87 m_value[i] = v[i];
88 }
89 m_handlers.useUpdateHandler( *this );
90 return *this;
91 }
92
94 // Property(const Property& other):
95 // PropertyBase(other), value(other.m_value) {}
96
98 const VerifierType& verifier() const { return m_verifier; }
100 VerifierType& verifier() { return m_verifier; }
101
104 const ValueType& value() const { return *this; }
105 ValueType& value() { return const_cast<ValueType&>( (const ValueType&)*this ); }
106 bool setValue( const ValueType& v )
107 {
108 *this = v;
109 return true;
110 }
111 bool set( const ValueType& v )
112 {
113 *this = v;
114 return true;
115 }
116 PropertyBase* clone() const override { return new Property( *this ); }
118
122 inline size_t size() const { return N; }
123 inline bool empty() const { return false; }
124 template <class T = const ValueType>
125 inline decltype( std::declval<T>()[typename T::key_type{}] ) operator[]( const typename T::key_type& key ) const
126 {
127 return value()[key];
128 }
129 template <class T = ValueType>
130 inline decltype( std::declval<T>()[typename T::key_type{}] ) operator[]( const typename T::key_type& key )
131 {
132 return value()[key];
133 }
135 // ==========================================================================
136 public:
138 bool assign( const PropertyBase& source ) override
139 {
140 // Is the property of "the same" type?
141 const Property* p = dynamic_cast<const Property*>( &source );
142 if ( p ) {
143 *this = p->value();
144 } else {
145 this->fromString( source.toString() ).ignore();
146 }
147 return true;
148 }
150 bool load( PropertyBase& dest ) const override
151 {
152 // delegate to the 'opposite' method
153 return dest.assign( *this );
154 }
156 StatusCode fromString( const std::string& source ) override
157 {
158 ValueType tmp;
159 if ( Parsers::parse( tmp, source ).isSuccess() ) {
160 *this = tmp;
161 } else {
162 throw std::invalid_argument( "cannot parse '" + source + "' to " + this->type() );
163 }
164 return StatusCode::SUCCESS;
165 }
167 std::string toString() const override
168 {
169 m_handlers.useReadHandler( *this );
170 return Utils::toString( m_value );
171 }
173 void toStream( std::ostream& out ) const override
174 {
175 m_handlers.useReadHandler( *this );
176 Utils::toStream( m_value, out );
177 }
178 };
179 template <class TYPE, size_t N, class VERIFIER, class HANDLERS>
180 class Property<TYPE (&) [N], VERIFIER, HANDLERS> : public Property<TYPE [N], VERIFIER, HANDLERS> {
181 public:
182 using Property<TYPE [N], VERIFIER, HANDLERS>::Property;
183 };
184 }
185 #endif
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::fromString
StatusCode fromString(const std::string &source) override
string -> value
Definition: CArrayAsProperty.h:156
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::VerifierType
VERIFIER VerifierType
Definition: CArrayAsProperty.h:18
StatusCode::SUCCESS
Definition: StatusCode.h:30
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:315
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::useUpdateHandler
bool useUpdateHandler() override
manual trigger for callback for update
Definition: CArrayAsProperty.h:64
std::function
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:314
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::HandlersType
HANDLERS HandlersType
Definition: CArrayAsProperty.h:19
Gaudi::Details::PropertyBase::name
const std::string name() const
property name
Definition: Property.h:40
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::m_value
StorageType m_value
Storage.
Definition: CArrayAsProperty.h:23
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:367
std::is_same
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_value
StorageType m_value
Storage.
Definition: Property.h:326
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::ValueType
typename std::remove_reference< StorageType >::type ValueType
Definition: CArrayAsProperty.h:17
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::value
ValueType & value()
Definition: CArrayAsProperty.h:105
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::StorageType
TYPE(&)[N] StorageType
Hosted type.
Definition: CArrayAsProperty.h:16
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:52
Gaudi::Property::Property
Property()
Construct an anonymous property with default constructed value.
Definition: Property.h:380
Gaudi::Details::PropertyBase::PropertyBase
PropertyBase()=delete
std::string
STL class.
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::value
const ValueType & value() const
Backward compatibility.
Definition: CArrayAsProperty.h:104
IOTest.N
int N
Definition: IOTest.py:90
gaudirun.dest
dest
Definition: gaudirun.py:162
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::load
bool load(PropertyBase &dest) const override
set value to another property
Definition: CArrayAsProperty.h:150
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::readCallBack
const std::function< void(PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
Definition: CArrayAsProperty.h:59
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 >::verifier
const VerifierType & verifier() const
Copy constructor.
Definition: CArrayAsProperty.h:98
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::assign
bool assign(const PropertyBase &source) override
get the value from another property
Definition: CArrayAsProperty.h:138
Property.h
fun
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
Gaudi::Details::PropertyBase::type
std::string type() const
property type
Definition: Property.h:46
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:36
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::setValue
bool setValue(const ValueType &v)
Definition: CArrayAsProperty.h:106
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::m_handlers
HandlersType m_handlers
Definition: CArrayAsProperty.h:25
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::declareReadHandler
PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun) override
set new callback for reading
Definition: CArrayAsProperty.h:46
Gaudi::Property::value
const ValueType & value() const
Backward compatibility (.
Definition: Property.h:475
std::remove_reference
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::toStream
void toStream(std::ostream &out) const override
value -> stream
Definition: CArrayAsProperty.h:173
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::m_verifier
VerifierType m_verifier
Definition: CArrayAsProperty.h:24
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::clone
PropertyBase * clone() const override
clones the current property
Definition: CArrayAsProperty.h:116
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::toString
std::string toString() const override
value -> string
Definition: CArrayAsProperty.h:167
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::updateCallBack
const std::function< void(PropertyBase &)> updateCallBack() const override
get a reference to the updateCallBack
Definition: CArrayAsProperty.h:61
std::ostream
STL class.
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::operator=
Property & operator=(const ValueType &v)
Assignment from value.
Definition: CArrayAsProperty.h:83
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
Gaudi::Property::m_verifier
VerifierType m_verifier
Definition: Property.h:327
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::size
size_t size() const
Definition: CArrayAsProperty.h:122
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::verifier
VerifierType & verifier()
Accessor to verifier.
Definition: CArrayAsProperty.h:100
std::invalid_argument
STL class.
Gaudi::Property::fromString
StatusCode fromString(const std::string &source) override
string -> value
Definition: Property.h:615
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::empty
bool empty() const
Definition: CArrayAsProperty.h:123