Gaudi Framework, version v20r2

Generated: 18 Jul 2008

Property.h

Go to the documentation of this file.
00001 // $Id: Property.h,v 1.25 2007/09/25 10:31:43 marcocle Exp $
00002 // ============================================================================
00003 // CVS tag $Name: v25r2 $ 
00004 // ============================================================================
00005 #ifndef GAUDIKERNEL_PROPERTY_H
00006 #define GAUDIKERNEL_PROPERTY_H
00007 // ============================================================================
00008 // STD & STL 
00009 // ============================================================================
00010 #include <string>
00011 #include <stdexcept>
00012 // ============================================================================
00013 // Application C++ Class Headers
00014 // ============================================================================
00015 #include "GaudiKernel/Kernel.h"
00016 #include "GaudiKernel/PropertyVerifier.h"
00017 #include "GaudiKernel/Parsers.h"
00018 #include "GaudiKernel/ToStream.h"
00019 #include "GaudiKernel/SmartIF.h"
00020 // ============================================================================
00021 
00022 // ============================================================================
00023 class Property   ;
00024 class PropertyCallbackFunctor ;
00025 class IProperty  ;
00026 class IInterface ;
00027 // ============================================================================
00028 
00029 // ============================================================================
00031 // ============================================================================
00032 std::ostream& 
00033 operator<<
00034   ( std::ostream&   stream , 
00035     const Property& prop   ) ;
00036 // ============================================================================
00045 class Property 
00046 {
00047 public:
00049   const std::string&    name      () const { return m_name             ; } ;
00051   const   std::string&    documentation() const { return m_documentation; };
00053   const std::type_info* type_info () const { return m_typeinfo         ; } ;
00055   std::string           type      () const { return m_typeinfo->name() ; } ;  
00057   virtual bool load   (       Property& dest   ) const = 0 ;
00059   virtual bool assign ( const Property& source )       = 0 ;
00060 public:
00062   virtual std::string  toString   ()  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 void 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   // the default constructor is disabled 
00111   Property() ;
00112 private:
00113   // property name 
00114   std::string              m_name           ;
00115   // property doc string
00116   std::string              m_documentation;
00117   // property type 
00118   const std::type_info*    m_typeinfo       ;
00119 protected:
00120   // call back funtor for reading 
00121   mutable PropertyCallbackFunctor* m_readCallBack   ;
00122   // call back funtor for update 
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 
00148   : public Property
00149 {
00150 protected:
00152   PropertyWithValue 
00153   ( const std::string& name  , 
00154     TYPE*              value , 
00155     const bool         owner ) ;
00157   PropertyWithValue ( const PropertyWithValue& rhs ) ;
00159   template <class OTHER>
00160   PropertyWithValue ( const PropertyWithValue<OTHER>& right ) ;
00162   virtual ~PropertyWithValue() ;  
00164   PropertyWithValue& operator=( const TYPE& value ) ;
00165   // assignement operator (don't let the compiler generate a buggy one)
00166   PropertyWithValue& operator=( const PropertyWithValue& rhs ) ;
00167   // assignement operator 
00168   template <class OTHER>
00169   PropertyWithValue& operator=( const PropertyWithValue<OTHER>& right ) ;
00170 public:
00171   operator const TYPE&      () const { return value() ;}
00172   const TYPE& value() const ;
00173 public:
00174   // NB: abstract : to be implemented when verifier is available 
00175   virtual bool setValue ( const TYPE&     value  )  = 0  ;
00177   virtual bool assign   ( const Property& source )       ;
00179   virtual bool load     (       Property& dest   ) const ;  
00181   virtual StatusCode fromString ( const std::string& s )  ;
00183   virtual std::string  toString   () const  ;
00184 protected:
00185   void  i_set ( const TYPE& value ) ;
00186   TYPE* i_get () const ; 
00187 private:
00188   TYPE* m_value ;
00189   bool  m_own ;
00190 };
00191 // ============================================================================
00193 // ============================================================================
00194 template <class TYPE>
00195 inline PropertyWithValue<TYPE>::PropertyWithValue 
00196 ( const std::string& name  , 
00197   TYPE*              value , 
00198   const bool         own   ) 
00199   : Property ( typeid( TYPE ) , name )
00200   , m_value  ( value ) 
00201   , m_own    ( own   ) 
00202 {}
00203 // ============================================================================
00204 // copy constructor
00205 // ============================================================================
00206 template <class TYPE>
00207 inline PropertyWithValue<TYPE>::PropertyWithValue 
00208 ( const PropertyWithValue& right ) 
00209   : Property( right         )
00210   , m_value ( right.m_value )
00211   , m_own   ( right.own     ) 
00212 { if ( m_own ) { m_value = new TYPE(right.value()) ; } }
00213 // ============================================================================
00214 // "copy" constructor form any other type 
00215 // ============================================================================
00216 template <class TYPE>
00217 template <class OTHER>
00218 inline PropertyWithValue<TYPE>::PropertyWithValue 
00219 ( const PropertyWithValue<OTHER>& right ) 
00220   : Property( right         )
00221   , m_value ( right.m_value )
00222   , m_own   ( right.own     ) 
00223 { if ( m_own ) { m_value = new TYPE(right.value()) ; } }
00224 // ============================================================================
00226 // ============================================================================
00227 template <class TYPE>
00228 inline PropertyWithValue<TYPE>::~PropertyWithValue() 
00229 { if ( m_own ) { delete m_value ; } ;  m_value = 0 ; }
00230 // ============================================================================
00232 // ============================================================================
00233 template <class TYPE>
00234 inline PropertyWithValue<TYPE>&
00235 PropertyWithValue<TYPE>::operator=( const TYPE& value ) 
00236 {
00237   if ( !setValue ( value ) ) 
00238   { throw std::out_of_range( "Value not verified" ) ; }
00239   return *this ;
00240 }
00241 // ============================================================================
00243 // ============================================================================
00244 template <class TYPE>
00245 inline bool
00246 PropertyWithValue<TYPE>::assign ( const Property& source ) 
00247 {
00248   // 1) Is the property of "the same" type? 
00249   const PropertyWithValue<TYPE>* p = 
00250     dynamic_cast<const PropertyWithValue<TYPE>*>       ( &source ) ;
00251   if ( 0 != p ) { return setValue ( p->value() ) ; }       // RETURN 
00252   // 2) Else use the string representation 
00253   return this->fromString( source.toString() ).isSuccess() ;
00254 }
00255 // ============================================================================
00257 // ============================================================================
00258 template <class TYPE>
00259 inline bool
00260 PropertyWithValue<TYPE>::load( Property& dest ) const 
00261 {
00262   // gelegate to the 'opposite' method ;
00263   return dest.assign( *this ) ;
00264 }
00265 // ============================================================================
00267 // ============================================================================
00268 template <class TYPE>
00269 inline std::string 
00270 PropertyWithValue<TYPE>::toString () const 
00271 {
00272   useReadHandler();
00273   return Gaudi::Utils::toString( *m_value ) ;
00274 }
00275 // ============================================================================
00277 // ============================================================================
00278 template <class TYPE>
00279 inline StatusCode
00280 PropertyWithValue<TYPE>::fromString ( const std::string& source )  
00281 {
00282   TYPE tmp ;
00283   StatusCode sc = Gaudi::Parsers::parse ( tmp , source ) ;
00284   if ( sc.isFailure() ) { return sc ; }
00285   return setValue ( tmp ) ? StatusCode::SUCCESS : StatusCode::FAILURE ;
00286 }
00287 // ============================================================================
00289 // ============================================================================
00290 template <>
00291 inline std::string 
00292 PropertyWithValue<std::string>::toString () const 
00293 { return this->value() ; }
00294 // ============================================================================
00295 template <>
00296 inline bool PropertyWithValue<std::string>::assign ( const Property& source ) 
00297 { return this->fromString( source.toString() ).isSuccess() ; }
00298 // ============================================================================
00299 
00300 // ============================================================================
00302 // ============================================================================
00303 template <class TYPE>
00304 inline const TYPE& 
00305 PropertyWithValue<TYPE>::value() const 
00306 { useReadHandler() ; return *m_value ; }
00307 // ============================================================================
00308 // the actual modification of internale data 
00309 // ============================================================================
00310 template <class TYPE>
00311 inline  void PropertyWithValue<TYPE>::i_set 
00312 ( const TYPE& value ) { *m_value = value ; }
00313 // ============================================================================
00314 // protected accessor to internal data 
00315 // ============================================================================
00316 template <class TYPE>
00317 inline TYPE* PropertyWithValue<TYPE>::i_get() const { return m_value ; }
00318 // ============================================================================
00319 // assignement operator 
00320 // ============================================================================
00321 template <class TYPE> 
00322 PropertyWithValue<TYPE>& PropertyWithValue<TYPE>::operator=
00323 ( const PropertyWithValue& right ) 
00324 {
00325   // assign the base class 
00326   Property::operator=( right ) ;
00327   // assign the value 
00328   PropertyWithValue<TYPE>::operator=( right.value() ) ;
00329   return *this ;
00330 }
00331 // ============================================================================
00332 // templated assignement operator 
00333 // ============================================================================
00334 template <class TYPE> 
00335 template <class OTHER>
00336 PropertyWithValue<TYPE>& PropertyWithValue<TYPE>::operator=
00337 ( const PropertyWithValue<OTHER>& right ) 
00338 {
00339   // assign the base class 
00340   Property::operator=( right ) ;
00341   // assign the value 
00342   PropertyWithValue<TYPE>::operator=( right.value() ) ;
00343   return *this ;
00344 }
00345 // ============================================================================
00346 
00347 // ============================================================================
00355 // ============================================================================
00356 template<class TYPE,class VERIFIER> 
00357 class PropertyWithVerifier 
00358   : public PropertyWithValue<TYPE>
00359 {
00360 protected:
00362   PropertyWithVerifier
00363   ( const std::string& name     ,  
00364     TYPE*              value    , 
00365     const bool         owner    , 
00366     const VERIFIER&    verifier ) 
00367     : PropertyWithValue<TYPE> ( name , value , owner ) 
00368     , m_verifier ( verifier ) 
00369   {}
00371   virtual ~PropertyWithVerifier() {};
00372 public:
00373   inline       VERIFIER& verifier()       { return m_verifier ; }
00374   inline const VERIFIER& verifier() const { return m_verifier ; }
00376   bool set( const TYPE& value ) ;
00378   virtual bool setValue( const TYPE& value ) { return set( value ) ; }
00380   template <class OTHER,class OTHERVERIFIER>
00381   PropertyWithVerifier& operator=
00382   ( const PropertyWithVerifier<OTHER,OTHERVERIFIER>& right ) ;
00384   template <class OTHER>
00385   PropertyWithVerifier& operator=( const PropertyWithValue<OTHER>& right ) ;
00387   PropertyWithVerifier& operator=( const TYPE& right ) ;
00388 private:
00390   PropertyWithVerifier() ;
00392   PropertyWithVerifier( const  PropertyWithVerifier& right );
00393 private:
00394   VERIFIER m_verifier ;
00395 } ;
00396 // ============================================================================
00398 // ============================================================================
00399 template <class TYPE,class VERIFIER>
00400 inline bool 
00401 PropertyWithVerifier<TYPE,VERIFIER>::set( const TYPE& value ) 
00402 {
00404   if ( !m_verifier.isValid( &value ) ) { return false ; }    
00406   i_set( value ) ;
00408   this->useUpdateHandler() ;
00409   return true ;
00410 }
00411 // ============================================================================
00413 // ============================================================================
00414 template <class TYPE,class VERIFIER>
00415 inline PropertyWithVerifier<TYPE,VERIFIER>& 
00416 PropertyWithVerifier<TYPE,VERIFIER>::operator=( const TYPE& right ) 
00417 {
00418   PropertyWithValue<TYPE>::operator=( right ) ;
00419   return *this ;
00420 }
00421 // ============================================================================
00423 // ============================================================================
00424 template <class TYPE,class VERIFIER>
00425 template <class OTHER>
00426 inline PropertyWithVerifier<TYPE,VERIFIER>& 
00427 PropertyWithVerifier<TYPE,VERIFIER>::operator=( const PropertyWithValue<OTHER>& right ) 
00428 {
00429   PropertyWithValue<TYPE>::operator=(right) ;
00430   return *this ;
00431 }
00432 // ============================================================================
00434 // ============================================================================
00435 template <class TYPE,class VERIFIER>
00436 template <class OTHER,class OTHERVERIFIER>
00437 inline PropertyWithVerifier<TYPE,VERIFIER>& 
00438 PropertyWithVerifier<TYPE,VERIFIER>::operator=
00439 ( const PropertyWithVerifier<OTHER,OTHERVERIFIER>& right ) 
00440 {
00441   PropertyWithValue<TYPE>::operator=(right) ;
00442   return *this ;
00443 }
00444 // ============================================================================
00445 
00446 // ============================================================================
00456 // ============================================================================
00457 template <class TYPE,class VERIFIER = BoundedVerifier<TYPE> >
00458 class SimpleProperty 
00459   : public PropertyWithVerifier<TYPE,VERIFIER> 
00460 {
00461 public:
00463   SimpleProperty 
00464   ( VERIFIER           verifier = VERIFIER() ) ;
00466   SimpleProperty 
00467   ( const TYPE&        value                 , 
00468     VERIFIER           verifier = VERIFIER() ) ;
00470   SimpleProperty 
00471   ( const std::string& name                  , 
00472     const TYPE&        value                 , 
00473     VERIFIER           verifier = VERIFIER() ) ;
00475   template <class OTHER>
00476   SimpleProperty ( const PropertyWithValue<OTHER>& right ) ;
00478   SimpleProperty ( const SimpleProperty& right ) ;
00480   virtual ~SimpleProperty() ;
00482   virtual SimpleProperty* clone() const ; 
00484   SimpleProperty& operator=( const TYPE& value ) ;
00486   template <class OTHER>
00487   SimpleProperty& operator=( const PropertyWithValue<OTHER>& right ) ;
00488 };
00489 // ============================================================================
00491 // ============================================================================
00492 template <class TYPE,class VERIFIER>
00493 SimpleProperty<TYPE,VERIFIER>::SimpleProperty 
00494 ( VERIFIER           verifier ) 
00495   : PropertyWithVerifier<TYPE,VERIFIER> 
00496 ( "" , new TYPE() , true , verifier ) 
00497 {}
00498 // ============================================================================
00500 // ============================================================================
00501 template <class TYPE,class VERIFIER>
00502 SimpleProperty<TYPE,VERIFIER>::SimpleProperty 
00503 ( const TYPE&        value    , 
00504   VERIFIER           verifier ) 
00505   : PropertyWithVerifier<TYPE,VERIFIER> 
00506 ( "" , new TYPE(value) , true , verifier ) 
00507 {}
00508 // ============================================================================
00510 // ============================================================================
00511 template <class TYPE,class VERIFIER>
00512 SimpleProperty<TYPE,VERIFIER>::SimpleProperty 
00513 ( const std::string& name     , 
00514   const TYPE&        value    , 
00515   VERIFIER           verifier ) 
00516   : PropertyWithVerifier<TYPE,VERIFIER> 
00517 ( name , new TYPE(value) , true , verifier ) 
00518 {}
00519 // ============================================================================
00521 // ============================================================================
00522 template <class TYPE,class VERIFIER>
00523 template <class OTHER>
00524 SimpleProperty<TYPE,VERIFIER>::SimpleProperty 
00525 ( const PropertyWithValue<OTHER>& right ) 
00526   : PropertyWithVerifier<TYPE,VERIFIER> 
00527 ( right.name() , new TYPE( right.value() ) , true , VERIFIER() ) 
00528 {}
00529 // ============================================================================
00531 // ============================================================================
00532 template <class TYPE,class VERIFIER>
00533 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00534 ( const SimpleProperty& right ) 
00535   : PropertyWithVerifier<TYPE,VERIFIER> 
00536 ( right.name() , new TYPE( right.value() ) , true , right.verifier() ) 
00537 {}
00538 // ============================================================================
00540 // ============================================================================
00541 template <class TYPE,class VERIFIER>
00542 SimpleProperty<TYPE,VERIFIER>::~SimpleProperty(){}
00543 // ============================================================================
00545 // ============================================================================
00546 template <class TYPE,class VERIFIER>
00547 inline 
00548 SimpleProperty<TYPE,VERIFIER>*
00549 SimpleProperty<TYPE,VERIFIER>::clone() const 
00550 { return new SimpleProperty(*this) ; }
00551 // ============================================================================
00553 // ============================================================================
00554 template <class TYPE,class VERIFIER>
00555 inline 
00556 SimpleProperty<TYPE,VERIFIER>& 
00557 SimpleProperty<TYPE,VERIFIER>::operator=( const TYPE& value ) 
00558 {
00559   PropertyWithVerifier<TYPE,VERIFIER>::operator=( value ); 
00560   return *this ; 
00561 }
00562 // ============================================================================
00564 // ============================================================================
00565 template <class TYPE,class VERIFIER>
00566 template <class OTHER>
00567 inline 
00568 SimpleProperty<TYPE,VERIFIER>& 
00569 SimpleProperty<TYPE,VERIFIER>::operator=
00570 ( const PropertyWithValue<OTHER>& right ) 
00571 {
00572   PropertyWithVerifier<TYPE,VERIFIER>::operator=( right ); 
00573   return *this ; 
00574 }
00575 // ============================================================================
00576 
00577 // ============================================================================
00586 // ============================================================================
00587 template< class TYPE, class VERIFIER = NullVerifier<TYPE> >
00588 class SimplePropertyRef : 
00589   public PropertyWithVerifier<TYPE,VERIFIER> 
00590 {
00591 public:
00593   SimplePropertyRef
00594   ( const std::string& name                  , 
00595     TYPE&              value                 ,  
00596     VERIFIER           verifier = VERIFIER() ) ;
00598   SimplePropertyRef ( const SimplePropertyRef& right ) ;
00600   virtual ~SimplePropertyRef() ;
00602   virtual SimplePropertyRef* clone() const ;
00604   SimplePropertyRef& operator=( const TYPE& value ) ;
00606   template <class OTHER>
00607   SimplePropertyRef& operator=( const PropertyWithValue<OTHER>& right ) ;
00608 private:
00609   // the default constructor is disabled 
00610   SimplePropertyRef() ;
00611 };
00612 // ============================================================================
00614 // ============================================================================
00615 template <class TYPE,class VERIFIER>
00616 SimplePropertyRef<TYPE,VERIFIER>::SimplePropertyRef
00617 ( const std::string& name     , 
00618   TYPE&              value    ,  
00619   VERIFIER           verifier ) 
00620   : PropertyWithVerifier<TYPE,VERIFIER> ( name , &value , false , verifier ) 
00621 {}
00622 // ============================================================================
00624 // ============================================================================
00625 template <class TYPE,class VERIFIER>
00626 SimplePropertyRef<TYPE,VERIFIER>::SimplePropertyRef
00627 ( const SimplePropertyRef& right ) 
00628   : PropertyWithVerifier<TYPE,VERIFIER> 
00629 ( right.name() , right.i_get() , false , right.verifier() ) 
00630 {}
00631 // ============================================================================
00633 // ============================================================================
00634 template <class TYPE,class VERIFIER>
00635 SimplePropertyRef<TYPE,VERIFIER>::~SimplePropertyRef(){}
00636 // ============================================================================
00638 // ============================================================================
00639 template <class TYPE,class VERIFIER>
00640 inline 
00641 SimplePropertyRef<TYPE,VERIFIER>*
00642 SimplePropertyRef<TYPE,VERIFIER>::clone() const
00643 { return new SimplePropertyRef(*this) ; }
00644 // ============================================================================
00646 // ============================================================================
00647 template <class TYPE,class VERIFIER>
00648 inline 
00649 SimplePropertyRef<TYPE,VERIFIER>&
00650 SimplePropertyRef<TYPE,VERIFIER>::operator=( const TYPE& value ) 
00651 {
00652   PropertyWithVerifier<TYPE,VERIFIER>::operator=( value ) ;
00653   return *this ;
00654 }
00655 // ============================================================================
00657 // ============================================================================
00658 template <class TYPE,class VERIFIER>
00659 template <class OTHER>
00660 inline 
00661 SimplePropertyRef<TYPE,VERIFIER>&
00662 SimplePropertyRef<TYPE,VERIFIER>::operator=
00663 ( const PropertyWithValue<OTHER>& right ) 
00664 {
00665   PropertyWithVerifier<TYPE,VERIFIER>::operator=( right ); 
00666   return *this ; 
00667 }
00668 // ============================================================================
00669 
00670 
00671 
00672 
00673 // Typedef Properties for built-in types
00674 typedef SimpleProperty< bool >              BooleanProperty;
00675 typedef SimpleProperty< char >              CharProperty;
00676 typedef SimpleProperty< signed char >       SignedCharProperty;
00677 typedef SimpleProperty< unsigned char >     UnsignedCharProperty;
00678 typedef SimpleProperty< short >             ShortProperty;
00679 typedef SimpleProperty< unsigned short >    UnsignedShortProperty;
00680 typedef SimpleProperty< int >               IntegerProperty;
00681 typedef SimpleProperty< unsigned int >      UnsignedIntegerProperty;
00682 typedef SimpleProperty< long >              LongProperty;
00683 typedef SimpleProperty< unsigned long >     UnsignedLongProperty;
00684 typedef SimpleProperty< long long>          LongLongProperty;
00685 typedef SimpleProperty< unsigned long long> UnsignedLongLongProperty;
00686 typedef SimpleProperty< float >             FloatProperty;
00687 typedef SimpleProperty< double >            DoubleProperty;
00688 typedef SimpleProperty< long double >       LongDoubleProperty;
00689 
00690 typedef SimpleProperty< std::string >       StringProperty;
00691 
00692 
00693 // Typedef PropertyRefs for built-in types
00694 typedef SimplePropertyRef< bool >                BooleanPropertyRef;
00695 typedef SimplePropertyRef< char >                CharPropertyRef;
00696 typedef SimplePropertyRef< signed char >         SignedCharPropertyRef;
00697 typedef SimplePropertyRef< unsigned char >       UnsignedCharPropertyRef;
00698 typedef SimplePropertyRef< short >               ShortPropertyRef;
00699 typedef SimplePropertyRef< unsigned short >      UnsignedShortPropertyRef;
00700 typedef SimplePropertyRef< int >                 IntegerPropertyRef;
00701 typedef SimplePropertyRef< unsigned int >        UnsignedIntegerPropertyRef;
00702 typedef SimplePropertyRef< long >                LongPropertyRef;
00703 typedef SimplePropertyRef< unsigned long >       UnsignedLongPropertyRef;
00704 typedef SimplePropertyRef< long long >           LongLongPropertyRef;
00705 typedef SimplePropertyRef< unsigned long long >  UnsignedLongLongPropertyRef;
00706 typedef SimplePropertyRef< float >               FloatPropertyRef;
00707 typedef SimplePropertyRef< double >              DoublePropertyRef;
00708 typedef SimplePropertyRef< long double >         LongDoublePropertyRef;
00709 
00710 typedef SimplePropertyRef< std::string >         StringPropertyRef;
00711 
00712 
00713 // Typedef "Arrays" of Properties for built-in types
00714 typedef SimpleProperty< std::vector< bool > >                BooleanArrayProperty;
00715 typedef SimpleProperty< std::vector< char > >                CharArrayProperty;
00716 typedef SimpleProperty< std::vector< signed char > >         SignedCharArrayProperty;
00717 typedef SimpleProperty< std::vector< unsigned char > >       UnsignedCharArrayProperty;
00718 typedef SimpleProperty< std::vector< short > >               ShortArrayProperty;
00719 typedef SimpleProperty< std::vector< unsigned short > >      UnsignedShortArrayProperty;
00720 typedef SimpleProperty< std::vector< int > >                 IntegerArrayProperty;
00721 typedef SimpleProperty< std::vector< unsigned int > >        UnsignedIntegerArrayProperty;
00722 typedef SimpleProperty< std::vector< long > >                LongArrayProperty;
00723 typedef SimpleProperty< std::vector< unsigned long > >       UnsignedLongArrayProperty;
00724 typedef SimpleProperty< std::vector< long long > >           LongLongArrayProperty;
00725 typedef SimpleProperty< std::vector< unsigned long long > >  UnsignedLongLongArrayProperty;
00726 typedef SimpleProperty< std::vector< float > >               FloatArrayProperty;
00727 typedef SimpleProperty< std::vector< double > >              DoubleArrayProperty;
00728 typedef SimpleProperty< std::vector< long double > >         LongDoubleArrayProperty;
00729 
00730 typedef SimpleProperty< std::vector< std::string > >         StringArrayProperty;
00731 
00732 
00733 // Typedef "Arrays" of PropertyRefs for built-in types
00734 typedef SimplePropertyRef< std::vector< bool > >                 BooleanArrayPropertyRef;
00735 typedef SimplePropertyRef< std::vector< char > >                 CharArrayPropertyRef;
00736 typedef SimplePropertyRef< std::vector< signed char > >          SignedCharArrayPropertyRef;
00737 typedef SimplePropertyRef< std::vector< unsigned char > >        UnsignedCharArrayPropertyRef;
00738 typedef SimplePropertyRef< std::vector< short > >                ShortArrayPropertyRef;
00739 typedef SimplePropertyRef< std::vector< unsigned short > >       UnsignedShortArrayPropertyRef;
00740 typedef SimplePropertyRef< std::vector< int > >                  IntegerArrayPropertyRef;
00741 typedef SimplePropertyRef< std::vector< unsigned int > >         UnsignedIntegerArrayPropertyRef;
00742 typedef SimplePropertyRef< std::vector< long > >                 LongArrayPropertyRef;
00743 typedef SimplePropertyRef< std::vector< unsigned long > >        UnsignedLongArrayPropertyRef;
00744 typedef SimplePropertyRef< std::vector< long long > >            LongLongArrayPropertyRef;
00745 typedef SimplePropertyRef< std::vector< unsigned long long > >   UnsignedLongLongArrayPropertyRef;
00746 typedef SimplePropertyRef< std::vector< float > >                FloatArrayPropertyRef;
00747 typedef SimplePropertyRef< std::vector< double > >               DoubleArrayPropertyRef;
00748 typedef SimplePropertyRef< std::vector< long double > >          LongDoubleArrayPropertyRef;
00749 
00750 typedef SimplePropertyRef< std::vector< std::string > >          StringArrayPropertyRef;
00751 
00752 // pre-declaration is sufficient here
00753 class GaudiHandleBase;
00754 
00755 class GaudiHandleProperty : public Property {
00756 public:
00757    GaudiHandleProperty( const std::string& name, GaudiHandleBase& ref );
00758 
00759   GaudiHandleProperty& operator=( const GaudiHandleBase& value );
00760   
00761   virtual GaudiHandleProperty* clone() const;
00762 
00763   virtual bool load( Property& destination ) const;
00764   
00765   virtual bool assign( const Property& source );
00766 
00767   virtual std::string toString() const;
00768   
00769   virtual StatusCode fromString(const std::string& s);
00770 
00771   const GaudiHandleBase& value() const;
00772 
00773   bool setValue( const GaudiHandleBase& value );
00774 
00775 private:
00778    GaudiHandleBase* m_pValue;
00779 };
00780 
00781 // implementation in header file only where the GaudiHandleBase class
00782 // definition is not needed. The rest goes into the .cpp file.
00783 // The goal is to decouple the header files, to avoid that the whole
00784 // world depends on GaudiHandle.h
00785 inline GaudiHandleProperty& GaudiHandleProperty::operator=( const GaudiHandleBase& value ) {
00786       setValue( value );
00787       return *this;
00788 }
00789   
00790 inline GaudiHandleProperty* GaudiHandleProperty::clone() const {
00791   return new GaudiHandleProperty( *this ); 
00792 }
00793 
00794 inline bool GaudiHandleProperty::load( Property& destination ) const {
00795   return destination.assign( *this );
00796 }
00797 
00798 inline bool GaudiHandleProperty::assign( const Property& source ) {
00799   return fromString( source.toString() ).isSuccess();
00800 }
00801 
00802 inline const GaudiHandleBase& GaudiHandleProperty::value() const {
00803   useReadHandler();
00804   return *m_pValue;
00805 }
00806 
00807 
00808 // pre-declaration is sufficient here
00809 class GaudiHandleArrayBase;
00810 
00811 class GaudiHandleArrayProperty : public Property {
00812 public:
00813 
00814   GaudiHandleArrayProperty( const std::string& name, GaudiHandleArrayBase& ref );
00815 
00816   GaudiHandleArrayProperty& operator=( const GaudiHandleArrayBase& value );
00817 
00818   virtual GaudiHandleArrayProperty* clone() const;
00819 
00820   virtual bool load( Property& destination ) const;
00821 
00822   virtual bool assign( const Property& source );
00823 
00824   virtual std::string toString() const;
00825   
00826   virtual StatusCode fromString(const std::string& s);
00827 
00828   const GaudiHandleArrayBase& value() const;
00829 
00830   bool setValue( const GaudiHandleArrayBase& value );
00831 
00832 private:
00835    GaudiHandleArrayBase* m_pValue;
00836 
00837 };
00838 
00839 // implementation in header file only where the GaudiHandleBase class
00840 // definition is not needed. The rest goes into the .cpp file.
00841 // The goal is to decouple the header files, to avoid that the whole
00842 // world depends on GaudiHandle.h
00843 inline GaudiHandleArrayProperty& GaudiHandleArrayProperty::operator=( const GaudiHandleArrayBase& value ) {
00844   setValue( value );
00845   return *this;
00846 }
00847 
00848 inline GaudiHandleArrayProperty* GaudiHandleArrayProperty::clone() const {
00849   return new GaudiHandleArrayProperty( *this ); 
00850 }
00851 
00852 inline bool GaudiHandleArrayProperty::load( Property& destination ) const {
00853   return destination.assign( *this );
00854 }
00855 
00856 inline bool GaudiHandleArrayProperty::assign( const Property& source ) {
00857   return fromString( source.toString() ) != 0;
00858 }
00859 
00860 inline const GaudiHandleArrayBase& GaudiHandleArrayProperty::value() const {
00861   useReadHandler();
00862   return *m_pValue;
00863 }
00864 
00865 
00866 namespace Gaudi
00867 {
00868   namespace Utils 
00869   {
00870     // ========================================================================
00888     bool hasProperty ( const IProperty*   p , const std::string& name ) ;
00889     // ========================================================================
00907     bool hasProperty ( const IInterface*   p , const std::string& name ) ;
00908     // ========================================================================
00926     Property* getProperty 
00927     ( const IProperty*   p , const std::string& name ) ;
00928     // ========================================================================
00946     Property* getProperty 
00947     ( const IInterface*   p , const std::string& name ) ;
00948     // ========================================================================
00971     bool hasProperty 
00972     ( const std::vector<const Property*>* p    , 
00973       const std::string&                  name ) ;
00974     // ========================================================================
00997     const Property* getProperty 
00998     ( const std::vector<const Property*>* p    , 
00999       const std::string&                  name ) ;
01000     // ========================================================================
01024     template <class TYPE>
01025     StatusCode setProperty 
01026     ( IProperty*         component  ,  
01027       const std::string& name       , 
01028       const TYPE&        value      , 
01029       const std::string& doc        ) ;
01030     // ========================================================================
01053     template <class TYPE>
01054     StatusCode setProperty 
01055     ( IProperty*         component  ,  
01056       const std::string& name       , 
01057       const TYPE&        value      ) 
01058     { return setProperty ( component , name , value , std::string() ) ; }
01059     // ========================================================================
01073     StatusCode setProperty 
01074     ( IProperty*         component  , 
01075       const std::string& name       , 
01076       const std::string& value      ,
01077       const std::string& doc   = "" ) ;
01078     // ========================================================================
01092     StatusCode setProperty 
01093     ( IProperty*         component  , 
01094       const std::string& name       , 
01095       const char*        value      ,
01096       const std::string& doc   = "" ) ;
01097     // ========================================================================
01111     template <unsigned N>
01112     StatusCode setProperty 
01113     ( IProperty*           component , 
01114       const std::string&   name      , 
01115       const char         (&value)[N] ,
01116       const std::string& doc   = ""  ) 
01117     { 
01118       if ( 0 == component                    ) { return StatusCode::FAILURE ; }
01119       const std::string val = std::string ( value , value + N ) ;
01120       return setProperty ( component , name , val , doc ) ; 
01121     }
01122     // ========================================================================
01153     template <class TYPE>
01154     StatusCode setProperty 
01155     ( IProperty*         component  ,  
01156       const std::string& name       , 
01157       const TYPE&        value      ,
01158       const std::string& doc        ) 
01159     {
01160       if ( 0 == component ) { return StatusCode::FAILURE ; }   // RETURN
01161       if ( !hasProperty ( component , name ) ) { return StatusCode::FAILURE ; }
01162       const std::string val = Gaudi::Utils::toString ( value ) ;
01163       return Gaudi::Utils::setProperty ( component , name , val , doc ) ;                        
01164     }
01165     // ========================================================================
01187     StatusCode 
01188     setProperty 
01189     ( IProperty*         component , 
01190       const std::string& name      , 
01191       const Property*    property  ,
01192       const std::string& doc = ""  ) ;
01193     // ========================================================================
01215     StatusCode 
01216     setProperty 
01217     ( IProperty*         component , 
01218       const std::string& name      , 
01219       const Property&    property  ,
01220       const std::string& doc = ""  ) ;
01221     // ========================================================================
01244     template <class TYPE>
01245     StatusCode 
01246     setProperty 
01247     ( IProperty*                  component , 
01248       const std::string&          name      , 
01249       const SimpleProperty<TYPE>& value     , 
01250       const std::string&          doc = ""  ) 
01251     {
01252       const Property* property = &value ;
01253       return setProperty ( component , name , property , doc ) ;
01254     }  
01255     // ========================================================================
01275     template <class TYPE>
01276     StatusCode setProperty 
01277     ( IInterface*        component ,  
01278       const std::string& name      , 
01279       const TYPE&        value     ,  
01280       const std::string& doc       ) ;
01281     // ========================================================================
01300     template <class TYPE>
01301     StatusCode setProperty 
01302     ( IInterface*        component ,  
01303       const std::string& name      , 
01304       const TYPE&        value     ) 
01305     {
01306       return setProperty ( component , name , value , std::string() ) ;
01307     }
01308     // ========================================================================
01321     StatusCode setProperty 
01322     ( IInterface*        component , 
01323       const std::string& name      , 
01324       const std::string& value     , 
01325       const std::string& doc  = "" ) ;
01326     // ========================================================================
01339     StatusCode setProperty 
01340     ( IInterface*        component , 
01341       const std::string& name      , 
01342       const char*        value     ,
01343       const std::string& doc  = "" ) ;
01344     // ========================================================================
01358     template <unsigned N>
01359     StatusCode setProperty 
01360     ( IInterface*          component , 
01361       const std::string&   name      , 
01362       const char         (&value)[N] ,
01363       const std::string& doc  = ""   ) 
01364     { 
01365       if ( 0 == component ) { return StatusCode::FAILURE ; }
01366       const std::string val = std::string ( value , value + N ) ;
01367       return setProperty ( component , name , val , doc ) ; 
01368     }
01369     // ========================================================================
01390     template <class TYPE>
01391     StatusCode setProperty 
01392     ( IInterface*        component ,  
01393       const std::string& name      , 
01394       const TYPE&        value     ,
01395       const std::string& doc  = "" ) 
01396     {
01397       if ( 0 == component ) { return StatusCode::FAILURE ; }
01398       SmartIF<IProperty> property ( component ) ;
01399       if ( !property      ) { return StatusCode::FAILURE ; }
01400       return setProperty ( property , name , value , doc ) ;
01401     }
01402     // ========================================================================
01424     StatusCode 
01425     setProperty 
01426     ( IInterface*        component , 
01427       const std::string& name      , 
01428       const Property*    property  ,
01429       const std::string& doc = ""  ) ;
01430     // ========================================================================
01452     StatusCode 
01453     setProperty 
01454     ( IInterface*        component , 
01455       const std::string& name      , 
01456       const Property&    property  ,
01457       const std::string& doc = ""  ) ;
01458     // ========================================================================
01481     template <class TYPE>
01482     StatusCode 
01483     setProperty 
01484     ( IInterface*                 component , 
01485       const std::string&          name      , 
01486       const SimpleProperty<TYPE>& value     , 
01487       const std::string&          doc = ""  ) 
01488     {
01489       const Property* property = &value ;
01490       return setProperty ( component , name , property , doc ) ;
01491     }  
01492     // ========================================================================    
01493   } // end of namespace Gaudi::Utils 
01494 } // end of namespace Gaudi 
01495 
01496   
01497 // ============================================================================
01498 // The END 
01499 // ============================================================================
01500 #endif // GAUDIKERNEL_PROPERTY_H
01501 // ============================================================================

Generated at Fri Jul 18 11:59:21 2008 for Gaudi Framework, version v20r2 by Doxygen version 1.5.1 written by Dimitri van Heesch, © 1997-2004