2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5 // $Id: ArenaHandleBaseT.icc 470529 2011-11-24 23:54:22Z ssnyder $
7 * @file AthAllocators/ArenaHandleBaseT.icc
10 * @brief Base class for @c Handle classes, containing parts that
11 * are independent of how the Allocator gets created.
12 * Inline and template implementations.
20 * @brief Constructor, passing in an index.
21 * @param header The group of Arenas which this Handle may reference.
22 * May be null to select the global default.
23 * @param index The index of this Handle's Allocator type.
25 template <typename T, typename ALLOC>
26 ArenaHandleBaseT<T, ALLOC>::ArenaHandleBaseT (ArenaHeader* header,
28 : Base (header, index)
34 * @brief Constructor, passing in an index, for a specific event slot.
35 * @param header The group of Arenas which this Handle may reference.
36 * May be null to select the global default.
37 * @param ctx Event context identifying the event slot.
38 * @param index The index of this Handle's Allocator type.
40 template <typename T, typename ALLOC>
41 ArenaHandleBaseT<T, ALLOC>::ArenaHandleBaseT (ArenaHeader* header,
42 const EventContext& ctx,
44 : Base (header, ctx, index)
50 * @brief Constructor, passing in an index, for a specific Arena.
51 * @param arena The Arena in which to find the allocator.
52 * @param index The index of this Handle's Allocator type.
54 template <typename T, typename ALLOC>
55 ArenaHandleBaseT<T, ALLOC>::ArenaHandleBaseT (ArenaBase* arena, size_t index)
63 * @param it The base iterator.
65 template <typename T, typename ALLOC>
67 ArenaHandleBaseT<T, ALLOC>::iterator::iterator
68 (const typename ALLOC::iterator& it)
69 : iterator::iterator_adaptor_ (it)
75 * @brief Dereference the iterator.
77 template <typename T, typename ALLOC>
79 typename ArenaHandleBaseT<T, ALLOC>::iterator::reference
80 ArenaHandleBaseT<T, ALLOC>::iterator::dereference() const
82 return reinterpret_cast<T&> (*this->base_reference());
88 * @param it The base iterator.
90 template <typename T, typename ALLOC>
92 ArenaHandleBaseT<T, ALLOC>::const_iterator::const_iterator
93 (const typename ALLOC::const_iterator& it)
94 : const_iterator::iterator_adaptor_ (it)
100 * @brief Constructor from a non-const iterator.
101 * @param it The non-const iterator.
103 template <typename T, typename ALLOC>
105 ArenaHandleBaseT<T, ALLOC>::const_iterator::const_iterator
107 : const_iterator::iterator_adaptor_ (it.base_reference())
113 * @brief Dereference the iterator.
115 template <typename T, typename ALLOC>
117 typename ArenaHandleBaseT<T, ALLOC>::const_iterator::reference
118 ArenaHandleBaseT<T, ALLOC>::const_iterator::dereference() const
120 return reinterpret_cast<const T&> (*this->base_reference());
125 * @brief Starting iterator.
127 * This will iterate over all allocated elements (in unspecified order).
128 * It is at least a @c forward_iterator.
129 * This may only be instantiated if the underlying Allocator
130 * supports iterators.
132 template <class T, class ALLOC>
133 typename ArenaHandleBaseT<T, ALLOC>::iterator
134 ArenaHandleBaseT<T, ALLOC>::begin()
136 return const_cast<ALLOC*>(this->allocator())->begin();
141 * @brief Starting const iterator.
143 * This will iterate over all allocated elements (in unspecified order).
144 * It is at least a @c forward_iterator.
145 * This may only be instantiated if the underlying Allocator
146 * supports iterators.
148 template <class T, class ALLOC>
149 typename ArenaHandleBaseT<T, ALLOC>::const_iterator
150 ArenaHandleBaseT<T, ALLOC>::begin() const
152 return this->allocator()->begin();
157 * @brief Ending iterator.
159 * This may only be instantiated if the underlying Allocator
160 * supports iterators.
162 template <class T, class ALLOC>
163 typename ArenaHandleBaseT<T, ALLOC>::iterator
164 ArenaHandleBaseT<T, ALLOC>::end()
166 return this->allocator()->end();
171 * @brief Ending const iterator.
173 * This may only be instantiated if the underlying Allocator
174 * supports iterators.
176 template <class T, class ALLOC>
177 typename ArenaHandleBaseT<T, ALLOC>::const_iterator
178 ArenaHandleBaseT<T, ALLOC>::end() const
180 return const_cast<const ALLOC*>(this->allocator())->end();
185 * @brief Free an element.
186 * @param p The element to be freed.
188 * @c clear() will be called on the element at this point,
189 * if it has been defined.
191 * This may only be instantiated if it's supported
192 * by the underlying Allocator.
194 template <class T, class ALLOC>
196 void ArenaHandleBaseT<T, ALLOC>::free (pointer p)
198 this->allocator()->free
199 (reinterpret_cast<typename ALLOC::pointer>(p));
204 * @brief Reset pool back to a previous state.
205 * @param p The pointer back to which to reset.
207 * This will free (a la @c reset) the element @c p and all elements
208 * that have been allocated after it from this allocator.
210 * This may only be instantiated if it's supported
211 * by the underlying Allocator.
213 template <class T, class ALLOC>
214 void ArenaHandleBaseT<T, ALLOC>::resetTo(pointer p)
216 return this->allocator()->resetTo
217 (reinterpret_cast<typename ALLOC::pointer>(p));