ATLAS Offline Software
Loading...
Searching...
No Matches
ArenaHandleBaseT.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: ArenaHandleBaseT.icc 470529 2011-11-24 23:54:22Z ssnyder $
6/**
7 * @file AthAllocators/ArenaHandleBaseT.icc
8 * @author scott snyder
9 * @date May 2007
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.
13 */
14
15
16namespace SG {
17
18
19/**
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.
24 */
25template <typename T, typename ALLOC>
26ArenaHandleBaseT<T, ALLOC>::ArenaHandleBaseT (ArenaHeader* header,
27 size_t index)
28 : Base (header, index)
29{
30}
31
32
33/**
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.
39 */
40template <typename T, typename ALLOC>
41ArenaHandleBaseT<T, ALLOC>::ArenaHandleBaseT (ArenaHeader* header,
42 const EventContext& ctx,
43 size_t index)
44 : Base (header, ctx, index)
45{
46}
47
48
49/**
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.
53 */
54template <typename T, typename ALLOC>
55ArenaHandleBaseT<T, ALLOC>::ArenaHandleBaseT (ArenaBase* arena, size_t index)
56 : Base (arena, index)
57{
58}
59
60
61/**
62 * @brief Constructor.
63 * @param it The base iterator.
64 */
65template <typename T, typename ALLOC>
66inline
67ArenaHandleBaseT<T, ALLOC>::iterator::iterator
68 (const typename ALLOC::iterator& it)
69 : iterator::iterator_adaptor_ (it)
70{
71}
72
73
74/**
75 * @brief Dereference the iterator.
76 */
77template <typename T, typename ALLOC>
78inline
79typename ArenaHandleBaseT<T, ALLOC>::iterator::reference
80ArenaHandleBaseT<T, ALLOC>::iterator::dereference() const
81{
82 return reinterpret_cast<T&> (*this->base_reference());
83}
84
85
86/**
87 * @brief Constructor.
88 * @param it The base iterator.
89 */
90template <typename T, typename ALLOC>
91inline
92ArenaHandleBaseT<T, ALLOC>::const_iterator::const_iterator
93 (const typename ALLOC::const_iterator& it)
94 : const_iterator::iterator_adaptor_ (it)
95{
96}
97
98
99/**
100 * @brief Constructor from a non-const iterator.
101 * @param it The non-const iterator.
102 */
103template <typename T, typename ALLOC>
104inline
105ArenaHandleBaseT<T, ALLOC>::const_iterator::const_iterator
106 (const iterator& it)
107 : const_iterator::iterator_adaptor_ (it.base_reference())
108{
109}
110
111
112/**
113 * @brief Dereference the iterator.
114 */
115template <typename T, typename ALLOC>
116inline
117typename ArenaHandleBaseT<T, ALLOC>::const_iterator::reference
118ArenaHandleBaseT<T, ALLOC>::const_iterator::dereference() const
119{
120 return reinterpret_cast<const T&> (*this->base_reference());
121}
122
123
124/**
125 * @brief Starting iterator.
126 *
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.
131 */
132template <class T, class ALLOC>
133typename ArenaHandleBaseT<T, ALLOC>::iterator
134ArenaHandleBaseT<T, ALLOC>::begin()
135{
136 return const_cast<ALLOC*>(this->allocator())->begin();
137}
138
139
140/**
141 * @brief Starting const iterator.
142 *
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.
147 */
148template <class T, class ALLOC>
149typename ArenaHandleBaseT<T, ALLOC>::const_iterator
150ArenaHandleBaseT<T, ALLOC>::begin() const
151{
152 return this->allocator()->begin();
153}
154
155
156/**
157 * @brief Ending iterator.
158 *
159 * This may only be instantiated if the underlying Allocator
160 * supports iterators.
161 */
162template <class T, class ALLOC>
163typename ArenaHandleBaseT<T, ALLOC>::iterator
164ArenaHandleBaseT<T, ALLOC>::end()
165{
166 return this->allocator()->end();
167}
168
169
170/**
171 * @brief Ending const iterator.
172 *
173 * This may only be instantiated if the underlying Allocator
174 * supports iterators.
175 */
176template <class T, class ALLOC>
177typename ArenaHandleBaseT<T, ALLOC>::const_iterator
178ArenaHandleBaseT<T, ALLOC>::end() const
179{
180 return const_cast<const ALLOC*>(this->allocator())->end();
181}
182
183
184/**
185 * @brief Free an element.
186 * @param p The element to be freed.
187 *
188 * @c clear() will be called on the element at this point,
189 * if it has been defined.
190 *
191 * This may only be instantiated if it's supported
192 * by the underlying Allocator.
193 */
194template <class T, class ALLOC>
195inline
196void ArenaHandleBaseT<T, ALLOC>::free (pointer p)
197{
198 this->allocator()->free
199 (reinterpret_cast<typename ALLOC::pointer>(p));
200}
201
202
203/**
204 * @brief Reset pool back to a previous state.
205 * @param p The pointer back to which to reset.
206 *
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.
209 *
210 * This may only be instantiated if it's supported
211 * by the underlying Allocator.
212 */
213template <class T, class ALLOC>
214void ArenaHandleBaseT<T, ALLOC>::resetTo(pointer p)
215{
216 return this->allocator()->resetTo
217 (reinterpret_cast<typename ALLOC::pointer>(p));
218}
219
220
221} // namespace SG