Gaudi Framework, version v21r8

Home   Generated: 17 Mar 2010

Property.h

Go to the documentation of this file.
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 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 StatusCode   fromString ( const std::string& value ) = 0 ;
00063 public:
00065   const PropertyCallbackFunctor* readCallBack   () const ;
00067   const PropertyCallbackFunctor* updateCallBack () const ;
00069   virtual void  declareReadHandler   ( PropertyCallbackFunctor* pf ) ;
00071   virtual void  declareUpdateHandler ( PropertyCallbackFunctor* pf ) ;
00072   template< class HT >
00073   void declareReadHandler
00074   ( void ( HT::* MF ) ( Property& ) , HT* instance ) ;
00075   template< class HT >
00076   void declareUpdateHandler
00077   ( void ( HT::* MF ) ( Property& ) , HT* instance ) ;
00079   virtual void useReadHandler   () const ;
00081   virtual bool useUpdateHandler ()       ;
00082 public:
00084   virtual ~Property() ;
00086   virtual Property*          clone     () const = 0 ;
00088   void setName ( const std::string& value ) { m_name = value ; }
00090   void setDocumentation( const std::string& documentation ) {
00091     m_documentation = documentation; };
00093   virtual std::ostream& fillStream ( std::ostream& ) const ;
00094 protected:
00096   Property
00097   ( const std::type_info& type      ,
00098     const std::string&    name = "" ) ;
00100   Property
00101   ( const std::string&    name      ,
00102     const std::type_info& type      ) ;
00104   Property           ( const Property& right ) ;
00106   Property& operator=( const Property& right ) ;
00107 private:
00108   // the default constructor is disabled
00109   Property() ;
00110 private:
00111   // property name
00112   std::string              m_name           ;
00113   // property doc string
00114   std::string              m_documentation;
00115   // property type
00116   const std::type_info*    m_typeinfo       ;
00117 protected:
00118   // call back functor for reading
00119   mutable PropertyCallbackFunctor* m_readCallBack   ;
00120   // call back functor for update
00121   PropertyCallbackFunctor* m_updateCallBack ;
00122 };
00123 // ============================================================================
00124 #include "GaudiKernel/PropertyCallbackFunctor.h"
00125 // ============================================================================
00126 template< class HT >
00127 inline void Property::declareReadHandler
00128 ( void ( HT::* MF ) ( Property& ) , HT* obj )
00129 { declareReadHandler ( new PropertyCallbackMemberFunctor< HT >( MF , obj ) ) ; }
00130 // ============================================================================
00131 template< class HT >
00132 inline void Property::declareUpdateHandler
00133 ( void ( HT::* MF ) ( Property& ) , HT* obj )
00134 { declareUpdateHandler ( new PropertyCallbackMemberFunctor< HT >( MF , obj ) ) ; }
00135 // ============================================================================
00143 // ============================================================================
00144 template <class TYPE>
00145 class PropertyWithValue : public Property
00146 {
00147 public:
00148   // ==========================================================================
00150   typedef Gaudi::Utils::PropertyTypeTraits<TYPE>         Traits ;
00152   typedef typename Traits::PVal                          PVal   ;
00153   // ==========================================================================
00154 protected:
00155   // ==========================================================================
00157   inline PropertyWithValue
00158   ( const std::string& name  ,
00159     PVal               value ,
00160     const bool         owner ) ;
00162   inline PropertyWithValue ( const PropertyWithValue& rhs ) ;
00164   template <class OTHER>
00165   inline PropertyWithValue ( const PropertyWithValue<OTHER>& right ) ;
00167   virtual inline ~PropertyWithValue() ;
00169   PropertyWithValue& operator=( const TYPE& value ) ;
00170   // assignment operator (don't let the compiler generate a buggy one)
00171   PropertyWithValue& operator=( const PropertyWithValue& rhs ) ;
00172   // assignment operator
00173   template <class OTHER>
00174   PropertyWithValue& operator=( const PropertyWithValue<OTHER>& right ) ;
00175   // ==========================================================================
00176 public:
00177   // ==========================================================================
00179   operator const TYPE&      () const { return value() ;}
00181   inline const TYPE& value() const ;
00182   // ==========================================================================
00183 public:
00184   // ==========================================================================
00186   virtual bool setValue ( const TYPE&     value  )  = 0  ;
00188   virtual bool assign   ( const Property& source )       ;
00190   virtual bool load     (       Property& dest   ) const ;
00192   virtual StatusCode fromString ( const std::string& s )  ;
00194   virtual std::string  toString   () const  ;
00195   // ==========================================================================
00196 protected:
00197   // ==========================================================================
00199   inline void  i_set ( const TYPE& value ) {
00200     Traits::assign(*m_value, value);
00201   }
00203   inline PVal  i_get () const {
00204     return m_value;
00205   }
00206   // ==========================================================================
00207 private:
00208   // ==========================================================================
00210   PVal m_value ;                                   // the actual property value 
00212   bool  m_own  ;                                   //      owner of the storage 
00213   // ==========================================================================
00214 };
00215 // ============================================================================
00217 // ============================================================================
00218 template <class TYPE>
00219 inline 
00220 PropertyWithValue<TYPE>::PropertyWithValue
00221 ( const std::string& name  ,
00222   PVal               value ,
00223   const bool         own   )
00224   : Property ( typeid( TYPE ) , name )
00225   , m_value  ( value )
00226   , m_own    ( own   )
00227 {}
00228 // ============================================================================
00229 // copy constructor
00230 // ============================================================================
00231 template <class TYPE>
00232 inline PropertyWithValue<TYPE>::PropertyWithValue
00233 ( const PropertyWithValue& right )
00234   : Property( right         )
00235   , m_value ( right.m_value )
00236   , m_own   ( right.m_own   )
00237 { 
00238   m_value = Traits::copy ( right.value() , m_own ) ;
00239 }
00240 // ============================================================================
00241 // "copy" constructor form any other type
00242 // ============================================================================
00243 template <class TYPE>
00244 template <class OTHER>
00245 inline PropertyWithValue<TYPE>::PropertyWithValue
00246 ( const PropertyWithValue<OTHER>& right )
00247   : Property( right         )
00248   , m_value ( right.m_value )
00249   , m_own   ( right.m_own   )
00250 { 
00251   m_value = Traits::copy ( right.value() , m_own ) ;
00252 }
00253 // ============================================================================
00255 // ============================================================================
00256 template <class TYPE>
00257 inline PropertyWithValue<TYPE>::~PropertyWithValue()
00258 {
00259   Traits::dele ( m_value , m_own ) ;
00260   m_value = 0 ;
00261 }
00262 // ============================================================================
00264 // ============================================================================
00265 template <class TYPE>
00266 inline PropertyWithValue<TYPE>&
00267 PropertyWithValue<TYPE>::operator=( const TYPE& value )
00268 {
00269   if ( !setValue ( value ) )
00270   { throw std::out_of_range( "Value not verified" ) ; }
00271   return *this ;
00272 }
00273 // ============================================================================
00275 // ============================================================================
00276 template <class TYPE>
00277 inline bool
00278 PropertyWithValue<TYPE>::assign ( const Property& source )
00279 {
00280   // 1) Is the property of "the same" type?
00281   const PropertyWithValue<TYPE>* p =
00282     dynamic_cast<const PropertyWithValue<TYPE>*>       ( &source ) ;
00283   if ( 0 != p ) { return setValue ( p->value() ) ; }       // RETURN
00284   // 2) Else use the string representation
00285   return this->fromString( source.toString() ).isSuccess() ;
00286 }
00287 // ============================================================================
00289 // ============================================================================
00290 template <class TYPE>
00291 inline bool
00292 PropertyWithValue<TYPE>::load( Property& dest ) const
00293 {
00294   // delegate to the 'opposite' method ;
00295   return dest.assign( *this ) ;
00296 }
00297 // ============================================================================
00299 // ============================================================================
00300 template <class TYPE>
00301 inline std::string
00302 PropertyWithValue<TYPE>::toString () const
00303 {
00304   useReadHandler();
00305   return Gaudi::Utils::toString( *m_value ) ;
00306 }
00307 // ============================================================================
00309 // ============================================================================
00310 template <class TYPE>
00311 inline StatusCode
00312 PropertyWithValue<TYPE>::fromString ( const std::string& source )
00313 {
00314   TYPE tmp ;
00315   StatusCode sc = Gaudi::Parsers::parse ( tmp , source ) ;
00316   if ( sc.isFailure() ) { return sc ; }
00317   return setValue ( tmp ) ? StatusCode::SUCCESS : StatusCode::FAILURE ;
00318 }
00319 // ============================================================================
00321 // ============================================================================
00322 template <>
00323 inline std::string
00324 PropertyWithValue<std::string>::toString () const
00325 { 
00326   useReadHandler();
00327   return this->value() ; 
00328 }
00329 // ============================================================================
00330 template <>
00331 inline bool PropertyWithValue<std::string>::assign ( const Property& source )
00332 { return this->fromString( source.toString() ).isSuccess() ; }
00333 // ============================================================================
00334 
00335 // ============================================================================
00337 // ============================================================================
00338 template <class TYPE>
00339 inline const TYPE&
00340 PropertyWithValue<TYPE>::value() const
00341 { useReadHandler() ; return *m_value ; }
00342 // ============================================================================
00343 // assignment operator
00344 // ============================================================================
00345 template <class TYPE>
00346 PropertyWithValue<TYPE>& PropertyWithValue<TYPE>::operator=
00347 ( const PropertyWithValue& right )
00348 {
00349   // assign the base class
00350   Property::operator=( right ) ;
00351   // assign the value
00352   PropertyWithValue<TYPE>::operator=( right.value() ) ;
00353   return *this ;
00354 }
00355 // ============================================================================
00356 // templated assignment operator
00357 // ============================================================================
00358 template <class TYPE>
00359 template <class OTHER>
00360 PropertyWithValue<TYPE>& PropertyWithValue<TYPE>::operator=
00361 ( const PropertyWithValue<OTHER>& right )
00362 {
00363   // assign the base class
00364   Property::operator=( right ) ;
00365   // assign the value
00366   PropertyWithValue<TYPE>::operator=( right.value() ) ;
00367   return *this ;
00368 }
00369 // ============================================================================
00370 
00371 // ============================================================================
00379 // ============================================================================
00380 template<class TYPE,class VERIFIER>
00381 class PropertyWithVerifier
00382   : public PropertyWithValue<TYPE>
00383 {
00384 protected:
00385   // ==========================================================================
00387   PropertyWithVerifier
00388   ( const std::string&                                    name     ,
00389     typename Gaudi::Utils::PropertyTypeTraits<TYPE>::PVal value    ,
00390     const bool                                            owner    ,
00391     const VERIFIER&                                       verifier )
00392     : PropertyWithValue<TYPE> ( name , value , owner )
00393     , m_verifier ( verifier )
00394   {}
00396   virtual ~PropertyWithVerifier() {};
00397   // ==========================================================================
00398 public:
00399   // ==========================================================================
00400   inline       VERIFIER& verifier()       { return m_verifier ; }
00401   inline const VERIFIER& verifier() const { return m_verifier ; }
00403   bool set( const TYPE& value ) ;
00405   virtual bool setValue( const TYPE& value ) { return set( value ) ; }
00407   template <class OTHER,class OTHERVERIFIER>
00408   PropertyWithVerifier& operator=
00409   ( const PropertyWithVerifier<OTHER,OTHERVERIFIER>& right ) ;
00411   template <class OTHER>
00412   PropertyWithVerifier& operator=( const PropertyWithValue<OTHER>& right ) ;
00414   PropertyWithVerifier& operator=( const TYPE& right ) ;
00415   // ==========================================================================
00416 private:
00417   // ==========================================================================
00419   PropertyWithVerifier() ;
00421   PropertyWithVerifier( const  PropertyWithVerifier& right );
00422   // ==========================================================================
00423 private:
00424   // ==========================================================================
00426   VERIFIER m_verifier ;                                  // the verifier itself 
00427   // ==========================================================================
00428 } ;
00429 // ============================================================================
00431 // ============================================================================
00432 template <class TYPE,class VERIFIER>
00433 inline bool
00434 PropertyWithVerifier<TYPE,VERIFIER>::set( const TYPE& value )
00435 {
00437   if ( !m_verifier.isValid( &value ) ) { return false ; }
00439   i_set( value ) ;
00441   return this->useUpdateHandler() ;
00442 }
00443 // ============================================================================
00445 // ============================================================================
00446 template <class TYPE,class VERIFIER>
00447 inline PropertyWithVerifier<TYPE,VERIFIER>&
00448 PropertyWithVerifier<TYPE,VERIFIER>::operator=( const TYPE& right )
00449 {
00450   PropertyWithValue<TYPE>::operator=( right ) ;
00451   return *this ;
00452 }
00453 // ============================================================================
00455 // ============================================================================
00456 template <class TYPE,class VERIFIER>
00457 template <class OTHER>
00458 inline PropertyWithVerifier<TYPE,VERIFIER>&
00459 PropertyWithVerifier<TYPE,VERIFIER>::operator=( const PropertyWithValue<OTHER>& right )
00460 {
00461   PropertyWithValue<TYPE>::operator=(right) ;
00462   return *this ;
00463 }
00464 // ============================================================================
00466 // ============================================================================
00467 template <class TYPE,class VERIFIER>
00468 template <class OTHER,class OTHERVERIFIER>
00469 inline PropertyWithVerifier<TYPE,VERIFIER>&
00470 PropertyWithVerifier<TYPE,VERIFIER>::operator=
00471 ( const PropertyWithVerifier<OTHER,OTHERVERIFIER>& right )
00472 {
00473   PropertyWithValue<TYPE>::operator=(right) ;
00474   return *this ;
00475 }
00476 // ============================================================================
00477 
00478 // ============================================================================
00488 // ============================================================================
00489 template <class TYPE,class VERIFIER = BoundedVerifier<TYPE> >
00490 class SimpleProperty
00491   : public PropertyWithVerifier<TYPE,VERIFIER>
00492 {
00493 protected:
00494   // ==========================================================================
00495   typedef Gaudi::Utils::PropertyTypeTraits<TYPE>  Traits ;
00496   // ==========================================================================
00497 public:
00498   // ==========================================================================
00500   SimpleProperty
00501   ( VERIFIER           verifier = VERIFIER() ) ;
00503   SimpleProperty
00504   ( const TYPE&        value                 ,
00505     VERIFIER           verifier = VERIFIER() ) ;
00507   SimpleProperty
00508   ( const std::string& name                  ,
00509     const TYPE&        value                 ,
00510     VERIFIER           verifier = VERIFIER() ) ;
00512   template <class OTHER>
00513   SimpleProperty ( const PropertyWithValue<OTHER>& right ) ;
00515   SimpleProperty ( const SimpleProperty& right ) ;
00517   virtual ~SimpleProperty() ;
00519   virtual SimpleProperty* clone() const ;
00521   SimpleProperty& operator=( const TYPE& value ) ;
00523   template <class OTHER>
00524   SimpleProperty& operator=( const PropertyWithValue<OTHER>& right ) ;
00525   // ==========================================================================
00526 };
00527 // ============================================================================
00529 // ============================================================================
00530 template <class TYPE,class VERIFIER>
00531 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00532 ( VERIFIER           verifier )
00533   : PropertyWithVerifier<TYPE,VERIFIER>
00534 ( "" , Traits::new_() , true , verifier )
00535 {}
00536 // ============================================================================
00538 // ============================================================================
00539 template <class TYPE,class VERIFIER>
00540 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00541 ( const TYPE&        value    ,
00542   VERIFIER           verifier )
00543   : PropertyWithVerifier<TYPE,VERIFIER>
00544 ( "" , Traits::new_(value) , true , verifier )
00545 {}
00546 // ============================================================================
00548 // ============================================================================
00549 template <class TYPE,class VERIFIER>
00550 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00551 ( const std::string& name     ,
00552   const TYPE&        value    ,
00553   VERIFIER           verifier )
00554   : PropertyWithVerifier<TYPE,VERIFIER>
00555 ( name , Traits::new_(value) , true , verifier )
00556 {}
00557 // ============================================================================
00559 // ============================================================================
00560 template <class TYPE,class VERIFIER>
00561 template <class OTHER>
00562 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00563 ( const PropertyWithValue<OTHER>& right )
00564   : PropertyWithVerifier<TYPE,VERIFIER>
00565 ( right.name() , Traits::new_( right.value() ) , true , VERIFIER() )
00566 {}
00567 // ============================================================================
00569 // ============================================================================
00570 template <class TYPE,class VERIFIER>
00571 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00572 ( const SimpleProperty& right )
00573   : PropertyWithVerifier<TYPE,VERIFIER>
00574 ( right.name() , Traits::new_( right.value() ) , true , right.verifier() )
00575 {}
00576 // ============================================================================
00578 // ============================================================================
00579 template <class TYPE,class VERIFIER>
00580 SimpleProperty<TYPE,VERIFIER>::~SimpleProperty(){}
00581 // ============================================================================
00583 // ============================================================================
00584 template <class TYPE,class VERIFIER>
00585 inline
00586 SimpleProperty<TYPE,VERIFIER>*
00587 SimpleProperty<TYPE,VERIFIER>::clone() const
00588 { return new SimpleProperty(*this) ; }
00589 // ============================================================================
00591 // ============================================================================
00592 template <class TYPE,class VERIFIER>
00593 inline
00594 SimpleProperty<TYPE,VERIFIER>&
00595 SimpleProperty<TYPE,VERIFIER>::operator=( const TYPE& value )
00596 {
00597   PropertyWithVerifier<TYPE,VERIFIER>::operator=( value );
00598   return *this ;
00599 }
00600 // ============================================================================
00602 // ============================================================================
00603 template <class TYPE,class VERIFIER>
00604 template <class OTHER>
00605 inline
00606 SimpleProperty<TYPE,VERIFIER>&
00607 SimpleProperty<TYPE,VERIFIER>::operator=
00608 ( const PropertyWithValue<OTHER>& right )
00609 {
00610   PropertyWithVerifier<TYPE,VERIFIER>::operator=( right );
00611   return *this ;
00612 }
00613 // ============================================================================
00614 
00615 // ============================================================================
00624 // ============================================================================
00625 template< class TYPE, class VERIFIER = NullVerifier<TYPE> >
00626 class SimplePropertyRef :
00627   public PropertyWithVerifier<TYPE,VERIFIER>
00628 {
00629 public:
00631   SimplePropertyRef
00632   ( const std::string& name                  ,
00633     TYPE&              value                 ,  
00634     VERIFIER           verifier = VERIFIER() ) ;
00636   SimplePropertyRef ( const SimplePropertyRef& right ) ;
00638   virtual ~SimplePropertyRef() ;
00640   virtual SimplePropertyRef* clone() const ;
00642   SimplePropertyRef& operator=( const TYPE& value ) ;
00644   template <class OTHER>
00645   SimplePropertyRef& operator=( const PropertyWithValue<OTHER>& right ) ;
00646 private:
00647   // the default constructor is disabled
00648   SimplePropertyRef() ;
00649 };
00650 // ============================================================================
00652 // ============================================================================
00653 template <class TYPE,class VERIFIER>
00654 SimplePropertyRef<TYPE,VERIFIER>::SimplePropertyRef
00655 ( const std::string& name     ,
00656   TYPE&              value    ,  
00657   VERIFIER           verifier )
00658   : PropertyWithVerifier<TYPE,VERIFIER> ( name , &value , false , verifier )
00659 {}
00660 // ============================================================================
00662 // ============================================================================
00663 template <class TYPE,class VERIFIER>
00664 SimplePropertyRef<TYPE,VERIFIER>::SimplePropertyRef
00665 ( const SimplePropertyRef& right )
00666   : PropertyWithVerifier<TYPE,VERIFIER>
00667 ( right.name() , right.i_get() , false , right.verifier() )
00668 {}
00669 // ============================================================================
00671 // ============================================================================
00672 template <class TYPE,class VERIFIER>
00673 SimplePropertyRef<TYPE,VERIFIER>::~SimplePropertyRef(){}
00674 // ============================================================================
00676 // ============================================================================
00677 template <class TYPE,class VERIFIER>
00678 inline
00679 SimplePropertyRef<TYPE,VERIFIER>*
00680 SimplePropertyRef<TYPE,VERIFIER>::clone() const
00681 { return new SimplePropertyRef(*this) ; }
00682 // ============================================================================
00684 // ============================================================================
00685 template <class TYPE,class VERIFIER>
00686 inline
00687 SimplePropertyRef<TYPE,VERIFIER>&
00688 SimplePropertyRef<TYPE,VERIFIER>::operator=( const TYPE& value )
00689 {
00690   PropertyWithVerifier<TYPE,VERIFIER>::operator=( value ) ;
00691   return *this ;
00692 }
00693 // ============================================================================
00695 // ============================================================================
00696 template <class TYPE,class VERIFIER>
00697 template <class OTHER>
00698 inline
00699 SimplePropertyRef<TYPE,VERIFIER>&
00700 SimplePropertyRef<TYPE,VERIFIER>::operator=
00701 ( const PropertyWithValue<OTHER>& right )
00702 {
00703   PropertyWithVerifier<TYPE,VERIFIER>::operator=( right );
00704   return *this ;
00705 }
00706 // ============================================================================
00707 
00708 
00709 
00710 
00711 // Typedef Properties for built-in types
00712 typedef SimpleProperty< bool >              BooleanProperty;
00713 typedef SimpleProperty< char >              CharProperty;
00714 typedef SimpleProperty< signed char >       SignedCharProperty;
00715 typedef SimpleProperty< unsigned char >     UnsignedCharProperty;
00716 typedef SimpleProperty< short >             ShortProperty;
00717 typedef SimpleProperty< unsigned short >    UnsignedShortProperty;
00718 typedef SimpleProperty< int >               IntegerProperty;
00719 typedef SimpleProperty< unsigned int >      UnsignedIntegerProperty;
00720 typedef SimpleProperty< long >              LongProperty;
00721 typedef SimpleProperty< unsigned long >     UnsignedLongProperty;
00722 typedef SimpleProperty< long long>          LongLongProperty;
00723 typedef SimpleProperty< unsigned long long> UnsignedLongLongProperty;
00724 typedef SimpleProperty< float >             FloatProperty;
00725 typedef SimpleProperty< double >            DoubleProperty;
00726 typedef SimpleProperty< long double >       LongDoubleProperty;
00727 
00728 typedef SimpleProperty< std::string >       StringProperty;
00729 
00730 
00731 // Typedef PropertyRefs for built-in types
00732 typedef SimplePropertyRef< bool >                BooleanPropertyRef;
00733 typedef SimplePropertyRef< char >                CharPropertyRef;
00734 typedef SimplePropertyRef< signed char >         SignedCharPropertyRef;
00735 typedef SimplePropertyRef< unsigned char >       UnsignedCharPropertyRef;
00736 typedef SimplePropertyRef< short >               ShortPropertyRef;
00737 typedef SimplePropertyRef< unsigned short >      UnsignedShortPropertyRef;
00738 typedef SimplePropertyRef< int >                 IntegerPropertyRef;
00739 typedef SimplePropertyRef< unsigned int >        UnsignedIntegerPropertyRef;
00740 typedef SimplePropertyRef< long >                LongPropertyRef;
00741 typedef SimplePropertyRef< unsigned long >       UnsignedLongPropertyRef;
00742 typedef SimplePropertyRef< long long >           LongLongPropertyRef;
00743 typedef SimplePropertyRef< unsigned long long >  UnsignedLongLongPropertyRef;
00744 typedef SimplePropertyRef< float >               FloatPropertyRef;
00745 typedef SimplePropertyRef< double >              DoublePropertyRef;
00746 typedef SimplePropertyRef< long double >         LongDoublePropertyRef;
00747 
00748 typedef SimplePropertyRef< std::string >         StringPropertyRef;
00749 
00750 
00751 // Typedef "Arrays" of Properties for built-in types
00752 typedef SimpleProperty< std::vector< bool > >                BooleanArrayProperty;
00753 typedef SimpleProperty< std::vector< char > >                CharArrayProperty;
00754 typedef SimpleProperty< std::vector< signed char > >         SignedCharArrayProperty;
00755 typedef SimpleProperty< std::vector< unsigned char > >       UnsignedCharArrayProperty;
00756 typedef SimpleProperty< std::vector< short > >               ShortArrayProperty;
00757 typedef SimpleProperty< std::vector< unsigned short > >      UnsignedShortArrayProperty;
00758 typedef SimpleProperty< std::vector< int > >                 IntegerArrayProperty;
00759 typedef SimpleProperty< std::vector< unsigned int > >        UnsignedIntegerArrayProperty;
00760 typedef SimpleProperty< std::vector< long > >                LongArrayProperty;
00761 typedef SimpleProperty< std::vector< unsigned long > >       UnsignedLongArrayProperty;
00762 typedef SimpleProperty< std::vector< long long > >           LongLongArrayProperty;
00763 typedef SimpleProperty< std::vector< unsigned long long > >  UnsignedLongLongArrayProperty;
00764 typedef SimpleProperty< std::vector< float > >               FloatArrayProperty;
00765 typedef SimpleProperty< std::vector< double > >              DoubleArrayProperty;
00766 typedef SimpleProperty< std::vector< long double > >         LongDoubleArrayProperty;
00767 
00768 typedef SimpleProperty< std::vector< std::string > >         StringArrayProperty;
00769 
00770 
00771 // Typedef "Arrays" of PropertyRefs for built-in types
00772 typedef SimplePropertyRef< std::vector< bool > >                 BooleanArrayPropertyRef;
00773 typedef SimplePropertyRef< std::vector< char > >                 CharArrayPropertyRef;
00774 typedef SimplePropertyRef< std::vector< signed char > >          SignedCharArrayPropertyRef;
00775 typedef SimplePropertyRef< std::vector< unsigned char > >        UnsignedCharArrayPropertyRef;
00776 typedef SimplePropertyRef< std::vector< short > >                ShortArrayPropertyRef;
00777 typedef SimplePropertyRef< std::vector< unsigned short > >       UnsignedShortArrayPropertyRef;
00778 typedef SimplePropertyRef< std::vector< int > >                  IntegerArrayPropertyRef;
00779 typedef SimplePropertyRef< std::vector< unsigned int > >         UnsignedIntegerArrayPropertyRef;
00780 typedef SimplePropertyRef< std::vector< long > >                 LongArrayPropertyRef;
00781 typedef SimplePropertyRef< std::vector< unsigned long > >        UnsignedLongArrayPropertyRef;
00782 typedef SimplePropertyRef< std::vector< long long > >            LongLongArrayPropertyRef;
00783 typedef SimplePropertyRef< std::vector< unsigned long long > >   UnsignedLongLongArrayPropertyRef;
00784 typedef SimplePropertyRef< std::vector< float > >                FloatArrayPropertyRef;
00785 typedef SimplePropertyRef< std::vector< double > >               DoubleArrayPropertyRef;
00786 typedef SimplePropertyRef< std::vector< long double > >          LongDoubleArrayPropertyRef;
00787 
00788 typedef SimplePropertyRef< std::vector< std::string > >          StringArrayPropertyRef;
00789 
00790 // pre-declaration is sufficient here
00791 class GaudiHandleBase;
00792 
00793 class GAUDI_API GaudiHandleProperty : public Property {
00794 public:
00795    GaudiHandleProperty( const std::string& name, GaudiHandleBase& ref );
00796 
00797   GaudiHandleProperty& operator=( const GaudiHandleBase& value );
00798 
00799   virtual GaudiHandleProperty* clone() const;
00800 
00801   virtual bool load( Property& destination ) const;
00802 
00803   virtual bool assign( const Property& source );
00804 
00805   virtual std::string toString() const;
00806 
00807   virtual StatusCode fromString(const std::string& s);
00808 
00809   const GaudiHandleBase& value() const;
00810 
00811   bool setValue( const GaudiHandleBase& value );
00812 
00813 private:
00816    GaudiHandleBase* m_pValue;
00817 };
00818 
00819 // implementation in header file only where the GaudiHandleBase class
00820 // definition is not needed. The rest goes into the .cpp file.
00821 // The goal is to decouple the header files, to avoid that the whole
00822 // world depends on GaudiHandle.h
00823 inline GaudiHandleProperty& GaudiHandleProperty::operator=( const GaudiHandleBase& value ) {
00824       setValue( value );
00825       return *this;
00826 }
00827 
00828 inline GaudiHandleProperty* GaudiHandleProperty::clone() const {
00829   return new GaudiHandleProperty( *this );
00830 }
00831 
00832 inline bool GaudiHandleProperty::load( Property& destination ) const {
00833   return destination.assign( *this );
00834 }
00835 
00836 inline bool GaudiHandleProperty::assign( const Property& source ) {
00837   return fromString( source.toString() ).isSuccess();
00838 }
00839 
00840 inline const GaudiHandleBase& GaudiHandleProperty::value() const {
00841   useReadHandler();
00842   return *m_pValue;
00843 }
00844 
00845 
00846 // pre-declaration is sufficient here
00847 class GaudiHandleArrayBase;
00848 
00849 class GAUDI_API GaudiHandleArrayProperty : public Property {
00850 public:
00851 
00852   GaudiHandleArrayProperty( const std::string& name, GaudiHandleArrayBase& ref );
00853 
00854   GaudiHandleArrayProperty& operator=( const GaudiHandleArrayBase& value );
00855 
00856   virtual GaudiHandleArrayProperty* clone() const;
00857 
00858   virtual bool load( Property& destination ) const;
00859 
00860   virtual bool assign( const Property& source );
00861 
00862   virtual std::string toString() const;
00863 
00864   virtual StatusCode fromString(const std::string& s);
00865 
00866   const GaudiHandleArrayBase& value() const;
00867 
00868   bool setValue( const GaudiHandleArrayBase& value );
00869 
00870 private:
00873    GaudiHandleArrayBase* m_pValue;
00874 
00875 };
00876 
00877 // implementation in header file only where the GaudiHandleBase class
00878 // definition is not needed. The rest goes into the .cpp file.
00879 // The goal is to decouple the header files, to avoid that the whole
00880 // world depends on GaudiHandle.h
00881 inline GaudiHandleArrayProperty& GaudiHandleArrayProperty::operator=( const GaudiHandleArrayBase& value ) {
00882   setValue( value );
00883   return *this;
00884 }
00885 
00886 inline GaudiHandleArrayProperty* GaudiHandleArrayProperty::clone() const {
00887   return new GaudiHandleArrayProperty( *this );
00888 }
00889 
00890 inline bool GaudiHandleArrayProperty::load( Property& destination ) const {
00891   return destination.assign( *this );
00892 }
00893 
00894 inline bool GaudiHandleArrayProperty::assign( const Property& source ) {
00895   return fromString( source.toString() ) != 0;
00896 }
00897 
00898 inline const GaudiHandleArrayBase& GaudiHandleArrayProperty::value() const {
00899   useReadHandler();
00900   return *m_pValue;
00901 }
00902 
00903 
00904 namespace Gaudi
00905 {
00906   namespace Utils
00907   {
00908     // ========================================================================
00926     GAUDI_API bool hasProperty ( const IProperty*   p , const std::string& name ) ;
00927     // ========================================================================
00945     GAUDI_API bool hasProperty ( const IInterface*   p , const std::string& name ) ;
00946     // ========================================================================
00964     GAUDI_API Property* getProperty
00965     ( const IProperty*   p , const std::string& name ) ;
00966     // ========================================================================
00984     GAUDI_API Property* getProperty
00985     ( const IInterface*   p , const std::string& name ) ;
00986     // ========================================================================
01009     GAUDI_API bool hasProperty
01010     ( const std::vector<const Property*>* p    ,
01011       const std::string&                  name ) ;
01012     // ========================================================================
01035     GAUDI_API const Property* getProperty
01036     ( const std::vector<const Property*>* p    ,
01037       const std::string&                  name ) ;
01038     // ========================================================================
01062     template <class TYPE>
01063     StatusCode setProperty
01064     ( IProperty*         component  ,
01065       const std::string& name       ,
01066       const TYPE&        value      ,
01067       const std::string& doc        ) ;
01068     // ========================================================================
01091     template <class TYPE>
01092     StatusCode setProperty
01093     ( IProperty*         component  ,
01094       const std::string& name       ,
01095       const TYPE&        value      )
01096     { return setProperty ( component , name , value , std::string() ) ; }
01097     // ========================================================================
01111     GAUDI_API StatusCode setProperty
01112     ( IProperty*         component  ,
01113       const std::string& name       ,
01114       const std::string& value      ,
01115       const std::string& doc   = "" ) ;
01116     // ========================================================================
01130     GAUDI_API StatusCode setProperty
01131     ( IProperty*         component  ,
01132       const std::string& name       ,
01133       const char*        value      ,
01134       const std::string& doc   = "" ) ;
01135     // ========================================================================
01149     template <unsigned N>
01150     StatusCode setProperty
01151     ( IProperty*           component ,
01152       const std::string&   name      ,
01153       const char         (&value)[N] ,
01154       const std::string& doc   = ""  )
01155     {
01156       if ( 0 == component                    ) { return StatusCode::FAILURE ; }
01157       const std::string val = std::string ( value , value + N ) ;
01158       return setProperty ( component , name , val , doc ) ;
01159     }
01160     // ========================================================================
01191     template <class TYPE>
01192     StatusCode setProperty
01193     ( IProperty*         component  ,
01194       const std::string& name       ,
01195       const TYPE&        value      ,
01196       const std::string& doc        )
01197     {
01198       if ( 0 == component ) { return StatusCode::FAILURE ; }   // RETURN
01199       if ( !hasProperty ( component , name ) ) { return StatusCode::FAILURE ; }
01200       const std::string val = Gaudi::Utils::toString ( value ) ;
01201       return Gaudi::Utils::setProperty ( component , name , val , doc ) ;
01202     }
01203     // ========================================================================
01225     GAUDI_API StatusCode setProperty
01226     ( IProperty*         component ,
01227       const std::string& name      ,
01228       const Property*    property  ,
01229       const std::string& doc = ""  ) ;
01230     // ========================================================================
01252     GAUDI_API StatusCode setProperty
01253     ( IProperty*         component ,
01254       const std::string& name      ,
01255       const Property&    property  ,
01256       const std::string& doc = ""  ) ;
01257     // ========================================================================
01280     template <class TYPE>
01281     StatusCode setProperty
01282     ( IProperty*                  component ,
01283       const std::string&          name      ,
01284       const SimpleProperty<TYPE>& value     ,
01285       const std::string&          doc = ""  )
01286     {
01287       const Property* property = &value ;
01288       return setProperty ( component , name , property , doc ) ;
01289     }
01290     // ========================================================================
01311     template <class TYPE>
01312     StatusCode setProperty
01313     ( IInterface*        component ,
01314       const std::string& name      ,
01315       const TYPE&        value     ,
01316       const std::string& doc = ""  )
01317     {
01318       if ( 0 == component ) { return StatusCode::FAILURE ; }
01319       SmartIF<IProperty> property ( component ) ;
01320       if ( !property      ) { return StatusCode::FAILURE ; }
01321       return setProperty ( property , name , value , doc ) ;
01322     }
01323     // ========================================================================
01336     GAUDI_API StatusCode setProperty
01337     ( IInterface*        component ,
01338       const std::string& name      ,
01339       const std::string& value     ,
01340       const std::string& doc  = "" ) ;
01341     // ========================================================================
01354     GAUDI_API StatusCode setProperty
01355     ( IInterface*        component ,
01356       const std::string& name      ,
01357       const char*        value     ,
01358       const std::string& doc  = "" ) ;
01359     // ========================================================================
01373     template <unsigned N>
01374     StatusCode setProperty
01375     ( IInterface*          component ,
01376       const std::string&   name      ,
01377       const char         (&value)[N] ,
01378       const std::string& doc  = ""   )
01379     {
01380       if ( 0 == component ) { return StatusCode::FAILURE ; }
01381       const std::string val = std::string ( value , value + N ) ;
01382       return setProperty ( component , name , val , doc ) ;
01383     }
01384     // ========================================================================
01406     GAUDI_API StatusCode setProperty
01407     ( IInterface*        component ,
01408       const std::string& name      ,
01409       const Property*    property  ,
01410       const std::string& doc = ""  ) ;
01411     // ========================================================================
01433     GAUDI_API StatusCode setProperty
01434     ( IInterface*        component ,
01435       const std::string& name      ,
01436       const Property&    property  ,
01437       const std::string& doc = ""  ) ;
01438     // ========================================================================
01461     template <class TYPE>
01462     StatusCode
01463     setProperty
01464     ( IInterface*                 component ,
01465       const std::string&          name      ,
01466       const SimpleProperty<TYPE>& value     ,
01467       const std::string&          doc = ""  )
01468     {
01469       const Property* property = &value ;
01470       return setProperty ( component , name , property , doc ) ;
01471     }
01472     // ========================================================================
01473   } // end of namespace Gaudi::Utils
01474 } // end of namespace Gaudi
01475 
01476 
01477 // ============================================================================
01478 // The END
01479 // ============================================================================
01480 #endif // GAUDIKERNEL_PROPERTY_H
01481 // ============================================================================

Generated at Wed Mar 17 18:06:23 2010 for Gaudi Framework, version v21r8 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004