Gaudi Framework, version v23r4

Home   Generated: Mon Sep 17 2012

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 void toStream(std::ostream& out) const = 0;
00064   virtual StatusCode   fromString ( const std::string& value ) = 0 ;
00065 public:
00067   const PropertyCallbackFunctor* readCallBack   () const ;
00069   const PropertyCallbackFunctor* updateCallBack () const ;
00071   virtual void  declareReadHandler   ( PropertyCallbackFunctor* pf ) ;
00073   virtual void  declareUpdateHandler ( PropertyCallbackFunctor* pf ) ;
00074   template< class HT >
00075   void declareReadHandler
00076   ( void ( HT::* MF ) ( Property& ) , HT* instance ) ;
00077   template< class HT >
00078   void declareUpdateHandler
00079   ( void ( HT::* MF ) ( Property& ) , HT* instance ) ;
00081   virtual void useReadHandler   () const ;
00083   virtual bool useUpdateHandler ()       ;
00084 public:
00086   virtual ~Property() ;
00088   virtual Property*          clone     () const = 0 ;
00090   void setName ( const std::string& value ) { m_name = value ; }
00092   void setDocumentation( const std::string& documentation ) {
00093     m_documentation = documentation; }
00095   virtual std::ostream& fillStream ( std::ostream& ) const ;
00096 protected:
00098   Property
00099   ( const std::type_info& type      ,
00100     const std::string&    name = "" ) ;
00102   Property
00103   ( const std::string&    name      ,
00104     const std::type_info& type      ) ;
00106   Property           ( const Property& right ) ;
00108   Property& operator=( const Property& right ) ;
00109 private:
00110   // 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 functor for reading
00121   mutable PropertyCallbackFunctor* m_readCallBack   ;
00122   // call back functor 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 : public Property
00148 {
00149 public:
00150   // ==========================================================================
00152   typedef Gaudi::Utils::PropertyTypeTraits<TYPE>         Traits ;
00154   typedef typename Traits::PVal                          PVal   ;
00155   // ==========================================================================
00156 protected:
00157   // ==========================================================================
00159   inline PropertyWithValue
00160   ( const std::string& name  ,
00161     PVal               value ,
00162     const bool         owner ) ;
00164   inline PropertyWithValue ( const PropertyWithValue& rhs ) ;
00166   template <class OTHER>
00167   inline PropertyWithValue ( const PropertyWithValue<OTHER>& right ) ;
00169   virtual inline ~PropertyWithValue() ;
00171   PropertyWithValue& operator=( const TYPE& value ) ;
00172   // assignment operator (don't let the compiler generate a buggy one)
00173   PropertyWithValue& operator=( const PropertyWithValue& rhs ) ;
00174   // assignment operator
00175   template <class OTHER>
00176   PropertyWithValue& operator=( const PropertyWithValue<OTHER>& right ) ;
00177   // ==========================================================================
00178 public:
00179   // ==========================================================================
00181   operator const TYPE&      () const { return value() ;}
00183   inline const TYPE& value() const ;
00184   // ==========================================================================
00185 public:
00186   // ==========================================================================
00188   virtual bool setValue ( const TYPE&     value  )  = 0  ;
00190   virtual bool assign   ( const Property& source )       ;
00192   virtual bool load     (       Property& dest   ) const ;
00194   virtual StatusCode fromString ( const std::string& s )  ;
00196   virtual std::string  toString   () const  ;
00198   virtual void  toStream (std::ostream& out) const  ;
00199   // ==========================================================================
00200 protected:
00201   // ==========================================================================
00203   inline void  i_set ( const TYPE& value ) {
00204     Traits::assign(*m_value, value);
00205   }
00207   inline PVal  i_get () const {
00208     return m_value;
00209   }
00210   // ==========================================================================
00211 private:
00212   // ==========================================================================
00214   PVal m_value ;                                   // the actual property value
00216   bool  m_own  ;                                   //      owner of the storage
00217   // ==========================================================================
00218 };
00219 
00220 // ============================================================================
00222 // ============================================================================
00223 template <class TYPE>
00224 inline
00225 PropertyWithValue<TYPE>::PropertyWithValue
00226 ( const std::string& name  ,
00227   PVal               value ,
00228   const bool         own   )
00229   : Property ( typeid( TYPE ) , name )
00230   , m_value  ( value )
00231   , m_own    ( own   )
00232 {}
00233 // ============================================================================
00234 // copy constructor
00235 // ============================================================================
00236 template <class TYPE>
00237 inline PropertyWithValue<TYPE>::PropertyWithValue
00238 ( const PropertyWithValue& right )
00239   : Property( right         )
00240   , m_value ( right.m_value )
00241   , m_own   ( right.m_own   )
00242 {
00243   m_value = Traits::copy ( right.value() , m_own ) ;
00244 }
00245 // ============================================================================
00246 // "copy" constructor form any other type
00247 // ============================================================================
00248 template <class TYPE>
00249 template <class OTHER>
00250 inline PropertyWithValue<TYPE>::PropertyWithValue
00251 ( const PropertyWithValue<OTHER>& right )
00252   : Property( right         )
00253   , m_value ( right.m_value )
00254   , m_own   ( right.m_own   )
00255 {
00256   m_value = Traits::copy ( right.value() , m_own ) ;
00257 }
00258 // ============================================================================
00260 // ============================================================================
00261 template <class TYPE>
00262 inline PropertyWithValue<TYPE>::~PropertyWithValue()
00263 {
00264   Traits::dele ( m_value , m_own ) ;
00265   m_value = 0 ;
00266 }
00267 // ============================================================================
00269 // ============================================================================
00270 template <class TYPE>
00271 inline PropertyWithValue<TYPE>&
00272 PropertyWithValue<TYPE>::operator=( const TYPE& value )
00273 {
00274   if ( !setValue ( value ) )
00275   { throw std::out_of_range( "Value not verified" ) ; }
00276   return *this ;
00277 }
00278 // ============================================================================
00280 // ============================================================================
00281 template <class TYPE>
00282 inline bool
00283 PropertyWithValue<TYPE>::assign ( const Property& source )
00284 {
00285   // 1) Is the property of "the same" type?
00286   const PropertyWithValue<TYPE>* p =
00287     dynamic_cast<const PropertyWithValue<TYPE>*>       ( &source ) ;
00288   if ( 0 != p ) { return setValue ( p->value() ) ; }       // RETURN
00289   // 2) Else use the string representation
00290   return this->fromString( source.toString() ).isSuccess() ;
00291 }
00292 // ============================================================================
00294 // ============================================================================
00295 template <class TYPE>
00296 inline bool
00297 PropertyWithValue<TYPE>::load( Property& dest ) const
00298 {
00299   // delegate to the 'opposite' method ;
00300   return dest.assign( *this ) ;
00301 }
00302 // ============================================================================
00304 // ============================================================================
00305 template <class TYPE>
00306 inline std::string
00307 PropertyWithValue<TYPE>::toString () const
00308 {
00309   useReadHandler();
00310   return Gaudi::Utils::toString( *m_value ) ;
00311 }
00312 // ============================================================================
00314 // ============================================================================
00315 template <class TYPE>
00316 inline void
00317 PropertyWithValue<TYPE>::toStream (std::ostream& out) const
00318 {
00319   useReadHandler();
00320   Gaudi::Utils::toStream( *m_value, out ) ;
00321 }
00322 // ============================================================================
00324 // ============================================================================
00325 template <class TYPE>
00326 inline StatusCode
00327 PropertyWithValue<TYPE>::fromString ( const std::string& source )
00328 {
00329   TYPE tmp ;
00330   StatusCode sc = Gaudi::Parsers::parse ( tmp , source ) ;
00331   if ( sc.isFailure() ) { return sc ; }
00332   return setValue ( tmp ) ? StatusCode::SUCCESS : StatusCode::FAILURE ;
00333 }
00334 // ============================================================================
00336 // ============================================================================
00337 template <>
00338 inline std::string
00339 PropertyWithValue<std::string>::toString () const
00340 {
00341   useReadHandler();
00342   return this->value() ;
00343 }
00344 // ============================================================================
00345 template <>
00346 inline bool PropertyWithValue<std::string>::assign ( const Property& source )
00347 { return this->fromString( source.toString() ).isSuccess() ; }
00348 // ============================================================================
00349 
00350 // ============================================================================
00352 // ============================================================================
00353 template <class TYPE>
00354 inline const TYPE&
00355 PropertyWithValue<TYPE>::value() const
00356 { useReadHandler() ; return *m_value ; }
00357 // ============================================================================
00358 // assignment operator
00359 // ============================================================================
00360 template <class TYPE>
00361 PropertyWithValue<TYPE>& PropertyWithValue<TYPE>::operator=
00362 ( const PropertyWithValue& right )
00363 {
00364   // assign the base class
00365   Property::operator=( right ) ;
00366   // assign the value
00367   PropertyWithValue<TYPE>::operator=( right.value() ) ;
00368   return *this ;
00369 }
00370 // ============================================================================
00371 // templated assignment operator
00372 // ============================================================================
00373 template <class TYPE>
00374 template <class OTHER>
00375 PropertyWithValue<TYPE>& PropertyWithValue<TYPE>::operator=
00376 ( const PropertyWithValue<OTHER>& right )
00377 {
00378   // assign the base class
00379   Property::operator=( right ) ;
00380   // assign the value
00381   PropertyWithValue<TYPE>::operator=( right.value() ) ;
00382   return *this ;
00383 }
00384 // ============================================================================
00385 
00386 // ============================================================================
00394 // ============================================================================
00395 template<class TYPE,class VERIFIER>
00396 class PropertyWithVerifier
00397   : public PropertyWithValue<TYPE>
00398 {
00399 protected:
00400   // ==========================================================================
00402   PropertyWithVerifier
00403   ( const std::string&                                    name     ,
00404     typename Gaudi::Utils::PropertyTypeTraits<TYPE>::PVal value    ,
00405     const bool                                            owner    ,
00406     const VERIFIER&                                       verifier )
00407     : PropertyWithValue<TYPE> ( name , value , owner )
00408     , m_verifier ( verifier )
00409   {}
00411   virtual ~PropertyWithVerifier() {}
00412   // ==========================================================================
00413 public:
00414   // ==========================================================================
00415   inline       VERIFIER& verifier()       { return m_verifier ; }
00416   inline const VERIFIER& verifier() const { return m_verifier ; }
00418   bool set( const TYPE& value ) ;
00420   virtual bool setValue( const TYPE& value ) { return set( value ) ; }
00422   template <class OTHER,class OTHERVERIFIER>
00423   PropertyWithVerifier& operator=
00424   ( const PropertyWithVerifier<OTHER,OTHERVERIFIER>& right ) ;
00426   template <class OTHER>
00427   PropertyWithVerifier& operator=( const PropertyWithValue<OTHER>& right ) ;
00429   PropertyWithVerifier& operator=( const TYPE& right ) ;
00430   // ==========================================================================
00431 private:
00432   // ==========================================================================
00434   PropertyWithVerifier() ;
00436   PropertyWithVerifier( const  PropertyWithVerifier& right );
00437   // ==========================================================================
00438 private:
00439   // ==========================================================================
00441   VERIFIER m_verifier ;                                  // the verifier itself
00442   // ==========================================================================
00443 } ;
00444 // ============================================================================
00446 // ============================================================================
00447 template <class TYPE,class VERIFIER>
00448 inline bool
00449 PropertyWithVerifier<TYPE,VERIFIER>::set( const TYPE& value )
00450 {
00452   if ( !m_verifier.isValid( &value ) ) { return false ; }
00454   this->i_set( value ) ;
00456   return this->useUpdateHandler() ;
00457 }
00458 // ============================================================================
00460 // ============================================================================
00461 template <class TYPE,class VERIFIER>
00462 inline PropertyWithVerifier<TYPE,VERIFIER>&
00463 PropertyWithVerifier<TYPE,VERIFIER>::operator=( const TYPE& right )
00464 {
00465   PropertyWithValue<TYPE>::operator=( right ) ;
00466   return *this ;
00467 }
00468 // ============================================================================
00470 // ============================================================================
00471 template <class TYPE,class VERIFIER>
00472 template <class OTHER>
00473 inline PropertyWithVerifier<TYPE,VERIFIER>&
00474 PropertyWithVerifier<TYPE,VERIFIER>::operator=( const PropertyWithValue<OTHER>& right )
00475 {
00476   PropertyWithValue<TYPE>::operator=(right) ;
00477   return *this ;
00478 }
00479 // ============================================================================
00481 // ============================================================================
00482 template <class TYPE,class VERIFIER>
00483 template <class OTHER,class OTHERVERIFIER>
00484 inline PropertyWithVerifier<TYPE,VERIFIER>&
00485 PropertyWithVerifier<TYPE,VERIFIER>::operator=
00486 ( const PropertyWithVerifier<OTHER,OTHERVERIFIER>& right )
00487 {
00488   PropertyWithValue<TYPE>::operator=(right) ;
00489   return *this ;
00490 }
00491 // ============================================================================
00492 
00493 // ============================================================================
00503 // ============================================================================
00504 template <class TYPE,class VERIFIER = BoundedVerifier<TYPE> >
00505 class SimpleProperty
00506   : public PropertyWithVerifier<TYPE,VERIFIER>
00507 {
00508 protected:
00509   // ==========================================================================
00510   typedef Gaudi::Utils::PropertyTypeTraits<TYPE>  Traits ;
00511   // ==========================================================================
00512 public:
00513   // ==========================================================================
00515   SimpleProperty
00516   ( VERIFIER           verifier = VERIFIER() ) ;
00518   SimpleProperty
00519   ( const TYPE&        value                 ,
00520     VERIFIER           verifier = VERIFIER() ) ;
00522   SimpleProperty
00523   ( const std::string& name                  ,
00524     const TYPE&        value                 ,
00525     VERIFIER           verifier = VERIFIER() ) ;
00527   template <class OTHER>
00528   SimpleProperty ( const PropertyWithValue<OTHER>& right ) ;
00530   SimpleProperty ( const SimpleProperty& right ) ;
00532   virtual ~SimpleProperty() ;
00534   virtual SimpleProperty* clone() const ;
00536   SimpleProperty& operator=( const TYPE& value ) ;
00538   template <class OTHER>
00539   SimpleProperty& operator=( const PropertyWithValue<OTHER>& right ) ;
00540   // ==========================================================================
00541 };
00542 // ============================================================================
00544 // ============================================================================
00545 template <class TYPE,class VERIFIER>
00546 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00547 ( VERIFIER           verifier )
00548   : PropertyWithVerifier<TYPE,VERIFIER>
00549 ( "" , Traits::new_() , true , verifier )
00550 {}
00551 // ============================================================================
00553 // ============================================================================
00554 template <class TYPE,class VERIFIER>
00555 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00556 ( const TYPE&        value    ,
00557   VERIFIER           verifier )
00558   : PropertyWithVerifier<TYPE,VERIFIER>
00559 ( "" , Traits::new_(value) , true , verifier )
00560 {}
00561 // ============================================================================
00563 // ============================================================================
00564 template <class TYPE,class VERIFIER>
00565 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00566 ( const std::string& name     ,
00567   const TYPE&        value    ,
00568   VERIFIER           verifier )
00569   : PropertyWithVerifier<TYPE,VERIFIER>
00570 ( name , Traits::new_(value) , true , verifier )
00571 {}
00572 // ============================================================================
00574 // ============================================================================
00575 template <class TYPE,class VERIFIER>
00576 template <class OTHER>
00577 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00578 ( const PropertyWithValue<OTHER>& right )
00579   : PropertyWithVerifier<TYPE,VERIFIER>
00580 ( right.name() , Traits::new_( right.value() ) , true , VERIFIER() )
00581 {}
00582 // ============================================================================
00584 // ============================================================================
00585 template <class TYPE,class VERIFIER>
00586 SimpleProperty<TYPE,VERIFIER>::SimpleProperty
00587 ( const SimpleProperty& right )
00588   : PropertyWithVerifier<TYPE,VERIFIER>
00589 ( right.name() , Traits::new_( right.value() ) , true , right.verifier() )
00590 {}
00591 // ============================================================================
00593 // ============================================================================
00594 template <class TYPE,class VERIFIER>
00595 SimpleProperty<TYPE,VERIFIER>::~SimpleProperty(){}
00596 // ============================================================================
00598 // ============================================================================
00599 template <class TYPE,class VERIFIER>
00600 inline
00601 SimpleProperty<TYPE,VERIFIER>*
00602 SimpleProperty<TYPE,VERIFIER>::clone() const
00603 { return new SimpleProperty(*this) ; }
00604 // ============================================================================
00606 // ============================================================================
00607 template <class TYPE,class VERIFIER>
00608 inline
00609 SimpleProperty<TYPE,VERIFIER>&
00610 SimpleProperty<TYPE,VERIFIER>::operator=( const TYPE& value )
00611 {
00612   PropertyWithVerifier<TYPE,VERIFIER>::operator=( value );
00613   return *this ;
00614 }
00615 // ============================================================================
00617 // ============================================================================
00618 template <class TYPE,class VERIFIER>
00619 template <class OTHER>
00620 inline
00621 SimpleProperty<TYPE,VERIFIER>&
00622 SimpleProperty<TYPE,VERIFIER>::operator=
00623 ( const PropertyWithValue<OTHER>& right )
00624 {
00625   PropertyWithVerifier<TYPE,VERIFIER>::operator=( right );
00626   return *this ;
00627 }
00628 // ============================================================================
00629 
00630 // ============================================================================
00639 // ============================================================================
00640 template< class TYPE, class VERIFIER = NullVerifier<TYPE> >
00641 class SimplePropertyRef :
00642   public PropertyWithVerifier<TYPE,VERIFIER>
00643 {
00644 public:
00646   SimplePropertyRef
00647   ( const std::string& name                  ,
00648     TYPE&              value                 ,  
00649     VERIFIER           verifier = VERIFIER() ) ;
00651   SimplePropertyRef ( const SimplePropertyRef& right ) ;
00653   virtual ~SimplePropertyRef() ;
00655   virtual SimplePropertyRef* clone() const ;
00657   SimplePropertyRef& operator=( const TYPE& value ) ;
00659   template <class OTHER>
00660   SimplePropertyRef& operator=( const PropertyWithValue<OTHER>& right ) ;
00661 private:
00662   // the default constructor is disabled
00663   SimplePropertyRef() ;
00664 };
00665 // ============================================================================
00667 // ============================================================================
00668 template <class TYPE,class VERIFIER>
00669 SimplePropertyRef<TYPE,VERIFIER>::SimplePropertyRef
00670 ( const std::string& name     ,
00671   TYPE&              value    ,  
00672   VERIFIER           verifier )
00673   : PropertyWithVerifier<TYPE,VERIFIER> ( name , &value , false , verifier )
00674 {}
00675 // ============================================================================
00677 // ============================================================================
00678 template <class TYPE,class VERIFIER>
00679 SimplePropertyRef<TYPE,VERIFIER>::SimplePropertyRef
00680 ( const SimplePropertyRef& right )
00681   : PropertyWithVerifier<TYPE,VERIFIER>
00682 ( right.name() , right.i_get() , false , right.verifier() )
00683 {}
00684 // ============================================================================
00686 // ============================================================================
00687 template <class TYPE,class VERIFIER>
00688 SimplePropertyRef<TYPE,VERIFIER>::~SimplePropertyRef(){}
00689 // ============================================================================
00691 // ============================================================================
00692 template <class TYPE,class VERIFIER>
00693 inline
00694 SimplePropertyRef<TYPE,VERIFIER>*
00695 SimplePropertyRef<TYPE,VERIFIER>::clone() const
00696 { return new SimplePropertyRef(*this) ; }
00697 // ============================================================================
00699 // ============================================================================
00700 template <class TYPE,class VERIFIER>
00701 inline
00702 SimplePropertyRef<TYPE,VERIFIER>&
00703 SimplePropertyRef<TYPE,VERIFIER>::operator=( const TYPE& value )
00704 {
00705   PropertyWithVerifier<TYPE,VERIFIER>::operator=( value ) ;
00706   return *this ;
00707 }
00708 // ============================================================================
00710 // ============================================================================
00711 template <class TYPE,class VERIFIER>
00712 template <class OTHER>
00713 inline
00714 SimplePropertyRef<TYPE,VERIFIER>&
00715 SimplePropertyRef<TYPE,VERIFIER>::operator=
00716 ( const PropertyWithValue<OTHER>& right )
00717 {
00718   PropertyWithVerifier<TYPE,VERIFIER>::operator=( right );
00719   return *this ;
00720 }
00721 // ============================================================================
00722 
00723 
00724 
00725 
00726 // Typedef Properties for built-in types
00727 typedef SimpleProperty< bool >              BooleanProperty;
00728 typedef SimpleProperty< char >              CharProperty;
00729 typedef SimpleProperty< signed char >       SignedCharProperty;
00730 typedef SimpleProperty< unsigned char >     UnsignedCharProperty;
00731 typedef SimpleProperty< short >             ShortProperty;
00732 typedef SimpleProperty< unsigned short >    UnsignedShortProperty;
00733 typedef SimpleProperty< int >               IntegerProperty;
00734 typedef SimpleProperty< unsigned int >      UnsignedIntegerProperty;
00735 typedef SimpleProperty< long >              LongProperty;
00736 typedef SimpleProperty< unsigned long >     UnsignedLongProperty;
00737 typedef SimpleProperty< long long>          LongLongProperty;
00738 typedef SimpleProperty< unsigned long long> UnsignedLongLongProperty;
00739 typedef SimpleProperty< float >             FloatProperty;
00740 typedef SimpleProperty< double >            DoubleProperty;
00741 typedef SimpleProperty< long double >       LongDoubleProperty;
00742 
00743 typedef SimpleProperty< std::string >       StringProperty;
00744 
00745 
00746 // Typedef PropertyRefs for built-in types
00747 typedef SimplePropertyRef< bool >                BooleanPropertyRef;
00748 typedef SimplePropertyRef< char >                CharPropertyRef;
00749 typedef SimplePropertyRef< signed char >         SignedCharPropertyRef;
00750 typedef SimplePropertyRef< unsigned char >       UnsignedCharPropertyRef;
00751 typedef SimplePropertyRef< short >               ShortPropertyRef;
00752 typedef SimplePropertyRef< unsigned short >      UnsignedShortPropertyRef;
00753 typedef SimplePropertyRef< int >                 IntegerPropertyRef;
00754 typedef SimplePropertyRef< unsigned int >        UnsignedIntegerPropertyRef;
00755 typedef SimplePropertyRef< long >                LongPropertyRef;
00756 typedef SimplePropertyRef< unsigned long >       UnsignedLongPropertyRef;
00757 typedef SimplePropertyRef< long long >           LongLongPropertyRef;
00758 typedef SimplePropertyRef< unsigned long long >  UnsignedLongLongPropertyRef;
00759 typedef SimplePropertyRef< float >               FloatPropertyRef;
00760 typedef SimplePropertyRef< double >              DoublePropertyRef;
00761 typedef SimplePropertyRef< long double >         LongDoublePropertyRef;
00762 
00763 typedef SimplePropertyRef< std::string >         StringPropertyRef;
00764 
00765 
00766 // Typedef "Arrays" of Properties for built-in types
00767 typedef SimpleProperty< std::vector< bool > >                BooleanArrayProperty;
00768 typedef SimpleProperty< std::vector< char > >                CharArrayProperty;
00769 typedef SimpleProperty< std::vector< signed char > >         SignedCharArrayProperty;
00770 typedef SimpleProperty< std::vector< unsigned char > >       UnsignedCharArrayProperty;
00771 typedef SimpleProperty< std::vector< short > >               ShortArrayProperty;
00772 typedef SimpleProperty< std::vector< unsigned short > >      UnsignedShortArrayProperty;
00773 typedef SimpleProperty< std::vector< int > >                 IntegerArrayProperty;
00774 typedef SimpleProperty< std::vector< unsigned int > >        UnsignedIntegerArrayProperty;
00775 typedef SimpleProperty< std::vector< long > >                LongArrayProperty;
00776 typedef SimpleProperty< std::vector< unsigned long > >       UnsignedLongArrayProperty;
00777 typedef SimpleProperty< std::vector< long long > >           LongLongArrayProperty;
00778 typedef SimpleProperty< std::vector< unsigned long long > >  UnsignedLongLongArrayProperty;
00779 typedef SimpleProperty< std::vector< float > >               FloatArrayProperty;
00780 typedef SimpleProperty< std::vector< double > >              DoubleArrayProperty;
00781 typedef SimpleProperty< std::vector< long double > >         LongDoubleArrayProperty;
00782 
00783 typedef SimpleProperty< std::vector< std::string > >         StringArrayProperty;
00784 
00785 
00786 // Typedef "Arrays" of PropertyRefs for built-in types
00787 typedef SimplePropertyRef< std::vector< bool > >                 BooleanArrayPropertyRef;
00788 typedef SimplePropertyRef< std::vector< char > >                 CharArrayPropertyRef;
00789 typedef SimplePropertyRef< std::vector< signed char > >          SignedCharArrayPropertyRef;
00790 typedef SimplePropertyRef< std::vector< unsigned char > >        UnsignedCharArrayPropertyRef;
00791 typedef SimplePropertyRef< std::vector< short > >                ShortArrayPropertyRef;
00792 typedef SimplePropertyRef< std::vector< unsigned short > >       UnsignedShortArrayPropertyRef;
00793 typedef SimplePropertyRef< std::vector< int > >                  IntegerArrayPropertyRef;
00794 typedef SimplePropertyRef< std::vector< unsigned int > >         UnsignedIntegerArrayPropertyRef;
00795 typedef SimplePropertyRef< std::vector< long > >                 LongArrayPropertyRef;
00796 typedef SimplePropertyRef< std::vector< unsigned long > >        UnsignedLongArrayPropertyRef;
00797 typedef SimplePropertyRef< std::vector< long long > >            LongLongArrayPropertyRef;
00798 typedef SimplePropertyRef< std::vector< unsigned long long > >   UnsignedLongLongArrayPropertyRef;
00799 typedef SimplePropertyRef< std::vector< float > >                FloatArrayPropertyRef;
00800 typedef SimplePropertyRef< std::vector< double > >               DoubleArrayPropertyRef;
00801 typedef SimplePropertyRef< std::vector< long double > >          LongDoubleArrayPropertyRef;
00802 
00803 typedef SimplePropertyRef< std::vector< std::string > >          StringArrayPropertyRef;
00804 
00805 // pre-declaration is sufficient here
00806 class GaudiHandleBase;
00807 
00808 class GAUDI_API GaudiHandleProperty : public Property {
00809 public:
00810    GaudiHandleProperty( const std::string& name, GaudiHandleBase& ref );
00811 
00812   GaudiHandleProperty& operator=( const GaudiHandleBase& value );
00813 
00814   virtual GaudiHandleProperty* clone() const;
00815 
00816   virtual bool load( Property& destination ) const;
00817 
00818   virtual bool assign( const Property& source );
00819 
00820   virtual std::string toString() const;
00821 
00822   virtual void toStream(std::ostream& out) const;
00823 
00824   virtual StatusCode fromString(const std::string& s);
00825 
00826   const GaudiHandleBase& value() const;
00827 
00828   bool setValue( const GaudiHandleBase& value );
00829 
00830 private:
00833    GaudiHandleBase* m_pValue;
00834 };
00835 
00836 // implementation in header file only where the GaudiHandleBase class
00837 // definition is not needed. The rest goes into the .cpp file.
00838 // The goal is to decouple the header files, to avoid that the whole
00839 // world depends on GaudiHandle.h
00840 inline GaudiHandleProperty& GaudiHandleProperty::operator=( const GaudiHandleBase& value ) {
00841       setValue( value );
00842       return *this;
00843 }
00844 
00845 inline GaudiHandleProperty* GaudiHandleProperty::clone() const {
00846   return new GaudiHandleProperty( *this );
00847 }
00848 
00849 inline bool GaudiHandleProperty::load( Property& destination ) const {
00850   return destination.assign( *this );
00851 }
00852 
00853 inline bool GaudiHandleProperty::assign( const Property& source ) {
00854   return fromString( source.toString() ).isSuccess();
00855 }
00856 
00857 inline const GaudiHandleBase& GaudiHandleProperty::value() const {
00858   useReadHandler();
00859   return *m_pValue;
00860 }
00861 
00862 
00863 // pre-declaration is sufficient here
00864 class GaudiHandleArrayBase;
00865 
00866 class GAUDI_API GaudiHandleArrayProperty : public Property {
00867 public:
00868 
00869   GaudiHandleArrayProperty( const std::string& name, GaudiHandleArrayBase& ref );
00870 
00871   GaudiHandleArrayProperty& operator=( const GaudiHandleArrayBase& value );
00872 
00873   virtual GaudiHandleArrayProperty* clone() const;
00874 
00875   virtual bool load( Property& destination ) const;
00876 
00877   virtual bool assign( const Property& source );
00878 
00879   virtual std::string toString() const;
00880 
00881   virtual void toStream(std::ostream& out) const;
00882 
00883   virtual StatusCode fromString(const std::string& s);
00884 
00885   const GaudiHandleArrayBase& value() const;
00886 
00887   bool setValue( const GaudiHandleArrayBase& value );
00888 
00889 private:
00892    GaudiHandleArrayBase* m_pValue;
00893 
00894 };
00895 
00896 // implementation in header file only where the GaudiHandleBase class
00897 // definition is not needed. The rest goes into the .cpp file.
00898 // The goal is to decouple the header files, to avoid that the whole
00899 // world depends on GaudiHandle.h
00900 inline GaudiHandleArrayProperty& GaudiHandleArrayProperty::operator=( const GaudiHandleArrayBase& value ) {
00901   setValue( value );
00902   return *this;
00903 }
00904 
00905 inline GaudiHandleArrayProperty* GaudiHandleArrayProperty::clone() const {
00906   return new GaudiHandleArrayProperty( *this );
00907 }
00908 
00909 inline bool GaudiHandleArrayProperty::load( Property& destination ) const {
00910   return destination.assign( *this );
00911 }
00912 
00913 inline bool GaudiHandleArrayProperty::assign( const Property& source ) {
00914   return fromString( source.toString() ) != 0;
00915 }
00916 
00917 inline const GaudiHandleArrayBase& GaudiHandleArrayProperty::value() const {
00918   useReadHandler();
00919   return *m_pValue;
00920 }
00921 
00922 
00923 namespace Gaudi
00924 {
00925   namespace Utils
00926   {
00927     // ========================================================================
00945     GAUDI_API bool hasProperty ( const IProperty*   p , const std::string& name ) ;
00946     // ========================================================================
00964     GAUDI_API bool hasProperty ( const IInterface*   p , const std::string& name ) ;
00965     // ========================================================================
00983     GAUDI_API Property* getProperty
00984     ( const IProperty*   p , const std::string& name ) ;
00985     // ========================================================================
01003     GAUDI_API Property* getProperty
01004     ( const IInterface*   p , const std::string& name ) ;
01005     // ========================================================================
01028     GAUDI_API bool hasProperty
01029     ( const std::vector<const Property*>* p    ,
01030       const std::string&                  name ) ;
01031     // ========================================================================
01054     GAUDI_API const Property* getProperty
01055     ( const std::vector<const Property*>* p    ,
01056       const std::string&                  name ) ;
01057     // ========================================================================
01081     template <class TYPE>
01082     StatusCode setProperty
01083     ( IProperty*         component  ,
01084       const std::string& name       ,
01085       const TYPE&        value      ,
01086       const std::string& doc        ) ;
01087     // ========================================================================
01110     template <class TYPE>
01111     StatusCode setProperty
01112     ( IProperty*         component  ,
01113       const std::string& name       ,
01114       const TYPE&        value      )
01115     { return setProperty ( component , name , value , std::string() ) ; }
01116     // ========================================================================
01130     GAUDI_API StatusCode setProperty
01131     ( IProperty*         component  ,
01132       const std::string& name       ,
01133       const std::string& value      ,
01134       const std::string& doc   = "" ) ;
01135     // ========================================================================
01149     GAUDI_API StatusCode setProperty
01150     ( IProperty*         component  ,
01151       const std::string& name       ,
01152       const char*        value      ,
01153       const std::string& doc   = "" ) ;
01154     // ========================================================================
01168     template <unsigned N>
01169     StatusCode setProperty
01170     ( IProperty*           component ,
01171       const std::string&   name      ,
01172       const char         (&value)[N] ,
01173       const std::string& doc   = ""  )
01174     {
01175       if ( 0 == component                    ) { return StatusCode::FAILURE ; }
01176       const std::string val = std::string ( value , value + N ) ;
01177       return setProperty ( component , name , val , doc ) ;
01178     }
01179     // ========================================================================
01210     template <class TYPE>
01211     StatusCode setProperty
01212     ( IProperty*         component  ,
01213       const std::string& name       ,
01214       const TYPE&        value      ,
01215       const std::string& doc        )
01216     {
01217       if ( 0 == component ) { return StatusCode::FAILURE ; }   // RETURN
01218       if ( !hasProperty ( component , name ) ) { return StatusCode::FAILURE ; }
01219       const std::string val = Gaudi::Utils::toString ( value ) ;
01220       return Gaudi::Utils::setProperty ( component , name , val , doc ) ;
01221     }
01222     // ========================================================================
01244     GAUDI_API StatusCode setProperty
01245     ( IProperty*         component ,
01246       const std::string& name      ,
01247       const Property*    property  ,
01248       const std::string& doc = ""  ) ;
01249     // ========================================================================
01271     GAUDI_API StatusCode setProperty
01272     ( IProperty*         component ,
01273       const std::string& name      ,
01274       const Property&    property  ,
01275       const std::string& doc = ""  ) ;
01276     // ========================================================================
01299     template <class TYPE>
01300     StatusCode setProperty
01301     ( IProperty*                  component ,
01302       const std::string&          name      ,
01303       const SimpleProperty<TYPE>& value     ,
01304       const std::string&          doc = ""  )
01305     {
01306       const Property* property = &value ;
01307       return setProperty ( component , name , property , doc ) ;
01308     }
01309     // ========================================================================
01330     template <class TYPE>
01331     StatusCode setProperty
01332     ( IInterface*        component ,
01333       const std::string& name      ,
01334       const TYPE&        value     ,
01335       const std::string& doc = ""  )
01336     {
01337       if ( 0 == component ) { return StatusCode::FAILURE ; }
01338       SmartIF<IProperty> property ( component ) ;
01339       if ( !property      ) { return StatusCode::FAILURE ; }
01340       return setProperty ( property , name , value , doc ) ;
01341     }
01342     // ========================================================================
01355     GAUDI_API StatusCode setProperty
01356     ( IInterface*        component ,
01357       const std::string& name      ,
01358       const std::string& value     ,
01359       const std::string& doc  = "" ) ;
01360     // ========================================================================
01373     GAUDI_API StatusCode setProperty
01374     ( IInterface*        component ,
01375       const std::string& name      ,
01376       const char*        value     ,
01377       const std::string& doc  = "" ) ;
01378     // ========================================================================
01392     template <unsigned N>
01393     StatusCode setProperty
01394     ( IInterface*          component ,
01395       const std::string&   name      ,
01396       const char         (&value)[N] ,
01397       const std::string& doc  = ""   )
01398     {
01399       if ( 0 == component ) { return StatusCode::FAILURE ; }
01400       const std::string val = std::string ( value , value + N ) ;
01401       return setProperty ( component , name , val , doc ) ;
01402     }
01403     // ========================================================================
01425     GAUDI_API StatusCode setProperty
01426     ( IInterface*        component ,
01427       const std::string& name      ,
01428       const Property*    property  ,
01429       const std::string& doc = ""  ) ;
01430     // ========================================================================
01452     GAUDI_API StatusCode setProperty
01453     ( IInterface*        component ,
01454       const std::string& name      ,
01455       const Property&    property  ,
01456       const std::string& doc = ""  ) ;
01457     // ========================================================================
01480     template <class TYPE>
01481     StatusCode
01482     setProperty
01483     ( IInterface*                 component ,
01484       const std::string&          name      ,
01485       const SimpleProperty<TYPE>& value     ,
01486       const std::string&          doc = ""  )
01487     {
01488       const Property* property = &value ;
01489       return setProperty ( component , name , property , doc ) ;
01490     }
01491     // ========================================================================
01492   } // end of namespace Gaudi::Utils
01493 } // end of namespace Gaudi
01494 
01495 
01496 // ============================================================================
01497 // The END
01498 // ============================================================================
01499 #endif // GAUDIKERNEL_PROPERTY_H
01500 // ============================================================================
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Sep 17 2012 13:49:29 for Gaudi Framework, version v23r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004