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 = nullptr );
39  // copy constructor
40  PropertyMgr ( const PropertyMgr& ) = delete;
41  // assignment operator
42  PropertyMgr& operator=( const PropertyMgr& ) = delete;
44  ~PropertyMgr() override = default;
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) override;
101  // ==========================================================================
105  StatusCode setProperty( const std::string& s ) override;
106  // ==========================================================================
110  StatusCode setProperty( const std::string& n, const std::string& v) override;
111  // ==========================================================================
115  StatusCode getProperty(Property* p) const override;
116  // ==========================================================================
120  const Property& getProperty( const std::string& name) const override;
121  // ==========================================================================
125  StatusCode getProperty( const std::string& n, std::string& v ) const override;
126  // ==========================================================================
130  const std::vector<Property*>& getProperties( ) const override;
131  // ==========================================================================
135  bool hasProperty(const std::string& name) const override;
136  // ==========================================================================
137  // IInterface implementation
138  StatusCode queryInterface(const InterfaceID& iid, void** pinterface) override;
139  // ==========================================================================
140 protected:
141 
142  // get local or remote property by name
143  Property* property ( const std::string& name ) const ;
144 
145 private:
146 
148  Property* property
149  ( const std::string& name ,
150  const std::vector<Property*>& props ) const ;
151 
154  void assertUniqueName(const std::string& name) const;
155 
156  // Some typedef to simply typing
157  typedef std::vector<Property*> Properties ;
158  typedef std::pair<std::string,
159  std::pair<IProperty*, std::string> > RemProperty;
160  typedef std::vector<RemProperty> RemoteProperties ;
161 
163  Properties m_properties ; // local properties
165  RemoteProperties m_remoteProperties; // Remote properties
167  std::vector<std::unique_ptr<Property>> m_todelete ; // properties to be deleted
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  assertUniqueName(name);
182  m_todelete.emplace_back( new SimplePropertyRef<TYPE> ( name , value ) );
183  Property* p = m_todelete.back().get();
184  //
185  p->setDocumentation( doc );
186  m_properties .push_back( p ) ;
187  //
188  return p ;
189 }
190 // ============================================================================
192 // ============================================================================
193 template <class TYPE>
194 inline Property*
196 ( const std::string& name ,
197  SimpleProperty<TYPE>& prop,
198  const std::string& doc )
199 {
200  assertUniqueName(name);
201  Property* p = &prop ;
202  //
203  p -> setName ( name ) ;
204  p -> setDocumentation ( doc ) ;
205  m_properties.push_back ( p ) ;
206  //
207  return p ;
208 }
209 // ============================================================================
211 // ============================================================================
212 template <class TYPE>
213 inline Property*
215 ( const std::string& name ,
217  const std::string& doc )
218 {
219  assertUniqueName(name);
220  Property* p = &prop ;
221  //
222  p -> setName ( name ) ;
223  p -> setDocumentation ( doc ) ;
224  m_properties.push_back ( p ) ;
225  //
226  return p ;
227 }
228 // ============================================================================
229 // Declare a property (templated)
230 // ============================================================================
231 template<class TYPE>
232 inline Property*
234 ( const std::string& name,
235  ToolHandle<TYPE>& ref,
236  const std::string& doc )
237 {
238  assertUniqueName(name);
239  m_todelete . emplace_back ( new GaudiHandleProperty( name, ref ) );
240  Property* p = m_todelete.back().get();
241  //
242  p -> setDocumentation ( doc ) ;
243  m_properties . push_back ( p ) ;
244  //
245  return p ;
246 }
247 // ============================================================================
248 template<class TYPE>
249 inline Property*
251 ( const std::string& name,
252  ServiceHandle<TYPE>& ref,
253  const std::string& doc )
254 {
255  assertUniqueName(name);
256  m_todelete . emplace_back (new GaudiHandleProperty( name, ref ));
257  Property* p = m_todelete.back().get();
258  //
259  p -> setDocumentation ( doc ) ;
260  m_properties . push_back ( p ) ;
261  //
262  return p ;
263 }
264 // ============================================================================
265 template<class TYPE>
266 inline Property*
268 ( const std::string& name,
270  const std::string& doc )
271 {
272  assertUniqueName(name);
273  m_todelete . emplace_back ( new GaudiHandleArrayProperty( name, ref ) );
274  Property* p = m_todelete.back().get();
275  //
276  p -> setDocumentation ( doc ) ;
277  m_properties . push_back ( p ) ;
278  //
279  return p ;
280 }
281 // ============================================================================
282 template<class TYPE>
283 inline Property*
285 ( const std::string& name,
287  const std::string& doc )
288 {
289  assertUniqueName(name);
290  m_todelete . emplace_back ( new GaudiHandleArrayProperty( name, ref ) );
291  Property* p = m_todelete.back().get();
292  //
293  p -> setDocumentation ( doc ) ;
294  m_properties . push_back ( p ) ;
295  //
296  return p ;
297 }
298 
299 // ============================================================================
300 // The END
301 // ============================================================================
302 #endif // GAUDIKERNEL_PROPERTYMGR_H
303 // ============================================================================
304 
Handle to be used in lieu of naked pointers to services.
Definition: PropertyMgr.h:21
Base class used to implement the interfaces.
Definition: implements.h:8
#define GAUDI_API
Definition: Kernel.h:107
SimplePropertyRef templated class.
Definition: HistoProperty.h:14
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:22
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:157
const char *PyHelper() getProperty(IInterface *p, char *name)
Definition: Bootstrap.cpp:259
Property manager helper class.
Definition: PropertyMgr.h:34
IInterface * m_pOuter
Interface hub reference (ApplicationMgr)
Definition: PropertyMgr.h:169
SimpleProperty concrete class which implements the full Property interface.
Definition: HistoProperty.h:13
implements & operator=(const implements &)
Assignment operator (do not touch the reference count).
Definition: implements.h:37
Interface ID class.
Definition: IInterface.h:30
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:163
RemoteProperties m_remoteProperties
Collection of all declared remote properties.
Definition: PropertyMgr.h:165
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:26
Definition of the basic interface.
Definition: IInterface.h:234
std::pair< std::string, std::pair< IProperty *, std::string > > RemProperty
Definition: PropertyMgr.h:159
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
Definition: Bootstrap.cpp:255
Array of Handles to be used in lieu of vector of naked pointers to tools.
Definition: PropertyMgr.h:23
Handle to be used in lieu of naked pointers to tools.
Definition: PropertyMgr.h:20
std::vector< std::unique_ptr< Property > > m_todelete
Properties to be deleted.
Definition: PropertyMgr.h:167
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
string s
Definition: gaudirun.py:246
StatusCode queryInterface(const InterfaceID &ti, void **pp) override
Implementation of IInterface::queryInterface.
Definition: implements.h:21
std::vector< RemProperty > RemoteProperties
Definition: PropertyMgr.h:160
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:21
std::vector< Property * > Properties
Definition: PropertyMgr.h:157