38#include <Inventor/SbBasic.h>
65#pragma warning(disable:4251)
66#pragma warning(disable:4275)
69template <
typename Type>
74 enum { DEFAULTSIZE = 4 };
78 SbList(
const int sizehint = DEFAULTSIZE)
79 : itembuffersize(DEFAULTSIZE), numitems(0), itembuffer(builtinbuffer) {
80 if (sizehint > DEFAULTSIZE) this->grow(sizehint);
84 : itembuffersize(DEFAULTSIZE), numitems(0), itembuffer(builtinbuffer) {
89 if (this->itembuffer != builtinbuffer)
delete[] this->itembuffer;
93 if (
this == &l)
return;
94 const int n = l.numitems;
96 for (
int i = 0; i < n; i++) this->itembuffer[i] = l.itembuffer[i];
105 const int items = this->numitems;
115 if (this->itembuffer != this->builtinbuffer)
delete[] this->itembuffer;
117 this->itembuffersize = items > DEFAULTSIZE ? items : DEFAULTSIZE;
122 if (this->numitems == this->itembuffersize) this->grow();
123 this->itembuffer[this->numitems++] =
item;
127 for (
int i = 0;
i < this->numitems;
i++)
128 if (this->itembuffer[
i] ==
item)
return i;
133#ifdef COIN_EXTRA_DEBUG
136 if (this->numitems == this->itembuffersize) this->grow();
139 this->itembuffer[
i] = this->itembuffer[
i-1];
145 int idx = this->
find(item);
146#ifdef COIN_EXTRA_DEBUG
153#ifdef COIN_EXTRA_DEBUG
157 for (
int i = index;
i < this->numitems;
i++)
158 this->itembuffer[
i] = this->itembuffer[
i + 1];
162#ifdef COIN_EXTRA_DEBUG
165 this->itembuffer[index] = this->itembuffer[--this->numitems];
169 return this->numitems;
173#ifdef COIN_EXTRA_DEBUG
176 this->numitems = length;
185#ifdef COIN_EXTRA_DEBUG
186 assert(this->numitems > 0);
188 return this->itembuffer[--this->numitems];
192 return &this->itembuffer[start];
196#ifdef COIN_EXTRA_DEBUG
199 return this->itembuffer[index];
203#ifdef COIN_EXTRA_DEBUG
206 return this->itembuffer[index];
210 if (
this == &
l)
return TRUE;
211 if (this->numitems !=
l.numitems)
return FALSE;
212 for (
int i = 0;
i < this->numitems;
i++)
213 if (this->itembuffer[
i] !=
l.itembuffer[
i])
return FALSE;
218 return !(*
this ==
l);
222 if ((size > itembuffersize) &&
223 (size > DEFAULTSIZE)) {
232 this->numitems = size;
236 return this->itembuffersize;
240 void grow(
const int size = -1) {
242 if (size == -1) this->itembuffersize <<= 1;
244 else { this->itembuffersize = size; }
246 Type *
newbuffer =
new Type[this->itembuffersize];
247 const int n = this->numitems;
249 if (this->itembuffer != this->builtinbuffer)
delete[] this->itembuffer;
256 Type builtinbuffer[DEFAULTSIZE];
The SbList class is a template container class for lists.
Definition SbList.h:70
void truncate(const int length, const int dofit=0)
Definition SbList.h:172
int getLength(void) const
Definition SbList.h:168
SbList(const SbList< Type > &l)
Definition SbList.h:83
Type pop(void)
Definition SbList.h:184
int find(const Type item) const
Definition SbList.h:126
SbList< Type > & operator=(const SbList< Type > &l)
Definition SbList.h:99
void removeFast(const int index)
Definition SbList.h:161
Type & operator[](const int index)
Definition SbList.h:202
int operator!=(const SbList< Type > &l) const
Definition SbList.h:217
int getArraySize(void) const
Definition SbList.h:235
const Type * getArrayPtr(const int start=0) const
Definition SbList.h:191
void remove(const int index)
Definition SbList.h:152
SbList(const int sizehint=DEFAULTSIZE)
Definition SbList.h:78
void removeItem(const Type item)
Definition SbList.h:144
int operator==(const SbList< Type > &l) const
Definition SbList.h:209
void copy(const SbList< Type > &l)
Definition SbList.h:92
void fit(void)
Definition SbList.h:104
void insert(const Type item, const int insertbefore)
Definition SbList.h:132
~SbList()
Definition SbList.h:88
void append(const Type item)
Definition SbList.h:121
void expand(const int size)
Definition SbList.h:230
void ensureCapacity(const int size)
Definition SbList.h:221
Type operator[](const int index) const
Definition SbList.h:195
void push(const Type item)
Definition SbList.h:180