All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PropertyMgr.h
Go to the documentation of this file.
1 // $Id: PropertyMgr.h,v 1.22 2008/04/03 17:27:01 marcocle Exp $
2 // ============================================================================
3 // CVS tag $Name: $, version $Revision: 1.22 $
4 // ============================================================================
5 #ifndef GAUDIKERNEL_PROPERTYMGR_H
6 #define GAUDIKERNEL_PROPERTYMGR_H
7 // ============================================================================
8 // Include files
9 // ============================================================================
10 // STD & STL
11 // ============================================================================
12 #include <iostream>
13 #include <vector>
14 #include <utility>
15 #include <stdexcept>
16 // ============================================================================
17 // GaudiKernel
18 // ============================================================================
19 #include "GaudiKernel/Property.h"
20 #include "GaudiKernel/IProperty.h"
21 // ============================================================================
22 
23 // pre-declaration of GaudiHandles is sufficient
24 template< class T> class ToolHandle;
25 template< class T> class ServiceHandle;
26 template< class T> class ToolHandleArray;
27 template< class T> class ServiceHandleArray;
28 
38 class GAUDI_API PropertyMgr : public implements1<IProperty>
39 {
40 public:
42  PropertyMgr ( IInterface* iface = 0 );
43  // copy constructor
44  PropertyMgr ( const PropertyMgr& ) ;
46  virtual ~PropertyMgr();
47  // assignment operator
48  PropertyMgr& operator=( const PropertyMgr& ) ;
49 public:
51  template<class TYPE>
52  Property* declareProperty
53  ( const std::string& name ,
54  TYPE& value,
55  const std::string& doc = "none" ) ;
57  template <class TYPE>
58  Property* declareProperty
59  ( const std::string& name ,
61  const std::string& doc = "none") ;
63  template <class TYPE>
64  Property* declareProperty
65  ( const std::string& name ,
67  const std::string& doc = "none") ;
68  // partial specializations for various GaudiHandles
70  template<class TYPE>
71  Property* declareProperty
72  ( const std::string& name,
73  ToolHandle<TYPE>& ref,
74  const std::string& doc = "none" ) ;
76  template<class TYPE>
77  Property* declareProperty
78  ( const std::string& name,
80  const std::string& doc = "none" ) ;
82  template<class TYPE>
83  Property* declareProperty
84  ( const std::string& name,
86  const std::string& doc = "none" ) ;
88  template<class TYPE>
89  Property* declareProperty
90  ( const std::string& name,
92  const std::string& doc = "none" ) ;
94  Property* declareRemoteProperty
95  ( const std::string& name ,
96  IProperty* rsvc ,
97  const std::string& rname = "" ) ;
98  // ==========================================================================
99  // IProperty implementation
100  // ==========================================================================
104  StatusCode setProperty(const Property& p);
105  // ==========================================================================
109  StatusCode setProperty( const std::string& s );
110  // ==========================================================================
114  StatusCode setProperty( const std::string& n, const std::string& v);
115  // ==========================================================================
119  StatusCode getProperty(Property* p) const;
120  // ==========================================================================
124  const Property& getProperty( const std::string& name) const;
125  // ==========================================================================
129  StatusCode getProperty( const std::string& n, std::string& v ) const;
130  // ==========================================================================
134  const std::vector<Property*>& getProperties( ) const;
135  // ==========================================================================
136  // IInterface implementation
137  StatusCode queryInterface(const InterfaceID& iid, void** pinterface);
138  // ==========================================================================
139 protected:
140 
141  // get local or remote property by name
142  Property* property ( const std::string& name ) const ;
143 
144 private:
146  Property* property
147  ( const std::string& name ,
148  const std::vector<Property*>& props ) const ;
149 
150 private:
151 
152  // Some typedef to simply typing
153  typedef std::vector<Property*> Properties ;
154  typedef std::pair<std::string,
155  std::pair<IProperty*, std::string> > RemProperty;
156  typedef std::vector<RemProperty> RemoteProperties ;
157 
158 private:
159 
161  Properties m_properties ; // local properties
163  RemoteProperties m_remoteProperties; // Remote properties
165  Properties m_todelete ; // properties to be deleted
167  std::vector<bool> m_isOwned ; // flag to delete
169  IInterface* m_pOuter ; // Interface hub reference
170 };
171 // ============================================================================
173 // ============================================================================
174 template<class TYPE>
175 inline Property*
177 ( const std::string& name ,
178  TYPE& value,
179  const std::string& doc )
180 {
181  Property* p = new SimplePropertyRef<TYPE> ( name , value ) ;
182  //
183  p->setDocumentation( doc );
184  m_properties .push_back( p ) ;
185  m_todelete .push_back( p ) ;
186  //
187  return p ;
188 }
189 // ============================================================================
191 // ============================================================================
192 template <class TYPE>
193 inline Property*
195 ( const std::string& name ,
196  SimpleProperty<TYPE>& prop,
197  const std::string& doc )
198 {
199  Property* p = &prop ;
200  //
201  p -> setName ( name ) ;
202  p -> setDocumentation ( doc ) ;
203  m_properties.push_back ( p ) ;
204  //
205  return p ;
206 }
207 // ============================================================================
209 // ============================================================================
210 template <class TYPE>
211 inline Property*
213 ( const std::string& name ,
215  const std::string& doc )
216 {
217  Property* p = &prop ;
218  //
219  p -> setName ( name ) ;
220  p -> setDocumentation ( doc ) ;
221  m_properties.push_back ( p ) ;
222  //
223  return p ;
224 }
225 // ============================================================================
226 // Declare a property (templated)
227 // ============================================================================
228 template<class TYPE>
229 inline Property*
231 ( const std::string& name,
232  ToolHandle<TYPE>& ref,
233  const std::string& doc )
234 {
235  Property* p = new GaudiHandleProperty( name, ref );
236  //
237  p -> setDocumentation ( doc ) ;
238  m_properties . push_back ( p ) ;
239  m_todelete . push_back ( p ) ;
240  //
241  return p ;
242 }
243 // ============================================================================
244 template<class TYPE>
245 inline Property*
247 ( const std::string& name,
248  ServiceHandle<TYPE>& ref,
249  const std::string& doc )
250 {
251  Property* p = new GaudiHandleProperty( name, ref );
252  //
253  p -> setDocumentation ( doc ) ;
254  m_properties . push_back ( p ) ;
255  m_todelete . push_back ( p ) ;
256  //
257  return p ;
258 }
259 // ============================================================================
260 template<class TYPE>
261 inline Property*
263 ( const std::string& name,
265  const std::string& doc )
266 {
267  Property* p = new GaudiHandleArrayProperty( name, ref );
268  //
269  p -> setDocumentation ( doc ) ;
270  m_properties . push_back ( p ) ;
271  m_todelete . push_back ( p ) ;
272  //
273  return p ;
274 }
275 // ============================================================================
276 template<class TYPE>
277 inline Property*
279 ( const std::string& name,
281  const std::string& doc )
282 {
283  Property* p = new GaudiHandleArrayProperty( name, ref );
284  //
285  p -> setDocumentation ( doc ) ;
286  m_properties . push_back ( p ) ;
287  m_todelete . push_back ( p ) ;
288  //
289  return p ;
290 }
291 
292 // ============================================================================
293 // The END
294 // ============================================================================
295 #endif // GAUDIKERNEL_PROPERTYMGR_H
296 // ============================================================================
297 
Handle to be used in lieu of naked pointers to services.
Definition: PropertyMgr.h:25
StatusCode setProperty(IProperty *component, const std::string &name, const TYPE &value, const std::string &doc)
simple function to set the property of the given object from the value
Definition: Property.h:1212
IInterface * m_pOuter
Interface hub reference (ApplicationMgr)
Definition: PropertyMgr.h:169
SimplePropertyRef templated class.
Definition: HistoProperty.h:16
Properties m_todelete
Properties to be deleted.
Definition: PropertyMgr.h:165
Array of Handles to be used in lieu of vector of naked pointers to tools.
Definition: PropertyMgr.h:26
GAUDI_API Property * getProperty(const IProperty *p, const std::string &name)
simple function which gets the property with given name from the component
Definition: Property.cpp:349
Property manager helper class.
Definition: PropertyMgr.h:38
std::vector< bool > m_isOwned
Flag to decide to delete or not a propertyRef.
Definition: PropertyMgr.h:167
SimpleProperty concrete class which implements the full Property interface.
Definition: HistoProperty.h:15
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
Definition: IInterface.h:164
Base class used to implement the interfaces.
Definition: implements.h:133
Interface ID class.
Definition: IInterface.h:55
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:161
RemoteProperties m_remoteProperties
Collection of all declared remote properties.
Definition: PropertyMgr.h:163
Property * declareProperty(const std::string &name, TYPE &value, const std::string &doc="none")
Declare a property (templated)
Definition: PropertyMgr.h:177
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
Definition of the basic interface.
Definition: IInterface.h:160
std::pair< std::string, std::pair< IProperty *, std::string > > RemProperty
Definition: PropertyMgr.h:155
Array of Handles to be used in lieu of vector of naked pointers to tools.
Definition: PropertyMgr.h:27
void setDocumentation(const std::string &documentation)
set the documentation string
Definition: Property.h:92
Handle to be used in lieu of naked pointers to tools.
Definition: PropertyMgr.h:24
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:43
string s
Definition: gaudirun.py:210
std::vector< RemProperty > RemoteProperties
Definition: PropertyMgr.h:156
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:22
#define GAUDI_API
Definition: Kernel.h:108
std::vector< Property * > Properties
Definition: PropertyMgr.h:153