![]() |
|
|
Generated: 8 Jan 2009 |
00001 // $Id: Property.h,v 1.26 2008/10/27 16:41:34 marcocle Exp $ 00002 // ============================================================================ 00003 // CVS tag $Name: $ 00004 // ============================================================================ 00005 #ifndef GAUDIKERNEL_PROPERTY_H 00006 #define GAUDIKERNEL_PROPERTY_H 00007 // ============================================================================ 00008 // STD & STL 00009 // ============================================================================ 00010 #include <string> 00011 #include <stdexcept> 00012 #include <typeinfo> 00013 // ============================================================================ 00014 // Application C++ Class Headers 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 std::ostream& 00034 operator<< 00035 ( std::ostream& stream , 00036 const Property& prop ) ; 00037 // ============================================================================ 00046 class Property 00047 { 00048 public: 00050 const std::string& name () const { return m_name ; } ; 00052 const std::string& documentation() const { return m_documentation; }; 00054 const std::type_info* type_info () const { return m_typeinfo ; } ; 00056 std::string type () const { return m_typeinfo->name() ; } ; 00058 virtual bool load ( Property& dest ) const = 0 ; 00060 virtual bool assign ( const Property& source ) = 0 ; 00061 public: 00063 virtual std::string toString () const = 0 ; 00065 virtual StatusCode fromString ( const std::string& value ) = 0 ; 00066 public: 00068 const PropertyCallbackFunctor* readCallBack () const ; 00070 const PropertyCallbackFunctor* updateCallBack () const ; 00072 virtual void declareReadHandler ( PropertyCallbackFunctor* pf ) ; 00074 virtual void declareUpdateHandler ( PropertyCallbackFunctor* pf ) ; 00075 template< class HT > 00076 void declareReadHandler 00077 ( void ( HT::* MF ) ( Property& ) , HT* instance ) ; 00078 template< class HT > 00079 void declareUpdateHandler 00080 ( void ( HT::* MF ) ( Property& ) , HT* instance ) ; 00082 virtual void useReadHandler () const ; 00084 virtual void useUpdateHandler () ; 00085 public: 00087 virtual ~Property() ; 00089 virtual Property* clone () const = 0 ; 00091 void setName ( const std::string& value ) { m_name = value ; } 00093 void setDocumentation( const std::string& documentation ) { 00094 m_documentation = documentation; }; 00096 virtual std::ostream& fillStream ( std::ostream& ) const ; 00097 protected: 00099 Property 00100 ( const std::type_info& type , 00101 const std::string& name = "" ) ; 00103 Property 00104 ( const std::string& name , 00105 const std::type_info& type ) ; 00107 Property ( const Property& right ) ; 00109 Property& operator=( const Property& right ) ; 00110 private: 00111 // the default constructor is disabled 00112 Property() ; 00113 private: 00114 // property name 00115 std::string m_name ; 00116 // property doc string 00117 std::string m_documentation; 00118 // property type 00119 const std::type_info* m_typeinfo ; 00120 protected: 00121 // call back funtor for reading 00122 mutable PropertyCallbackFunctor* m_readCallBack ; 00123 // call back funtor for update 00124 PropertyCallbackFunctor* m_updateCallBack ; 00125 }; 00126 // ============================================================================ 00127 #include "GaudiKernel/PropertyCallbackFunctor.h" 00128 // ============================================================================ 00129 template< class HT > 00130 inline void Property::declareReadHandler 00131 ( void ( HT::* MF ) ( Property& ) , HT* obj ) 00132 { declareReadHandler ( new PropertyCallbackMemberFunctor< HT >( MF , obj ) ) ; } 00133 // ============================================================================ 00134 template< class HT > 00135 inline void Property::declareUpdateHandler 00136 ( void ( HT::* MF ) ( Property& ) , HT* obj ) 00137 { declareUpdateHandler ( new PropertyCallbackMemberFunctor< HT >( MF , obj ) ) ; } 00138 // ============================================================================ 00146 // ============================================================================ 00147 template <class TYPE> 00148 class PropertyWithValue 00149 : public Property 00150 { 00151 protected: 00153 PropertyWithValue 00154 ( const std::string& name , 00155 TYPE* value , 00156 const bool owner ) ; 00158 PropertyWithValue ( const PropertyWithValue& rhs ) ; 00160 template <class OTHER> 00161 PropertyWithValue ( const PropertyWithValue<OTHER>& right ) ; 00163 virtual ~PropertyWithValue() ; 00165 PropertyWithValue& operator=( const TYPE& value ) ; 00166 // assignement operator (don't let the compiler generate a buggy one) 00167 PropertyWithValue& operator=( const PropertyWithValue& rhs ) ; 00168 // assignement operator 00169 template <class OTHER> 00170 PropertyWithValue& operator=( const PropertyWithValue<OTHER>& right ) ; 00171 public: 00172 operator const TYPE& () const { return value() ;} 00173 const TYPE& value() const ; 00174 public: 00175 // NB: abstract : to be implemented when verifier is available 00176 virtual bool setValue ( const TYPE& value ) = 0 ; 00178 virtual bool assign ( const Property& source ) ; 00180 virtual bool load ( Property& dest ) const ; 00182 virtual StatusCode fromString ( const std::string& s ) ; 00184 virtual std::string toString () const ; 00185 protected: 00186 void i_set ( const TYPE& value ) ; 00187 TYPE* i_get () const ; 00188 private: 00189 TYPE* m_value ; 00190 bool m_own ; 00191 }; 00192 // ============================================================================ 00194 // ============================================================================ 00195 template <class TYPE> 00196 inline PropertyWithValue<TYPE>::PropertyWithValue 00197 ( const std::string& name , 00198 TYPE* value , 00199 const bool own ) 00200 : Property ( typeid( TYPE ) , name ) 00201 , m_value ( value ) 00202 , m_own ( own ) 00203 {} 00204 // ============================================================================ 00205 // copy constructor 00206 // ============================================================================ 00207 template <class TYPE> 00208 inline PropertyWithValue<TYPE>::PropertyWithValue 00209 ( const PropertyWithValue& right ) 00210 : Property( right ) 00211 , m_value ( right.m_value ) 00212 , m_own ( right.own ) 00213 { if ( m_own ) { m_value = new TYPE(right.value()) ; } } 00214 // ============================================================================ 00215 // "copy" constructor form any other type 00216 // ============================================================================ 00217 template <class TYPE> 00218 template <class OTHER> 00219 inline PropertyWithValue<TYPE>::PropertyWithValue 00220 ( const PropertyWithValue<OTHER>& right ) 00221 : Property( right ) 00222 , m_value ( right.m_value ) 00223 , m_own ( right.own ) 00224 { if ( m_own ) { m_value = new TYPE(right.value()) ; } } 00225 // ============================================================================ 00227 // ============================================================================ 00228 template <class TYPE> 00229 inline PropertyWithValue<TYPE>::~PropertyWithValue() 00230 { if ( m_own ) { delete m_value ; } ; m_value = 0 ; } 00231 // ============================================================================ 00233 // ============================================================================ 00234 template <class TYPE> 00235 inline PropertyWithValue<TYPE>& 00236 PropertyWithValue<TYPE>::operator=( const TYPE& value ) 00237 { 00238 if ( !setValue ( value ) ) 00239 { throw std::out_of_range( "Value not verified" ) ; } 00240 return *this ; 00241 } 00242 // ============================================================================ 00244 // ============================================================================ 00245 template <class TYPE> 00246 inline bool 00247 PropertyWithValue<TYPE>::assign ( const Property& source ) 00248 { 00249 // 1) Is the property of "the same" type? 00250 const PropertyWithValue<TYPE>* p = 00251 dynamic_cast<const PropertyWithValue<TYPE>*> ( &source ) ; 00252 if ( 0 != p ) { return setValue ( p->value() ) ; } // RETURN 00253 // 2) Else use the string representation 00254 return this->fromString( source.toString() ).isSuccess() ; 00255 } 00256 // ============================================================================ 00258 // ============================================================================ 00259 template <class TYPE> 00260 inline bool 00261 PropertyWithValue<TYPE>::load( Property& dest ) const 00262 { 00263 // gelegate to the 'opposite' method ; 00264 return dest.assign( *this ) ; 00265 } 00266 // ============================================================================ 00268 // ============================================================================ 00269 template <class TYPE> 00270 inline std::string 00271 PropertyWithValue<TYPE>::toString () const 00272 { 00273 useReadHandler(); 00274 return Gaudi::Utils::toString( *m_value ) ; 00275 } 00276 // ============================================================================ 00278 // ============================================================================ 00279 template <class TYPE> 00280 inline StatusCode 00281 PropertyWithValue<TYPE>::fromString ( const std::string& source ) 00282 { 00283 TYPE tmp ; 00284 StatusCode sc = Gaudi::Parsers::parse ( tmp , source ) ; 00285 if ( sc.isFailure() ) { return sc ; } 00286 return setValue ( tmp ) ? StatusCode::SUCCESS : StatusCode::FAILURE ; 00287 } 00288 // ============================================================================ 00290 // ============================================================================ 00291 template <> 00292 inline std::string 00293 PropertyWithValue<std::string>::toString () const 00294 { return this->value() ; } 00295 // ============================================================================ 00296 template <> 00297 inline bool PropertyWithValue<std::string>::assign ( const Property& source ) 00298 { return this->fromString( source.toString() ).isSuccess() ; } 00299 // ============================================================================ 00300 00301 // ============================================================================ 00303 // ============================================================================ 00304 template <class TYPE> 00305 inline const TYPE& 00306 PropertyWithValue<TYPE>::value() const 00307 { useReadHandler() ; return *m_value ; } 00308 // ============================================================================ 00309 // the actual modification of internale data 00310 // ============================================================================ 00311 template <class TYPE> 00312 inline void PropertyWithValue<TYPE>::i_set 00313 ( const TYPE& value ) { *m_value = value ; } 00314 // ============================================================================ 00315 // protected accessor to internal data 00316 // ============================================================================ 00317 template <class TYPE> 00318 inline TYPE* PropertyWithValue<TYPE>::i_get() const { return m_value ; } 00319 // ============================================================================ 00320 // assignement operator 00321 // ============================================================================ 00322 template <class TYPE> 00323 PropertyWithValue<TYPE>& PropertyWithValue<TYPE>::operator= 00324 ( const PropertyWithValue& right ) 00325 { 00326 // assign the base class 00327 Property::operator=( right ) ; 00328 // assign the value 00329 PropertyWithValue<TYPE>::operator=( right.value() ) ; 00330 return *this ; 00331 } 00332 // ============================================================================ 00333 // templated assignement operator 00334 // ============================================================================ 00335 template <class TYPE> 00336 template <class OTHER> 00337 PropertyWithValue<TYPE>& PropertyWithValue<TYPE>::operator= 00338 ( const PropertyWithValue<OTHER>& right ) 00339 { 00340 // assign the base class 00341 Property::operator=( right ) ; 00342 // assign the value 00343 PropertyWithValue<TYPE>::operator=( right.value() ) ; 00344 return *this ; 00345 } 00346 // ============================================================================ 00347 00348 // ============================================================================ 00356 // ============================================================================ 00357 template<class TYPE,class VERIFIER> 00358 class PropertyWithVerifier 00359 : public PropertyWithValue<TYPE> 00360 { 00361 protected: 00363 PropertyWithVerifier 00364 ( const std::string& name , 00365 TYPE* value , 00366 const bool owner , 00367 const VERIFIER& verifier ) 00368 : PropertyWithValue<TYPE> ( name , value , owner ) 00369 , m_verifier ( verifier ) 00370 {} 00372 virtual ~PropertyWithVerifier() {}; 00373 public: 00374 inline VERIFIER& verifier() { return m_verifier ; } 00375 inline const VERIFIER& verifier() const { return m_verifier ; } 00377 bool set( const TYPE& value ) ; 00379 virtual bool setValue( const TYPE& value ) { return set( value ) ; } 00381 template <class OTHER,class OTHERVERIFIER> 00382 PropertyWithVerifier& operator= 00383 ( const PropertyWithVerifier<OTHER,OTHERVERIFIER>& right ) ; 00385 template <class OTHER> 00386 PropertyWithVerifier& operator=( const PropertyWithValue<OTHER>& right ) ; 00388 PropertyWithVerifier& operator=( const TYPE& right ) ; 00389 private: 00391 PropertyWithVerifier() ; 00393 PropertyWithVerifier( const PropertyWithVerifier& right ); 00394 private: 00395 VERIFIER m_verifier ; 00396 } ; 00397 // ============================================================================ 00399 // ============================================================================ 00400 template <class TYPE,class VERIFIER> 00401 inline bool 00402 PropertyWithVerifier<TYPE,VERIFIER>::set( const TYPE& value ) 00403 { 00405 if ( !m_verifier.isValid( &value ) ) { return false ; } 00407 i_set( value ) ; 00409 this->useUpdateHandler() ; 00410 return true ; 00411 } 00412 // ============================================================================ 00414 // ============================================================================ 00415 template <class TYPE,class VERIFIER> 00416 inline PropertyWithVerifier<TYPE,VERIFIER>& 00417 PropertyWithVerifier<TYPE,VERIFIER>::operator=( const TYPE& right ) 00418 { 00419 PropertyWithValue<TYPE>::operator=( right ) ; 00420 return *this ; 00421 } 00422 // ============================================================================ 00424 // ============================================================================ 00425 template <class TYPE,class VERIFIER> 00426 template <class OTHER> 00427 inline PropertyWithVerifier<TYPE,VERIFIER>& 00428 PropertyWithVerifier<TYPE,VERIFIER>::operator=( const PropertyWithValue<OTHER>& right ) 00429 { 00430 PropertyWithValue<TYPE>::operator=(right) ; 00431 return *this ; 00432 } 00433 // ============================================================================ 00435 // ============================================================================ 00436 template <class TYPE,class VERIFIER> 00437 template <class OTHER,class OTHERVERIFIER> 00438 inline PropertyWithVerifier<TYPE,VERIFIER>& 00439 PropertyWithVerifier<TYPE,VERIFIER>::operator= 00440 ( const PropertyWithVerifier<OTHER,OTHERVERIFIER>& right ) 00441 { 00442 PropertyWithValue<TYPE>::operator=(right) ; 00443 return *this ; 00444 } 00445 // ============================================================================ 00446 00447 // ============================================================================ 00457 // ============================================================================ 00458 template <class TYPE,class VERIFIER = BoundedVerifier<TYPE> > 00459 class SimpleProperty 00460 : public PropertyWithVerifier<TYPE,VERIFIER> 00461 { 00462 public: 00464 SimpleProperty 00465 ( VERIFIER verifier = VERIFIER() ) ; 00467 SimpleProperty 00468 ( const TYPE& value , 00469 VERIFIER verifier = VERIFIER() ) ; 00471 SimpleProperty 00472 ( const std::string& name , 00473 const TYPE& value , 00474 VERIFIER verifier = VERIFIER() ) ; 00476 template <class OTHER> 00477 SimpleProperty ( const PropertyWithValue<OTHER>& right ) ; 00479 SimpleProperty ( const SimpleProperty& right ) ; 00481 virtual ~SimpleProperty() ; 00483 virtual SimpleProperty* clone() const ; 00485 SimpleProperty& operator=( const TYPE& value ) ; 00487 template <class OTHER> 00488 SimpleProperty& operator=( const PropertyWithValue<OTHER>& right ) ; 00489 }; 00490 // ============================================================================ 00492 // ============================================================================ 00493 template <class TYPE,class VERIFIER> 00494 SimpleProperty<TYPE,VERIFIER>::SimpleProperty 00495 ( VERIFIER verifier ) 00496 : PropertyWithVerifier<TYPE,VERIFIER> 00497 ( "" , new TYPE() , true , verifier ) 00498 {} 00499 // ============================================================================ 00501 // ============================================================================ 00502 template <class TYPE,class VERIFIER> 00503 SimpleProperty<TYPE,VERIFIER>::SimpleProperty 00504 ( const TYPE& value , 00505 VERIFIER verifier ) 00506 : PropertyWithVerifier<TYPE,VERIFIER> 00507 ( "" , new TYPE(value) , true , verifier ) 00508 {} 00509 // ============================================================================ 00511 // ============================================================================ 00512 template <class TYPE,class VERIFIER> 00513 SimpleProperty<TYPE,VERIFIER>::SimpleProperty 00514 ( const std::string& name , 00515 const TYPE& value , 00516 VERIFIER verifier ) 00517 : PropertyWithVerifier<TYPE,VERIFIER> 00518 ( name , new TYPE(value) , true , verifier ) 00519 {} 00520 // ============================================================================ 00522 // ============================================================================ 00523 template <class TYPE,class VERIFIER> 00524 template <class OTHER> 00525 SimpleProperty<TYPE,VERIFIER>::SimpleProperty 00526 ( const PropertyWithValue<OTHER>& right ) 00527 : PropertyWithVerifier<TYPE,VERIFIER> 00528 ( right.name() , new TYPE( right.value() ) , true , VERIFIER() ) 00529 {} 00530 // ============================================================================ 00532 // ============================================================================ 00533 template <class TYPE,class VERIFIER> 00534 SimpleProperty<TYPE,VERIFIER>::SimpleProperty 00535 ( const SimpleProperty& right ) 00536 : PropertyWithVerifier<TYPE,VERIFIER> 00537 ( right.name() , new TYPE( right.value() ) , true , right.verifier() ) 00538 {} 00539 // ============================================================================ 00541 // ============================================================================ 00542 template <class TYPE,class VERIFIER> 00543 SimpleProperty<TYPE,VERIFIER>::~SimpleProperty(){} 00544 // ============================================================================ 00546 // ============================================================================ 00547 template <class TYPE,class VERIFIER> 00548 inline 00549 SimpleProperty<TYPE,VERIFIER>* 00550 SimpleProperty<TYPE,VERIFIER>::clone() const 00551 { return new SimpleProperty(*this) ; } 00552 // ============================================================================ 00554 // ============================================================================ 00555 template <class TYPE,class VERIFIER> 00556 inline 00557 SimpleProperty<TYPE,VERIFIER>& 00558 SimpleProperty<TYPE,VERIFIER>::operator=( const TYPE& value ) 00559 { 00560 PropertyWithVerifier<TYPE,VERIFIER>::operator=( value ); 00561 return *this ; 00562 } 00563 // ============================================================================ 00565 // ============================================================================ 00566 template <class TYPE,class VERIFIER> 00567 template <class OTHER> 00568 inline 00569 SimpleProperty<TYPE,VERIFIER>& 00570 SimpleProperty<TYPE,VERIFIER>::operator= 00571 ( const PropertyWithValue<OTHER>& right ) 00572 { 00573 PropertyWithVerifier<TYPE,VERIFIER>::operator=( right ); 00574 return *this ; 00575 } 00576 // ============================================================================ 00577 00578 // ============================================================================ 00587 // ============================================================================ 00588 template< class TYPE, class VERIFIER = NullVerifier<TYPE> > 00589 class SimplePropertyRef : 00590 public PropertyWithVerifier<TYPE,VERIFIER> 00591 { 00592 public: 00594 SimplePropertyRef 00595 ( const std::string& name , 00596 TYPE& value , 00597 VERIFIER verifier = VERIFIER() ) ; 00599 SimplePropertyRef ( const SimplePropertyRef& right ) ; 00601 virtual ~SimplePropertyRef() ; 00603 virtual SimplePropertyRef* clone() const ; 00605 SimplePropertyRef& operator=( const TYPE& value ) ; 00607 template <class OTHER> 00608 SimplePropertyRef& operator=( const PropertyWithValue<OTHER>& right ) ; 00609 private: 00610 // the default constructor is disabled 00611 SimplePropertyRef() ; 00612 }; 00613 // ============================================================================ 00615 // ============================================================================ 00616 template <class TYPE,class VERIFIER> 00617 SimplePropertyRef<TYPE,VERIFIER>::SimplePropertyRef 00618 ( const std::string& name , 00619 TYPE& value , 00620 VERIFIER verifier ) 00621 : PropertyWithVerifier<TYPE,VERIFIER> ( name , &value , false , verifier ) 00622 {} 00623 // ============================================================================ 00625 // ============================================================================ 00626 template <class TYPE,class VERIFIER> 00627 SimplePropertyRef<TYPE,VERIFIER>::SimplePropertyRef 00628 ( const SimplePropertyRef& right ) 00629 : PropertyWithVerifier<TYPE,VERIFIER> 00630 ( right.name() , right.i_get() , false , right.verifier() ) 00631 {} 00632 // ============================================================================ 00634 // ============================================================================ 00635 template <class TYPE,class VERIFIER> 00636 SimplePropertyRef<TYPE,VERIFIER>::~SimplePropertyRef(){} 00637 // ============================================================================ 00639 // ============================================================================ 00640 template <class TYPE,class VERIFIER> 00641 inline 00642 SimplePropertyRef<TYPE,VERIFIER>* 00643 SimplePropertyRef<TYPE,VERIFIER>::clone() const 00644 { return new SimplePropertyRef(*this) ; } 00645 // ============================================================================ 00647 // ============================================================================ 00648 template <class TYPE,class VERIFIER> 00649 inline 00650 SimplePropertyRef<TYPE,VERIFIER>& 00651 SimplePropertyRef<TYPE,VERIFIER>::operator=( const TYPE& value ) 00652 { 00653 PropertyWithVerifier<TYPE,VERIFIER>::operator=( value ) ; 00654 return *this ; 00655 } 00656 // ============================================================================ 00658 // ============================================================================ 00659 template <class TYPE,class VERIFIER> 00660 template <class OTHER> 00661 inline 00662 SimplePropertyRef<TYPE,VERIFIER>& 00663 SimplePropertyRef<TYPE,VERIFIER>::operator= 00664 ( const PropertyWithValue<OTHER>& right ) 00665 { 00666 PropertyWithVerifier<TYPE,VERIFIER>::operator=( right ); 00667 return *this ; 00668 } 00669 // ============================================================================ 00670 00671 00672 00673 00674 // Typedef Properties for built-in types 00675 typedef SimpleProperty< bool > BooleanProperty; 00676 typedef SimpleProperty< char > CharProperty; 00677 typedef SimpleProperty< signed char > SignedCharProperty; 00678 typedef SimpleProperty< unsigned char > UnsignedCharProperty; 00679 typedef SimpleProperty< short > ShortProperty; 00680 typedef SimpleProperty< unsigned short > UnsignedShortProperty; 00681 typedef SimpleProperty< int > IntegerProperty; 00682 typedef SimpleProperty< unsigned int > UnsignedIntegerProperty; 00683 typedef SimpleProperty< long > LongProperty; 00684 typedef SimpleProperty< unsigned long > UnsignedLongProperty; 00685 typedef SimpleProperty< long long> LongLongProperty; 00686 typedef SimpleProperty< unsigned long long> UnsignedLongLongProperty; 00687 typedef SimpleProperty< float > FloatProperty; 00688 typedef SimpleProperty< double > DoubleProperty; 00689 typedef SimpleProperty< long double > LongDoubleProperty; 00690 00691 typedef SimpleProperty< std::string > StringProperty; 00692 00693 00694 // Typedef PropertyRefs for built-in types 00695 typedef SimplePropertyRef< bool > BooleanPropertyRef; 00696 typedef SimplePropertyRef< char > CharPropertyRef; 00697 typedef SimplePropertyRef< signed char > SignedCharPropertyRef; 00698 typedef SimplePropertyRef< unsigned char > UnsignedCharPropertyRef; 00699 typedef SimplePropertyRef< short > ShortPropertyRef; 00700 typedef SimplePropertyRef< unsigned short > UnsignedShortPropertyRef; 00701 typedef SimplePropertyRef< int > IntegerPropertyRef; 00702 typedef SimplePropertyRef< unsigned int > UnsignedIntegerPropertyRef; 00703 typedef SimplePropertyRef< long > LongPropertyRef; 00704 typedef SimplePropertyRef< unsigned long > UnsignedLongPropertyRef; 00705 typedef SimplePropertyRef< long long > LongLongPropertyRef; 00706 typedef SimplePropertyRef< unsigned long long > UnsignedLongLongPropertyRef; 00707 typedef SimplePropertyRef< float > FloatPropertyRef; 00708 typedef SimplePropertyRef< double > DoublePropertyRef; 00709 typedef SimplePropertyRef< long double > LongDoublePropertyRef; 00710 00711 typedef SimplePropertyRef< std::string > StringPropertyRef; 00712 00713 00714 // Typedef "Arrays" of Properties for built-in types 00715 typedef SimpleProperty< std::vector< bool > > BooleanArrayProperty; 00716 typedef SimpleProperty< std::vector< char > > CharArrayProperty; 00717 typedef SimpleProperty< std::vector< signed char > > SignedCharArrayProperty; 00718 typedef SimpleProperty< std::vector< unsigned char > > UnsignedCharArrayProperty; 00719 typedef SimpleProperty< std::vector< short > > ShortArrayProperty; 00720 typedef SimpleProperty< std::vector< unsigned short > > UnsignedShortArrayProperty; 00721 typedef SimpleProperty< std::vector< int > > IntegerArrayProperty; 00722 typedef SimpleProperty< std::vector< unsigned int > > UnsignedIntegerArrayProperty; 00723 typedef SimpleProperty< std::vector< long > > LongArrayProperty; 00724 typedef SimpleProperty< std::vector< unsigned long > > UnsignedLongArrayProperty; 00725 typedef SimpleProperty< std::vector< long long > > LongLongArrayProperty; 00726 typedef SimpleProperty< std::vector< unsigned long long > > UnsignedLongLongArrayProperty; 00727 typedef SimpleProperty< std::vector< float > > FloatArrayProperty; 00728 typedef SimpleProperty< std::vector< double > > DoubleArrayProperty; 00729 typedef SimpleProperty< std::vector< long double > > LongDoubleArrayProperty; 00730 00731 typedef SimpleProperty< std::vector< std::string > > StringArrayProperty; 00732 00733 00734 // Typedef "Arrays" of PropertyRefs for built-in types 00735 typedef SimplePropertyRef< std::vector< bool > > BooleanArrayPropertyRef; 00736 typedef SimplePropertyRef< std::vector< char > > CharArrayPropertyRef; 00737 typedef SimplePropertyRef< std::vector< signed char > > SignedCharArrayPropertyRef; 00738 typedef SimplePropertyRef< std::vector< unsigned char > > UnsignedCharArrayPropertyRef; 00739 typedef SimplePropertyRef< std::vector< short > > ShortArrayPropertyRef; 00740 typedef SimplePropertyRef< std::vector< unsigned short > > UnsignedShortArrayPropertyRef; 00741 typedef SimplePropertyRef< std::vector< int > > IntegerArrayPropertyRef; 00742 typedef SimplePropertyRef< std::vector< unsigned int > > UnsignedIntegerArrayPropertyRef; 00743 typedef SimplePropertyRef< std::vector< long > > LongArrayPropertyRef; 00744 typedef SimplePropertyRef< std::vector< unsigned long > > UnsignedLongArrayPropertyRef; 00745 typedef SimplePropertyRef< std::vector< long long > > LongLongArrayPropertyRef; 00746 typedef SimplePropertyRef< std::vector< unsigned long long > > UnsignedLongLongArrayPropertyRef; 00747 typedef SimplePropertyRef< std::vector< float > > FloatArrayPropertyRef; 00748 typedef SimplePropertyRef< std::vector< double > > DoubleArrayPropertyRef; 00749 typedef SimplePropertyRef< std::vector< long double > > LongDoubleArrayPropertyRef; 00750 00751 typedef SimplePropertyRef< std::vector< std::string > > StringArrayPropertyRef; 00752 00753 // pre-declaration is sufficient here 00754 class GaudiHandleBase; 00755 00756 class GaudiHandleProperty : public Property { 00757 public: 00758 GaudiHandleProperty( const std::string& name, GaudiHandleBase& ref ); 00759 00760 GaudiHandleProperty& operator=( const GaudiHandleBase& value ); 00761 00762 virtual GaudiHandleProperty* clone() const; 00763 00764 virtual bool load( Property& destination ) const; 00765 00766 virtual bool assign( const Property& source ); 00767 00768 virtual std::string toString() const; 00769 00770 virtual StatusCode fromString(const std::string& s); 00771 00772 const GaudiHandleBase& value() const; 00773 00774 bool setValue( const GaudiHandleBase& value ); 00775 00776 private: 00779 GaudiHandleBase* m_pValue; 00780 }; 00781 00782 // implementation in header file only where the GaudiHandleBase class 00783 // definition is not needed. The rest goes into the .cpp file. 00784 // The goal is to decouple the header files, to avoid that the whole 00785 // world depends on GaudiHandle.h 00786 inline GaudiHandleProperty& GaudiHandleProperty::operator=( const GaudiHandleBase& value ) { 00787 setValue( value ); 00788 return *this; 00789 } 00790 00791 inline GaudiHandleProperty* GaudiHandleProperty::clone() const { 00792 return new GaudiHandleProperty( *this ); 00793 } 00794 00795 inline bool GaudiHandleProperty::load( Property& destination ) const { 00796 return destination.assign( *this ); 00797 } 00798 00799 inline bool GaudiHandleProperty::assign( const Property& source ) { 00800 return fromString( source.toString() ).isSuccess(); 00801 } 00802 00803 inline const GaudiHandleBase& GaudiHandleProperty::value() const { 00804 useReadHandler(); 00805 return *m_pValue; 00806 } 00807 00808 00809 // pre-declaration is sufficient here 00810 class GaudiHandleArrayBase; 00811 00812 class GaudiHandleArrayProperty : public Property { 00813 public: 00814 00815 GaudiHandleArrayProperty( const std::string& name, GaudiHandleArrayBase& ref ); 00816 00817 GaudiHandleArrayProperty& operator=( const GaudiHandleArrayBase& value ); 00818 00819 virtual GaudiHandleArrayProperty* clone() const; 00820 00821 virtual bool load( Property& destination ) const; 00822 00823 virtual bool assign( const Property& source ); 00824 00825 virtual std::string toString() const; 00826 00827 virtual StatusCode fromString(const std::string& s); 00828 00829 const GaudiHandleArrayBase& value() const; 00830 00831 bool setValue( const GaudiHandleArrayBase& value ); 00832 00833 private: 00836 GaudiHandleArrayBase* m_pValue; 00837 00838 }; 00839 00840 // implementation in header file only where the GaudiHandleBase class 00841 // definition is not needed. The rest goes into the .cpp file. 00842 // The goal is to decouple the header files, to avoid that the whole 00843 // world depends on GaudiHandle.h 00844 inline GaudiHandleArrayProperty& GaudiHandleArrayProperty::operator=( const GaudiHandleArrayBase& value ) { 00845 setValue( value ); 00846 return *this; 00847 } 00848 00849 inline GaudiHandleArrayProperty* GaudiHandleArrayProperty::clone() const { 00850 return new GaudiHandleArrayProperty( *this ); 00851 } 00852 00853 inline bool GaudiHandleArrayProperty::load( Property& destination ) const { 00854 return destination.assign( *this ); 00855 } 00856 00857 inline bool GaudiHandleArrayProperty::assign( const Property& source ) { 00858 return fromString( source.toString() ) != 0; 00859 } 00860 00861 inline const GaudiHandleArrayBase& GaudiHandleArrayProperty::value() const { 00862 useReadHandler(); 00863 return *m_pValue; 00864 } 00865 00866 00867 namespace Gaudi 00868 { 00869 namespace Utils 00870 { 00871 // ======================================================================== 00889 bool hasProperty ( const IProperty* p , const std::string& name ) ; 00890 // ======================================================================== 00908 bool hasProperty ( const IInterface* p , const std::string& name ) ; 00909 // ======================================================================== 00927 Property* getProperty 00928 ( const IProperty* p , const std::string& name ) ; 00929 // ======================================================================== 00947 Property* getProperty 00948 ( const IInterface* p , const std::string& name ) ; 00949 // ======================================================================== 00972 bool hasProperty 00973 ( const std::vector<const Property*>* p , 00974 const std::string& name ) ; 00975 // ======================================================================== 00998 const Property* getProperty 00999 ( const std::vector<const Property*>* p , 01000 const std::string& name ) ; 01001 // ======================================================================== 01025 template <class TYPE> 01026 StatusCode setProperty 01027 ( IProperty* component , 01028 const std::string& name , 01029 const TYPE& value , 01030 const std::string& doc ) ; 01031 // ======================================================================== 01054 template <class TYPE> 01055 StatusCode setProperty 01056 ( IProperty* component , 01057 const std::string& name , 01058 const TYPE& value ) 01059 { return setProperty ( component , name , value , std::string() ) ; } 01060 // ======================================================================== 01074 StatusCode setProperty 01075 ( IProperty* component , 01076 const std::string& name , 01077 const std::string& value , 01078 const std::string& doc = "" ) ; 01079 // ======================================================================== 01093 StatusCode setProperty 01094 ( IProperty* component , 01095 const std::string& name , 01096 const char* value , 01097 const std::string& doc = "" ) ; 01098 // ======================================================================== 01112 template <unsigned N> 01113 StatusCode setProperty 01114 ( IProperty* component , 01115 const std::string& name , 01116 const char (&value)[N] , 01117 const std::string& doc = "" ) 01118 { 01119 if ( 0 == component ) { return StatusCode::FAILURE ; } 01120 const std::string val = std::string ( value , value + N ) ; 01121 return setProperty ( component , name , val , doc ) ; 01122 } 01123 // ======================================================================== 01154 template <class TYPE> 01155 StatusCode setProperty 01156 ( IProperty* component , 01157 const std::string& name , 01158 const TYPE& value , 01159 const std::string& doc ) 01160 { 01161 if ( 0 == component ) { return StatusCode::FAILURE ; } // RETURN 01162 if ( !hasProperty ( component , name ) ) { return StatusCode::FAILURE ; } 01163 const std::string val = Gaudi::Utils::toString ( value ) ; 01164 return Gaudi::Utils::setProperty ( component , name , val , doc ) ; 01165 } 01166 // ======================================================================== 01188 StatusCode 01189 setProperty 01190 ( IProperty* component , 01191 const std::string& name , 01192 const Property* property , 01193 const std::string& doc = "" ) ; 01194 // ======================================================================== 01216 StatusCode 01217 setProperty 01218 ( IProperty* component , 01219 const std::string& name , 01220 const Property& property , 01221 const std::string& doc = "" ) ; 01222 // ======================================================================== 01245 template <class TYPE> 01246 StatusCode 01247 setProperty 01248 ( IProperty* component , 01249 const std::string& name , 01250 const SimpleProperty<TYPE>& value , 01251 const std::string& doc = "" ) 01252 { 01253 const Property* property = &value ; 01254 return setProperty ( component , name , property , doc ) ; 01255 } 01256 // ======================================================================== 01277 template <class TYPE> 01278 StatusCode setProperty 01279 ( IInterface* component , 01280 const std::string& name , 01281 const TYPE& value , 01282 const std::string& doc = "" ) 01283 { 01284 if ( 0 == component ) { return StatusCode::FAILURE ; } 01285 SmartIF<IProperty> property ( component ) ; 01286 if ( !property ) { return StatusCode::FAILURE ; } 01287 return setProperty ( property , name , value , doc ) ; 01288 } 01289 // ======================================================================== 01302 StatusCode setProperty 01303 ( IInterface* component , 01304 const std::string& name , 01305 const std::string& value , 01306 const std::string& doc = "" ) ; 01307 // ======================================================================== 01320 StatusCode setProperty 01321 ( IInterface* component , 01322 const std::string& name , 01323 const char* value , 01324 const std::string& doc = "" ) ; 01325 // ======================================================================== 01339 template <unsigned N> 01340 StatusCode setProperty 01341 ( IInterface* component , 01342 const std::string& name , 01343 const char (&value)[N] , 01344 const std::string& doc = "" ) 01345 { 01346 if ( 0 == component ) { return StatusCode::FAILURE ; } 01347 const std::string val = std::string ( value , value + N ) ; 01348 return setProperty ( component , name , val , doc ) ; 01349 } 01350 // ======================================================================== 01372 StatusCode 01373 setProperty 01374 ( IInterface* component , 01375 const std::string& name , 01376 const Property* property , 01377 const std::string& doc = "" ) ; 01378 // ======================================================================== 01400 StatusCode 01401 setProperty 01402 ( IInterface* component , 01403 const std::string& name , 01404 const Property& property , 01405 const std::string& doc = "" ) ; 01406 // ======================================================================== 01429 template <class TYPE> 01430 StatusCode 01431 setProperty 01432 ( IInterface* component , 01433 const std::string& name , 01434 const SimpleProperty<TYPE>& value , 01435 const std::string& doc = "" ) 01436 { 01437 const Property* property = &value ; 01438 return setProperty ( component , name , property , doc ) ; 01439 } 01440 // ======================================================================== 01441 } // end of namespace Gaudi::Utils 01442 } // end of namespace Gaudi 01443 01444 01445 // ============================================================================ 01446 // The END 01447 // ============================================================================ 01448 #endif // GAUDIKERNEL_PROPERTY_H 01449 // ============================================================================