Gaudi Framework, version v24r2

Home   Generated: Wed Dec 4 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ToolHandle.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_TOOLHANDLE_H
2 #define GAUDIKERNEL_TOOLHANDLE_H
3 
4 //Includes
7 #include "GaudiKernel/IToolSvc.h"
9 //#include "GaudiKernel/SmartIF.h"
10 
11 #include <string>
12 #include <vector>
13 #include <stdexcept>
14 
15 // forward declarations
16 class IInterface;
17 class IAlgTool;
18 class IToolSvc;
19 
22 protected:
23  ToolHandleInfo( const IInterface* parent = 0, bool createIf = true )
25  {}
26 
27 public:
28  virtual ~ToolHandleInfo() {};
29 
30  bool isPublic() const {
31  return !m_parent;
32  }
33 
34  bool createIf() const {
35  return m_createIf;
36  }
37 
38  const IInterface* parent() const {
39  return m_parent;
40  }
41 
42  //
43  // Some helper functions
44  //
46  return parent ? "PrivateTool" : "PublicTool";
47  }
48 
49  const std::string toolParentName( const IInterface* parent ) const {
50  if (parent) {
51  //SmartIF<INamedInterface> pNamed(const_cast<IInterface*>(parent));
52  //if (pNamed.isValid()) {
53  const INamedInterface* pNamed = dynamic_cast<const INamedInterface*>(parent);
54  if (pNamed) {
55  return pNamed->name();
56  } else {
57  return "";
58  }
59  } else {
60  return "ToolSvc";
61  }
62  }
63 
64 private:
66  bool m_createIf;
67 };
68 
79 template< class T >
80 class ToolHandle : public ToolHandleInfo, public GaudiHandle<T> {
81 public:
82  //
83  // Constructors etc.
84  //
88  ToolHandle( const IInterface* parent = 0, bool createIf = true )
93  m_pToolSvc( "ToolSvc", GaudiHandleBase::parentName() )
94  {}
95 
113  ToolHandle( const std::string& toolTypeAndName, const IInterface* parent = 0, bool createIf = true )
115  GaudiHandle<T>( toolTypeAndName,
118  m_pToolSvc( "ToolSvc", GaudiHandleBase::parentName() )
119  {}
120 
123  StatusCode retrieve() const { // not really const, because it updates m_pObject
124  return GaudiHandle<T>::retrieve();
125  }
126 
129  StatusCode release() const { // not really const, because it updates m_pObject
130  return GaudiHandle<T>::release();
131  }
132 
134  virtual StatusCode retrieve( T*& algTool ) const {
135  return m_pToolSvc->retrieve( GaudiHandleBase::typeAndName(), T::interfaceID(),
136  (IAlgTool*&)(algTool),
138  }
139 
141  virtual StatusCode release( T* algTool ) const {
142  return m_pToolSvc->releaseTool( algTool );
143  }
144 
145 private:
146  //
147  // Private data members
148  //
150 };
151 
162 template < class T >
163 class ToolHandleArray : public ToolHandleInfo, public GaudiHandleArray< ToolHandle<T> > {
164 public:
165  //
166  // Constructors
167  //
175  const IInterface* parent = 0, bool createIf = true )
177  GaudiHandleArray< ToolHandle<T> >( myTypesAndNames,
180  {}
181 
186  ToolHandleArray( const IInterface* parent = 0, bool createIf = true )
190  { }
191 
196  virtual bool push_back( const std::string& toolTypeAndName ) {
197  ToolHandle<T> handle( toolTypeAndName,
201  return true;
202  }
203 
205  virtual bool push_back( const ToolHandle<T>& myHandle ) {
206  return push_back( myHandle.typeAndName() );
207  }
208 
209 };
210 
211 
212 template <class T>
213 inline std::ostream& operator<<( std::ostream& os, const ToolHandle<T>& handle ) {
214  return operator<<(os, static_cast<const GaudiHandleInfo&>(handle) );
215 }
216 
217 
218 template <class T>
219 inline std::ostream& operator<<( std::ostream& os, const ToolHandleArray<T>& handle ) {
220  return operator<<(os, static_cast<const GaudiHandleInfo&>(handle) );
221 }
222 
223 
224 #endif // ! GAUDIKERNEL_TOOLHANDLE_H

Generated at Wed Dec 4 2013 14:33:09 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004