40#include <Inventor/SbBasic.h>
67#pragma warning(disable:4251)
68#pragma warning(disable:4275)
71template <
typename Type>
76 enum { DEFAULTSIZE = 4 };
80 SbList(
const int sizehint = DEFAULTSIZE)
81 : itembuffersize(DEFAULTSIZE), numitems(0), itembuffer(builtinbuffer) {
82 if (sizehint > DEFAULTSIZE) this->grow(sizehint);
86 : itembuffersize(DEFAULTSIZE), numitems(0), itembuffer(builtinbuffer) {
91 if (this->itembuffer != builtinbuffer)
delete[] this->itembuffer;
95 if (
this == &l)
return;
96 const int n = l.numitems;
98 for (
int i = 0; i < n; i++) this->itembuffer[i] = l.itembuffer[i];
107 const int items = this->numitems;
123 if (this->itembuffer != this->builtinbuffer)
delete[] this->itembuffer;
125 this->itembuffersize = items > DEFAULTSIZE ? items : DEFAULTSIZE;
130 if (this->numitems == this->itembuffersize) this->grow();
131 this->itembuffer[this->numitems++] =
item;
135 for (
int i = 0;
i < this->numitems;
i++)
136 if (this->itembuffer[
i] ==
item)
return i;
141#ifdef COIN_EXTRA_DEBUG
144 if (this->numitems == this->itembuffersize) this->grow();
147 this->itembuffer[
i] = this->itembuffer[
i-1];
153 int idx = this->
find(item);
154#ifdef COIN_EXTRA_DEBUG
157 if (idx >= 0) this->
remove(idx);
161#ifdef COIN_EXTRA_DEBUG
165 for (
int i = index;
i < this->numitems;
i++)
166 this->itembuffer[
i] = this->itembuffer[
i + 1];
170#ifdef COIN_EXTRA_DEBUG
173 this->itembuffer[index] = this->itembuffer[--this->numitems];
177 return this->numitems;
181#ifdef COIN_EXTRA_DEBUG
184 this->numitems = length;
193#ifdef COIN_EXTRA_DEBUG
194 assert(this->numitems > 0);
196 return this->itembuffer[--this->numitems];
200 return &this->itembuffer[start];
204#ifdef COIN_EXTRA_DEBUG
207 return this->itembuffer[index];
211#ifdef COIN_EXTRA_DEBUG
214 return this->itembuffer[index];
218 if (
this == &
l)
return TRUE;
219 if (this->numitems !=
l.numitems)
return FALSE;
220 for (
int i = 0;
i < this->numitems;
i++)
221 if (this->itembuffer[
i] !=
l.itembuffer[
i])
return FALSE;
226 return !(*
this ==
l);
230 if ((size > itembuffersize) &&
231 (size > DEFAULTSIZE)) {
240 this->numitems = size;
244 return this->itembuffersize;
248 void grow(
const int size = -1) {
253 if (this->itembuffersize >
INT_MAX / 2)
throw std::bad_alloc();
254 newsize = this->itembuffersize * 2;
260 const int n = this->numitems;
268 if (this->itembuffer != this->builtinbuffer)
delete[] this->itembuffer;
270 this->itembuffersize =
newsize;
276 Type builtinbuffer[DEFAULTSIZE];
The SbList class is a template container class for lists.
Definition SbList.h:72
void truncate(const int length, const int dofit=0)
Definition SbList.h:180
int getLength(void) const
Definition SbList.h:176
SbList(const SbList< Type > &l)
Definition SbList.h:85
Type pop(void)
Definition SbList.h:192
int find(const Type item) const
Definition SbList.h:134
SbList< Type > & operator=(const SbList< Type > &l)
Definition SbList.h:101
void removeFast(const int index)
Definition SbList.h:169
Type & operator[](const int index)
Definition SbList.h:210
int operator!=(const SbList< Type > &l) const
Definition SbList.h:225
int getArraySize(void) const
Definition SbList.h:243
const Type * getArrayPtr(const int start=0) const
Definition SbList.h:199
void remove(const int index)
Definition SbList.h:160
SbList(const int sizehint=DEFAULTSIZE)
Definition SbList.h:80
void removeItem(const Type item)
Definition SbList.h:152
int operator==(const SbList< Type > &l) const
Definition SbList.h:217
void copy(const SbList< Type > &l)
Definition SbList.h:94
void fit(void)
Definition SbList.h:106
void insert(const Type item, const int insertbefore)
Definition SbList.h:140
~SbList()
Definition SbList.h:90
void append(const Type item)
Definition SbList.h:129
void expand(const int size)
Definition SbList.h:238
void ensureCapacity(const int size)
Definition SbList.h:229
Type operator[](const int index) const
Definition SbList.h:203
void push(const Type item)
Definition SbList.h:188