Gaudi Framework, version v21r8

Home   Generated: 17 Mar 2010

PropertyMgr.h

Go to the documentation of this file.
00001 // $Id: PropertyMgr.h,v 1.22 2008/04/03 17:27:01 marcocle Exp $
00002 // ============================================================================
00003 // CVS tag $Name:  $, version $Revision: 1.22 $
00004 // ============================================================================
00005 #ifndef GAUDIKERNEL_PROPERTYMGR_H
00006 #define GAUDIKERNEL_PROPERTYMGR_H
00007 // ============================================================================
00008 // Include files
00009 // ============================================================================
00010 // STD & STL
00011 // ============================================================================
00012 #include <iostream>
00013 #include <vector>
00014 #include <utility>
00015 #include <stdexcept>
00016 // ============================================================================
00017 // GaudiKernel
00018 // ============================================================================
00019 #include "GaudiKernel/Property.h"
00020 #include "GaudiKernel/IProperty.h"
00021 // ============================================================================
00022 
00023 // pre-declaration of GaudiHandles is sufficient
00024 template< class T> class ToolHandle;
00025 template< class T> class ServiceHandle;
00026 template< class T> class ToolHandleArray;
00027 template< class T> class ServiceHandleArray;
00028 
00038 class GAUDI_API PropertyMgr : public implements1<IProperty>
00039 {
00040 public:
00042   PropertyMgr ( IInterface* iface = 0 );
00043   // copy constructor
00044   PropertyMgr ( const PropertyMgr& ) ;
00046   virtual ~PropertyMgr();
00047   // assignment operator
00048   PropertyMgr& operator=( const PropertyMgr& ) ;
00049 public:
00051   template<class TYPE>
00052   Property* declareProperty
00053   ( const std::string&       name  ,
00054     TYPE&                    value,
00055     const std::string&       doc = "none" ) ;
00057   template <class TYPE>
00058   Property* declareProperty
00059   ( const std::string&       name  ,
00060     SimpleProperty<TYPE>&    prop,
00061     const std::string&       doc = "none") ;
00063   template <class TYPE>
00064   Property* declareProperty
00065   ( const std::string&       name  ,
00066     SimplePropertyRef<TYPE>& prop,
00067     const std::string&       doc = "none") ;
00068   // partial specializations for various GaudiHandles
00070   template<class TYPE>
00071   Property* declareProperty
00072   ( const std::string& name,
00073     ToolHandle<TYPE>& ref,
00074     const std::string& doc = "none" ) ;
00076   template<class TYPE>
00077   Property* declareProperty
00078   ( const std::string& name,
00079     ServiceHandle<TYPE>& ref,
00080     const std::string& doc = "none" ) ;
00082   template<class TYPE>
00083   Property* declareProperty
00084   ( const std::string& name,
00085     ToolHandleArray<TYPE>& ref,
00086     const std::string& doc = "none" ) ;
00088   template<class TYPE>
00089   Property* declareProperty
00090   ( const std::string& name, 
00091     ServiceHandleArray<TYPE>& ref, 
00092     const std::string& doc = "none" ) ;  
00094   Property* declareRemoteProperty
00095   ( const std::string& name       ,
00096     IProperty*         rsvc       ,
00097     const std::string& rname = "" ) ;
00098   // ==========================================================================
00099         // IProperty implementation
00100   // ==========================================================================
00104         StatusCode setProperty(const Property& p);
00105   // ==========================================================================
00109   StatusCode setProperty( const std::string& s );
00110   // ==========================================================================
00114   StatusCode setProperty( const std::string& n, const std::string& v);
00115   // ==========================================================================
00119         StatusCode getProperty(Property* p) const;
00120   // ==========================================================================
00124   const Property& getProperty( const std::string& name) const;
00125   // ==========================================================================
00129   StatusCode getProperty( const std::string& n, std::string& v ) const;
00130   // ==========================================================================
00134   const std::vector<Property*>& getProperties( ) const;
00135   // ==========================================================================
00136   // IInterface implementation
00137   StatusCode queryInterface(const InterfaceID& iid, void** pinterface);
00138   // ==========================================================================
00139 protected:
00140 
00141   // get local or remote property by name
00142   Property* property       ( const std::string& name  ) const ;
00143 
00144 private:
00146   Property* property
00147   ( const std::string&             name  ,
00148     const std::vector<Property*>&  props ) const ;
00149 
00150 private:
00151 
00152   // Some typedef to simply typing
00153   typedef std::vector<Property*>   Properties       ;
00154   typedef std::pair<std::string,
00155                     std::pair<IProperty*, std::string> > RemProperty;
00156   typedef std::vector<RemProperty> RemoteProperties ;
00157 
00158 private:
00159 
00161   Properties             m_properties      ;  // local  properties
00163   RemoteProperties       m_remoteProperties;  // Remote properties
00165   Properties             m_todelete        ;  // properties to be deleted
00167   std::vector<bool>      m_isOwned         ;  // flag to delete
00169   IInterface*            m_pOuter  ;  // Interface hub reference
00170 };
00171 // ============================================================================
00173 // ============================================================================
00174 template<class TYPE>
00175 inline Property*
00176 PropertyMgr::declareProperty
00177 ( const std::string& name  ,
00178   TYPE&              value,
00179   const std::string& doc )
00180 {
00181   Property* p = new SimplePropertyRef<TYPE> ( name , value ) ;
00182   //
00183   p->setDocumentation( doc );
00184   m_properties .push_back( p ) ;
00185   m_todelete   .push_back( p ) ;
00186   //
00187   return p ;
00188 }
00189 // ============================================================================
00191 // ============================================================================
00192 template <class TYPE>
00193 inline Property*
00194 PropertyMgr::declareProperty
00195 ( const std::string&       name ,
00196   SimpleProperty<TYPE>&    prop,
00197   const std::string&       doc )
00198 {
00199   Property* p = &prop ;
00200   //
00201   p -> setName           ( name  ) ;
00202   p -> setDocumentation  ( doc   ) ;
00203   m_properties.push_back ( p     ) ;
00204   //
00205   return p ;
00206 }
00207 // ============================================================================
00209 // ============================================================================
00210 template <class TYPE>
00211 inline Property*
00212 PropertyMgr::declareProperty
00213 ( const std::string&       name ,
00214   SimplePropertyRef<TYPE>& prop,
00215   const std::string&       doc )
00216 {
00217   Property* p = &prop ;
00218   //
00219   p -> setName             ( name  ) ;
00220   p -> setDocumentation    ( doc   ) ;
00221   m_properties.push_back   ( p     ) ;
00222   //
00223   return p ;
00224 }
00225 // ============================================================================
00226 // Declare a property (templated)
00227 // ============================================================================
00228 template<class TYPE>
00229 inline Property*
00230 PropertyMgr::declareProperty
00231 ( const std::string& name,
00232   ToolHandle<TYPE>& ref,
00233   const std::string& doc )
00234 {
00235   Property* p = new GaudiHandleProperty( name, ref );
00236   //
00237   p -> setDocumentation    ( doc ) ;
00238   m_properties . push_back ( p   ) ;
00239   m_todelete   . push_back ( p   ) ;
00240   //
00241   return p ;
00242 }
00243 // ============================================================================
00244 template<class TYPE>
00245 inline Property*
00246 PropertyMgr::declareProperty
00247 ( const std::string& name,
00248   ServiceHandle<TYPE>& ref,
00249   const std::string& doc )
00250 {
00251   Property* p = new GaudiHandleProperty( name, ref );
00252   //
00253   p -> setDocumentation    ( doc ) ;
00254   m_properties . push_back ( p   ) ;
00255   m_todelete   . push_back ( p   ) ;
00256   //
00257   return p ;
00258 }
00259 // ============================================================================
00260 template<class TYPE>
00261 inline Property*
00262 PropertyMgr::declareProperty
00263 ( const std::string& name,
00264   ToolHandleArray<TYPE>& ref,
00265   const std::string& doc )
00266 {
00267   Property* p = new GaudiHandleArrayProperty( name, ref );
00268   //
00269   p -> setDocumentation    ( doc ) ;
00270   m_properties . push_back ( p   ) ;
00271   m_todelete   . push_back ( p   ) ;
00272   //
00273   return p ;
00274 }
00275 // ============================================================================
00276 template<class TYPE>
00277 inline Property* 
00278 PropertyMgr::declareProperty
00279 ( const std::string& name, 
00280   ServiceHandleArray<TYPE>& ref, 
00281   const std::string& doc ) 
00282 {
00283   Property* p = new GaudiHandleArrayProperty( name, ref );
00284   //
00285   p -> setDocumentation    ( doc ) ;
00286   m_properties . push_back ( p   ) ;
00287   m_todelete   . push_back ( p   ) ;
00288   //
00289   return p ;
00290 }
00291 
00292 // ============================================================================
00293 // The END
00294 // ============================================================================
00295 #endif // GAUDIKERNEL_PROPERTYMGR_H
00296 // ============================================================================
00297 

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