1 #ifndef GAUDIKERNEL_PROPERTY_H
2 #define GAUDIKERNEL_PROPERTY_H
12 #include "GaudiKernel/Kernel.h"
13 #include "GaudiKernel/PropertyVerifier.h"
14 #include "GaudiKernel/Parsers.h"
15 #include "GaudiKernel/ToStream.h"
16 #include "GaudiKernel/SmartIF.h"
45 const std::string&
name ()
const {
return m_name ; }
47 const std::string& documentation()
const {
return m_documentation; }
49 const std::type_info* type_info ()
const {
return m_typeinfo ; }
51 std::string
type ()
const {
return m_typeinfo->name() ; }
55 virtual bool assign (
const Property& source ) = 0 ;
58 virtual std::string
toString ()
const = 0 ;
60 virtual void toStream(std::ostream& out)
const = 0;
65 const std::function<void(Property&)>& readCallBack()
const {
return m_readCallBack; }
67 const std::function<void(Property&)>& updateCallBack()
const {
return m_updateCallBack; }
75 inline Property& declareReadHandler(
void ( HT::* MF ) (
Property& ) , HT* instance )
76 {
return declareReadHandler( [=](
Property& p) { (instance->*MF)(p); } ) ; }
79 inline Property& declareUpdateHandler(
void ( HT::* MF ) (
Property& ) , HT* instance )
80 {
return declareUpdateHandler ( [=](
Property& p) { (instance->*MF)(p); } ); }
83 virtual void useReadHandler ()
const ;
85 virtual bool useUpdateHandler () ;
90 virtual Property* clone ()
const = 0 ;
92 void setName ( std::string
value ) { m_name = std::move(value) ; }
94 void setDocumentation( std::string documentation ) {
95 m_documentation = std::move(documentation); }
97 virtual std::ostream& fillStream ( std::ostream& )
const ;
101 (
const std::type_info&
type ,
102 std::string
name =
"" ) ;
106 const std::type_info&
type ) ;
115 std::string m_documentation;
117 const std::type_info* m_typeinfo ;
120 mutable std::function<void(Property&)> m_readCallBack;
122 std::function<void(Property&)> m_updateCallBack;
133 template <
class TYPE>
141 typedef typename Traits::PVal
PVal ;
153 template <
class OTHER>
162 template <
class OTHER>
168 operator const TYPE& ()
const {
return value() ;}
170 inline const TYPE&
value()
const ;
183 std::string
toString ()
const override;
185 void toStream (std::ostream& out)
const override;
191 Traits::assign(*
m_value, value);
194 inline PVal
i_get ()
const {
210 template <
class TYPE>
223 template <
class TYPE>
227 , m_value ( right.m_value )
228 , m_own ( right.m_own )
230 m_value = Traits::copy ( right.
value() , m_own ) ;
235 template <
class TYPE>
236 template <
class OTHER>
240 , m_value ( right.m_value )
241 , m_own ( right.m_own )
243 m_value = Traits::copy ( right.
value() , m_own ) ;
248 template <
class TYPE>
251 Traits::dele ( m_value , m_own ) ;
256 template <
class TYPE>
260 if ( !setValue ( value ) )
261 {
throw std::out_of_range(
"Value not verified" ) ; }
267 template <
class TYPE>
274 if ( p ) {
return setValue ( p->
value() ) ; }
276 return this->fromString( source.
toString() ).isSuccess() ;
281 template <
class TYPE>
286 return dest.
assign( *
this ) ;
291 template <
class TYPE>
301 template <
class TYPE>
311 template <
class TYPE>
328 return this->
value() ;
333 {
return this->fromString( source.
toString() ).isSuccess() ; }
339 template <
class TYPE>
342 { useReadHandler() ;
return *m_value ; }
346 template <
class TYPE>
359 template <
class TYPE>
360 template <
class OTHER>
381 template<
class TYPE,
class VERIFIER>
392 const VERIFIER& verifier )
394 , m_verifier ( verifier )
401 inline VERIFIER& verifier() {
return m_verifier ; }
402 inline const VERIFIER& verifier()
const {
return m_verifier ; }
404 bool set(
const TYPE& value ) ;
406 bool setValue(
const TYPE& value )
override {
return set( value ) ; }
408 template <
class OTHER,
class OTHERVERIFIER>
412 template <
class OTHER>
426 VERIFIER m_verifier ;
432 template <
class TYPE,
class VERIFIER>
437 if ( !m_verifier.isValid( &value ) ) {
return false ; }
439 this->i_set( value ) ;
441 return this->useUpdateHandler() ;
446 template <
class TYPE,
class VERIFIER>
456 template <
class TYPE,
class VERIFIER>
457 template <
class OTHER>
467 template <
class TYPE,
class VERIFIER>
468 template <
class OTHER,
class OTHERVERIFIER>
489 template <
class TYPE,
class VERIFIER = BoundedVerifier<TYPE> >
501 ( VERIFIER verifier = VERIFIER() ) ;
504 (
const TYPE& value ,
505 VERIFIER verifier = VERIFIER() ) ;
510 VERIFIER verifier = VERIFIER() ) ;
512 template <
class OTHER>
523 template <
class OTHER>
530 template <
class TYPE,
class VERIFIER>
532 ( VERIFIER verifier )
534 (
"" , Traits::new_() , true , verifier )
539 template <
class TYPE,
class VERIFIER>
541 (
const TYPE& value ,
544 (
"" , Traits::new_(value) , true , verifier )
549 template <
class TYPE,
class VERIFIER>
555 (
std::move(name) , Traits::new_(value) , true , verifier )
560 template <
class TYPE,
class VERIFIER>
561 template <
class OTHER>
565 ( right.
name() , Traits::new_( right.value() ) , true , VERIFIER() )
570 template <
class TYPE,
class VERIFIER>
574 ( right.
name() , Traits::new_( right.value() ) , true , right.verifier() )
579 template <
class TYPE,
class VERIFIER>
587 template <
class TYPE,
class VERIFIER>
598 template <
class TYPE,
class VERIFIER>
599 template <
class OTHER>
620 template<
class TYPE,
class VERIFIER = NullVerifier<TYPE> >
629 VERIFIER verifier = VERIFIER() ) ;
639 template <
class OTHER>
648 template <
class TYPE,
class VERIFIER>
658 template <
class TYPE,
class VERIFIER>
662 ( right.
name() , right.i_get() , false , right.verifier() )
667 template <
class TYPE,
class VERIFIER>
675 template <
class TYPE,
class VERIFIER>
686 template <
class TYPE,
class VERIFIER>
687 template <
class OTHER>
791 bool load(
Property& destination )
const override;
793 bool assign(
const Property& source )
override;
795 std::string
toString()
const override;
797 void toStream(std::ostream& out)
const override;
799 StatusCode fromString(
const std::string&
s)
override;
825 return destination.
assign( *
this );
829 return fromString( source.
toString() ).isSuccess();
850 bool load(
Property& destination )
const override;
852 bool assign(
const Property& source )
override;
854 std::string
toString()
const override;
856 void toStream(std::ostream& out)
const override;
858 StatusCode fromString(
const std::string&
s)
override;
885 return destination.
assign( *
this );
889 return fromString( source.
toString() ) != 0;
1004 (
const std::vector<const Property*>* p ,
1005 const std::string&
name ) ;
1030 (
const std::vector<const Property*>* p ,
1031 const std::string&
name ) ;
1056 template <
class TYPE>
1059 const std::string&
name ,
1061 const std::string& doc ) ;
1085 template <
class TYPE>
1088 const std::string&
name ,
1090 {
return setProperty ( component , name , value , std::string() ) ; }
1107 const std::string& name ,
1108 const std::string& value ,
1109 const std::string& doc =
"" ) ;
1126 const std::string& name ,
1128 const std::string& doc =
"" ) ;
1143 template <
unsigned N>
1146 const std::string& name ,
1147 const char (&value)[
N] ,
1148 const std::string& doc =
"" )
1150 return component ?
setProperty ( component , name ,
1151 std::string ( value , value + N ), doc )
1185 template <
class TYPE>
1188 const std::string& name ,
1190 const std::string& doc )
1221 const std::string& name ,
1223 const std::string& doc =
"" ) ;
1248 const std::string& name ,
1250 const std::string& doc =
"" ) ;
1274 template <
class TYPE>
1277 const std::string& name ,
1279 const std::string& doc =
"" )
1281 return setProperty ( component , name , &value , doc ) ;
1304 template <
class TYPE>
1307 const std::string& name ,
1309 const std::string& doc =
"" )
1313 return property ?
setProperty ( property , name , value , doc )
1331 const std::string& name ,
1332 const std::string& value ,
1333 const std::string& doc =
"" ) ;
1349 const std::string& name ,
1351 const std::string& doc =
"" ) ;
1366 template <
unsigned N>
1369 const std::string& name ,
1370 const char (&value)[N] ,
1371 const std::string& doc =
"" )
1375 std::string{
value , value + N }, doc ) ;
1401 const std::string& name ,
1403 const std::string& doc =
"" ) ;
1428 const std::string& name ,
1430 const std::string& doc =
"" ) ;
1454 template <
class TYPE>
1458 const std::string& name ,
1460 const std::string& doc =
"" )
1462 return setProperty ( component , name , &value , doc ) ;
1472 #endif // GAUDIKERNEL_PROPERTY_H
GaudiHandleProperty & operator=(const GaudiHandleBase &value)
SimpleProperty< bool > BooleanProperty
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
const GaudiHandleArrayBase & value() const
helper structure to define the types for properties
bool load(Property &destination) const override
export the property value to the destination
SimplePropertyRef< unsigned long > UnsignedLongPropertyRef
SimplePropertyRef< std::vector< unsigned long > > UnsignedLongArrayPropertyRef
GaudiHandleArrayProperty * clone() const override
clone: "virtual constructor"
SimplePropertyRef< unsigned int > UnsignedIntegerPropertyRef
PropertyWithValue(std::string name, PVal value, const bool owner)
the constructor with property name and value
PVal i_get() const
get the value
SimpleProperty< std::vector< long long > > LongLongArrayProperty
SimpleProperty< short > ShortProperty
virtual bool assign(const Property &source)=0
import the property value form the source
~PropertyWithValue() override
virtual destructor
PropertyWithValue & operator=(const TYPE &value)
assignment operator
virtual std::string toString() const =0
value -> string
SimpleProperty & operator=(const TYPE &value)
assignment form the value
SimplePropertyRef templated class.
const std::string & name() const
property name
virtual bool setValue(const TYPE &value)=0
NB: abstract : to be implemented when verifier is available.
SimpleProperty< char > CharProperty
Helper intermediate class which represent partly implemented property with value of concrete type and...
GaudiHandleProperty * clone() const override
clone: "virtual constructor"
bool assign(const Property &source) override
import the property value form the source
SimplePropertyRef< long double > LongDoublePropertyRef
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
SimplePropertyRef< std::vector< std::string > > StringArrayPropertyRef
SimpleProperty< std::vector< bool > > BooleanArrayProperty
SimplePropertyRef & operator=(const TYPE &value)
assignment form the value
SimplePropertyRef< std::vector< unsigned int > > UnsignedIntegerArrayPropertyRef
SimplePropertyRef< unsigned long long > UnsignedLongLongPropertyRef
SimpleProperty< std::vector< unsigned short > > UnsignedShortArrayProperty
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
SimpleProperty< unsigned long > UnsignedLongProperty
SimpleProperty< std::vector< unsigned long > > UnsignedLongArrayProperty
bool set(const TYPE &value)
update the value of the property/check the verifier
SimplePropertyRef< std::vector< long > > LongArrayPropertyRef
const char *PyHelper() getProperty(IInterface *p, char *name)
PropertyWithVerifier & operator=(const PropertyWithVerifier< OTHER, OTHERVERIFIER > &right)
templated assignment
SimplePropertyRef< unsigned char > UnsignedCharPropertyRef
SimpleProperty< double > DoubleProperty
SimpleProperty< unsigned int > UnsignedIntegerProperty
Gaudi::Utils::PropertyTypeTraits< TYPE > Traits
the type-traits for properties
bool assign(const Property &source) override
import the property value form the source
bool isFailure() const
Test for a status code of FAILURE.
SimplePropertyRef< bool > BooleanPropertyRef
SimpleProperty concrete class which implements the full Property interface.
PVal m_value
the actual property value
SimplePropertyRef< long > LongPropertyRef
SimplePropertyRef< std::vector< unsigned short > > UnsignedShortArrayPropertyRef
SimpleProperty< std::string > StringProperty
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
SimpleProperty< long double > LongDoubleProperty
Helper intermediate class which represent partly implemented property with value of concrete type...
SimpleProperty< float > FloatProperty
SimplePropertyRef< std::vector< bool > > BooleanArrayPropertyRef
SimplePropertyRef< signed char > SignedCharPropertyRef
SimplePropertyRef< std::vector< unsigned long long > > UnsignedLongLongArrayPropertyRef
SimplePropertyRef< char > CharPropertyRef
This class is used for returning status codes from appropriate routines.
SimpleProperty< std::vector< char > > CharArrayProperty
std::string toString() const override
value -> string
Definition of the basic interface.
SimpleProperty< int > IntegerProperty
SimplePropertyRef< std::vector< double > > DoubleArrayPropertyRef
void i_set(const TYPE &value)
set the value
SimpleProperty< std::vector< long > > LongArrayProperty
SimplePropertyRef< std::string > StringPropertyRef
SimpleProperty< std::vector< unsigned int > > UnsignedIntegerArrayProperty
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
SimplePropertyRef< int > IntegerPropertyRef
SimplePropertyRef< double > DoublePropertyRef
SimpleProperty< std::vector< std::string > > StringArrayProperty
SimpleProperty< std::vector< signed char > > SignedCharArrayProperty
SimplePropertyRef< unsigned short > UnsignedShortPropertyRef
SimplePropertyRef< std::vector< short > > ShortArrayPropertyRef
SimpleProperty< std::vector< unsigned char > > UnsignedCharArrayProperty
const TYPE & value() const
explicit conversion
SimpleProperty * clone() const override
implementation of Property::clone
SimpleProperty< std::vector< float > > FloatArrayProperty
Property & operator=(const Property &)=default
assignment operator
SimpleProperty< unsigned long long > UnsignedLongLongProperty
SimpleProperty(VERIFIER verifier=VERIFIER())
"Almost default" constructor from verifier
Base class of array's of various gaudihandles.
Property base class allowing Property* collections to be "homogeneous".
bool assign(const Property &source) override
get the value from another property
StatusCode fromString(const std::string &s) override
string -> value
SimpleProperty< long long > LongLongProperty
bool m_own
owner of the storage
SimplePropertyRef< std::vector< signed char > > SignedCharArrayPropertyRef
SimpleProperty< long > LongProperty
SimplePropertyRef< std::vector< unsigned char > > UnsignedCharArrayPropertyRef
SimplePropertyRef * clone() const override
implementation of Property::clone
GaudiHandleArrayProperty & operator=(const GaudiHandleArrayBase &value)
SimplePropertyRef< float > FloatPropertyRef
SimplePropertyRef< std::vector< long double > > LongDoubleArrayPropertyRef
SimpleProperty< unsigned short > UnsignedShortProperty
void toStream(std::ostream &out) const override
value -> stream
SimplePropertyRef< long long > LongLongPropertyRef
double fun(const std::vector< double > &x)
const GaudiHandleBase & value() const
SimpleProperty< std::vector< short > > ShortArrayProperty
SimpleProperty< std::vector< int > > IntegerArrayProperty
SimpleProperty< signed char > SignedCharProperty
bool load(Property &destination) const override
export the property value to the destination
bool load(Property &dest) const override
set value for another property
SimpleProperty< std::vector< long double > > LongDoubleArrayProperty
SimpleProperty< std::vector< unsigned long long > > UnsignedLongLongArrayProperty
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
GAUDI_API std::ostream & operator<<(std::ostream &stream, const Property &prop)
The output operator for friendly printout.
GAUDI_API bool hasProperty(const std::vector< const Property * > *p, const std::string &name)
check the property by name from the list of the properties
The IProperty is the basic interface for all components which have properties that can be set or get...
SimplePropertyRef< std::vector< int > > IntegerArrayPropertyRef
Traits::PVal PVal
the actual storage type
SimplePropertyRef< std::vector< char > > CharArrayPropertyRef
SimpleProperty< unsigned char > UnsignedCharProperty
Helper functions to set/get the application return code.
SimplePropertyRef< std::vector< float > > FloatArrayPropertyRef
SimplePropertyRef< short > ShortPropertyRef
SimpleProperty< std::vector< double > > DoubleArrayProperty
SimplePropertyRef< std::vector< long long > > LongLongArrayPropertyRef