00001
00002
00003
00004
00005 #ifndef GAUDIKERNEL_PROPERTY_H
00006 #define GAUDIKERNEL_PROPERTY_H
00007
00008
00009
00010 #include <string>
00011 #include <stdexcept>
00012 #include <typeinfo>
00013
00014
00015
00016 #include "GaudiKernel/Kernel.h"
00017 #include "GaudiKernel/PropertyVerifier.h"
00018 #include "GaudiKernel/Parsers.h"
00019 #include "GaudiKernel/ToStream.h"
00020 #include "GaudiKernel/SmartIF.h"
00021
00022
00023
00024 class Property ;
00025 class PropertyCallbackFunctor ;
00026 class IProperty ;
00027 class IInterface ;
00028
00029
00030
00032
00033 GAUDI_API std::ostream& operator<<(std::ostream& stream, const Property& prop);
00034
00043 class GAUDI_API Property
00044 {
00045 public:
00047 const std::string& name () const { return m_name ; }
00049 const std::string& documentation() const { return m_documentation; }
00051 const std::type_info* type_info () const { return m_typeinfo ; }
00053 std::string type () const { return m_typeinfo->name() ; }
00055 virtual bool load ( Property& dest ) const = 0 ;
00057 virtual bool assign ( const Property& source ) = 0 ;
00058 public:
00060 virtual std::string toString () const = 0 ;
00062 virtual void toStream(std::ostream& out) const = 0;
00064 virtual StatusCode fromString ( const std::string& value ) = 0 ;
00065 public:
00067 const PropertyCallbackFunctor* readCallBack () const ;
00069 const PropertyCallbackFunctor* updateCallBack () const ;
00071 virtual void declareReadHandler ( PropertyCallbackFunctor* pf ) ;
00073 virtual void declareUpdateHandler ( PropertyCallbackFunctor* pf ) ;
00074 template< class HT >
00075 void declareReadHandler
00076 ( void ( HT::* MF ) ( Property& ) , HT* instance ) ;
00077 template< class HT >
00078 void declareUpdateHandler
00079 ( void ( HT::* MF ) ( Property& ) , HT* instance ) ;
00081 virtual void useReadHandler () const ;
00083 virtual bool useUpdateHandler () ;
00084 public:
00086 virtual ~Property() ;
00088 virtual Property* clone () const = 0 ;
00090 void setName ( const std::string& value ) { m_name = value ; }
00092 void setDocumentation( const std::string& documentation ) {
00093 m_documentation = documentation; }
00095 virtual std::ostream& fillStream ( std::ostream& ) const ;
00096 protected:
00098 Property
00099 ( const std::type_info& type ,
00100 const std::string& name = "" ) ;
00102 Property
00103 ( const std::string& name ,
00104 const std::type_info& type ) ;
00106 Property ( const Property& right ) ;
00108 Property& operator=( const Property& right ) ;
00109 private:
00110
00111 Property() ;
00112 private:
00113
00114 std::string m_name ;
00115
00116 std::string m_documentation;
00117
00118 const std::type_info* m_typeinfo ;
00119 protected:
00120
00121 mutable PropertyCallbackFunctor* m_readCallBack ;
00122
00123 PropertyCallbackFunctor* m_updateCallBack ;
00124 };
00125
00126 #include "GaudiKernel/PropertyCallbackFunctor.h"
00127
00128 template< class HT >
00129 inline void Property::declareReadHandler
00130 ( void ( HT::* MF ) ( Property& ) , HT* obj )
00131 { declareReadHandler ( new PropertyCallbackMemberFunctor< HT >( MF , obj ) ) ; }
00132
00133 template< class HT >
00134 inline void Property::declareUpdateHandler
00135 ( void ( HT::* MF ) ( Property& ) , HT* obj )
00136 { declareUpdateHandler ( new PropertyCallbackMemberFunctor< HT >( MF , obj ) ) ; }
00137
00145
00146 template <class TYPE>
00147 class PropertyWithValue : public Property
00148 {
00149 public:
00150
00152 typedef Gaudi::Utils::PropertyTypeTraits<TYPE> Traits ;
00154 typedef typename Traits::PVal PVal ;
00155
00156 protected:
00157
00159 inline PropertyWithValue
00160 ( const std::string& name ,
00161 PVal value ,
00162 const bool owner ) ;
00164 inline PropertyWithValue ( const PropertyWithValue& rhs ) ;
00166 template <class OTHER>
00167 inline PropertyWithValue ( const PropertyWithValue<OTHER>& right ) ;
00169 virtual inline ~PropertyWithValue() ;
00171 PropertyWithValue& operator=( const TYPE& value ) ;
00172
00173 PropertyWithValue& operator=( const PropertyWithValue& rhs ) ;
00174
00175 template <class OTHER>
00176 PropertyWithValue& operator=( const PropertyWithValue<OTHER>& right ) ;
00177
00178 public:
00179
00181 operator const TYPE& () const { return value() ;}
00183 inline const TYPE& value() const ;
00184
00185 public:
00186
00188 virtual bool setValue ( const TYPE& value ) = 0 ;
00190 virtual bool assign ( const Property& source ) ;
00192 virtual bool load ( Property& dest ) const ;
00194 virtual StatusCode fromString ( const std::string& s ) ;
00196 virtual std::string toString () const ;
00198 virtual void toStream (std::ostream& out) const ;
00199
00200 protected:
00201
00203 inline void i_set ( const TYPE& value ) {
00204 Traits::assign(*m_value, value);
00205 }
00207 inline PVal i_get () const {
00208 return m_value;
00209 }
00210
00211 private:
00212
00214 PVal m_value ;
00216 bool m_own ;
00217
00218 };
00219
00221
00222 template <class TYPE>
00223 inline
00224 PropertyWithValue<TYPE>::PropertyWithValue
00225 ( const std::string& name ,
00226 PVal value ,
00227 const bool own )
00228 : Property ( typeid( TYPE ) , name )
00229 , m_value ( value )
00230 , m_own ( own )
00231 {}
00232
00233
00234
00235 template <class TYPE>
00236 inline PropertyWithValue<TYPE>::PropertyWithValue
00237 ( const PropertyWithValue& right )
00238 : Property( right )
00239 , m_value ( right.m_value )
00240 , m_own ( right.m_own )
00241 {
00242 m_value = Traits::copy ( right.value() , m_own ) ;
00243 }
00244
00245
00246
00247 template <class TYPE>
00248 template <class OTHER>
00249 inline PropertyWithValue<TYPE>::PropertyWithValue
00250 ( const PropertyWithValue<OTHER>& right )
00251 : Property( right )
00252 , m_value ( right.m_value )
00253 , m_own ( right.m_own )
00254 {
00255 m_value = Traits::copy ( right.value() , m_own ) ;
00256 }
00257
00259
00260 template <class TYPE>
00261 inline PropertyWithValue<TYPE>::~PropertyWithValue()
00262 {
00263 Traits::dele ( m_value , m_own ) ;
00264 m_value = 0 ;
00265 }
00266
00268
00269 template <class TYPE>
00270 inline PropertyWithValue<TYPE>&
00271 PropertyWithValue<TYPE>::operator=( const TYPE& value )
00272 {
00273 if ( !setValue ( value ) )
00274 { throw std::out_of_range( "Value not verified" ) ; }
00275 return *this ;
00276 }
00277
00279
00280 template <class TYPE>
00281 inline bool
00282 PropertyWithValue<TYPE>::assign ( const Property& source )
00283 {
00284
00285 const PropertyWithValue<TYPE>* p =
00286 dynamic_cast<const PropertyWithValue<TYPE>*> ( &source ) ;
00287 if ( 0 != p ) { return setValue ( p->value() ) ; }
00288
00289 return this->fromString( source.toString() ).isSuccess() ;
00290 }
00291
00293
00294 template <class TYPE>
00295 inline bool
00296 PropertyWithValue<TYPE>::load( Property& dest ) const
00297 {
00298
00299 return dest.assign( *this ) ;
00300 }
00301
00303
00304 template <class TYPE>
00305 inline std::string
00306 PropertyWithValue<TYPE>::toString () const
00307 {
00308 useReadHandler();
00309 return Gaudi::Utils::toString( *m_value ) ;
00310 }
00311
00313
00314 template <class TYPE>
00315 inline void
00316 PropertyWithValue<TYPE>::toStream (std::ostream& out) const
00317 {
00318 useReadHandler();
00319 Gaudi::Utils::toStream( *m_value, out ) ;
00320 }
00321
00323
00324 template <class TYPE>
00325 inline StatusCode
00326 PropertyWithValue<TYPE>::fromString ( const std::string& source )
00327 {
00328 TYPE tmp ;
00329 StatusCode sc = Gaudi::Parsers::parse ( tmp , source ) ;
00330 if ( sc.isFailure() ) { return sc ; }
00331 return setValue ( tmp ) ? StatusCode::SUCCESS : StatusCode::FAILURE ;
00332 }
00333
00335
00336 template <>
00337 inline std::string
00338 PropertyWithValue<std::string>::toString () const
00339 {
00340 useReadHandler();
00341 return this->value() ;
00342 }
00343
00344 template <>
00345 inline bool PropertyWithValue<std::string>::assign ( const Property& source )
00346 { return this->fromString( source.toString() ).isSuccess() ; }
00347
00348
00349
00351
00352 template <class TYPE>
00353 inline const TYPE&
00354 PropertyWithValue<TYPE>::value() const
00355 { useReadHandler() ; return *m_value ; }
00356
00357
00358
00359 template <class TYPE>
00360 PropertyWithValue<TYPE>& PropertyWithValue<TYPE>::operator=
00361 ( const PropertyWithValue& right )
00362 {
00363
00364 Property::operator=( right ) ;
00365
00366 PropertyWithValue<TYPE>::operator=( right.value() ) ;
00367 return *this ;
00368 }
00369
00370
00371
00372 template <class TYPE>
00373 template <class OTHER>
00374 PropertyWithValue<TYPE>& PropertyWithValue<TYPE>::operator=
00375 ( const PropertyWithValue<OTHER>& right )
00376 {
00377
00378 Property::operator=( right ) ;
00379
00380 PropertyWithValue<TYPE>::operator=( right.value() ) ;
00381 return *this ;
00382 }
00383
00384
00385
00393
00394 template<class TYPE,class VERIFIER>
00395 class PropertyWithVerifier
00396 : public PropertyWithValue<TYPE>
00397 {
00398 protected:
00399
00401 PropertyWithVerifier
00402 ( const std::string& name ,
00403 typename Gaudi::Utils::PropertyTypeTraits<TYPE>::PVal value ,
00404 const bool owner ,
00405 const VERIFIER& verifier )
00406 : PropertyWithValue<TYPE> ( name , value , owner )
00407 , m_verifier ( verifier )
00408 {}
00410 virtual ~PropertyWithVerifier() {}
00411
00412 public:
00413
00414 inline VERIFIER& verifier() { return m_verifier ; }
00415 inline const VERIFIER& verifier() const { return m_verifier ; }
00417 bool set( const TYPE& value ) ;
00419 virtual bool setValue( const TYPE& value ) { return set( value ) ; }
00421 template <class OTHER,class OTHERVERIFIER>
00422 PropertyWithVerifier& operator=
00423 ( const PropertyWithVerifier<OTHER,OTHERVERIFIER>& right ) ;
00425 template <class OTHER>
00426 PropertyWithVerifier& operator=( const PropertyWithValue<OTHER>& right ) ;
00428 PropertyWithVerifier& operator=( const TYPE& right ) ;
00429
00430 private:
00431
00433 PropertyWithVerifier() ;
00435 PropertyWithVerifier( const PropertyWithVerifier& right );
00436
00437 private:
00438
00440 VERIFIER m_verifier ;
00441
00442 } ;
00443
00445
00446 template <class TYPE,class VERIFIER>
00447 inline bool
00448 PropertyWithVerifier<TYPE,VERIFIER>::set( const TYPE& value )
00449 {
00451 if ( !m_verifier.isValid( &value ) ) { return false ; }
00453 this->i_set( value ) ;
00455 return this->useUpdateHandler() ;
00456 }
00457
00459
00460 template <class TYPE,class VERIFIER>
00461 inline PropertyWithVerifier<TYPE,VERIFIER>&
00462 PropertyWithVerifier<TYPE,VERIFIER>::operator=( const TYPE& right )
00463 {
00464 PropertyWithValue<TYPE>::operator=( right ) ;
00465 return *this ;
00466 }
00467
00469
00470 template <class TYPE,class VERIFIER>
00471 template <class OTHER>
00472 inline PropertyWithVerifier<TYPE,VERIFIER>&
00473 PropertyWithVerifier<TYPE,VERIFIER>::operator=( const PropertyWithValue<OTHER>& right )
00474 {
00475 PropertyWithValue<TYPE>::operator=(right) ;
00476 return *this ;
00477 }
00478
00480
00481 template <class TYPE,class VERIFIER>
00482 template <class OTHER,class OTHERVERIFIER>
00483 inline PropertyWithVerifier<TYPE,VERIFIER>&
00484 PropertyWithVerifier<TYPE,VERIFIER>::operator=
00485 ( const PropertyWithVerifier<OTHER,OTHERVERIFIER>& right )
00486 {
00487 PropertyWithValue<TYPE>::operator=(right) ;
00488 return *this ;
00489 }
00490
00491
00492
00502
00503 template <class TYPE,class VERIFIER = BoundedVerifier<TYPE> >
00504 class SimpleProperty
00505 : public PropertyWithVerifier<TYPE,VERIFIER>
00506 {
00507 protected:
00508
00509 typedef Gaudi::Utils::PropertyTypeTraits<TYPE> Traits ;
00510
00511 public:
00512
00514 SimpleProperty
00515 ( VERIFIER verifier = VERIFIER() ) ;
00517 SimpleProperty
00518 ( const TYPE& value ,
00519 VERIFIER verifier = VERIFIER() ) ;
00521 SimpleProperty
00522 ( const std::string& name ,
00523 const TYPE& value ,
00524 VERIFIER verifier = VERIFIER() ) ;
00526 template <class OTHER>
00527 SimpleProperty ( const PropertyWithValue<OTHER>& right ) ;
00529 SimpleProperty ( const SimpleProperty& right ) ;
00531 virtual ~SimpleProperty() ;
00533 virtual SimpleProperty* clone() const ;
00535 SimpleProperty& operator=( const TYPE& value ) ;
00537 template <class OTHER>
00538 SimpleProperty& operator=( const PropertyWithValue<OTHER>& right ) ;
00539
00540 };
00541
00543
00544 template <class TYPE,class VERIFIER>
00545 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00546 ( VERIFIER verifier )
00547 : PropertyWithVerifier<TYPE,VERIFIER>
00548 ( "" , Traits::new_() , true , verifier )
00549 {}
00550
00552
00553 template <class TYPE,class VERIFIER>
00554 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00555 ( const TYPE& value ,
00556 VERIFIER verifier )
00557 : PropertyWithVerifier<TYPE,VERIFIER>
00558 ( "" , Traits::new_(value) , true , verifier )
00559 {}
00560
00562
00563 template <class TYPE,class VERIFIER>
00564 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00565 ( const std::string& name ,
00566 const TYPE& value ,
00567 VERIFIER verifier )
00568 : PropertyWithVerifier<TYPE,VERIFIER>
00569 ( name , Traits::new_(value) , true , verifier )
00570 {}
00571
00573
00574 template <class TYPE,class VERIFIER>
00575 template <class OTHER>
00576 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00577 ( const PropertyWithValue<OTHER>& right )
00578 : PropertyWithVerifier<TYPE,VERIFIER>
00579 ( right.name() , Traits::new_( right.value() ) , true , VERIFIER() )
00580 {}
00581
00583
00584 template <class TYPE,class VERIFIER>
00585 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00586 ( const SimpleProperty& right )
00587 : PropertyWithVerifier<TYPE,VERIFIER>
00588 ( right.name() , Traits::new_( right.value() ) , true , right.verifier() )
00589 {}
00590
00592
00593 template <class TYPE,class VERIFIER>
00594 SimpleProperty<TYPE,VERIFIER>::~SimpleProperty(){}
00595
00597
00598 template <class TYPE,class VERIFIER>
00599 inline
00600 SimpleProperty<TYPE,VERIFIER>*
00601 SimpleProperty<TYPE,VERIFIER>::clone() const
00602 { return new SimpleProperty(*this) ; }
00603
00605
00606 template <class TYPE,class VERIFIER>
00607 inline
00608 SimpleProperty<TYPE,VERIFIER>&
00609 SimpleProperty<TYPE,VERIFIER>::operator=( const TYPE& value )
00610 {
00611 PropertyWithVerifier<TYPE,VERIFIER>::operator=( value );
00612 return *this ;
00613 }
00614
00616
00617 template <class TYPE,class VERIFIER>
00618 template <class OTHER>
00619 inline
00620 SimpleProperty<TYPE,VERIFIER>&
00621 SimpleProperty<TYPE,VERIFIER>::operator=
00622 ( const PropertyWithValue<OTHER>& right )
00623 {
00624 PropertyWithVerifier<TYPE,VERIFIER>::operator=( right );
00625 return *this ;
00626 }
00627
00628
00629
00638
00639 template< class TYPE, class VERIFIER = NullVerifier<TYPE> >
00640 class SimplePropertyRef :
00641 public PropertyWithVerifier<TYPE,VERIFIER>
00642 {
00643 public:
00645 SimplePropertyRef
00646 ( const std::string& name ,
00647 TYPE& value ,
00648 VERIFIER verifier = VERIFIER() ) ;
00650 SimplePropertyRef ( const SimplePropertyRef& right ) ;
00652 virtual ~SimplePropertyRef() ;
00654 virtual SimplePropertyRef* clone() const ;
00656 SimplePropertyRef& operator=( const TYPE& value ) ;
00658 template <class OTHER>
00659 SimplePropertyRef& operator=( const PropertyWithValue<OTHER>& right ) ;
00660 private:
00661
00662 SimplePropertyRef() ;
00663 };
00664
00666
00667 template <class TYPE,class VERIFIER>
00668 SimplePropertyRef<TYPE,VERIFIER>::SimplePropertyRef
00669 ( const std::string& name ,
00670 TYPE& value ,
00671 VERIFIER verifier )
00672 : PropertyWithVerifier<TYPE,VERIFIER> ( name , &value , false , verifier )
00673 {}
00674
00676
00677 template <class TYPE,class VERIFIER>
00678 SimplePropertyRef<TYPE,VERIFIER>::SimplePropertyRef
00679 ( const SimplePropertyRef& right )
00680 : PropertyWithVerifier<TYPE,VERIFIER>
00681 ( right.name() , right.i_get() , false , right.verifier() )
00682 {}
00683
00685
00686 template <class TYPE,class VERIFIER>
00687 SimplePropertyRef<TYPE,VERIFIER>::~SimplePropertyRef(){}
00688
00690
00691 template <class TYPE,class VERIFIER>
00692 inline
00693 SimplePropertyRef<TYPE,VERIFIER>*
00694 SimplePropertyRef<TYPE,VERIFIER>::clone() const
00695 { return new SimplePropertyRef(*this) ; }
00696
00698
00699 template <class TYPE,class VERIFIER>
00700 inline
00701 SimplePropertyRef<TYPE,VERIFIER>&
00702 SimplePropertyRef<TYPE,VERIFIER>::operator=( const TYPE& value )
00703 {
00704 PropertyWithVerifier<TYPE,VERIFIER>::operator=( value ) ;
00705 return *this ;
00706 }
00707
00709
00710 template <class TYPE,class VERIFIER>
00711 template <class OTHER>
00712 inline
00713 SimplePropertyRef<TYPE,VERIFIER>&
00714 SimplePropertyRef<TYPE,VERIFIER>::operator=
00715 ( const PropertyWithValue<OTHER>& right )
00716 {
00717 PropertyWithVerifier<TYPE,VERIFIER>::operator=( right );
00718 return *this ;
00719 }
00720
00721
00722
00723
00724
00725
00726 typedef SimpleProperty< bool > BooleanProperty;
00727 typedef SimpleProperty< char > CharProperty;
00728 typedef SimpleProperty< signed char > SignedCharProperty;
00729 typedef SimpleProperty< unsigned char > UnsignedCharProperty;
00730 typedef SimpleProperty< short > ShortProperty;
00731 typedef SimpleProperty< unsigned short > UnsignedShortProperty;
00732 typedef SimpleProperty< int > IntegerProperty;
00733 typedef SimpleProperty< unsigned int > UnsignedIntegerProperty;
00734 typedef SimpleProperty< long > LongProperty;
00735 typedef SimpleProperty< unsigned long > UnsignedLongProperty;
00736 typedef SimpleProperty< long long> LongLongProperty;
00737 typedef SimpleProperty< unsigned long long> UnsignedLongLongProperty;
00738 typedef SimpleProperty< float > FloatProperty;
00739 typedef SimpleProperty< double > DoubleProperty;
00740 typedef SimpleProperty< long double > LongDoubleProperty;
00741
00742 typedef SimpleProperty< std::string > StringProperty;
00743
00744
00745
00746 typedef SimplePropertyRef< bool > BooleanPropertyRef;
00747 typedef SimplePropertyRef< char > CharPropertyRef;
00748 typedef SimplePropertyRef< signed char > SignedCharPropertyRef;
00749 typedef SimplePropertyRef< unsigned char > UnsignedCharPropertyRef;
00750 typedef SimplePropertyRef< short > ShortPropertyRef;
00751 typedef SimplePropertyRef< unsigned short > UnsignedShortPropertyRef;
00752 typedef SimplePropertyRef< int > IntegerPropertyRef;
00753 typedef SimplePropertyRef< unsigned int > UnsignedIntegerPropertyRef;
00754 typedef SimplePropertyRef< long > LongPropertyRef;
00755 typedef SimplePropertyRef< unsigned long > UnsignedLongPropertyRef;
00756 typedef SimplePropertyRef< long long > LongLongPropertyRef;
00757 typedef SimplePropertyRef< unsigned long long > UnsignedLongLongPropertyRef;
00758 typedef SimplePropertyRef< float > FloatPropertyRef;
00759 typedef SimplePropertyRef< double > DoublePropertyRef;
00760 typedef SimplePropertyRef< long double > LongDoublePropertyRef;
00761
00762 typedef SimplePropertyRef< std::string > StringPropertyRef;
00763
00764
00765
00766 typedef SimpleProperty< std::vector< bool > > BooleanArrayProperty;
00767 typedef SimpleProperty< std::vector< char > > CharArrayProperty;
00768 typedef SimpleProperty< std::vector< signed char > > SignedCharArrayProperty;
00769 typedef SimpleProperty< std::vector< unsigned char > > UnsignedCharArrayProperty;
00770 typedef SimpleProperty< std::vector< short > > ShortArrayProperty;
00771 typedef SimpleProperty< std::vector< unsigned short > > UnsignedShortArrayProperty;
00772 typedef SimpleProperty< std::vector< int > > IntegerArrayProperty;
00773 typedef SimpleProperty< std::vector< unsigned int > > UnsignedIntegerArrayProperty;
00774 typedef SimpleProperty< std::vector< long > > LongArrayProperty;
00775 typedef SimpleProperty< std::vector< unsigned long > > UnsignedLongArrayProperty;
00776 typedef SimpleProperty< std::vector< long long > > LongLongArrayProperty;
00777 typedef SimpleProperty< std::vector< unsigned long long > > UnsignedLongLongArrayProperty;
00778 typedef SimpleProperty< std::vector< float > > FloatArrayProperty;
00779 typedef SimpleProperty< std::vector< double > > DoubleArrayProperty;
00780 typedef SimpleProperty< std::vector< long double > > LongDoubleArrayProperty;
00781
00782 typedef SimpleProperty< std::vector< std::string > > StringArrayProperty;
00783
00784
00785
00786 typedef SimplePropertyRef< std::vector< bool > > BooleanArrayPropertyRef;
00787 typedef SimplePropertyRef< std::vector< char > > CharArrayPropertyRef;
00788 typedef SimplePropertyRef< std::vector< signed char > > SignedCharArrayPropertyRef;
00789 typedef SimplePropertyRef< std::vector< unsigned char > > UnsignedCharArrayPropertyRef;
00790 typedef SimplePropertyRef< std::vector< short > > ShortArrayPropertyRef;
00791 typedef SimplePropertyRef< std::vector< unsigned short > > UnsignedShortArrayPropertyRef;
00792 typedef SimplePropertyRef< std::vector< int > > IntegerArrayPropertyRef;
00793 typedef SimplePropertyRef< std::vector< unsigned int > > UnsignedIntegerArrayPropertyRef;
00794 typedef SimplePropertyRef< std::vector< long > > LongArrayPropertyRef;
00795 typedef SimplePropertyRef< std::vector< unsigned long > > UnsignedLongArrayPropertyRef;
00796 typedef SimplePropertyRef< std::vector< long long > > LongLongArrayPropertyRef;
00797 typedef SimplePropertyRef< std::vector< unsigned long long > > UnsignedLongLongArrayPropertyRef;
00798 typedef SimplePropertyRef< std::vector< float > > FloatArrayPropertyRef;
00799 typedef SimplePropertyRef< std::vector< double > > DoubleArrayPropertyRef;
00800 typedef SimplePropertyRef< std::vector< long double > > LongDoubleArrayPropertyRef;
00801
00802 typedef SimplePropertyRef< std::vector< std::string > > StringArrayPropertyRef;
00803
00804
00805 class GaudiHandleBase;
00806
00807 class GAUDI_API GaudiHandleProperty : public Property {
00808 public:
00809 GaudiHandleProperty( const std::string& name, GaudiHandleBase& ref );
00810
00811 GaudiHandleProperty& operator=( const GaudiHandleBase& value );
00812
00813 virtual GaudiHandleProperty* clone() const;
00814
00815 virtual bool load( Property& destination ) const;
00816
00817 virtual bool assign( const Property& source );
00818
00819 virtual std::string toString() const;
00820
00821 virtual void toStream(std::ostream& out) const;
00822
00823 virtual StatusCode fromString(const std::string& s);
00824
00825 const GaudiHandleBase& value() const;
00826
00827 bool setValue( const GaudiHandleBase& value );
00828
00829 private:
00832 GaudiHandleBase* m_pValue;
00833 };
00834
00835
00836
00837
00838
00839 inline GaudiHandleProperty& GaudiHandleProperty::operator=( const GaudiHandleBase& value ) {
00840 setValue( value );
00841 return *this;
00842 }
00843
00844 inline GaudiHandleProperty* GaudiHandleProperty::clone() const {
00845 return new GaudiHandleProperty( *this );
00846 }
00847
00848 inline bool GaudiHandleProperty::load( Property& destination ) const {
00849 return destination.assign( *this );
00850 }
00851
00852 inline bool GaudiHandleProperty::assign( const Property& source ) {
00853 return fromString( source.toString() ).isSuccess();
00854 }
00855
00856 inline const GaudiHandleBase& GaudiHandleProperty::value() const {
00857 useReadHandler();
00858 return *m_pValue;
00859 }
00860
00861
00862
00863 class GaudiHandleArrayBase;
00864
00865 class GAUDI_API GaudiHandleArrayProperty : public Property {
00866 public:
00867
00868 GaudiHandleArrayProperty( const std::string& name, GaudiHandleArrayBase& ref );
00869
00870 GaudiHandleArrayProperty& operator=( const GaudiHandleArrayBase& value );
00871
00872 virtual GaudiHandleArrayProperty* clone() const;
00873
00874 virtual bool load( Property& destination ) const;
00875
00876 virtual bool assign( const Property& source );
00877
00878 virtual std::string toString() const;
00879
00880 virtual void toStream(std::ostream& out) const;
00881
00882 virtual StatusCode fromString(const std::string& s);
00883
00884 const GaudiHandleArrayBase& value() const;
00885
00886 bool setValue( const GaudiHandleArrayBase& value );
00887
00888 private:
00891 GaudiHandleArrayBase* m_pValue;
00892
00893 };
00894
00895
00896
00897
00898
00899 inline GaudiHandleArrayProperty& GaudiHandleArrayProperty::operator=( const GaudiHandleArrayBase& value ) {
00900 setValue( value );
00901 return *this;
00902 }
00903
00904 inline GaudiHandleArrayProperty* GaudiHandleArrayProperty::clone() const {
00905 return new GaudiHandleArrayProperty( *this );
00906 }
00907
00908 inline bool GaudiHandleArrayProperty::load( Property& destination ) const {
00909 return destination.assign( *this );
00910 }
00911
00912 inline bool GaudiHandleArrayProperty::assign( const Property& source ) {
00913 return fromString( source.toString() ) != 0;
00914 }
00915
00916 inline const GaudiHandleArrayBase& GaudiHandleArrayProperty::value() const {
00917 useReadHandler();
00918 return *m_pValue;
00919 }
00920
00921
00922 namespace Gaudi
00923 {
00924 namespace Utils
00925 {
00926
00944 GAUDI_API bool hasProperty ( const IProperty* p , const std::string& name ) ;
00945
00963 GAUDI_API bool hasProperty ( const IInterface* p , const std::string& name ) ;
00964
00982 GAUDI_API Property* getProperty
00983 ( const IProperty* p , const std::string& name ) ;
00984
01002 GAUDI_API Property* getProperty
01003 ( const IInterface* p , const std::string& name ) ;
01004
01027 GAUDI_API bool hasProperty
01028 ( const std::vector<const Property*>* p ,
01029 const std::string& name ) ;
01030
01053 GAUDI_API const Property* getProperty
01054 ( const std::vector<const Property*>* p ,
01055 const std::string& name ) ;
01056
01080 template <class TYPE>
01081 StatusCode setProperty
01082 ( IProperty* component ,
01083 const std::string& name ,
01084 const TYPE& value ,
01085 const std::string& doc ) ;
01086
01109 template <class TYPE>
01110 StatusCode setProperty
01111 ( IProperty* component ,
01112 const std::string& name ,
01113 const TYPE& value )
01114 { return setProperty ( component , name , value , std::string() ) ; }
01115
01129 GAUDI_API StatusCode setProperty
01130 ( IProperty* component ,
01131 const std::string& name ,
01132 const std::string& value ,
01133 const std::string& doc = "" ) ;
01134
01148 GAUDI_API StatusCode setProperty
01149 ( IProperty* component ,
01150 const std::string& name ,
01151 const char* value ,
01152 const std::string& doc = "" ) ;
01153
01167 template <unsigned N>
01168 StatusCode setProperty
01169 ( IProperty* component ,
01170 const std::string& name ,
01171 const char (&value)[N] ,
01172 const std::string& doc = "" )
01173 {
01174 if ( 0 == component ) { return StatusCode::FAILURE ; }
01175 const std::string val = std::string ( value , value + N ) ;
01176 return setProperty ( component , name , val , doc ) ;
01177 }
01178
01209 template <class TYPE>
01210 StatusCode setProperty
01211 ( IProperty* component ,
01212 const std::string& name ,
01213 const TYPE& value ,
01214 const std::string& doc )
01215 {
01216 if ( 0 == component ) { return StatusCode::FAILURE ; }
01217 if ( !hasProperty ( component , name ) ) { return StatusCode::FAILURE ; }
01218 const std::string val = Gaudi::Utils::toString ( value ) ;
01219 return Gaudi::Utils::setProperty ( component , name , val , doc ) ;
01220 }
01221
01243 GAUDI_API StatusCode setProperty
01244 ( IProperty* component ,
01245 const std::string& name ,
01246 const Property* property ,
01247 const std::string& doc = "" ) ;
01248
01270 GAUDI_API StatusCode setProperty
01271 ( IProperty* component ,
01272 const std::string& name ,
01273 const Property& property ,
01274 const std::string& doc = "" ) ;
01275
01298 template <class TYPE>
01299 StatusCode setProperty
01300 ( IProperty* component ,
01301 const std::string& name ,
01302 const SimpleProperty<TYPE>& value ,
01303 const std::string& doc = "" )
01304 {
01305 const Property* property = &value ;
01306 return setProperty ( component , name , property , doc ) ;
01307 }
01308
01329 template <class TYPE>
01330 StatusCode setProperty
01331 ( IInterface* component ,
01332 const std::string& name ,
01333 const TYPE& value ,
01334 const std::string& doc = "" )
01335 {
01336 if ( 0 == component ) { return StatusCode::FAILURE ; }
01337 SmartIF<IProperty> property ( component ) ;
01338 if ( !property ) { return StatusCode::FAILURE ; }
01339 return setProperty ( property , name , value , doc ) ;
01340 }
01341
01354 GAUDI_API StatusCode setProperty
01355 ( IInterface* component ,
01356 const std::string& name ,
01357 const std::string& value ,
01358 const std::string& doc = "" ) ;
01359
01372 GAUDI_API StatusCode setProperty
01373 ( IInterface* component ,
01374 const std::string& name ,
01375 const char* value ,
01376 const std::string& doc = "" ) ;
01377
01391 template <unsigned N>
01392 StatusCode setProperty
01393 ( IInterface* component ,
01394 const std::string& name ,
01395 const char (&value)[N] ,
01396 const std::string& doc = "" )
01397 {
01398 if ( 0 == component ) { return StatusCode::FAILURE ; }
01399 const std::string val = std::string ( value , value + N ) ;
01400 return setProperty ( component , name , val , doc ) ;
01401 }
01402
01424 GAUDI_API StatusCode setProperty
01425 ( IInterface* component ,
01426 const std::string& name ,
01427 const Property* property ,
01428 const std::string& doc = "" ) ;
01429
01451 GAUDI_API StatusCode setProperty
01452 ( IInterface* component ,
01453 const std::string& name ,
01454 const Property& property ,
01455 const std::string& doc = "" ) ;
01456
01479 template <class TYPE>
01480 StatusCode
01481 setProperty
01482 ( IInterface* component ,
01483 const std::string& name ,
01484 const SimpleProperty<TYPE>& value ,
01485 const std::string& doc = "" )
01486 {
01487 const Property* property = &value ;
01488 return setProperty ( component , name , property , doc ) ;
01489 }
01490
01491 }
01492 }
01493
01494
01495
01496
01497
01498 #endif // GAUDIKERNEL_PROPERTY_H
01499