1 /* Copyright (c) 2003, 2005 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
19 #include "ArrayPool.hpp"
22 #include <ErrorReporter.hpp>
25 * Template class used for implementing an
26 * array of object retreived from a pool
31 Array(ArrayPool
<T
> & thePool
);
34 * Allocate an <b>n</b> objects from pool
35 * These can now be addressed with 0 <= ptr.i < n
40 * Release all object from array
45 * Return current size of array
47 Uint32
getSize() const;
52 inline bool empty() const { return sz
== 0;}
55 * Update i & p value according to <b>i</b>
57 void getPtr(Ptr
<T
> &, Uint32 i
) const;
60 * Update p value for ptr according to i value
62 void getPtr(Ptr
<T
> &) const ;
65 * Get pointer for i value
67 T
* getPtr(Uint32 i
) const;
71 ArrayPool
<T
> & thePool
;
76 Array
<T
>::Array(ArrayPool
<T
> & _pool
)
86 Array
<T
>::seize(Uint32 n
){
87 if(base
== RNIL
&& n
> 0){
88 base
= thePool
.seizeN(n
);
95 ErrorReporter::handleAssert("Array<T>::seize failed", __FILE__
, __LINE__
);
104 thePool
.releaseN(base
, sz
);
114 Array
<T
>::getSize() const {
121 Array
<T
>::getPtr(Ptr
<T
> & p
, Uint32 i
) const {
124 if(i
< sz
&& base
!= RNIL
){
125 p
.p
= thePool
.getPtr(i
+ base
);
128 ErrorReporter::handleAssert("Array::getPtr failed", __FILE__
, __LINE__
);
131 p
.p
= thePool
.getPtr(i
+ base
);
137 Array
<T
>::getPtr(Ptr
<T
> & ptr
) const {
139 if(ptr
.i
< sz
&& base
!= RNIL
){
140 ptr
.p
= thePool
.getPtr(ptr
.i
+ base
);
143 ErrorReporter::handleAssert("Array<T>::getPtr failed", __FILE__
, __LINE__
);
146 ptr
.p
= thePool
.getPtr(ptr
.i
+ base
);
152 Array
<T
>::getPtr(Uint32 i
) const {
154 if(i
< sz
&& base
!= RNIL
){
155 return thePool
.getPtr(i
+ base
);
157 ErrorReporter::handleAssert("Array<T>::getPtr failed", __FILE__
, __LINE__
);
160 return thePool
.getPtr(i
+ base
);