ATLAS Offline Software
SingleAssociationTool.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id$
6 /**
7  * @file D3PDMakerUtils/SingleAssociationTool.icc
8  * @author scott snyder <snyder@bnl.gov>
9  * @date Aug, 2009
10  * @brief Type-safe wrapper for single associator tools.
11  */
12 
13 
14 namespace D3PD {
15 
16 
17 /**
18  * @brief Standard Gaudi tool constructor.
19  * @param type The name of the tool type.
20  * @param name The tool name.
21  * @param parent The tool's Gaudi parent.
22  */
23 template <typename TO_T>
24 SingleAssociationToolTo<TO_T>::SingleAssociationToolTo
25  (const std::string& type,
26  const std::string& name,
27  const IInterface* parent)
28  : SingleAssociationToolImpl (type, name, parent)
29 {
30 }
31 
32 
33 /**
34  * @brief Return the type of object retrieved by this tool.
35  */
36 template <typename TO_T>
37 const std::type_info&
38 SingleAssociationToolTo<TO_T>::typeinfo () const
39 {
40  return typeid (TO_T);
41 }
42 
43 
44 /**
45  * @brief Release an object retrieved from the association.
46  * @param p The object to release.
47  *
48  * Call this when you are done with the object returned by
49  * @c get(). The default implementation is a no-op,
50  * but if the association dynamically allocated the object which
51  * it returned, this gives it a chance to free it.
52  */
53 template <typename TO_T>
54 void
55 SingleAssociationToolTo<TO_T>::releaseObject (const typename SelectType<TO_T, 0>::type* /*p*/)
56 {
57 }
58 
59 
60 /**
61  * @brief Release an object retrieved from the association.
62  * @param p The object to release.
63  *
64  * Call this when you are done with the object returned by
65  * @c getUntyped(). The default implementation is a no-op,
66  * but if the association dynamically allocated the object which
67  * it returned, this gives it a chance to free it.
68  */
69 template <typename TO_T>
70 void
71 SingleAssociationToolTo<TO_T>::releaseObjectUntyped (const void* p)
72 {
73  releaseObject (reinterpret_cast<const typename SelectType<TO_T, 0>::type*> (p));
74 }
75 
76 
77 //=========================================================================
78 
79 
80 /**
81  * @brief Standard Gaudi tool constructor.
82  * @param type The name of the tool type.
83  * @param name The tool name.
84  * @param parent The tool's Gaudi parent.
85  */
86 template <typename FROM_T, typename TO_T>
87 SingleAssociationTool<FROM_T, TO_T>::SingleAssociationTool
88  (const std::string& type,
89  const std::string& name,
90  const IInterface* parent)
91  : SingleAssociationToolTo<TO_T> (type, name, parent)
92 {
93 }
94 
95 
96 /**
97  * @brief Return the target object.
98  * @param p The source object for the association.
99  *
100  * Return the target of the association, or 0.
101  * Should be of the type given by @c typeinfo.
102  */
103 template <typename FROM_T, typename TO_T>
104 const void*
105 SingleAssociationTool<FROM_T, TO_T>::getUntyped (const void* p)
106 {
107  const FROM_T* pp =
108  reinterpret_cast<const FROM_T*> (this->doConversion (p));
109  if (!pp) return 0;
110  return get (*pp);
111 }
112 
113 
114 /**
115  * @brief Return the @c std::type_info for the source of the association.
116  */
117 template <typename FROM_T, typename TO_T>
118 const std::type_info&
119 SingleAssociationTool<FROM_T, TO_T>::fromTypeinfo () const
120 {
121  return typeid (FROM_T);
122 }
123 
124 
125 } // namespace D3PD