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"
18 
19 // ============================================================================
20 
21 // pre-declaration of GaudiHandles is sufficient
22 template< class T> class ToolHandle;
23 template< class T> class ServiceHandle;
24 template< class T> class ToolHandleArray;
25 template< class T> class ServiceHandleArray;
26 template< class T> class DataObjectHandle;
27 
37 class GAUDI_API PropertyMgr : public implements<IProperty>
38 {
39 public:
41  PropertyMgr ( IInterface* iface = nullptr );
42  // copy constructor
43  PropertyMgr ( const PropertyMgr& ) = delete;
44  // assignment operator
45  PropertyMgr& operator=( const PropertyMgr& ) = delete;
47  ~PropertyMgr() override = default;
48 public:
50  template<class TYPE>
51  Property* declareProperty
52  ( const std::string& name ,
53  TYPE& value,
54  const std::string& doc = "none" ) ;
56  template <class TYPE>
57  Property* declareProperty
58  ( const std::string& name ,
60  const std::string& doc = "none") ;
62  template <class TYPE>
63  Property* declareProperty
64  ( const std::string& name ,
66  const std::string& doc = "none") ;
67  // partial specializations for various GaudiHandles
69  template<class TYPE>
70  Property* declareProperty
71  ( const std::string& name,
73  const std::string& doc = "none" ) ;
75  template<class TYPE>
76  Property* declareProperty
77  ( const std::string& name,
79  const std::string& doc = "none" ) ;
81  template<class TYPE>
82  Property* declareProperty
83  ( const std::string& name,
85  const std::string& doc = "none" ) ;
87  template<class TYPE>
88  Property* declareProperty
89  ( const std::string& name,
91  const std::string& doc = "none" ) ;
93  template<class TYPE>
94  Property* declareProperty
95  ( const std::string& name,
97  const std::string& doc = "none" ) ;
99  Property* declareRemoteProperty
100  ( const std::string& name ,
101  IProperty* rsvc ,
102  const std::string& rname = "" ) ;
103  // ==========================================================================
104  // IProperty implementation
105  // ==========================================================================
109  StatusCode setProperty(const Property& p) override;
110  // ==========================================================================
114  StatusCode setProperty( const std::string& s ) override;
115  // ==========================================================================
119  StatusCode setProperty( const std::string& n, const std::string& v) override;
120  // ==========================================================================
124  StatusCode getProperty(Property* p) const override;
125  // ==========================================================================
129  const Property& getProperty( const std::string& name) const override;
130  // ==========================================================================
134  StatusCode getProperty( const std::string& n, std::string& v ) const override;
135  // ==========================================================================
139  const std::vector<Property*>& getProperties( ) const override;
140  // ==========================================================================
144  bool hasProperty(const std::string& name) const override;
145  // ==========================================================================
146  // IInterface implementation
147  StatusCode queryInterface(const InterfaceID& iid, void** pinterface) override;
148  // ==========================================================================
149 protected:
150 
151  // get local or remote property by name
152  Property* property ( const std::string& name ) const ;
153 
154 private:
155 
157  Property* property
158  ( const std::string& name ,
159  const std::vector<Property*>& props ) const ;
160 
163  void assertUniqueName(const std::string& name) const;
164 
165  // Some typedef to simply typing
167  typedef std::pair<std::string,
170 
172  Properties m_properties ; // local properties
174  RemoteProperties m_remoteProperties; // Remote properties
176  std::vector<std::unique_ptr<Property>> m_todelete ; // properties to be deleted
178  IInterface* m_pOuter ; // Interface hub reference
179 };
180 // ============================================================================
182 // ============================================================================
183 template<class TYPE>
184 inline Property*
186 ( const std::string& name ,
187  TYPE& value,
188  const std::string& doc )
189 {
190  assertUniqueName(name);
191  m_todelete.emplace_back( new SimplePropertyRef<TYPE> ( name , value ) );
192  Property* p = m_todelete.back().get();
193  //
194  p->setDocumentation( doc );
195  m_properties .push_back( p ) ;
196  //
197  return p ;
198 }
199 // ============================================================================
201 // ============================================================================
202 template <class TYPE>
203 inline Property*
205 ( const std::string& name ,
206  SimpleProperty<TYPE>& prop,
207  const std::string& doc )
208 {
209  assertUniqueName(name);
210  Property* p = &prop ;
211  //
212  p -> setName ( name ) ;
213  p -> setDocumentation ( doc ) ;
214  m_properties.push_back ( p ) ;
215  //
216  return p ;
217 }
218 // ============================================================================
220 // ============================================================================
221 template <class TYPE>
222 inline Property*
224 ( const std::string& name ,
226  const std::string& doc )
227 {
228  assertUniqueName(name);
229  Property* p = &prop ;
230  //
231  p -> setName ( name ) ;
232  p -> setDocumentation ( doc ) ;
233  m_properties.push_back ( p ) ;
234  //
235  return p ;
236 }
237 // ============================================================================
238 // Declare a property (templated)
239 // ============================================================================
240 template<class TYPE>
241 inline Property*
243 ( const std::string& name,
245  const std::string& doc )
246 {
247  assertUniqueName(name);
248  m_todelete . emplace_back ( new GaudiHandleProperty( name, ref ) );
249  Property* p = m_todelete.back().get();
250  //
251  p -> setDocumentation ( doc ) ;
252  m_properties . push_back ( p ) ;
253  //
254  return p ;
255 }
256 // ============================================================================
257 template<class TYPE>
258 inline Property*
260 ( const std::string& name,
261  ServiceHandle<TYPE>& ref,
262  const std::string& doc )
263 {
264  assertUniqueName(name);
265  m_todelete . emplace_back (new GaudiHandleProperty( name, ref ));
266  Property* p = m_todelete.back().get();
267  //
268  p -> setDocumentation ( doc ) ;
269  m_properties . push_back ( p ) ;
270  //
271  return p ;
272 }
273 // ============================================================================
274 template<class TYPE>
275 inline Property*
277 ( const std::string& name,
279  const std::string& doc )
280 {
281  assertUniqueName(name);
282  m_todelete . emplace_back ( new GaudiHandleArrayProperty( name, ref ) );
283  Property* p = m_todelete.back().get();
284  //
285  p -> setDocumentation ( doc ) ;
286  m_properties . push_back ( p ) ;
287  //
288  return p ;
289 }
290 // ============================================================================
291 template<class TYPE>
292 inline Property*
294 ( const std::string& name,
296  const std::string& doc )
297 {
298  assertUniqueName(name);
299  m_todelete . emplace_back ( new GaudiHandleArrayProperty( name, ref ) );
300  Property* p = m_todelete.back().get();
301  //
302  p -> setDocumentation ( doc ) ;
303  m_properties . push_back ( p ) ;
304  //
305  return p ;
306 }
307 
308 // ============================================================================
309 template<class TYPE>
310 inline Property*
312 ( const std::string& name,
314  const std::string& doc )
315 {
316  assertUniqueName(name);
317  Property* p = new DataObjectHandleProperty( name, ref );
318  //
319  p -> setDocumentation ( doc ) ;
320  m_properties . push_back ( p ) ;
321  //
322  return p ;
323 }
324 
325 // ============================================================================
326 // The END
327 // ============================================================================
328 #endif // GAUDIKERNEL_PROPERTYMGR_H
329 // ============================================================================
330 
Handle to be used in lieu of naked pointers to services.
Definition: PropertyMgr.h:23
Base class used to implement the interfaces.
Definition: implements.h:9
IInterface * m_pOuter
Interface hub reference (ApplicationMgr)
Definition: PropertyMgr.h:178
SimplePropertyRef templated class.
Definition: HistoProperty.h:14
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:159
void setDocumentation(std::string documentation)
set the documentation string
Definition: Property.h:94
Array of Handles to be used in lieu of vector of naked pointers to tools.
Definition: PropertyMgr.h:24
const char *PyHelper() getProperty(IInterface *p, char *name)
Definition: Bootstrap.cpp:258
Property manager helper class.
Definition: PropertyMgr.h:37
DataObjectHandleProperty.h GaudiKernel/DataObjectHandleProperty.h.
STL class.
SimpleProperty concrete class which implements the full Property interface.
Definition: HistoProperty.h:13
DataObjectHandle.h GaudiKernel/DataObjectHandle.h.
Definition: AlgTool.h:24
implements & operator=(const implements &)
Assignment operator (do not touch the reference count).
Definition: implements.h:38
Interface ID class.
Definition: IInterface.h:30
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:172
RemoteProperties m_remoteProperties
Collection of all declared remote properties.
Definition: PropertyMgr.h:174
Property * declareProperty(const std::string &name, TYPE &value, const std::string &doc="none")
Declare a property (templated)
Definition: PropertyMgr.h:186
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Definition of the basic interface.
Definition: IInterface.h:234
std::pair< std::string, std::pair< IProperty *, std::string > > RemProperty
Definition: PropertyMgr.h:168
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
Definition: Bootstrap.cpp:254
Array of Handles to be used in lieu of vector of naked pointers to tools.
Definition: PropertyMgr.h:25
Handle to be used in lieu of naked pointers to tools.
Definition: PropertyMgr.h:22
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
string s
Definition: gaudirun.py:245
StatusCode queryInterface(const InterfaceID &ti, void **pp) override
Implementation of IInterface::queryInterface.
Definition: implements.h:22
std::vector< RemProperty > RemoteProperties
Definition: PropertyMgr.h:169
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:21
#define GAUDI_API
Definition: Kernel.h:107
std::vector< Property * > Properties
Definition: PropertyMgr.h:166
std::vector< std::unique_ptr< Property > > m_todelete
Properties to be deleted.
Definition: PropertyMgr.h:176