1 #ifndef GAUDIKERNEL_PROPERTY_H 2 #define GAUDIKERNEL_PROPERTY_H 6 #include <boost/utility/string_ref.hpp> 68 virtual bool useUpdateHandler() = 0;
72 return declareReadHandler( [=](
PropertyBase& p ) { ( instance->*MF )( p ); } );
77 return declareUpdateHandler( [=](
PropertyBase& p ) { ( instance->*MF )( p ); } );
96 template <
class OWNER>
98 setOwnerType(
typeid( OWNER ) );
112 : m_name( to_view(
std::move(
name ) ) )
113 , m_documentation( to_view(
std::move( doc ) ) )
114 , m_typeinfo( &type ) {}
117 : m_name( to_view(
std::move( name ) ) ), m_documentation( m_name ), m_typeinfo( &type ) {}
125 static boost::string_ref to_view(
std::string str );
165 template <
class TYPE>
177 virtual TYPE fromString(
const TYPE& ref_value,
const std::string&
s ) = 0;
182 if ( !
parse( buffer, InputData{s} ).isSuccess() ) {
200 template <
typename TYPE,
typename Enable =
void>
203 TYPE buffer = ref_value;
204 this->fromStringImpl( buffer,
s );
209 template <
class TYPE>
214 this->fromStringImpl( buffer,
s );
220 template <
typename TYPE>
224 template <
class TYPE>
227 template <
class TYPE>
232 if ( ( m_hasLowerBound && ( value < m_lowerBound ) ) || ( m_hasUpperBound && ( m_upperBound < value ) ) )
241 const TYPE&
lower()
const {
return m_lowerBound; }
243 const TYPE&
upper()
const {
return m_upperBound; }
247 m_hasLowerBound =
true;
248 m_lowerBound = value;
252 m_hasUpperBound =
true;
253 m_upperBound = value;
257 m_hasLowerBound =
false;
258 m_lowerBound = TYPE();
262 m_hasUpperBound =
false;
263 m_upperBound = TYPE();
267 void setBounds(
const TYPE& lower,
const TYPE& upper ) {
280 bool m_hasLowerBound{
false};
281 bool m_hasUpperBound{
false};
303 throw std::logic_error(
"setUpdateHandler not implemented for this class" );
318 if ( m_updateCallBack ) {
330 using ReadHandler::getReadHandler;
331 using ReadHandler::setReadHandler;
332 using ReadHandler::useReadHandler;
333 using UpdateHandler::getUpdateHandler;
334 using UpdateHandler::setUpdateHandler;
335 using UpdateHandler::useUpdateHandler;
350 template <
class TYPE,
class VERIFIER = Details::Property::NullVerifier,
351 class HANDLERS = Details::Property::UpdateHandler>
377 template <
class T = StorageType>
379 : Details::PropertyBase( typeid(
ValueType ),
std::move( name ),
std::move( doc ) )
380 , m_value(
std::forward<T>( value ) ) {
381 m_verifier( m_value );
385 template <
typename OWNER,
typename T =
ValueType,
386 typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>,
387 typename = std::enable_if_t<std::is_default_constructible<T>::value>>
389 owner->declareProperty( *
this );
390 setOwnerType<OWNER>();
395 template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>>
398 owner->declareProperty( *
this );
399 setOwnerType<OWNER>();
404 template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>>
407 :
Property( owner,
std::move( name ),
std::forward<T>( value ),
std::move( doc ) ) {
408 declareUpdateHandler(
std::move( handler ) );
413 template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>>
417 [owner, handler]( PropertyBase& p ) { ( owner->*handler )( p ); },
std::move( doc ) ) {}
420 template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>>
423 [owner, handler]( PropertyBase& ) { ( owner->*handler )(); },
std::move( doc ) ) {}
427 template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>>
430 :
Property( owner,
std::move( name ),
std::forward<T>( value ),
std::move( handler ),
std::move( doc ) ) {
431 if ( invoke ) useUpdateHandler();
437 template <
typename T,
typename = not_copying<T>>
442 template <typename T = StorageType, typename = std::enable_if_t<!std::is_reference<T>::value>>
461 return m_handlers.getReadHandler();
465 return m_handlers.getUpdateHandler();
470 m_handlers.useUpdateHandler( *
this );
476 m_handlers.useReadHandler( *
this );
488 return m_value == other;
494 return m_value != other;
500 return m_value < other;
505 decltype(
auto )
operator+(
const T& other )
const {
506 return m_value + other;
510 template <
class T = ValueType>
513 m_value = std::forward<T>( v );
514 m_handlers.useUpdateHandler( *
this );
541 template <
class T = const ValueType>
542 decltype(
auto )
size()
const {
543 return value().
size();
545 template <
class T = const ValueType>
546 decltype(
auto ) length()
const {
549 template <
class T = const ValueType>
550 decltype(
auto ) empty()
const {
551 return value().
empty();
553 template <
class T = ValueType>
554 decltype(
auto ) clear() {
557 template <
class T = const ValueType>
558 decltype(
auto )
begin()
const {
559 return value().
begin();
561 template <
class T = const ValueType>
562 decltype(
auto )
end()
const {
563 return value().
end();
565 template <
class T = ValueType>
566 decltype(
auto )
begin() {
567 return value().
begin();
569 template <
class T = ValueType>
570 decltype(
auto )
end() {
571 return value().
end();
574 decltype(
auto ) operator[](
const ARG& arg )
const {
578 decltype(
auto ) operator[](
const ARG& arg ) {
581 template <
class T = const ValueType>
582 decltype(
auto ) find(
const typename T::key_type& key )
const {
583 return value().
find( key );
585 template <
class T = ValueType>
586 decltype(
auto ) find(
const typename T::key_type& key ) {
587 return value().
find( key );
589 template <
class ARG,
class T = ValueType>
590 decltype(
auto ) erase( ARG arg ) {
591 return value().
erase( arg );
593 template <
class = ValueType>
598 template <
class = ValueType>
602 template <
class = ValueType>
607 template <
class = ValueType>
611 template <
class T = ValueType>
616 template <
class T = ValueType>
622 template <
class T = const ValueType>
623 decltype(
auto ) key()
const {
624 return value().key();
626 template <
class T = const ValueType>
627 decltype(
auto ) objKey()
const {
628 return value().objKey();
630 template <
class T = const ValueType>
631 decltype(
auto ) fullKey()
const {
632 return value().fullKey();
634 template <
class T = ValueType>
635 decltype(
auto ) initialize() {
636 return value().initialize();
638 template <
class T = ValueType>
639 decltype(
auto ) makeHandles()
const {
640 return value().makeHandles();
642 template <
class ARG,
class T = ValueType>
643 decltype(
auto ) makeHandles(
const ARG& arg )
const {
644 return value().makeHandles( arg );
650 template <
class... Args>
651 decltype( std::declval<ValueType>()( std::declval<Args&&>()... ) ) operator()( Args&&...
args ) const
652 noexcept( noexcept(
std::declval<
ValueType>()(
std::declval<Args&&>()... ) ) ) {
653 return value()( std::forward<Args>(
args )... );
665 this->fromString( source.
toString() ).ignore();
672 return dest.
assign( *
this );
676 using Converter = Details::Property::StringConverter<ValueType>;
677 *
this =
Converter().fromString( m_value, source );
682 using Converter = Details::Property::StringConverter<ValueType>;
687 m_handlers.useReadHandler( *
this );
694 template <
class T,
class TP,
class V,
class H>
700 template <
class T,
class TP,
class V,
class H>
706 template <
class T,
class TP,
class V,
class H>
707 decltype(
auto ) operator+( const T& v, const
Property<TP, V, H>& p ) {
708 return v + p.
value();
711 template <
class TYPE,
class HANDLERS = Details::Property::UpdateHandler>
714 template <
class TYPE>
720 template <
class TYPE>
723 template <
class TYPE>
804 template <
typename Handler =
typename Gaudi::Details::Property::UpdateHandler>
832 m_handlers.useUpdateHandler( *
this );
855 bool load( PropertyBase& destination )
const override {
return destination.assign( *
this ); }
857 bool assign(
const PropertyBase& source )
override {
return fromString( source.toString() ).isSuccess(); }
892 bool load( PropertyBase& destination )
const override {
return destination.assign( *
this ); }
894 bool assign(
const PropertyBase& source )
override {
return fromString( source.toString() ).isSuccess(); }
1066 template <
class TYPE>
1091 template <
class TYPE>
1141 template <
unsigned N>
1177 template <
class TYPE>
1180 return component &&
hasProperty( component, name )
1255 template <
class TYPE>
1258 return setProperty( component, name, &value, doc );
1281 template <
class TYPE>
1332 template <
unsigned N>
1409 template <
class TYPE>
1412 return setProperty( component, name, &value, doc );
1420 #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
Property(OWNER *owner, std::string name)
Autodeclaring constructor with property name, value and documentation.
std::function< void(PropertyBase &)> m_readCallBack
Gaudi::Property< unsigned int & > UnsignedIntegerPropertyRef
TYPE fromString(const TYPE &ref_value, const std::string &s) final override
Property(OWNER *owner, std::string name, T &&value, std::function< void(PropertyBase &)> handler, Details::Property::ImmediatelyInvokeHandler invoke, std::string doc="")
Autodeclaring constructor with property name, value, updateHandler and documentation.
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
const std::function< void(PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
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
TYPE fromString(const TYPE &, const std::string &s) final override
virtual bool assign(const PropertyBase &source)=0
import the property value form the source
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::tagged_bool< class ImmediatelyInvokeHandler_tag > ImmediatelyInvokeHandler
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
constexpr static const auto SUCCESS
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
std::string toString(const TYPE &v)
Property(OWNER *owner, std::string name, T &&value, void(OWNER::*handler)(), std::string doc="")
Autodeclaring constructor with property name, value, pointer to member function updateHandler and doc...
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
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
The declaration of major parsing functions used e.g for (re)implementation of new extended properties...
PropertyBase(const std::type_info &type, std::string name="", std::string doc="")
constructor from the property name and the type
constexpr auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
Details::PropertyBase & declareUpdateHandler(std::function< void(Details::PropertyBase &)> fun) override
set new callback for update
Property()
Construct an anonymous property with default constructed value.
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
Property(OWNER *owner, std::string name, T &&value, void(OWNER::*handler)(PropertyBase &), std::string doc="")
Autodeclaring constructor with property name, value, pointer to member function updateHandler and doc...
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
Gaudi::Property< unsigned int > UnsignedIntegerProperty
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
PropertyBase & declareUpdateHandler(std::function< void(PropertyBase &)> fun) override
set new callback for update
Gaudi::Property< std::vector< unsigned long long > > UnsignedLongLongArrayProperty
VerifierType & verifier()
Accessor to verifier.
PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun) override
set new callback for reading
const GaudiHandleArrayBase & value() const
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)
void fromStringImpl(TYPE &buffer, const std::string &s)
std::ostream & toStream(const DataObjID &d, std::ostream &os)
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
bool assign(const PropertyBase &source) override
void operator()(const TYPE &) const
Gaudi::Property< std::vector< long long > & > LongLongArrayPropertyRef
std::enable_if_t<!is_this_type< T >::value > not_copying
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
bool hasUpper() const
Return if it has a lower bound.
bool load(Details::PropertyBase &dest) const override
set value to another property
StatusCode parse(DataObjID &dest, const std::string &src)
Base class of array's of various gaudihandles.
std::function< void(PropertyBase &)> getUpdateHandler() const
Gaudi::Property< long double & > LongDoublePropertyRef
void useReadHandler() const
use the call-back function at reading, if available
Gaudi::Property< std::vector< signed char > > SignedCharArrayProperty
bool useUpdateHandler() override
use the call-back function at update, if available
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
decltype(auto) operator+(const T &v, const Property< TP, V, H > &p)
implemantation of (value + property)
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
constexpr static const auto FAILURE
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
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 (.
Property(OWNER *owner, std::string name, T &&value, std::function< void(PropertyBase &)> handler, std::string doc="")
Autodeclaring constructor with property name, value, updateHandler and documentation.
void clearLower()
Clear lower bound value.
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
AttribStringParser::Iterator begin(const AttribStringParser &parser)
auto invoke(F &&f, ArgTypes &&...args) noexcept(noexcept(detail2::INVOKE(std::forward< F >(f), std::forward< ArgTypes >(args)...))) -> decltype(detail2::INVOKE(std::forward< F >(f), std::forward< ArgTypes >(args)...))
implementation of various functions for streaming.
Property(T &&v)
Construct an anonymous property from a value.
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
Property(OWNER *owner, std::string name, T &&value, std::string doc="")
Autodeclaring constructor with property name, value and documentation.
const std::function< void(PropertyBase &)> updateCallBack() const override
get a reference to the updateCallBack
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
std::string toString(const Type &)
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)
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)