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