1 #ifndef GAUDIKERNEL_PROPERTY_H 2 #define GAUDIKERNEL_PROPERTY_H 6 #include <boost/utility/string_ref.hpp> 72 virtual bool useUpdateHandler() = 0;
77 return declareReadHandler( [=](
PropertyBase& p ) { ( instance->*MF )( p ); } );
83 return declareUpdateHandler( [=](
PropertyBase& p ) { ( instance->*MF )( p ); } );
102 template <
class OWNER>
105 setOwnerType(
typeid( OWNER ) );
120 : m_name( to_view(
std::move(
name ) ) ), m_documentation( to_view(
std::move( doc ) ) ), m_typeinfo( &type )
125 : m_name( to_view(
std::move( name ) ) ), m_documentation( m_name ), m_typeinfo( &type )
135 static boost::string_ref to_view(
std::string str );
153 template <
class TYPE>
160 if ( !
parse( tmp, s ).isSuccess() ) {
172 template <
class TYPE>
177 template <
class TYPE>
182 if ( ( m_hasLowerBound && ( value < m_lowerBound ) ) || ( m_hasUpperBound && ( m_upperBound < value ) ) )
191 const TYPE&
lower()
const {
return m_lowerBound; }
193 const TYPE&
upper()
const {
return m_upperBound; }
198 m_hasLowerBound =
true;
199 m_lowerBound = value;
204 m_hasUpperBound =
true;
205 m_upperBound = value;
210 m_hasLowerBound =
false;
211 m_lowerBound = TYPE();
216 m_hasUpperBound =
false;
217 m_upperBound = TYPE();
236 bool m_hasLowerBound{
false};
237 bool m_hasUpperBound{
false};
261 throw std::logic_error(
"setUpdateHandler not implemented for this class" );
269 if ( m_readCallBack ) {
280 if ( m_updateCallBack ) {
292 using ReadHandler::useReadHandler;
293 using ReadHandler::setReadHandler;
294 using ReadHandler::getReadHandler;
295 using UpdateHandler::useUpdateHandler;
296 using UpdateHandler::setUpdateHandler;
297 using UpdateHandler::getUpdateHandler;
312 template <
class TYPE,
class VERIFIER = Details::Property::NullVerifier,
313 class HANDLERS = Details::Property::UpdateHandler>
339 template <
class T = ValueType>
341 : Details::PropertyBase( typeid(
ValueType ),
std::move( name ),
std::move( doc ) )
342 , m_value(
std::forward<T>( value ) )
344 m_verifier( m_value );
348 template <
class OWNER,
class T =
ValueType,
353 owner->declareProperty( *
this );
354 setOwnerType<OWNER>();
367 template <typename T = StorageType, typename = typename std::enable_if<!std::is_reference<T>::value>
::type>
391 return m_handlers.getReadHandler();
396 return m_handlers.getUpdateHandler();
402 m_handlers.useUpdateHandler( *
this );
409 m_handlers.useReadHandler( *
this );
422 return m_value == other;
429 return m_value != other;
436 return m_value < other;
441 decltype( std::declval<ValueType>() + std::declval<T>() )
operator+(
const T& other )
const 443 return m_value + other;
447 template <
class T = ValueType>
451 m_value = std::forward<T>( v );
452 m_handlers.useUpdateHandler( *
this );
481 template <
class T = const ValueType>
482 inline decltype( std::declval<T>().size() ) size()
const 484 return value().
size();
486 template <
class T = const ValueType>
487 inline decltype( std::declval<T>().length() ) length()
const 491 template <
class T = const ValueType>
492 inline decltype( std::declval<T>().empty() ) empty()
const 494 return value().
empty();
496 template <
class T = ValueType>
497 inline decltype( std::declval<T>().clear() ) clear()
501 template <
class T = const ValueType>
502 inline decltype( std::declval<T>().
begin() )
begin()
const 504 return value().
begin();
506 template <
class T = const ValueType>
507 inline decltype( std::declval<T>().
end() )
end()
const 509 return value().
end();
511 template <
class T = ValueType>
512 inline decltype( std::declval<T>().
begin() )
begin()
514 return value().
begin();
516 template <
class T = ValueType>
517 inline decltype( std::declval<T>().
end() )
end()
519 return value().
end();
521 template <
class ARG,
class T = const ValueType>
522 inline decltype( std::declval<T>()[ARG{}] )
operator[](
const ARG& arg )
const 526 template <
class ARG,
class T = ValueType>
527 inline decltype( std::declval<T>()[ARG{}] )
operator[](
const ARG& arg )
531 template <
class T = const ValueType>
532 inline decltype( std::declval<T>().find(
typename T::key_type{} ) ) find(
const typename T::key_type& key )
const 534 return value().
find( key );
536 template <
class T = ValueType>
537 inline decltype( std::declval<T>().find(
typename T::key_type{} ) ) find(
const typename T::key_type& key )
539 return value().
find( key );
541 template <
class ARG,
class T = ValueType>
542 inline decltype( std::declval<T>().erase( ARG{} ) ) erase( ARG arg )
544 return value().
erase( arg );
546 template <
class = ValueType>
552 template <
class = ValueType>
557 template <
class = ValueType>
563 template <
class = ValueType>
568 template <
class T = ValueType>
574 template <
class T = ValueType>
592 this->fromString( source.
toString() ).ignore();
600 return dest.
assign( *
this );
605 using Converter = Details::Property::StringConverter<ValueType>;
606 *
this =
Converter().fromString( source );
612 using Converter = Details::Property::StringConverter<ValueType>;
618 m_handlers.useReadHandler( *
this );
625 template <
class T,
class TP,
class V,
class H>
632 template <
class T,
class TP,
class V,
class H>
639 template <
class T,
class TP,
class V,
class H>
640 decltype( std::declval<TP>() + std::declval<T>() ) operator+( const T& v, const
Property<TP, V, H>& p )
642 return v + p.
value();
645 template <
class TYPE,
class HANDLERS = Details::Property::UpdateHandler>
648 template <
class TYPE>
654 template <
class TYPE>
657 template <
class TYPE>
794 bool load( PropertyBase& destination )
const override {
return destination.assign( *
this ); }
796 bool assign(
const PropertyBase& source )
override {
return fromString( source.toString() ); }
834 bool load( PropertyBase& destination )
const override {
return destination.assign( *
this ); }
836 bool assign(
const PropertyBase& source )
override {
return fromString( source.toString() ); }
1011 template <
class TYPE>
1036 template <
class TYPE>
1087 template <
unsigned N>
1124 template <
class TYPE>
1127 return component &&
hasProperty( component, name )
1202 template <
class TYPE>
1206 return setProperty( component, name, &value, doc );
1229 template <
class TYPE>
1283 template <
unsigned N>
1287 if ( 0 == component ) {
1363 template <
class TYPE>
1367 return setProperty( component, name, &value, doc );
1375 #endif // GAUDIKERNEL_PROPERTY_H Gaudi::Property< std::vector< float > & > FloatArrayPropertyRef
StatusCode setProperty(IProperty *component, const std::string &name, const TYPE &value, const std::string &doc)
simple function to set the property of the given object from the value
Gaudi::Property< signed char & > SignedCharPropertyRef
Details::Property::NullVerifier VerifierType
Gaudi::Property< std::vector< signed char > & > SignedCharArrayPropertyRef
std::function< void(PropertyBase &)> m_readCallBack
std::string toString(const TYPE &v)
Gaudi::Property< unsigned int & > UnsignedIntegerPropertyRef
bool operator!=(const T &v, const Property< TP, V, H > &p)
delegate (value != property) to property operator!=
GaudiHandleProperty * clone() const override
clones the current property
bool setValue(const ValueType &v)
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
std::function< void(PropertyBase &)> getReadHandler() const
void useUpdateHandler(const PropertyBase &) const
Gaudi::Property< std::vector< unsigned short > > UnsignedShortArrayProperty
Gaudi::Property< TYPE > SimpleProperty
Gaudi::Property< long long & > LongLongPropertyRef
PropertyBase & declareReadHandler(void(HT::*MF)(PropertyBase &), HT *instance)
Gaudi::Property< std::vector< int > > IntegerArrayProperty
std::ostream & operator<<(std::ostream &stream, const PropertyBase &prop)
bool operator==(const T &v, const Property< TP, V, H > &p)
delegate (value == property) to property operator==
bool useUpdateHandler() override
manual trigger for callback for update
void setDocumentation(std::string value)
set the documentation string
Gaudi::Property< long long > LongLongProperty
PropertyBase & declareUpdateHandler(std::function< void(PropertyBase &)> fun) override
set new callback for update
Implementation of property with value of concrete type.
Gaudi::Property< long & > LongPropertyRef
std::function< void(PropertyBase &)> m_updateCallBack
virtual PropertyBase & declareUpdateHandler(std::function< void(PropertyBase &)> fun)=0
set new callback for update
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Gaudi::Property< std::vector< double > & > DoubleArrayPropertyRef
virtual bool assign(const PropertyBase &source)=0
import the property value form the source
The declaration of major parsing functions used e.g for (re)implementation of new extended properties...
bool load(PropertyBase &destination) const override
const std::string name() const
property name
Property & operator=(T &&v)
Assignment from value.
Gaudi::Property< float > FloatProperty
Gaudi::Property< int > IntegerProperty
Gaudi::Property< std::vector< unsigned long long > & > UnsignedLongLongArrayPropertyRef
void setOwnerType()
set the type of the owner class (used for documentation)
void clearUpper()
Clear upper bound value.
const TYPE & upper() const
Return the upper bound value.
GaudiHandleArrayProperty * clone() const override
clones the current property
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Gaudi::Property< unsigned long long > UnsignedLongLongProperty
Gaudi::Property< float & > FloatPropertyRef
vector< std::string > StorageType
Hosted type.
Gaudi::Details::PropertyBase * property(const std::string &name) const
std::string ownerTypeName() const
get the string for the type of the owner class (used for documentation)
std::string toString() const override
value -> string
Gaudi::Property< std::vector< std::string > > StringArrayProperty
Gaudi::Property< std::vector< unsigned short > & > UnsignedShortArrayPropertyRef
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
Gaudi::Property< std::vector< unsigned char > > UnsignedCharArrayProperty
void setLower(const TYPE &value)
Set lower bound value.
Gaudi::Property< unsigned short > UnsignedShortProperty
const std::function< void(Details::PropertyBase &)> updateCallBack() const override
get a reference to the updateCallBack
Gaudi::Property< unsigned long > UnsignedLongProperty
Gaudi::Property< std::string & > StringPropertyRef
Gaudi::Details::Property::ReadUpdateHandler m_handlers
StorageType m_value
Storage.
Gaudi::Property< char & > CharPropertyRef
Gaudi::Property< std::vector< bool > & > BooleanArrayPropertyRef
Gaudi::Property< std::vector< long double > > LongDoubleArrayProperty
Gaudi::Property< std::vector< long long > > LongLongArrayProperty
Gaudi::Property< std::vector< double > > DoubleArrayProperty
bool operator<(const T &other) const
"less" comparison
void setOwnerType(const std::type_info &ownerType)
set the type of the owner class (used for documentation)
virtual std::string toString() const =0
value -> string
Gaudi::Property< std::vector< short > > ShortArrayProperty
Gaudi::Details::PropertyBase Property
backward compatibility hack for old Property base class
Gaudi::Property< std::vector< unsigned long > & > UnsignedLongArrayPropertyRef
Gaudi::Property< std::vector< unsigned int > > UnsignedIntegerArrayProperty
PropertyBase(const std::type_info &type, std::string name="", std::string doc="")
constructor from the property name and the type
Details::PropertyBase & declareUpdateHandler(std::function< void(Details::PropertyBase &)> fun) override
set new callback for update
Property()
Construct an anonymous property with default constructed value.
auto begin(reverse_wrapper< T > &w)
Helper class to simplify the migration old properties deriving directly from PropertyBase.
PropertyMgr & operator=(const PropertyMgr &)=delete
Property & operator+=(const T &other)
Gaudi::Property< std::vector< long > > LongArrayProperty
typename std::remove_reference< StorageType >::type ValueType
Gaudi::Property< std::vector< long > & > LongArrayPropertyRef
void operator()(PropertyBase &p) const
void operator()(const TYPE &value) const
Gaudi::Property< signed char > SignedCharProperty
Gaudi::Property< char > CharProperty
Property & operator-=(const T &other)
const VerifierType & verifier() const
Accessor to verifier.
Gaudi::Property< int & > IntegerPropertyRef
GaudiHandleBase * m_pValue
Pointer to the real property.
Gaudi::Property< unsigned long & > UnsignedLongPropertyRef
const std::type_info * ownerType() const
get the type of the owner class (used for documentation)
boost::string_ref m_name
property name
PropertyBase(std::string name, const std::type_info &type)
constructor from the property name and the type
bool hasProperty(const std::string &name) const override
Return true if we have a property with the given name.
void setBounds(const TYPE &lower, const TYPE &upper)
Set both bounds (lower and upper) at the same time.
Gaudi::Property< std::vector< long double > & > LongDoubleArrayPropertyRef
This class is used for returning status codes from appropriate routines.
Property(std::string name, T &&value, std::string doc="")
the constructor with property name, value and documentation.
Definition of the basic interface.
const std::type_info * m_typeinfo
property type
bool useUpdateHandler() override
use the call-back function at update, if available
Gaudi::Property< unsigned int > UnsignedIntegerProperty
TYPE fromString(const std::string &s)
const TYPE & lower() const
Return the lower bound value.
Gaudi::Property< std::vector< char > > CharArrayProperty
virtual PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun)=0
set new callback for reading
const GaudiHandleBase & value() const
Gaudi::Property< bool > BooleanProperty
Gaudi::Property< std::vector< unsigned long long > > UnsignedLongLongArrayProperty
VerifierType & verifier()
Accessor to verifier.
const GaudiHandleArrayBase & value() const
auto end(reverse_wrapper< T > &w)
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
virtual std::ostream & fillStream(std::ostream &) const
the printout of the property value
PropertyBase & declareUpdateHandler(void(HT::*MF)(PropertyBase &), HT *instance)
bool hasLower() const
Return if it has a lower bound.
Gaudi::Property< double > DoubleProperty
void setName(std::string value)
set the new value for the property name
Gaudi::Property< std::vector< int > & > IntegerArrayPropertyRef
void useReadHandler() const
use the call-back function at reading, if available
bool assign(const PropertyBase &source) override
void operator()(const TYPE &) const
Gaudi::Property< std::vector< long long > & > LongLongArrayPropertyRef
Gaudi::Property< double & > DoublePropertyRef
std::function< void(PropertyBase &)> getUpdateHandler() const
bool operator==(const T &other) const
equality comparison
Gaudi::Property< std::vector< unsigned char > & > UnsignedCharArrayPropertyRef
void useReadHandler(const PropertyBase &p) const
Property(OWNER *owner, std::string name, T &&value=ValueType{}, std::string doc="")
Autodeclaring constructor with property name, value and documentation.
bool hasUpper() const
Return if it has a lower bound.
bool load(Details::PropertyBase &dest) const override
set value to another property
Base class of array's of various gaudihandles.
std::function< void(PropertyBase &)> getUpdateHandler() const
Gaudi::Property< long double & > LongDoublePropertyRef
PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun) override
set new callback for reading
Gaudi::Property< std::vector< signed char > > SignedCharArrayProperty
Gaudi::Property< std::string > StringProperty
void setUpdateHandler(std::function< void(PropertyBase &)> fun)
Gaudi::Property< long double > LongDoubleProperty
GaudiHandleArrayProperty & operator=(const GaudiHandleArrayBase &value)
SwapCall(callback_t &input)
GaudiHandleArrayBase * m_pValue
Pointer to the real property.
double fun(const std::vector< double > &x)
Gaudi::Property< short > ShortProperty
std::string type() const
property type
std::string documentation() const
property documentation
Gaudi::Property< std::vector< unsigned long > > UnsignedLongArrayProperty
Details::PropertyBase * clone() const override
clones the current property
Gaudi::Property< TYPE & > SimplePropertyRef
Gaudi::Property< unsigned long long & > UnsignedLongLongPropertyRef
void clearBounds()
Clear both bounds (lower and upper) at the same time.
void setReadHandler(std::function< void(PropertyBase &)> fun)
GAUDI_API const Gaudi::Details::PropertyBase * getProperty(const std::vector< const Gaudi::Details::PropertyBase * > *p, const std::string &name)
get the property by name from the list of the properties
const std::function< void(PropertyBase &)> updateCallBack() const override
get a reference to the updateCallBack
StatusCode setProperty(IInterface *component, const std::string &name, const Gaudi::Property< TYPE > &value, const std::string &doc="")
simple function to set the property of the given object from another property
std::function< void(PropertyBase &)> getReadHandler() const
Gaudi::Property< std::vector< std::string > & > StringArrayPropertyRef
bool assign(const Details::PropertyBase &source) override
get the value from another property
bool assign(const PropertyBase &source) override
bool operator!=(const T &other) const
inequality comparison
Gaudi::Property< long > LongProperty
void setUpdateHandler(std::function< void(PropertyBase &)>)
Gaudi::Property< std::vector< char > & > CharArrayPropertyRef
const ValueType & value() const
Backward compatibility (.
void clearLower()
Clear lower bound value.
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
implementation of various functions for streaming.
Property(T &&v)
Construct an anonymous property from a value.
const std::function< void(PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
Gaudi::Property< unsigned short & > UnsignedShortPropertyRef
Gaudi::Property< std::vector< float > > FloatArrayProperty
ValueType operator++(int)
The IProperty is the basic interface for all components which have properties that can be set or get...
helper to disable a while triggering it, to avoid infinite recursion
boost::string_ref m_documentation
property doc string
bool load(PropertyBase &destination) const override
GaudiHandleProperty & operator=(const GaudiHandleBase &value)
Gaudi::Property< std::vector< short > & > ShortArrayPropertyRef
Details::PropertyBase & declareReadHandler(std::function< void(Details::PropertyBase &)> fun) override
set new callback for reading
Helper functions to set/get the application return code.
Gaudi::Property< unsigned char > UnsignedCharProperty
const std::function< void(Details::PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
Gaudi::Property< short & > ShortPropertyRef
void setUpper(const TYPE &value)
Set upper bound value.
void setReadHandler(std::function< void(PropertyBase &)>)
Details::Property::UpdateHandler HandlersType
Gaudi::Property< unsigned char & > UnsignedCharPropertyRef
ValueType operator--(int)
decltype(std::declval< TP >()+std::declval< T >()) operator+(const T &v, const Property< TP, V, H > &p)
implemantation of (value + property)
void useReadHandler(const PropertyBase &) const
Gaudi::Property< std::vector< bool > > BooleanArrayProperty
const std::type_info * type_info() const
property type-info
Gaudi::Property< std::vector< unsigned int > & > UnsignedIntegerArrayPropertyRef
StatusCode fromString(const std::string &source) override
string -> value
void toStream(std::ostream &out) const override
value -> stream
Gaudi::Property< bool & > BooleanPropertyRef
void useUpdateHandler(PropertyBase &p)