PropertyMgr.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_PROPERTYMGR_H
2 #define GAUDIKERNEL_PROPERTYMGR_H
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // STD & STL
7 // ============================================================================
8 #include <iostream>
9 #include <vector>
10 #include <utility>
11 #include <stdexcept>
12 // ============================================================================
13 // GaudiKernel
14 // ============================================================================
15 #include "GaudiKernel/Property.h"
16 #include "GaudiKernel/IProperty.h"
17 // ============================================================================
18 
19 // pre-declaration of GaudiHandles is sufficient
20 template< class T> class ToolHandle;
21 template< class T> class ServiceHandle;
22 template< class T> class ToolHandleArray;
23 template< class T> class ServiceHandleArray;
24 
34 class GAUDI_API PropertyMgr : public implements1<IProperty>
35 {
36 public:
38  PropertyMgr ( IInterface* iface = 0 );
39  // copy constructor
40  PropertyMgr ( const PropertyMgr& ) ;
42  virtual ~PropertyMgr();
43  // assignment operator
44  PropertyMgr& operator=( const PropertyMgr& ) ;
45 public:
47  template<class TYPE>
48  Property* declareProperty
49  ( const std::string& name ,
50  TYPE& value,
51  const std::string& doc = "none" ) ;
53  template <class TYPE>
54  Property* declareProperty
55  ( const std::string& name ,
57  const std::string& doc = "none") ;
59  template <class TYPE>
60  Property* declareProperty
61  ( const std::string& name ,
63  const std::string& doc = "none") ;
64  // partial specializations for various GaudiHandles
66  template<class TYPE>
67  Property* declareProperty
68  ( const std::string& name,
69  ToolHandle<TYPE>& ref,
70  const std::string& doc = "none" ) ;
72  template<class TYPE>
73  Property* declareProperty
74  ( const std::string& name,
76  const std::string& doc = "none" ) ;
78  template<class TYPE>
79  Property* declareProperty
80  ( const std::string& name,
82  const std::string& doc = "none" ) ;
84  template<class TYPE>
85  Property* declareProperty
86  ( const std::string& name,
88  const std::string& doc = "none" ) ;
90  Property* declareRemoteProperty
91  ( const std::string& name ,
92  IProperty* rsvc ,
93  const std::string& rname = "" ) ;
94  // ==========================================================================
95  // IProperty implementation
96  // ==========================================================================
100  StatusCode setProperty(const Property& p);
101  // ==========================================================================
105  StatusCode setProperty( const std::string& s );
106  // ==========================================================================
110  StatusCode setProperty( const std::string& n, const std::string& v);
111  // ==========================================================================
115  StatusCode getProperty(Property* p) const;
116  // ==========================================================================
120  const Property& getProperty( const std::string& name) const;
121  // ==========================================================================
125  StatusCode getProperty( const std::string& n, std::string& v ) const;
126  // ==========================================================================
130  const std::vector<Property*>& getProperties( ) const;
131  // ==========================================================================
135  bool hasProperty(const std::string& name) const;
136  // ==========================================================================
137  // IInterface implementation
138  StatusCode queryInterface(const InterfaceID& iid, void** pinterface);
139  // ==========================================================================
140 protected:
141 
142  // get local or remote property by name
143  Property* property ( const std::string& name ) const ;
144 
145 private:
147  Property* property
148  ( const std::string& name ,
149  const std::vector<Property*>& props ) const ;
150 
153  void assertUniqueName(const std::string& name) const;
154 
155 private:
156 
157  // Some typedef to simply typing
158  typedef std::vector<Property*> Properties ;
159  typedef std::pair<std::string,
160  std::pair<IProperty*, std::string> > RemProperty;
161  typedef std::vector<RemProperty> RemoteProperties ;
162 
163 private:
164 
166  Properties m_properties ; // local properties
168  RemoteProperties m_remoteProperties; // Remote properties
170  Properties m_todelete ; // properties to be deleted
172  std::vector<bool> m_isOwned ; // flag to delete
174  IInterface* m_pOuter ; // Interface hub reference
175 };
176 // ============================================================================
178 // ============================================================================
179 template<class TYPE>
180 inline Property*
182 ( const std::string& name ,
183  TYPE& value,
184  const std::string& doc )
185 {
186  assertUniqueName(name);
187  Property* p = new SimplePropertyRef<TYPE> ( name , value ) ;
188  //
189  p->setDocumentation( doc );
190  m_properties .push_back( p ) ;
191  m_todelete .push_back( p ) ;
192  //
193  return p ;
194 }
195 // ============================================================================
197 // ============================================================================
198 template <class TYPE>
199 inline Property*
201 ( const std::string& name ,
202  SimpleProperty<TYPE>& prop,
203  const std::string& doc )
204 {
205  assertUniqueName(name);
206  Property* p = &prop ;
207  //
208  p -> setName ( name ) ;
209  p -> setDocumentation ( doc ) ;
210  m_properties.push_back ( p ) ;
211  //
212  return p ;
213 }
214 // ============================================================================
216 // ============================================================================
217 template <class TYPE>
218 inline Property*
220 ( const std::string& name ,
222  const std::string& doc )
223 {
224  assertUniqueName(name);
225  Property* p = &prop ;
226  //
227  p -> setName ( name ) ;
228  p -> setDocumentation ( doc ) ;
229  m_properties.push_back ( p ) ;
230  //
231  return p ;
232 }
233 // ============================================================================
234 // Declare a property (templated)
235 // ============================================================================
236 template<class TYPE>
237 inline Property*
239 ( const std::string& name,
240  ToolHandle<TYPE>& ref,
241  const std::string& doc )
242 {
243  assertUniqueName(name);
244  Property* p = new GaudiHandleProperty( name, ref );
245  //
246  p -> setDocumentation ( doc ) ;
247  m_properties . push_back ( p ) ;
248  m_todelete . push_back ( p ) ;
249  //
250  return p ;
251 }
252 // ============================================================================
253 template<class TYPE>
254 inline Property*
256 ( const std::string& name,
257  ServiceHandle<TYPE>& ref,
258  const std::string& doc )
259 {
260  assertUniqueName(name);
261  Property* p = new GaudiHandleProperty( name, ref );
262  //
263  p -> setDocumentation ( doc ) ;
264  m_properties . push_back ( p ) ;
265  m_todelete . push_back ( p ) ;
266  //
267  return p ;
268 }
269 // ============================================================================
270 template<class TYPE>
271 inline Property*
273 ( const std::string& name,
275  const std::string& doc )
276 {
277  assertUniqueName(name);
278  Property* p = new GaudiHandleArrayProperty( name, ref );
279  //
280  p -> setDocumentation ( doc ) ;
281  m_properties . push_back ( p ) ;
282  m_todelete . push_back ( p ) ;
283  //
284  return p ;
285 }
286 // ============================================================================
287 template<class TYPE>
288 inline Property*
290 ( const std::string& name,
292  const std::string& doc )
293 {
294  assertUniqueName(name);
295  Property* p = new GaudiHandleArrayProperty( name, ref );
296  //
297  p -> setDocumentation ( doc ) ;
298  m_properties . push_back ( p ) ;
299  m_todelete . push_back ( p ) ;
300  //
301  return p ;
302 }
303 
304 // ============================================================================
305 // The END
306 // ============================================================================
307 #endif // GAUDIKERNEL_PROPERTYMGR_H
308 // ============================================================================
309 
Handle to be used in lieu of naked pointers to services.
Definition: PropertyMgr.h:21
IInterface * m_pOuter
Interface hub reference (ApplicationMgr)
Definition: PropertyMgr.h:174
SimplePropertyRef templated class.
Definition: HistoProperty.h:16
GAUDI_API bool hasProperty(const IProperty *p, const std::string &name)
simple function which check the existence of the property with the given name.
Definition: Property.cpp:232
Properties m_todelete
Properties to be deleted.
Definition: PropertyMgr.h:170
Array of Handles to be used in lieu of vector of naked pointers to tools.
Definition: PropertyMgr.h:22
const char *PyHelper() getProperty(IInterface *p, char *name)
Definition: Bootstrap.cpp:297
Property manager helper class.
Definition: PropertyMgr.h:34
std::vector< bool > m_isOwned
Flag to decide to delete or not a propertyRef.
Definition: PropertyMgr.h:172
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:166
RemoteProperties m_remoteProperties
Collection of all declared remote properties.
Definition: PropertyMgr.h:168
Property * declareProperty(const std::string &name, TYPE &value, const std::string &doc="none")
Declare a property (templated)
Definition: PropertyMgr.h:182
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:160
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
Definition: Bootstrap.cpp:290
Array of Handles to be used in lieu of vector of naked pointers to tools.
Definition: PropertyMgr.h:23
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:20
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:43
string s
Definition: gaudirun.py:217
std::vector< RemProperty > RemoteProperties
Definition: PropertyMgr.h:161
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:158