The Gaudi Framework  v36r7 (7f57a304)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
CArrayAsProperty.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef NO_C_ARRAY_AS_PROPERTY_WARNING
12 # warning deprecated header (will be removed in Gaudi v29r0), think about using std::array<T,N> instead of T[N]
13 #endif
14 #ifndef GAUDIKERNEL_CARRAYASPROPERTY_H
15 # define GAUDIKERNEL_CARRAYASPROPERTY_H
16 # include <Gaudi/Property.h>
17 
18 namespace Gaudi {
19  template <class TYPE, size_t N, class VERIFIER, class HANDLERS>
20  class Property<TYPE[N], VERIFIER, HANDLERS> : public Details::PropertyBase {
21  public:
22  // ==========================================================================
24  using StorageType = TYPE ( & )[N];
26  using VerifierType = VERIFIER;
27  using HandlersType = HANDLERS;
28 
29  private:
36  template <class T>
37  static inline constexpr bool is_this_type_v = std::is_same_v<Property, typename std::remove_reference_t<T>>;
38  template <class T>
41  public:
42  // ==========================================================================
45  : PropertyBase( typeid( ValueType ), std::move( name ), std::move( doc ) ), m_value( value ) {
47  }
48 
49  using PropertyBase::declareReadHandler;
50  using PropertyBase::declareUpdateHandler;
51 
54  m_handlers.setReadHandler( std::move( fun ) );
55  return *this;
56  }
59  m_handlers.setUpdateHandler( std::move( fun ) );
60  return *this;
61  }
62 
64  const std::function<void( PropertyBase& )> readCallBack() const override { return m_handlers.getReadHandler(); }
66  const std::function<void( PropertyBase& )> updateCallBack() const override { return m_handlers.getUpdateHandler(); }
67 
69  bool useUpdateHandler() override {
70  m_handlers.useUpdateHandler( *this );
71  return true;
72  }
73 
75  operator const ValueType&() const {
76  m_handlers.useReadHandler( *this );
77  return m_value;
78  }
79  // /// Automatic conversion to value (reference).
80  // operator ValueType& () {
81  // useReadHandler();
82  // return m_value;
83  // }
84 
87  m_verifier( v );
88  for ( size_t i = 0; i != N; ++i ) { m_value[i] = v[i]; }
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  *this = v;
108  return true;
109  }
110  bool set( const ValueType& v ) {
111  *this = v;
112  return true;
113  }
114  PropertyBase* clone() const override { return new Property( *this ); }
116 
120  inline size_t size() const { return N; }
121  inline bool empty() const { return false; }
122  template <class T = const ValueType>
123  inline decltype( std::declval<T>()[typename T::key_type{}] ) operator[]( const typename T::key_type& key ) const {
124  return value()[key];
125  }
126  template <class T = ValueType>
127  inline decltype( std::declval<T>()[typename T::key_type{}] ) operator[]( const typename T::key_type& key ) {
128  return value()[key];
129  }
131  // ==========================================================================
132  public:
134  bool assign( const PropertyBase& source ) override {
135  // Is the property of "the same" type?
136  const Property* p = dynamic_cast<const Property*>( &source );
137  if ( p ) {
138  *this = p->value();
139  } else {
140  this->fromString( source.toString() ).ignore();
141  }
142  return true;
143  }
145  bool load( PropertyBase& dest ) const override {
146  // delegate to the 'opposite' method
147  return dest.assign( *this );
148  }
150  StatusCode fromString( const std::string& source ) override {
151  ValueType tmp;
152  if ( Parsers::parse( tmp, source ).isSuccess() ) {
153  *this = tmp;
154  } else {
155  throw std::invalid_argument( "cannot parse '" + source + "' to " + this->type() );
156  }
157  return StatusCode::SUCCESS;
158  }
160  std::string toString() const override {
161  m_handlers.useReadHandler( *this );
162  return Utils::toString( m_value );
163  }
165  void toStream( std::ostream& out ) const override {
166  m_handlers.useReadHandler( *this );
168  }
169  };
170  template <class TYPE, size_t N, class VERIFIER, class HANDLERS>
171  class Property<TYPE ( & )[N], VERIFIER, HANDLERS> : public Property<TYPE[N], VERIFIER, HANDLERS> {
172  public:
174  };
175 } // namespace Gaudi
176 #endif
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: PropertyBase.h:35
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::empty
bool empty() const
Definition: CArrayAsProperty.h:121
Gaudi::Details::PropertyBase::name
const std::string name() const
property name
Definition: PropertyBase.h:39
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::declareReadHandler
PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun) override
set new callback for reading
Definition: CArrayAsProperty.h:53
std::string
STL class.
std::move
T move(T... args)
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::HandlersType
HANDLERS HandlersType
Definition: CArrayAsProperty.h:27
Gaudi::Details::PropertyBase::type
std::string type() const
property type
Definition: PropertyBase.h:47
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::value
ValueType & value()
Definition: CArrayAsProperty.h:105
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::fromString
StatusCode fromString(const std::string &source) override
string -> value
Definition: CArrayAsProperty.h:150
IOTest.N
int N
Definition: IOTest.py:115
Gaudi::Property::m_handlers
HandlersType m_handlers
Definition: Property.h:53
std::function
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::readCallBack
const std::function< void(PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
Definition: CArrayAsProperty.h:64
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::StorageType
TYPE(&)[N] StorageType
Hosted type.
Definition: CArrayAsProperty.h:24
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::VerifierType
VERIFIER VerifierType
Definition: CArrayAsProperty.h:26
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::operator=
Property & operator=(const ValueType &v)
Assignment from value.
Definition: CArrayAsProperty.h:86
Gaudi::Property::fromString
StatusCode fromString(const std::string &source) override
string -> value
Definition: Property.h:390
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::toString
std::string toString() const override
value -> string
Definition: CArrayAsProperty.h:160
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:44
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::clone
PropertyBase * clone() const override
clones the current property
Definition: CArrayAsProperty.h:114
StatusCode
Definition: StatusCode.h:65
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::declareUpdateHandler
PropertyBase & declareUpdateHandler(std::function< void(PropertyBase &)> fun) override
set new callback for update
Definition: CArrayAsProperty.h:58
std::enable_if
std::ostream
STL class.
Gaudi::Property::value
const ValueType & value() const
Backward compatibility (.
Definition: Property.h:240
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::toStream
void toStream(std::ostream &out) const override
value -> stream
Definition: CArrayAsProperty.h:165
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::assign
bool assign(const PropertyBase &source) override
get the value from another property
Definition: CArrayAsProperty.h:134
Gaudi::Details::PropertyBase::PropertyBase
PropertyBase(const std::type_info &type, std::string name="", std::string doc="", std::string semantics="")
constructor from the property name and the type
Definition: PropertyBase.h:118
Gaudi::Property::m_verifier
VerifierType m_verifier
Definition: Property.h:52
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::setValue
bool setValue(const ValueType &v)
Definition: CArrayAsProperty.h:106
std::invalid_argument
STL class.
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::set
bool set(const ValueType &v)
Definition: CArrayAsProperty.h:110
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::m_handlers
HandlersType m_handlers
Definition: CArrayAsProperty.h:33
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::ValueType
typename std::remove_reference< StorageType >::type ValueType
Definition: CArrayAsProperty.h:25
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::value
const ValueType & value() const
Backward compatibility.
Definition: CArrayAsProperty.h:104
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::updateCallBack
const std::function< void(PropertyBase &)> updateCallBack() const override
get a reference to the updateCallBack
Definition: CArrayAsProperty.h:66
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::verifier
const VerifierType & verifier() const
Copy constructor.
Definition: CArrayAsProperty.h:98
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
gaudirun.dest
dest
Definition: gaudirun.py:224
HistoDumpEx.v
v
Definition: HistoDumpEx.py:27
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::size
size_t size() const
Definition: CArrayAsProperty.h:120
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::m_verifier
VerifierType m_verifier
Definition: CArrayAsProperty.h:32
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:353
std::remove_reference
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
Gaudi::Property::m_value
StorageType m_value
Storage.
Definition: Property.h:51
std
STL namespace.
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:299
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:21
Gaudi::Property::is_this_type_v
static constexpr bool is_this_type_v
helper typedefs for SFINAE
Definition: Property.h:57
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::useUpdateHandler
bool useUpdateHandler() override
manual trigger for callback for update
Definition: CArrayAsProperty.h:69
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::load
bool load(PropertyBase &dest) const override
set value to another property
Definition: CArrayAsProperty.h:145
ProduceConsume.key
key
Definition: ProduceConsume.py:81
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::verifier
VerifierType & verifier()
Accessor to verifier.
Definition: CArrayAsProperty.h:100
Gaudi::Property< TYPE[N], VERIFIER, HANDLERS >::m_value
StorageType m_value
Storage.
Definition: CArrayAsProperty.h:31
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:39
Property.h
PrepareBase.out
out
Definition: PrepareBase.py:20
Gaudi::Property::Property
Property()
Construct an anonymous property with default constructed value.
Definition: Property.h:135