73 enum { DEFAULTSIZE = 4 };
77 SbList(
const int sizehint = DEFAULTSIZE)
78 : itembuffersize(DEFAULTSIZE), numitems(0), itembuffer(builtinbuffer) {
79 if (sizehint > DEFAULTSIZE) this->grow(sizehint);
83 : itembuffersize(DEFAULTSIZE), numitems(0), itembuffer(builtinbuffer) {
88 if (this->itembuffer != builtinbuffer)
delete[] this->itembuffer;
92 if (
this == &l)
return;
93 const int n = l.numitems;
95 for (
int i = 0; i < n; i++) this->itembuffer[i] = l.itembuffer[i];
104 const int items = this->numitems;
114 if (this->itembuffer != this->builtinbuffer)
delete[] this->itembuffer;
116 this->itembuffersize = items > DEFAULTSIZE ? items : DEFAULTSIZE;
120 void append(
const Type
item) {
121 if (this->numitems == this->itembuffersize) this->grow();
122 this->itembuffer[this->numitems++] =
item;
125 int find(
const Type
item)
const {
126 for (
int i = 0;
i < this->numitems;
i++)
127 if (this->itembuffer[
i] ==
item)
return i;
132#ifdef COIN_EXTRA_DEBUG
135 if (this->numitems == this->itembuffersize) this->grow();
138 this->itembuffer[
i] = this->itembuffer[
i-1];
143 void removeItem(
const Type
item) {
144 int idx = this->find(
item);
145#ifdef COIN_EXTRA_DEBUG
151 void remove(
const int index) {
152#ifdef COIN_EXTRA_DEBUG
156 for (
int i = index;
i < this->numitems;
i++)
157 this->itembuffer[
i] = this->itembuffer[
i + 1];
160 void removeFast(
const int index) {
161#ifdef COIN_EXTRA_DEBUG
164 this->itembuffer[index] = this->itembuffer[--this->numitems];
167 int getLength(
void)
const {
168 return this->numitems;
171 void truncate(
const int length,
const int fit = 0) {
172#ifdef COIN_EXTRA_DEBUG
175 this->numitems = length;
176 if (fit) this->fit();
179 void push(
const Type
item) {
184#ifdef COIN_EXTRA_DEBUG
185 assert(this->numitems > 0);
187 return this->itembuffer[--this->numitems];
191 assert(this->numitems > 0);
192 return this->itembuffer[this->numitems - 1];
195 const Type * getArrayPtr(
const int start = 0)
const {
196 return &this->itembuffer[
start];
199 Type operator[](
const int index)
const {
200#ifdef COIN_EXTRA_DEBUG
203 return this->itembuffer[index];
206 Type & operator[](
const int index) {
207#ifdef COIN_EXTRA_DEBUG
210 return this->itembuffer[index];
214 if (
this == &
l)
return TRUE;
215 if (this->numitems !=
l.numitems)
return FALSE;
216 for (
int i = 0;
i < this->numitems;
i++)
217 if (this->itembuffer[
i] !=
l.itembuffer[
i])
return FALSE;
222 return !(*
this ==
l);
227 void expand(
const int size) {
229 this->numitems = size;
232 int getArraySize(
void)
const {
233 return this->itembuffersize;
237 void grow(
const int size = -1) {
239 if (size == -1) this->itembuffersize <<= 1;
241 else { this->itembuffersize = size; }
243 Type *
newbuffer =
new Type[this->itembuffersize];
244 const int n = this->numitems;
246 if (this->itembuffer != this->builtinbuffer)
delete[] this->itembuffer;
253 Type builtinbuffer[DEFAULTSIZE];