ATLAS Offline Software
CollectionGetterFilterTool.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/CollectionGetterFilterTool.icc
8  * @author scott snyder <snyder@bnl.gov>
9  * @date Dec, 2009
10  * @brief A collection getter that filters the results of another.
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 <class T>
24 CollectionGetterFilterTool<T>::CollectionGetterFilterTool
25  (const std::string& type,
26  const std::string& name,
27  const IInterface* parent)
28  : CollectionGetterFilterToolImpl (type, name, parent)
29 {
30 }
31 
32 
33 /**
34  * @brief Return the element type of the collection.
35  *
36  * I.e., @c nextUntyped returns a pointer to this type.
37  */
38 template <class T>
39 const std::type_info& CollectionGetterFilterTool<T>::elementTypeinfo() const
40 {
41  return typeid (T);
42 }
43 
44 
45 /**
46  * @brief Return a pointer to the next element in the collection.
47  *
48  * Return 0 when the collection has been exhausted.
49  */
50 template <class T>
51 const void* CollectionGetterFilterTool<T>::nextUntyped()
52 {
53  // Loop until the filter passes.
54  while (const T* p = m_getter->next<T>()) {
55  if (filter (p))
56  return p;
57  else
58  m_getter->releaseElement<T> (p);
59  }
60  return 0;
61 }
62 
63 
64 /**
65  * @brief Release an object retrieved from the getter.
66  * @param p The object to release.
67  *
68  * Call this when you are done with the object returned by
69  * @c nextUntyped(). The default implementation is a no-op,
70  * but if the getter dynamically allocated the object which
71  * it returned, this gives it a chance to free it.
72  */
73 template <class T>
74 void CollectionGetterFilterTool<T>::releaseElementUntyped (const void* p)
75 {
76  m_getter->releaseElementUntyped (p);
77 }
78 
79 
80 } // namespace D3PD