xref: /aosp_15_r20/external/deqp/framework/delibs/decpp/dePoolArray.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker #ifndef _DEPOOLARRAY_HPP
2*35238bceSAndroid Build Coastguard Worker #define _DEPOOLARRAY_HPP
3*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  * drawElements C++ Base Library
5*35238bceSAndroid Build Coastguard Worker  * -----------------------------
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
8*35238bceSAndroid Build Coastguard Worker  *
9*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
10*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
11*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
14*35238bceSAndroid Build Coastguard Worker  *
15*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
16*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
17*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
19*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
20*35238bceSAndroid Build Coastguard Worker  *
21*35238bceSAndroid Build Coastguard Worker  *//*!
22*35238bceSAndroid Build Coastguard Worker  * \file
23*35238bceSAndroid Build Coastguard Worker  * \brief Array template backed by memory pool.
24*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
25*35238bceSAndroid Build Coastguard Worker 
26*35238bceSAndroid Build Coastguard Worker #include "deDefs.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "deMemPool.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "deInt32.h"
29*35238bceSAndroid Build Coastguard Worker 
30*35238bceSAndroid Build Coastguard Worker #include <iterator>
31*35238bceSAndroid Build Coastguard Worker 
32*35238bceSAndroid Build Coastguard Worker namespace de
33*35238bceSAndroid Build Coastguard Worker {
34*35238bceSAndroid Build Coastguard Worker 
35*35238bceSAndroid Build Coastguard Worker //! Self-test for PoolArray
36*35238bceSAndroid Build Coastguard Worker void PoolArray_selfTest(void);
37*35238bceSAndroid Build Coastguard Worker 
38*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
39*35238bceSAndroid Build Coastguard Worker class PoolArrayConstIterator;
40*35238bceSAndroid Build Coastguard Worker 
41*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
42*35238bceSAndroid Build Coastguard Worker class PoolArrayIterator;
43*35238bceSAndroid Build Coastguard Worker 
44*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
45*35238bceSAndroid Build Coastguard Worker  * \brief Array template backed by memory pool
46*35238bceSAndroid Build Coastguard Worker  *
47*35238bceSAndroid Build Coastguard Worker  * \note Memory in PoolArray is not contiguous so pointer arithmetic
48*35238bceSAndroid Build Coastguard Worker  *       to access next element(s) doesn't work.
49*35238bceSAndroid Build Coastguard Worker  * \todo [2013-02-11 pyry] Make elements per page template argument.
50*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
51*35238bceSAndroid Build Coastguard Worker template <typename T,
52*35238bceSAndroid Build Coastguard Worker           uint32_t Alignment = (sizeof(T) > sizeof(void *) ? (uint32_t)sizeof(void *) : (uint32_t)sizeof(T))>
53*35238bceSAndroid Build Coastguard Worker class PoolArray
54*35238bceSAndroid Build Coastguard Worker {
55*35238bceSAndroid Build Coastguard Worker public:
56*35238bceSAndroid Build Coastguard Worker     typedef PoolArrayIterator<T, Alignment> Iterator;
57*35238bceSAndroid Build Coastguard Worker     typedef PoolArrayConstIterator<T, Alignment> ConstIterator;
58*35238bceSAndroid Build Coastguard Worker 
59*35238bceSAndroid Build Coastguard Worker     typedef Iterator iterator;
60*35238bceSAndroid Build Coastguard Worker     typedef ConstIterator const_iterator;
61*35238bceSAndroid Build Coastguard Worker 
62*35238bceSAndroid Build Coastguard Worker     explicit PoolArray(MemPool *pool);
63*35238bceSAndroid Build Coastguard Worker     PoolArray(MemPool *pool, const PoolArray<T, Alignment> &other);
64*35238bceSAndroid Build Coastguard Worker     ~PoolArray(void);
65*35238bceSAndroid Build Coastguard Worker 
66*35238bceSAndroid Build Coastguard Worker     void clear(void);
67*35238bceSAndroid Build Coastguard Worker 
68*35238bceSAndroid Build Coastguard Worker     void reserve(uintptr_t capacity);
69*35238bceSAndroid Build Coastguard Worker     void resize(uintptr_t size);
70*35238bceSAndroid Build Coastguard Worker     void resize(uintptr_t size, const T &value);
71*35238bceSAndroid Build Coastguard Worker 
size(void) const72*35238bceSAndroid Build Coastguard Worker     uintptr_t size(void) const
73*35238bceSAndroid Build Coastguard Worker     {
74*35238bceSAndroid Build Coastguard Worker         return m_numElements;
75*35238bceSAndroid Build Coastguard Worker     }
empty(void) const76*35238bceSAndroid Build Coastguard Worker     bool empty(void) const
77*35238bceSAndroid Build Coastguard Worker     {
78*35238bceSAndroid Build Coastguard Worker         return m_numElements == 0;
79*35238bceSAndroid Build Coastguard Worker     }
80*35238bceSAndroid Build Coastguard Worker 
81*35238bceSAndroid Build Coastguard Worker     void pushBack(const T &value);
82*35238bceSAndroid Build Coastguard Worker     T popBack(void);
83*35238bceSAndroid Build Coastguard Worker 
at(intptr_t ndx) const84*35238bceSAndroid Build Coastguard Worker     const T &at(intptr_t ndx) const
85*35238bceSAndroid Build Coastguard Worker     {
86*35238bceSAndroid Build Coastguard Worker         return *getPtr(ndx);
87*35238bceSAndroid Build Coastguard Worker     }
at(intptr_t ndx)88*35238bceSAndroid Build Coastguard Worker     T &at(intptr_t ndx)
89*35238bceSAndroid Build Coastguard Worker     {
90*35238bceSAndroid Build Coastguard Worker         return *getPtr(ndx);
91*35238bceSAndroid Build Coastguard Worker     }
92*35238bceSAndroid Build Coastguard Worker 
operator [](intptr_t ndx) const93*35238bceSAndroid Build Coastguard Worker     const T &operator[](intptr_t ndx) const
94*35238bceSAndroid Build Coastguard Worker     {
95*35238bceSAndroid Build Coastguard Worker         return at(ndx);
96*35238bceSAndroid Build Coastguard Worker     }
operator [](intptr_t ndx)97*35238bceSAndroid Build Coastguard Worker     T &operator[](intptr_t ndx)
98*35238bceSAndroid Build Coastguard Worker     {
99*35238bceSAndroid Build Coastguard Worker         return at(ndx);
100*35238bceSAndroid Build Coastguard Worker     }
101*35238bceSAndroid Build Coastguard Worker 
begin(void)102*35238bceSAndroid Build Coastguard Worker     Iterator begin(void)
103*35238bceSAndroid Build Coastguard Worker     {
104*35238bceSAndroid Build Coastguard Worker         return Iterator(this, 0);
105*35238bceSAndroid Build Coastguard Worker     }
end(void)106*35238bceSAndroid Build Coastguard Worker     Iterator end(void)
107*35238bceSAndroid Build Coastguard Worker     {
108*35238bceSAndroid Build Coastguard Worker         return Iterator(this, (intptr_t)m_numElements);
109*35238bceSAndroid Build Coastguard Worker     }
110*35238bceSAndroid Build Coastguard Worker 
begin(void) const111*35238bceSAndroid Build Coastguard Worker     ConstIterator begin(void) const
112*35238bceSAndroid Build Coastguard Worker     {
113*35238bceSAndroid Build Coastguard Worker         return ConstIterator(this, 0);
114*35238bceSAndroid Build Coastguard Worker     }
end(void) const115*35238bceSAndroid Build Coastguard Worker     ConstIterator end(void) const
116*35238bceSAndroid Build Coastguard Worker     {
117*35238bceSAndroid Build Coastguard Worker         return ConstIterator(this, (intptr_t)m_numElements);
118*35238bceSAndroid Build Coastguard Worker     }
119*35238bceSAndroid Build Coastguard Worker 
front(void) const120*35238bceSAndroid Build Coastguard Worker     const T &front(void) const
121*35238bceSAndroid Build Coastguard Worker     {
122*35238bceSAndroid Build Coastguard Worker         return at(0);
123*35238bceSAndroid Build Coastguard Worker     }
front(void)124*35238bceSAndroid Build Coastguard Worker     T &front(void)
125*35238bceSAndroid Build Coastguard Worker     {
126*35238bceSAndroid Build Coastguard Worker         return at(0);
127*35238bceSAndroid Build Coastguard Worker     }
128*35238bceSAndroid Build Coastguard Worker 
back(void) const129*35238bceSAndroid Build Coastguard Worker     const T &back(void) const
130*35238bceSAndroid Build Coastguard Worker     {
131*35238bceSAndroid Build Coastguard Worker         return at(m_numElements - 1);
132*35238bceSAndroid Build Coastguard Worker     }
back(void)133*35238bceSAndroid Build Coastguard Worker     T &back(void)
134*35238bceSAndroid Build Coastguard Worker     {
135*35238bceSAndroid Build Coastguard Worker         return at(m_numElements - 1);
136*35238bceSAndroid Build Coastguard Worker     }
137*35238bceSAndroid Build Coastguard Worker 
138*35238bceSAndroid Build Coastguard Worker private:
139*35238bceSAndroid Build Coastguard Worker     enum
140*35238bceSAndroid Build Coastguard Worker     {
141*35238bceSAndroid Build Coastguard Worker         ELEMENTS_PER_PAGE_LOG2 = 4 //!< 16 elements per page.
142*35238bceSAndroid Build Coastguard Worker     };
143*35238bceSAndroid Build Coastguard Worker 
144*35238bceSAndroid Build Coastguard Worker     PoolArray(const PoolArray<T, Alignment>
145*35238bceSAndroid Build Coastguard Worker                   &other); // \note Default copy ctor is not allowed, use PoolArray(pool, copy) instead.
146*35238bceSAndroid Build Coastguard Worker 
147*35238bceSAndroid Build Coastguard Worker     T *getPtr(intptr_t ndx) const;
148*35238bceSAndroid Build Coastguard Worker 
149*35238bceSAndroid Build Coastguard Worker     MemPool *m_pool;
150*35238bceSAndroid Build Coastguard Worker 
151*35238bceSAndroid Build Coastguard Worker     uintptr_t m_numElements; //!< Number of elements in the array.
152*35238bceSAndroid Build Coastguard Worker     uintptr_t m_capacity;    //!< Number of allocated elements in the array.
153*35238bceSAndroid Build Coastguard Worker 
154*35238bceSAndroid Build Coastguard Worker     uintptr_t m_pageTableCapacity; //!< Size of the page table.
155*35238bceSAndroid Build Coastguard Worker     void **m_pageTable;            //!< Pointer to the page table.
156*35238bceSAndroid Build Coastguard Worker };
157*35238bceSAndroid Build Coastguard Worker 
158*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
159*35238bceSAndroid Build Coastguard Worker class PoolArrayIteratorBase
160*35238bceSAndroid Build Coastguard Worker {
161*35238bceSAndroid Build Coastguard Worker public:
PoolArrayIteratorBase(uintptr_t ndx)162*35238bceSAndroid Build Coastguard Worker     PoolArrayIteratorBase(uintptr_t ndx) : m_ndx(ndx)
163*35238bceSAndroid Build Coastguard Worker     {
164*35238bceSAndroid Build Coastguard Worker     }
~PoolArrayIteratorBase(void)165*35238bceSAndroid Build Coastguard Worker     ~PoolArrayIteratorBase(void)
166*35238bceSAndroid Build Coastguard Worker     {
167*35238bceSAndroid Build Coastguard Worker     }
168*35238bceSAndroid Build Coastguard Worker 
getNdx(void) const169*35238bceSAndroid Build Coastguard Worker     intptr_t getNdx(void) const throw()
170*35238bceSAndroid Build Coastguard Worker     {
171*35238bceSAndroid Build Coastguard Worker         return m_ndx;
172*35238bceSAndroid Build Coastguard Worker     }
173*35238bceSAndroid Build Coastguard Worker 
174*35238bceSAndroid Build Coastguard Worker protected:
175*35238bceSAndroid Build Coastguard Worker     intptr_t m_ndx;
176*35238bceSAndroid Build Coastguard Worker };
177*35238bceSAndroid Build Coastguard Worker 
178*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
179*35238bceSAndroid Build Coastguard Worker class PoolArrayConstIterator : public PoolArrayIteratorBase<T, Alignment>
180*35238bceSAndroid Build Coastguard Worker {
181*35238bceSAndroid Build Coastguard Worker public:
182*35238bceSAndroid Build Coastguard Worker     PoolArrayConstIterator(void);
183*35238bceSAndroid Build Coastguard Worker     PoolArrayConstIterator(const PoolArray<T, Alignment> *array, intptr_t ndx);
184*35238bceSAndroid Build Coastguard Worker     PoolArrayConstIterator(const PoolArrayIterator<T, Alignment> &iterator);
185*35238bceSAndroid Build Coastguard Worker     ~PoolArrayConstIterator(void);
186*35238bceSAndroid Build Coastguard Worker 
187*35238bceSAndroid Build Coastguard Worker     // \note Default assignment and copy-constructor are auto-generated.
188*35238bceSAndroid Build Coastguard Worker 
getArray(void) const189*35238bceSAndroid Build Coastguard Worker     const PoolArray<T, Alignment> *getArray(void) const throw()
190*35238bceSAndroid Build Coastguard Worker     {
191*35238bceSAndroid Build Coastguard Worker         return m_array;
192*35238bceSAndroid Build Coastguard Worker     }
193*35238bceSAndroid Build Coastguard Worker 
194*35238bceSAndroid Build Coastguard Worker     // De-reference operators.
operator ->(void) const195*35238bceSAndroid Build Coastguard Worker     const T *operator->(void) const throw()
196*35238bceSAndroid Build Coastguard Worker     {
197*35238bceSAndroid Build Coastguard Worker         return &(*m_array)[this->m_ndx];
198*35238bceSAndroid Build Coastguard Worker     }
operator *(void) const199*35238bceSAndroid Build Coastguard Worker     const T &operator*(void) const throw()
200*35238bceSAndroid Build Coastguard Worker     {
201*35238bceSAndroid Build Coastguard Worker         return (*m_array)[this->m_ndx];
202*35238bceSAndroid Build Coastguard Worker     }
operator [](uintptr_t offs) const203*35238bceSAndroid Build Coastguard Worker     const T &operator[](uintptr_t offs) const throw()
204*35238bceSAndroid Build Coastguard Worker     {
205*35238bceSAndroid Build Coastguard Worker         return (*m_array)[this->m_ndx + offs];
206*35238bceSAndroid Build Coastguard Worker     }
207*35238bceSAndroid Build Coastguard Worker 
208*35238bceSAndroid Build Coastguard Worker     // Pre-increment and decrement.
operator ++(void)209*35238bceSAndroid Build Coastguard Worker     PoolArrayConstIterator<T, Alignment> &operator++(void)
210*35238bceSAndroid Build Coastguard Worker     {
211*35238bceSAndroid Build Coastguard Worker         this->m_ndx += 1;
212*35238bceSAndroid Build Coastguard Worker         return *this;
213*35238bceSAndroid Build Coastguard Worker     }
operator --(void)214*35238bceSAndroid Build Coastguard Worker     PoolArrayConstIterator<T, Alignment> &operator--(void)
215*35238bceSAndroid Build Coastguard Worker     {
216*35238bceSAndroid Build Coastguard Worker         this->m_ndx -= 1;
217*35238bceSAndroid Build Coastguard Worker         return *this;
218*35238bceSAndroid Build Coastguard Worker     }
219*35238bceSAndroid Build Coastguard Worker 
220*35238bceSAndroid Build Coastguard Worker     // Post-increment and decrement.
operator ++(int)221*35238bceSAndroid Build Coastguard Worker     PoolArrayConstIterator<T, Alignment> operator++(int)
222*35238bceSAndroid Build Coastguard Worker     {
223*35238bceSAndroid Build Coastguard Worker         PoolArrayConstIterator<T, Alignment> copy(*this);
224*35238bceSAndroid Build Coastguard Worker         this->m_ndx += 1;
225*35238bceSAndroid Build Coastguard Worker         return copy;
226*35238bceSAndroid Build Coastguard Worker     }
operator --(int)227*35238bceSAndroid Build Coastguard Worker     PoolArrayConstIterator<T, Alignment> operator--(int)
228*35238bceSAndroid Build Coastguard Worker     {
229*35238bceSAndroid Build Coastguard Worker         PoolArrayConstIterator<T, Alignment> copy(*this);
230*35238bceSAndroid Build Coastguard Worker         this->m_ndx -= 1;
231*35238bceSAndroid Build Coastguard Worker         return copy;
232*35238bceSAndroid Build Coastguard Worker     }
233*35238bceSAndroid Build Coastguard Worker 
234*35238bceSAndroid Build Coastguard Worker     // Compound assignment.
operator +=(intptr_t offs)235*35238bceSAndroid Build Coastguard Worker     PoolArrayConstIterator<T, Alignment> &operator+=(intptr_t offs)
236*35238bceSAndroid Build Coastguard Worker     {
237*35238bceSAndroid Build Coastguard Worker         this->m_ndx += offs;
238*35238bceSAndroid Build Coastguard Worker         return *this;
239*35238bceSAndroid Build Coastguard Worker     }
operator -=(intptr_t offs)240*35238bceSAndroid Build Coastguard Worker     PoolArrayConstIterator<T, Alignment> &operator-=(intptr_t offs)
241*35238bceSAndroid Build Coastguard Worker     {
242*35238bceSAndroid Build Coastguard Worker         this->m_ndx -= offs;
243*35238bceSAndroid Build Coastguard Worker         return *this;
244*35238bceSAndroid Build Coastguard Worker     }
245*35238bceSAndroid Build Coastguard Worker 
246*35238bceSAndroid Build Coastguard Worker     // Assignment from non-const.
247*35238bceSAndroid Build Coastguard Worker     PoolArrayConstIterator<T, Alignment> &operator=(const PoolArrayIterator<T, Alignment> &iter);
248*35238bceSAndroid Build Coastguard Worker 
249*35238bceSAndroid Build Coastguard Worker private:
250*35238bceSAndroid Build Coastguard Worker     const PoolArray<T, Alignment> *m_array;
251*35238bceSAndroid Build Coastguard Worker };
252*35238bceSAndroid Build Coastguard Worker 
253*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
254*35238bceSAndroid Build Coastguard Worker class PoolArrayIterator : public PoolArrayIteratorBase<T, Alignment>
255*35238bceSAndroid Build Coastguard Worker {
256*35238bceSAndroid Build Coastguard Worker public:
257*35238bceSAndroid Build Coastguard Worker     PoolArrayIterator(void);
258*35238bceSAndroid Build Coastguard Worker     PoolArrayIterator(PoolArray<T, Alignment> *array, intptr_t ndx);
259*35238bceSAndroid Build Coastguard Worker     ~PoolArrayIterator(void);
260*35238bceSAndroid Build Coastguard Worker 
261*35238bceSAndroid Build Coastguard Worker     // \note Default assignment and copy-constructor are auto-generated.
262*35238bceSAndroid Build Coastguard Worker 
getArray(void) const263*35238bceSAndroid Build Coastguard Worker     PoolArray<T, Alignment> *getArray(void) const throw()
264*35238bceSAndroid Build Coastguard Worker     {
265*35238bceSAndroid Build Coastguard Worker         return m_array;
266*35238bceSAndroid Build Coastguard Worker     }
267*35238bceSAndroid Build Coastguard Worker 
268*35238bceSAndroid Build Coastguard Worker     // De-reference operators.
operator ->(void) const269*35238bceSAndroid Build Coastguard Worker     T *operator->(void) const throw()
270*35238bceSAndroid Build Coastguard Worker     {
271*35238bceSAndroid Build Coastguard Worker         return &(*m_array)[this->m_ndx];
272*35238bceSAndroid Build Coastguard Worker     }
operator *(void) const273*35238bceSAndroid Build Coastguard Worker     T &operator*(void) const throw()
274*35238bceSAndroid Build Coastguard Worker     {
275*35238bceSAndroid Build Coastguard Worker         return (*m_array)[this->m_ndx];
276*35238bceSAndroid Build Coastguard Worker     }
operator [](uintptr_t offs) const277*35238bceSAndroid Build Coastguard Worker     T &operator[](uintptr_t offs) const throw()
278*35238bceSAndroid Build Coastguard Worker     {
279*35238bceSAndroid Build Coastguard Worker         return (*m_array)[this->m_ndx + offs];
280*35238bceSAndroid Build Coastguard Worker     }
281*35238bceSAndroid Build Coastguard Worker 
282*35238bceSAndroid Build Coastguard Worker     // Pre-increment and decrement.
operator ++(void)283*35238bceSAndroid Build Coastguard Worker     PoolArrayIterator<T, Alignment> &operator++(void)
284*35238bceSAndroid Build Coastguard Worker     {
285*35238bceSAndroid Build Coastguard Worker         this->m_ndx += 1;
286*35238bceSAndroid Build Coastguard Worker         return *this;
287*35238bceSAndroid Build Coastguard Worker     }
operator --(void)288*35238bceSAndroid Build Coastguard Worker     PoolArrayIterator<T, Alignment> &operator--(void)
289*35238bceSAndroid Build Coastguard Worker     {
290*35238bceSAndroid Build Coastguard Worker         this->m_ndx -= 1;
291*35238bceSAndroid Build Coastguard Worker         return *this;
292*35238bceSAndroid Build Coastguard Worker     }
293*35238bceSAndroid Build Coastguard Worker 
294*35238bceSAndroid Build Coastguard Worker     // Post-increment and decrement.
operator ++(int)295*35238bceSAndroid Build Coastguard Worker     PoolArrayIterator<T, Alignment> operator++(int)
296*35238bceSAndroid Build Coastguard Worker     {
297*35238bceSAndroid Build Coastguard Worker         PoolArrayIterator<T, Alignment> copy(*this);
298*35238bceSAndroid Build Coastguard Worker         this->m_ndx += 1;
299*35238bceSAndroid Build Coastguard Worker         return copy;
300*35238bceSAndroid Build Coastguard Worker     }
operator --(int)301*35238bceSAndroid Build Coastguard Worker     PoolArrayIterator<T, Alignment> operator--(int)
302*35238bceSAndroid Build Coastguard Worker     {
303*35238bceSAndroid Build Coastguard Worker         PoolArrayIterator<T, Alignment> copy(*this);
304*35238bceSAndroid Build Coastguard Worker         this->m_ndx -= 1;
305*35238bceSAndroid Build Coastguard Worker         return copy;
306*35238bceSAndroid Build Coastguard Worker     }
307*35238bceSAndroid Build Coastguard Worker 
308*35238bceSAndroid Build Coastguard Worker     // Compound assignment.
operator +=(intptr_t offs)309*35238bceSAndroid Build Coastguard Worker     PoolArrayIterator<T, Alignment> &operator+=(intptr_t offs)
310*35238bceSAndroid Build Coastguard Worker     {
311*35238bceSAndroid Build Coastguard Worker         this->m_ndx += offs;
312*35238bceSAndroid Build Coastguard Worker         return *this;
313*35238bceSAndroid Build Coastguard Worker     }
operator -=(intptr_t offs)314*35238bceSAndroid Build Coastguard Worker     PoolArrayIterator<T, Alignment> &operator-=(intptr_t offs)
315*35238bceSAndroid Build Coastguard Worker     {
316*35238bceSAndroid Build Coastguard Worker         this->m_ndx -= offs;
317*35238bceSAndroid Build Coastguard Worker         return *this;
318*35238bceSAndroid Build Coastguard Worker     }
319*35238bceSAndroid Build Coastguard Worker 
320*35238bceSAndroid Build Coastguard Worker private:
321*35238bceSAndroid Build Coastguard Worker     PoolArray<T, Alignment> *m_array;
322*35238bceSAndroid Build Coastguard Worker };
323*35238bceSAndroid Build Coastguard Worker 
324*35238bceSAndroid Build Coastguard Worker // Initializer helper for array.
325*35238bceSAndroid Build Coastguard Worker template <typename T>
326*35238bceSAndroid Build Coastguard Worker struct PoolArrayElement
327*35238bceSAndroid Build Coastguard Worker {
constructDefaultde::PoolArrayElement328*35238bceSAndroid Build Coastguard Worker     static void constructDefault(void *ptr)
329*35238bceSAndroid Build Coastguard Worker     {
330*35238bceSAndroid Build Coastguard Worker         new (ptr) T();
331*35238bceSAndroid Build Coastguard Worker     } //!< Called for non-initialized memory.
constructCopyde::PoolArrayElement332*35238bceSAndroid Build Coastguard Worker     static void constructCopy(void *ptr, const T &val)
333*35238bceSAndroid Build Coastguard Worker     {
334*35238bceSAndroid Build Coastguard Worker         new (ptr) T(val);
335*35238bceSAndroid Build Coastguard Worker     } //!< Called for non-initialized memory when initial value is provided.
destructde::PoolArrayElement336*35238bceSAndroid Build Coastguard Worker     static void destruct(T *ptr)
337*35238bceSAndroid Build Coastguard Worker     {
338*35238bceSAndroid Build Coastguard Worker         ptr->~T();
339*35238bceSAndroid Build Coastguard Worker     } //!< Called when element is destructed.
340*35238bceSAndroid Build Coastguard Worker };
341*35238bceSAndroid Build Coastguard Worker 
342*35238bceSAndroid Build Coastguard Worker // Specialization for basic types.
343*35238bceSAndroid Build Coastguard Worker #define DE_SPECIALIZE_POOL_ARRAY_ELEMENT_BASIC_TYPE(TYPE) \
344*35238bceSAndroid Build Coastguard Worker     template <>                                           \
345*35238bceSAndroid Build Coastguard Worker     struct PoolArrayElement<TYPE>                         \
346*35238bceSAndroid Build Coastguard Worker     {                                                     \
347*35238bceSAndroid Build Coastguard Worker         static void constructDefault(void *)              \
348*35238bceSAndroid Build Coastguard Worker         {                                                 \
349*35238bceSAndroid Build Coastguard Worker         }                                                 \
350*35238bceSAndroid Build Coastguard Worker         static void constructCopy(void *ptr, TYPE val)    \
351*35238bceSAndroid Build Coastguard Worker         {                                                 \
352*35238bceSAndroid Build Coastguard Worker             *(TYPE *)ptr = val;                           \
353*35238bceSAndroid Build Coastguard Worker         }                                                 \
354*35238bceSAndroid Build Coastguard Worker         static void destruct(TYPE *)                      \
355*35238bceSAndroid Build Coastguard Worker         {                                                 \
356*35238bceSAndroid Build Coastguard Worker         }                                                 \
357*35238bceSAndroid Build Coastguard Worker     }
358*35238bceSAndroid Build Coastguard Worker 
359*35238bceSAndroid Build Coastguard Worker DE_SPECIALIZE_POOL_ARRAY_ELEMENT_BASIC_TYPE(uint8_t);
360*35238bceSAndroid Build Coastguard Worker DE_SPECIALIZE_POOL_ARRAY_ELEMENT_BASIC_TYPE(uint16_t);
361*35238bceSAndroid Build Coastguard Worker DE_SPECIALIZE_POOL_ARRAY_ELEMENT_BASIC_TYPE(uint32_t);
362*35238bceSAndroid Build Coastguard Worker DE_SPECIALIZE_POOL_ARRAY_ELEMENT_BASIC_TYPE(uint64_t);
363*35238bceSAndroid Build Coastguard Worker DE_SPECIALIZE_POOL_ARRAY_ELEMENT_BASIC_TYPE(int8_t);
364*35238bceSAndroid Build Coastguard Worker DE_SPECIALIZE_POOL_ARRAY_ELEMENT_BASIC_TYPE(int16_t);
365*35238bceSAndroid Build Coastguard Worker DE_SPECIALIZE_POOL_ARRAY_ELEMENT_BASIC_TYPE(int32_t);
366*35238bceSAndroid Build Coastguard Worker DE_SPECIALIZE_POOL_ARRAY_ELEMENT_BASIC_TYPE(int64_t);
367*35238bceSAndroid Build Coastguard Worker 
368*35238bceSAndroid Build Coastguard Worker // PoolArray<T> implementation.
369*35238bceSAndroid Build Coastguard Worker 
370*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
PoolArray(MemPool * pool)371*35238bceSAndroid Build Coastguard Worker PoolArray<T, Alignment>::PoolArray(MemPool *pool)
372*35238bceSAndroid Build Coastguard Worker     : m_pool(pool)
373*35238bceSAndroid Build Coastguard Worker     , m_numElements(0)
374*35238bceSAndroid Build Coastguard Worker     , m_capacity(0)
375*35238bceSAndroid Build Coastguard Worker     , m_pageTableCapacity(0)
376*35238bceSAndroid Build Coastguard Worker     , m_pageTable(0)
377*35238bceSAndroid Build Coastguard Worker {
378*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(deIsPowerOfTwo32(Alignment));
379*35238bceSAndroid Build Coastguard Worker }
380*35238bceSAndroid Build Coastguard Worker 
381*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
~PoolArray(void)382*35238bceSAndroid Build Coastguard Worker PoolArray<T, Alignment>::~PoolArray(void)
383*35238bceSAndroid Build Coastguard Worker {
384*35238bceSAndroid Build Coastguard Worker     // Clear resets values to T()
385*35238bceSAndroid Build Coastguard Worker     clear();
386*35238bceSAndroid Build Coastguard Worker }
387*35238bceSAndroid Build Coastguard Worker 
388*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
clear(void)389*35238bceSAndroid Build Coastguard Worker inline void PoolArray<T, Alignment>::clear(void)
390*35238bceSAndroid Build Coastguard Worker {
391*35238bceSAndroid Build Coastguard Worker     resize(0);
392*35238bceSAndroid Build Coastguard Worker }
393*35238bceSAndroid Build Coastguard Worker 
394*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
resize(uintptr_t newSize)395*35238bceSAndroid Build Coastguard Worker inline void PoolArray<T, Alignment>::resize(uintptr_t newSize)
396*35238bceSAndroid Build Coastguard Worker {
397*35238bceSAndroid Build Coastguard Worker     if (newSize < m_numElements)
398*35238bceSAndroid Build Coastguard Worker     {
399*35238bceSAndroid Build Coastguard Worker         // Destruct elements that are no longer active.
400*35238bceSAndroid Build Coastguard Worker         for (uintptr_t ndx = newSize; ndx < m_numElements; ndx++)
401*35238bceSAndroid Build Coastguard Worker             PoolArrayElement<T>::destruct(getPtr(ndx));
402*35238bceSAndroid Build Coastguard Worker 
403*35238bceSAndroid Build Coastguard Worker         m_numElements = newSize;
404*35238bceSAndroid Build Coastguard Worker     }
405*35238bceSAndroid Build Coastguard Worker     else if (newSize > m_numElements)
406*35238bceSAndroid Build Coastguard Worker     {
407*35238bceSAndroid Build Coastguard Worker         uintptr_t prevSize = m_numElements;
408*35238bceSAndroid Build Coastguard Worker 
409*35238bceSAndroid Build Coastguard Worker         reserve(newSize);
410*35238bceSAndroid Build Coastguard Worker         m_numElements = newSize;
411*35238bceSAndroid Build Coastguard Worker 
412*35238bceSAndroid Build Coastguard Worker         // Fill new elements with default values
413*35238bceSAndroid Build Coastguard Worker         for (uintptr_t ndx = prevSize; ndx < m_numElements; ndx++)
414*35238bceSAndroid Build Coastguard Worker             PoolArrayElement<T>::constructDefault(getPtr(ndx));
415*35238bceSAndroid Build Coastguard Worker     }
416*35238bceSAndroid Build Coastguard Worker }
417*35238bceSAndroid Build Coastguard Worker 
418*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
resize(uintptr_t newSize,const T & value)419*35238bceSAndroid Build Coastguard Worker inline void PoolArray<T, Alignment>::resize(uintptr_t newSize, const T &value)
420*35238bceSAndroid Build Coastguard Worker {
421*35238bceSAndroid Build Coastguard Worker     if (newSize < m_numElements)
422*35238bceSAndroid Build Coastguard Worker         resize(newSize); // value is not used
423*35238bceSAndroid Build Coastguard Worker     else if (newSize > m_numElements)
424*35238bceSAndroid Build Coastguard Worker     {
425*35238bceSAndroid Build Coastguard Worker         uintptr_t prevSize = m_numElements;
426*35238bceSAndroid Build Coastguard Worker 
427*35238bceSAndroid Build Coastguard Worker         reserve(newSize);
428*35238bceSAndroid Build Coastguard Worker         m_numElements = newSize;
429*35238bceSAndroid Build Coastguard Worker 
430*35238bceSAndroid Build Coastguard Worker         // Fill new elements with copies of value
431*35238bceSAndroid Build Coastguard Worker         for (uintptr_t ndx = prevSize; ndx < m_numElements; ndx++)
432*35238bceSAndroid Build Coastguard Worker             PoolArrayElement<T>::constructCopy(getPtr(ndx), value);
433*35238bceSAndroid Build Coastguard Worker     }
434*35238bceSAndroid Build Coastguard Worker }
435*35238bceSAndroid Build Coastguard Worker 
436*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
reserve(uintptr_t capacity)437*35238bceSAndroid Build Coastguard Worker inline void PoolArray<T, Alignment>::reserve(uintptr_t capacity)
438*35238bceSAndroid Build Coastguard Worker {
439*35238bceSAndroid Build Coastguard Worker     if (capacity >= m_capacity)
440*35238bceSAndroid Build Coastguard Worker     {
441*35238bceSAndroid Build Coastguard Worker         void *oldPageTable         = DE_NULL;
442*35238bceSAndroid Build Coastguard Worker         uintptr_t oldPageTableSize = 0;
443*35238bceSAndroid Build Coastguard Worker 
444*35238bceSAndroid Build Coastguard Worker         uintptr_t newCapacity          = (uintptr_t)deAlignPtr((void *)capacity, 1 << ELEMENTS_PER_PAGE_LOG2);
445*35238bceSAndroid Build Coastguard Worker         uintptr_t reqPageTableCapacity = newCapacity >> ELEMENTS_PER_PAGE_LOG2;
446*35238bceSAndroid Build Coastguard Worker 
447*35238bceSAndroid Build Coastguard Worker         if (m_pageTableCapacity < reqPageTableCapacity)
448*35238bceSAndroid Build Coastguard Worker         {
449*35238bceSAndroid Build Coastguard Worker             uintptr_t newPageTableCapacity = max(2 * m_pageTableCapacity, reqPageTableCapacity);
450*35238bceSAndroid Build Coastguard Worker             void **newPageTable            = (void **)m_pool->alloc(newPageTableCapacity * sizeof(void *));
451*35238bceSAndroid Build Coastguard Worker             uintptr_t i;
452*35238bceSAndroid Build Coastguard Worker 
453*35238bceSAndroid Build Coastguard Worker             for (i = 0; i < m_pageTableCapacity; i++)
454*35238bceSAndroid Build Coastguard Worker                 newPageTable[i] = m_pageTable[i];
455*35238bceSAndroid Build Coastguard Worker 
456*35238bceSAndroid Build Coastguard Worker             for (; i < newPageTableCapacity; i++)
457*35238bceSAndroid Build Coastguard Worker                 newPageTable[i] = DE_NULL;
458*35238bceSAndroid Build Coastguard Worker 
459*35238bceSAndroid Build Coastguard Worker             // Grab information about old page table for recycling purposes.
460*35238bceSAndroid Build Coastguard Worker             oldPageTable     = m_pageTable;
461*35238bceSAndroid Build Coastguard Worker             oldPageTableSize = m_pageTableCapacity * sizeof(T *);
462*35238bceSAndroid Build Coastguard Worker 
463*35238bceSAndroid Build Coastguard Worker             m_pageTable         = newPageTable;
464*35238bceSAndroid Build Coastguard Worker             m_pageTableCapacity = newPageTableCapacity;
465*35238bceSAndroid Build Coastguard Worker         }
466*35238bceSAndroid Build Coastguard Worker 
467*35238bceSAndroid Build Coastguard Worker         // Allocate new pages.
468*35238bceSAndroid Build Coastguard Worker         {
469*35238bceSAndroid Build Coastguard Worker             uintptr_t elementSize   = (uintptr_t)deAlignPtr((void *)(uintptr_t)sizeof(T), Alignment);
470*35238bceSAndroid Build Coastguard Worker             uintptr_t pageAllocSize = elementSize << ELEMENTS_PER_PAGE_LOG2;
471*35238bceSAndroid Build Coastguard Worker             uintptr_t pageTableNdx  = m_capacity >> ELEMENTS_PER_PAGE_LOG2;
472*35238bceSAndroid Build Coastguard Worker 
473*35238bceSAndroid Build Coastguard Worker             // Allocate new pages from recycled old page table.
474*35238bceSAndroid Build Coastguard Worker             for (;;)
475*35238bceSAndroid Build Coastguard Worker             {
476*35238bceSAndroid Build Coastguard Worker                 void *newPage          = deAlignPtr(oldPageTable, Alignment);
477*35238bceSAndroid Build Coastguard Worker                 uintptr_t alignPadding = (uintptr_t)newPage - (uintptr_t)oldPageTable;
478*35238bceSAndroid Build Coastguard Worker 
479*35238bceSAndroid Build Coastguard Worker                 if (oldPageTableSize < pageAllocSize + alignPadding)
480*35238bceSAndroid Build Coastguard Worker                     break; // No free space for alloc + alignment.
481*35238bceSAndroid Build Coastguard Worker 
482*35238bceSAndroid Build Coastguard Worker                 DE_ASSERT(m_pageTableCapacity > pageTableNdx);
483*35238bceSAndroid Build Coastguard Worker                 DE_ASSERT(!m_pageTable[pageTableNdx]);
484*35238bceSAndroid Build Coastguard Worker                 m_pageTable[pageTableNdx++] = newPage;
485*35238bceSAndroid Build Coastguard Worker 
486*35238bceSAndroid Build Coastguard Worker                 oldPageTable = (void *)((uint8_t *)newPage + pageAllocSize);
487*35238bceSAndroid Build Coastguard Worker                 oldPageTableSize -= pageAllocSize + alignPadding;
488*35238bceSAndroid Build Coastguard Worker             }
489*35238bceSAndroid Build Coastguard Worker 
490*35238bceSAndroid Build Coastguard Worker             // Allocate the rest of the needed pages from the pool.
491*35238bceSAndroid Build Coastguard Worker             for (; pageTableNdx < reqPageTableCapacity; pageTableNdx++)
492*35238bceSAndroid Build Coastguard Worker             {
493*35238bceSAndroid Build Coastguard Worker                 DE_ASSERT(!m_pageTable[pageTableNdx]);
494*35238bceSAndroid Build Coastguard Worker                 m_pageTable[pageTableNdx] = m_pool->alignedAlloc(pageAllocSize, Alignment);
495*35238bceSAndroid Build Coastguard Worker             }
496*35238bceSAndroid Build Coastguard Worker 
497*35238bceSAndroid Build Coastguard Worker             m_capacity = pageTableNdx << ELEMENTS_PER_PAGE_LOG2;
498*35238bceSAndroid Build Coastguard Worker             DE_ASSERT(m_capacity >= newCapacity);
499*35238bceSAndroid Build Coastguard Worker         }
500*35238bceSAndroid Build Coastguard Worker     }
501*35238bceSAndroid Build Coastguard Worker }
502*35238bceSAndroid Build Coastguard Worker 
503*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
pushBack(const T & value)504*35238bceSAndroid Build Coastguard Worker inline void PoolArray<T, Alignment>::pushBack(const T &value)
505*35238bceSAndroid Build Coastguard Worker {
506*35238bceSAndroid Build Coastguard Worker     resize(size() + 1);
507*35238bceSAndroid Build Coastguard Worker     at(size() - 1) = value;
508*35238bceSAndroid Build Coastguard Worker }
509*35238bceSAndroid Build Coastguard Worker 
510*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
popBack(void)511*35238bceSAndroid Build Coastguard Worker inline T PoolArray<T, Alignment>::popBack(void)
512*35238bceSAndroid Build Coastguard Worker {
513*35238bceSAndroid Build Coastguard Worker     T val = at(size() - 1);
514*35238bceSAndroid Build Coastguard Worker     resize(size() - 1);
515*35238bceSAndroid Build Coastguard Worker     return val;
516*35238bceSAndroid Build Coastguard Worker }
517*35238bceSAndroid Build Coastguard Worker 
518*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
getPtr(intptr_t ndx) const519*35238bceSAndroid Build Coastguard Worker inline T *PoolArray<T, Alignment>::getPtr(intptr_t ndx) const
520*35238bceSAndroid Build Coastguard Worker {
521*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(inBounds<intptr_t>(ndx, 0, (intptr_t)m_numElements));
522*35238bceSAndroid Build Coastguard Worker     uintptr_t pageNdx  = ((uintptr_t)ndx >> ELEMENTS_PER_PAGE_LOG2);
523*35238bceSAndroid Build Coastguard Worker     uintptr_t subNdx   = (uintptr_t)ndx & ((1 << ELEMENTS_PER_PAGE_LOG2) - 1);
524*35238bceSAndroid Build Coastguard Worker     uintptr_t elemSize = (uintptr_t)deAlignPtr((void *)(uintptr_t)sizeof(T), Alignment);
525*35238bceSAndroid Build Coastguard Worker     T *ptr             = (T *)((uint8_t *)m_pageTable[pageNdx] + (subNdx * elemSize));
526*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(deIsAlignedPtr(ptr, Alignment));
527*35238bceSAndroid Build Coastguard Worker     return ptr;
528*35238bceSAndroid Build Coastguard Worker }
529*35238bceSAndroid Build Coastguard Worker 
530*35238bceSAndroid Build Coastguard Worker // PoolArrayIteratorBase implementation
531*35238bceSAndroid Build Coastguard Worker 
532*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
operator ==(const PoolArrayIteratorBase<T,Alignment> & a,const PoolArrayIteratorBase<T,Alignment> & b)533*35238bceSAndroid Build Coastguard Worker inline bool operator==(const PoolArrayIteratorBase<T, Alignment> &a, const PoolArrayIteratorBase<T, Alignment> &b)
534*35238bceSAndroid Build Coastguard Worker {
535*35238bceSAndroid Build Coastguard Worker     // \todo [2013-02-08 pyry] Compare array ptr.
536*35238bceSAndroid Build Coastguard Worker     return a.getNdx() == b.getNdx();
537*35238bceSAndroid Build Coastguard Worker }
538*35238bceSAndroid Build Coastguard Worker 
539*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
operator !=(const PoolArrayIteratorBase<T,Alignment> & a,const PoolArrayIteratorBase<T,Alignment> & b)540*35238bceSAndroid Build Coastguard Worker inline bool operator!=(const PoolArrayIteratorBase<T, Alignment> &a, const PoolArrayIteratorBase<T, Alignment> &b)
541*35238bceSAndroid Build Coastguard Worker {
542*35238bceSAndroid Build Coastguard Worker     // \todo [2013-02-08 pyry] Compare array ptr.
543*35238bceSAndroid Build Coastguard Worker     return a.getNdx() != b.getNdx();
544*35238bceSAndroid Build Coastguard Worker }
545*35238bceSAndroid Build Coastguard Worker 
546*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
operator <(const PoolArrayIteratorBase<T,Alignment> & a,const PoolArrayIteratorBase<T,Alignment> & b)547*35238bceSAndroid Build Coastguard Worker inline bool operator<(const PoolArrayIteratorBase<T, Alignment> &a, const PoolArrayIteratorBase<T, Alignment> &b)
548*35238bceSAndroid Build Coastguard Worker {
549*35238bceSAndroid Build Coastguard Worker     return a.getNdx() < b.getNdx();
550*35238bceSAndroid Build Coastguard Worker }
551*35238bceSAndroid Build Coastguard Worker 
552*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
operator >(const PoolArrayIteratorBase<T,Alignment> & a,const PoolArrayIteratorBase<T,Alignment> & b)553*35238bceSAndroid Build Coastguard Worker inline bool operator>(const PoolArrayIteratorBase<T, Alignment> &a, const PoolArrayIteratorBase<T, Alignment> &b)
554*35238bceSAndroid Build Coastguard Worker {
555*35238bceSAndroid Build Coastguard Worker     return a.getNdx() > b.getNdx();
556*35238bceSAndroid Build Coastguard Worker }
557*35238bceSAndroid Build Coastguard Worker 
558*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
operator <=(const PoolArrayIteratorBase<T,Alignment> & a,const PoolArrayIteratorBase<T,Alignment> & b)559*35238bceSAndroid Build Coastguard Worker inline bool operator<=(const PoolArrayIteratorBase<T, Alignment> &a, const PoolArrayIteratorBase<T, Alignment> &b)
560*35238bceSAndroid Build Coastguard Worker {
561*35238bceSAndroid Build Coastguard Worker     return a.getNdx() <= b.getNdx();
562*35238bceSAndroid Build Coastguard Worker }
563*35238bceSAndroid Build Coastguard Worker 
564*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
operator >=(const PoolArrayIteratorBase<T,Alignment> & a,const PoolArrayIteratorBase<T,Alignment> & b)565*35238bceSAndroid Build Coastguard Worker inline bool operator>=(const PoolArrayIteratorBase<T, Alignment> &a, const PoolArrayIteratorBase<T, Alignment> &b)
566*35238bceSAndroid Build Coastguard Worker {
567*35238bceSAndroid Build Coastguard Worker     return a.getNdx() >= b.getNdx();
568*35238bceSAndroid Build Coastguard Worker }
569*35238bceSAndroid Build Coastguard Worker 
570*35238bceSAndroid Build Coastguard Worker // PoolArrayConstIterator<T> implementation
571*35238bceSAndroid Build Coastguard Worker 
572*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
PoolArrayConstIterator(void)573*35238bceSAndroid Build Coastguard Worker inline PoolArrayConstIterator<T, Alignment>::PoolArrayConstIterator(void)
574*35238bceSAndroid Build Coastguard Worker     : PoolArrayIteratorBase<T, Alignment>(0)
575*35238bceSAndroid Build Coastguard Worker     , m_array(DE_NULL)
576*35238bceSAndroid Build Coastguard Worker {
577*35238bceSAndroid Build Coastguard Worker }
578*35238bceSAndroid Build Coastguard Worker 
579*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
PoolArrayConstIterator(const PoolArray<T,Alignment> * array,intptr_t ndx)580*35238bceSAndroid Build Coastguard Worker inline PoolArrayConstIterator<T, Alignment>::PoolArrayConstIterator(const PoolArray<T, Alignment> *array, intptr_t ndx)
581*35238bceSAndroid Build Coastguard Worker     : PoolArrayIteratorBase<T, Alignment>(ndx)
582*35238bceSAndroid Build Coastguard Worker     , m_array(array)
583*35238bceSAndroid Build Coastguard Worker {
584*35238bceSAndroid Build Coastguard Worker }
585*35238bceSAndroid Build Coastguard Worker 
586*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
PoolArrayConstIterator(const PoolArrayIterator<T,Alignment> & iter)587*35238bceSAndroid Build Coastguard Worker inline PoolArrayConstIterator<T, Alignment>::PoolArrayConstIterator(const PoolArrayIterator<T, Alignment> &iter)
588*35238bceSAndroid Build Coastguard Worker     : PoolArrayIteratorBase<T, Alignment>(iter)
589*35238bceSAndroid Build Coastguard Worker     , m_array(iter.getArray())
590*35238bceSAndroid Build Coastguard Worker {
591*35238bceSAndroid Build Coastguard Worker }
592*35238bceSAndroid Build Coastguard Worker 
593*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
~PoolArrayConstIterator(void)594*35238bceSAndroid Build Coastguard Worker inline PoolArrayConstIterator<T, Alignment>::~PoolArrayConstIterator(void)
595*35238bceSAndroid Build Coastguard Worker {
596*35238bceSAndroid Build Coastguard Worker }
597*35238bceSAndroid Build Coastguard Worker 
598*35238bceSAndroid Build Coastguard Worker // Arithmetic operators.
599*35238bceSAndroid Build Coastguard Worker 
600*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
operator +(const PoolArrayConstIterator<T,Alignment> & iter,intptr_t offs)601*35238bceSAndroid Build Coastguard Worker inline PoolArrayConstIterator<T, Alignment> operator+(const PoolArrayConstIterator<T, Alignment> &iter, intptr_t offs)
602*35238bceSAndroid Build Coastguard Worker {
603*35238bceSAndroid Build Coastguard Worker     return PoolArrayConstIterator<T, Alignment>(iter->getArray(), iter->getNdx() + offs);
604*35238bceSAndroid Build Coastguard Worker }
605*35238bceSAndroid Build Coastguard Worker 
606*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
operator +(uintptr_t offs,const PoolArrayConstIterator<T,Alignment> & iter)607*35238bceSAndroid Build Coastguard Worker inline PoolArrayConstIterator<T, Alignment> operator+(uintptr_t offs, const PoolArrayConstIterator<T, Alignment> &iter)
608*35238bceSAndroid Build Coastguard Worker {
609*35238bceSAndroid Build Coastguard Worker     return PoolArrayConstIterator<T, Alignment>(iter->getArray(), iter->getNdx() + offs);
610*35238bceSAndroid Build Coastguard Worker }
611*35238bceSAndroid Build Coastguard Worker 
612*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
operator -(const PoolArrayConstIterator<T,Alignment> & iter,intptr_t offs)613*35238bceSAndroid Build Coastguard Worker PoolArrayConstIterator<T, Alignment> operator-(const PoolArrayConstIterator<T, Alignment> &iter, intptr_t offs)
614*35238bceSAndroid Build Coastguard Worker {
615*35238bceSAndroid Build Coastguard Worker     return PoolArrayConstIterator<T, Alignment>(iter.getArray(), iter.getNdx() - offs);
616*35238bceSAndroid Build Coastguard Worker }
617*35238bceSAndroid Build Coastguard Worker 
618*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
operator -(const PoolArrayConstIterator<T,Alignment> & iter,const PoolArrayConstIterator<T,Alignment> & other)619*35238bceSAndroid Build Coastguard Worker intptr_t operator-(const PoolArrayConstIterator<T, Alignment> &iter, const PoolArrayConstIterator<T, Alignment> &other)
620*35238bceSAndroid Build Coastguard Worker {
621*35238bceSAndroid Build Coastguard Worker     return iter.getNdx() - other.getNdx();
622*35238bceSAndroid Build Coastguard Worker }
623*35238bceSAndroid Build Coastguard Worker 
624*35238bceSAndroid Build Coastguard Worker // PoolArrayIterator<T> implementation.
625*35238bceSAndroid Build Coastguard Worker 
626*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
PoolArrayIterator(void)627*35238bceSAndroid Build Coastguard Worker inline PoolArrayIterator<T, Alignment>::PoolArrayIterator(void)
628*35238bceSAndroid Build Coastguard Worker     : PoolArrayIteratorBase<T, Alignment>(0)
629*35238bceSAndroid Build Coastguard Worker     , m_array(DE_NULL)
630*35238bceSAndroid Build Coastguard Worker {
631*35238bceSAndroid Build Coastguard Worker }
632*35238bceSAndroid Build Coastguard Worker 
633*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
PoolArrayIterator(PoolArray<T,Alignment> * array,intptr_t ndx)634*35238bceSAndroid Build Coastguard Worker inline PoolArrayIterator<T, Alignment>::PoolArrayIterator(PoolArray<T, Alignment> *array, intptr_t ndx)
635*35238bceSAndroid Build Coastguard Worker     : PoolArrayIteratorBase<T, Alignment>(ndx)
636*35238bceSAndroid Build Coastguard Worker     , m_array(array)
637*35238bceSAndroid Build Coastguard Worker {
638*35238bceSAndroid Build Coastguard Worker }
639*35238bceSAndroid Build Coastguard Worker 
640*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
~PoolArrayIterator(void)641*35238bceSAndroid Build Coastguard Worker inline PoolArrayIterator<T, Alignment>::~PoolArrayIterator(void)
642*35238bceSAndroid Build Coastguard Worker {
643*35238bceSAndroid Build Coastguard Worker }
644*35238bceSAndroid Build Coastguard Worker 
645*35238bceSAndroid Build Coastguard Worker // Arithmetic operators.
646*35238bceSAndroid Build Coastguard Worker 
647*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
operator +(const PoolArrayIterator<T,Alignment> & iter,intptr_t offs)648*35238bceSAndroid Build Coastguard Worker inline PoolArrayIterator<T, Alignment> operator+(const PoolArrayIterator<T, Alignment> &iter, intptr_t offs)
649*35238bceSAndroid Build Coastguard Worker {
650*35238bceSAndroid Build Coastguard Worker     return PoolArrayIterator<T, Alignment>(iter.getArray(), iter.getNdx() + offs);
651*35238bceSAndroid Build Coastguard Worker }
652*35238bceSAndroid Build Coastguard Worker 
653*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
operator +(uintptr_t offs,const PoolArrayIterator<T,Alignment> & iter)654*35238bceSAndroid Build Coastguard Worker inline PoolArrayIterator<T, Alignment> operator+(uintptr_t offs, const PoolArrayIterator<T, Alignment> &iter)
655*35238bceSAndroid Build Coastguard Worker {
656*35238bceSAndroid Build Coastguard Worker     return PoolArrayIterator<T, Alignment>(iter.getArray(), iter.getNdx() + offs);
657*35238bceSAndroid Build Coastguard Worker }
658*35238bceSAndroid Build Coastguard Worker 
659*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
operator -(const PoolArrayIterator<T,Alignment> & iter,intptr_t offs)660*35238bceSAndroid Build Coastguard Worker PoolArrayIterator<T, Alignment> operator-(const PoolArrayIterator<T, Alignment> &iter, intptr_t offs)
661*35238bceSAndroid Build Coastguard Worker {
662*35238bceSAndroid Build Coastguard Worker     return PoolArrayIterator<T, Alignment>(iter.getArray(), iter.getNdx() - offs);
663*35238bceSAndroid Build Coastguard Worker }
664*35238bceSAndroid Build Coastguard Worker 
665*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
operator -(const PoolArrayIterator<T,Alignment> & iter,const PoolArrayIterator<T,Alignment> & other)666*35238bceSAndroid Build Coastguard Worker intptr_t operator-(const PoolArrayIterator<T, Alignment> &iter, const PoolArrayIterator<T, Alignment> &other)
667*35238bceSAndroid Build Coastguard Worker {
668*35238bceSAndroid Build Coastguard Worker     return iter.getNdx() - other.getNdx();
669*35238bceSAndroid Build Coastguard Worker }
670*35238bceSAndroid Build Coastguard Worker 
671*35238bceSAndroid Build Coastguard Worker } // namespace de
672*35238bceSAndroid Build Coastguard Worker 
673*35238bceSAndroid Build Coastguard Worker // std::iterator_traits specializations
674*35238bceSAndroid Build Coastguard Worker namespace std
675*35238bceSAndroid Build Coastguard Worker {
676*35238bceSAndroid Build Coastguard Worker 
677*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
678*35238bceSAndroid Build Coastguard Worker struct iterator_traits<de::PoolArrayConstIterator<T, Alignment>>
679*35238bceSAndroid Build Coastguard Worker {
680*35238bceSAndroid Build Coastguard Worker     typedef intptr_t difference_type;
681*35238bceSAndroid Build Coastguard Worker     typedef T value_type;
682*35238bceSAndroid Build Coastguard Worker     typedef const T *pointer;
683*35238bceSAndroid Build Coastguard Worker     typedef const T &reference;
684*35238bceSAndroid Build Coastguard Worker     typedef random_access_iterator_tag iterator_category;
685*35238bceSAndroid Build Coastguard Worker };
686*35238bceSAndroid Build Coastguard Worker 
687*35238bceSAndroid Build Coastguard Worker template <typename T, uint32_t Alignment>
688*35238bceSAndroid Build Coastguard Worker struct iterator_traits<de::PoolArrayIterator<T, Alignment>>
689*35238bceSAndroid Build Coastguard Worker {
690*35238bceSAndroid Build Coastguard Worker     typedef intptr_t difference_type;
691*35238bceSAndroid Build Coastguard Worker     typedef T value_type;
692*35238bceSAndroid Build Coastguard Worker     typedef T *pointer;
693*35238bceSAndroid Build Coastguard Worker     typedef T &reference;
694*35238bceSAndroid Build Coastguard Worker     typedef random_access_iterator_tag iterator_category;
695*35238bceSAndroid Build Coastguard Worker };
696*35238bceSAndroid Build Coastguard Worker 
697*35238bceSAndroid Build Coastguard Worker } // namespace std
698*35238bceSAndroid Build Coastguard Worker 
699*35238bceSAndroid Build Coastguard Worker #endif // _DEPOOLARRAY_HPP
700