Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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];
16  using VerifierType = VERIFIER;
17  using HandlersType = HANDLERS;
18 
19  private:
26  template <class T>
28  template <class T>
31  public:
32  // ==========================================================================
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 
44  m_handlers.setReadHandler( std::move( fun ) );
45  return *this;
46  }
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; }
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:
164  };
165 } // namespace Gaudi
166 #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:284
bool useUpdateHandler() override
manual trigger for callback for update
Implementation of property with value of concrete type.
Definition: Property.h:352
const std::string name() const
property name
Definition: Property.h:36
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:334
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
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:364
typename std::remove_reference< StorageType >::type ValueType
PropertyBase(const std::type_info &type, std::string name="", std::string doc="")
constructor from the property name and the type
Definition: Property.h:111
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:443
STL class.
const ValueType & value() const
Backward compatibility.
int N
Definition: IOTest.py:99
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
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:42
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:525
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:365
VerifierType & verifier()
Accessor to verifier.
StatusCode fromString(const std::string &source) override
string -> value
Definition: Property.h:675