The Gaudi Framework  v29r0 (ff2e7097)
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];
18  using VerifierType = VERIFIER;
19  using HandlersType = HANDLERS;
20 
21  private:
28  template <class T>
30  template <class T>
33  public:
34  // ==========================================================================
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 
47  {
48  m_handlers.setReadHandler( std::move( fun ) );
49  return *this;
50  }
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 
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; }
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  {
182  public:
184  };
185 }
186 #endif
StatusCode fromString(const std::string &source) override
string -> value
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:293
bool useUpdateHandler() override
manual trigger for callback for update
Implementation of property with value of concrete type.
Definition: Property.h:319
const std::string name() const
property name
Definition: Property.h:40
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:346
STL namespace.
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
StorageType m_value
Storage.
Definition: Property.h:331
typename std::remove_reference< StorageType >::type ValueType
PropertyBase & declareUpdateHandler(std::function< void(PropertyBase &)> fun) override
set new callback for update
Property()
Construct an anonymous property with default constructed value.
Definition: Property.h:384
STL class.
const ValueType & value() const
Backward compatibility.
int N
Definition: IOTest.py:101
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
bool load(PropertyBase &dest) const override
set value to another property
const std::function< void(PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
T move(T...args)
const VerifierType & verifier() const
Copy constructor.
bool assign(const PropertyBase &source) override
get the value from another property
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
std::string type() const
property type
Definition: Property.h:46
Property(std::string name, StorageType value, std::string doc="")
the constructor with property name, value and documentation.
PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun) override
set new callback for reading
const ValueType & value() const
Backward compatibility (.
Definition: Property.h:479
void toStream(std::ostream &out) const override
value -> stream
PropertyBase * clone() const override
clones the current property
std::string toString() const override
value -> string
const std::function< void(PropertyBase &)> updateCallBack() const override
get a reference to the updateCallBack
STL class.
Property & operator=(const ValueType &v)
Assignment from value.
Helper functions to set/get the application return code.
Definition: __init__.py:1
VerifierType m_verifier
Definition: Property.h:332
VerifierType & verifier()
Accessor to verifier.
StatusCode fromString(const std::string &source) override
string -> value
Definition: Property.h:650