38#include <Inventor/SbBasic.h>
65#pragma warning(disable:4251)
66#pragma warning(disable:4275)
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;
107 if (items < this->itembuffersize) {
108 Type * newitembuffer = this->builtinbuffer;
109 if (items > DEFAULTSIZE) newitembuffer =
new Type[items];
111 if (newitembuffer != this->itembuffer) {
112 for (
int i = 0; i < items; i++) newitembuffer[i] = this->itembuffer[i];
115 if (this->itembuffer != this->builtinbuffer)
delete[] this->itembuffer;
116 this->itembuffer = newitembuffer;
117 this->itembuffersize = items > DEFAULTSIZE ? items : DEFAULTSIZE;
122 if (this->numitems == this->itembuffersize) this->grow();
123 this->itembuffer[this->numitems++] = item;
126 int find(
const Type item)
const {
127 for (
int i = 0; i < this->numitems; i++)
128 if (this->itembuffer[i] == item)
return i;
132 void insert(
const Type item,
const int insertbefore) {
133#ifdef COIN_EXTRA_DEBUG
134 assert(insertbefore >= 0 && insertbefore <= this->numitems);
136 if (this->numitems == this->itembuffersize) this->grow();
138 for (
int i = this->numitems; i > insertbefore; i--)
139 this->itembuffer[i] = this->itembuffer[i-1];
140 this->itembuffer[insertbefore] = item;
145 int idx = this->
find(item);
146#ifdef COIN_EXTRA_DEBUG
153#ifdef COIN_EXTRA_DEBUG
154 assert(index >= 0 && index < this->numitems);
157 for (
int i = index; i < this->numitems; i++)
158 this->itembuffer[i] = this->itembuffer[i + 1];
162#ifdef COIN_EXTRA_DEBUG
163 assert(index >= 0 && index < this->numitems);
165 this->itembuffer[index] = this->itembuffer[--this->numitems];
169 return this->numitems;
172 void truncate(
const int length,
const int dofit = 0) {
173#ifdef COIN_EXTRA_DEBUG
174 assert(length <= this->numitems);
176 this->numitems = length;
177 if (dofit) this->
fit();
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
197 assert(index >= 0 && index < this->numitems);
199 return this->itembuffer[index];
203#ifdef COIN_EXTRA_DEBUG
204 assert(index >= 0 && index < this->numitems);
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;
243 else if (size <= this->itembuffersize)
return;
244 else { this->itembuffersize = size; }
246 Type * newbuffer =
new Type[this->itembuffersize];
247 const int n = this->numitems;
248 for (
int i = 0; i < n; i++) newbuffer[i] = this->itembuffer[i];
249 if (this->itembuffer != this->builtinbuffer)
delete[] this->itembuffer;
250 this->itembuffer = newbuffer;
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
int operator!=(const SbList< Type > &l) const
Definition SbList.h:217
int operator==(const SbList< Type > &l) const
Definition SbList.h:209
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 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
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