00001
00002
00003
00004
00005 #ifndef GAUDIKERNEL_PROPERTYMGR_H
00006 #define GAUDIKERNEL_PROPERTYMGR_H
00007
00008
00009
00010
00011
00012 #include <iostream>
00013 #include <vector>
00014 #include <utility>
00015 #include <stdexcept>
00016
00017
00018
00019 #include "GaudiKernel/Property.h"
00020 #include "GaudiKernel/IProperty.h"
00021
00022
00023
00024 template< class T> class ToolHandle;
00025 template< class T> class ServiceHandle;
00026 template< class T> class ToolHandleArray;
00027
00037 class PropertyMgr : virtual public IProperty
00038 {
00039 public:
00041 PropertyMgr ( IInterface* iface = 0 );
00042
00043 PropertyMgr ( const PropertyMgr& ) ;
00045 virtual ~PropertyMgr();
00046
00047 PropertyMgr& operator=( const PropertyMgr& ) ;
00048 public:
00050 template<class TYPE>
00051 Property* declareProperty
00052 ( const std::string& name ,
00053 TYPE& value,
00054 const std::string& doc = "none" ) ;
00056 template <class TYPE>
00057 Property* declareProperty
00058 ( const std::string& name ,
00059 SimpleProperty<TYPE>& prop,
00060 const std::string& doc = "none") ;
00062 template <class TYPE>
00063 Property* declareProperty
00064 ( const std::string& name ,
00065 SimplePropertyRef<TYPE>& prop,
00066 const std::string& doc = "none") ;
00067
00069 template<class TYPE>
00070 Property* declareProperty
00071 ( const std::string& name,
00072 ToolHandle<TYPE>& ref,
00073 const std::string& doc = "none" ) ;
00075 template<class TYPE>
00076 Property* declareProperty
00077 ( const std::string& name,
00078 ServiceHandle<TYPE>& ref,
00079 const std::string& doc = "none" ) ;
00081 template<class TYPE>
00082 Property* declareProperty
00083 ( const std::string& name,
00084 ToolHandleArray<TYPE>& ref,
00085 const std::string& doc = "none" ) ;
00087 Property* declareRemoteProperty
00088 ( const std::string& name ,
00089 IProperty* rsvc ,
00090 const std::string& rname = "" ) ;
00091
00092
00093
00097 StatusCode setProperty(const Property& p);
00098
00102 StatusCode setProperty( const std::string& s );
00103
00107 StatusCode setProperty( const std::string& n, const std::string& v);
00108
00112 StatusCode getProperty(Property* p) const;
00113
00117 const Property& getProperty( const std::string& name) const;
00118
00122 StatusCode getProperty( const std::string& n, std::string& v ) const;
00123
00127 const std::vector<Property*>& getProperties( ) const;
00128
00129
00130 StatusCode queryInterface(const InterfaceID& riid, void** ppvInterface);
00131 unsigned long addRef();
00132 unsigned long release();
00133
00134 protected:
00135
00136
00137 Property* property ( const std::string& name ) const ;
00138
00139 private:
00141 Property* property
00142 ( const std::string& name ,
00143 const std::vector<Property*>& props ) const ;
00144
00145 private:
00146
00147
00148 typedef std::vector<Property*> Properties ;
00149 typedef std::pair<std::string,
00150 std::pair<IProperty*, std::string> > RemProperty;
00151 typedef std::vector<RemProperty> RemoteProperties ;
00152
00153 private:
00154
00156 Properties m_properties ;
00158 RemoteProperties m_remoteProperties;
00160 Properties m_todelete ;
00162 std::vector<bool> m_isOwned ;
00164 IInterface* m_pOuter ;
00166 unsigned long m_refcount;
00167 };
00168
00170
00171 template<class TYPE>
00172 inline Property*
00173 PropertyMgr::declareProperty
00174 ( const std::string& name ,
00175 TYPE& value,
00176 const std::string& doc )
00177 {
00178 Property* p = new SimplePropertyRef<TYPE> ( name , value ) ;
00179
00180 p->setDocumentation( doc );
00181 m_properties .push_back( p ) ;
00182 m_todelete .push_back( p ) ;
00183
00184 return p ;
00185 }
00186
00188
00189 template <class TYPE>
00190 inline Property*
00191 PropertyMgr::declareProperty
00192 ( const std::string& name ,
00193 SimpleProperty<TYPE>& prop,
00194 const std::string& doc )
00195 {
00196 Property* p = &prop ;
00197
00198 p -> setName ( name ) ;
00199 p -> setDocumentation ( doc ) ;
00200 m_properties.push_back ( p ) ;
00201
00202 return p ;
00203 }
00204
00206
00207 template <class TYPE>
00208 inline Property*
00209 PropertyMgr::declareProperty
00210 ( const std::string& name ,
00211 SimplePropertyRef<TYPE>& prop,
00212 const std::string& doc )
00213 {
00214 Property* p = &prop ;
00215
00216 p -> setName ( name ) ;
00217 p -> setDocumentation ( doc ) ;
00218 m_properties.push_back ( p ) ;
00219
00220 return p ;
00221 }
00222
00223
00224
00225 template<class TYPE>
00226 inline Property*
00227 PropertyMgr::declareProperty
00228 ( const std::string& name,
00229 ToolHandle<TYPE>& ref,
00230 const std::string& doc )
00231 {
00232 Property* p = new GaudiHandleProperty( name, ref );
00233
00234 p -> setDocumentation ( doc ) ;
00235 m_properties . push_back ( p ) ;
00236 m_todelete . push_back ( p ) ;
00237
00238 return p ;
00239 }
00240
00241 template<class TYPE>
00242 inline Property*
00243 PropertyMgr::declareProperty
00244 ( const std::string& name,
00245 ServiceHandle<TYPE>& ref,
00246 const std::string& doc )
00247 {
00248 Property* p = new GaudiHandleProperty( name, ref );
00249
00250 p -> setDocumentation ( doc ) ;
00251 m_properties . push_back ( p ) ;
00252 m_todelete . push_back ( p ) ;
00253
00254 return p ;
00255 }
00256
00257 template<class TYPE>
00258 inline Property*
00259 PropertyMgr::declareProperty
00260 ( const std::string& name,
00261 ToolHandleArray<TYPE>& ref,
00262 const std::string& doc )
00263 {
00264 Property* p = new GaudiHandleArrayProperty( name, ref );
00265
00266 p -> setDocumentation ( doc ) ;
00267 m_properties . push_back ( p ) ;
00268 m_todelete . push_back ( p ) ;
00269
00270 return p ;
00271 }
00272
00273
00274
00275 #endif // GAUDIKERNEL_PROPERTYMGR_H
00276
00277