38 #include <Inventor/SbBasic.h> 64 #ifdef _MSC_VER // Microsoft Visual C++ 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);
135 #endif // COIN_EXTRA_DEBUG 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 148 #endif // COIN_EXTRA_DEBUG 152 void remove(
const int index) {
153 #ifdef COIN_EXTRA_DEBUG 154 assert(index >= 0 && index < this->numitems);
155 #endif // 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 163 assert(index >= 0 && index < this->numitems);
164 #endif // COIN_EXTRA_DEBUG 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);
175 #endif // COIN_EXTRA_DEBUG 176 this->numitems = length;
177 if (dofit) this->
fit();
185 #ifdef COIN_EXTRA_DEBUG 186 assert(this->numitems > 0);
187 #endif // COIN_EXTRA_DEBUG 188 return this->itembuffer[--this->numitems];
192 return &this->itembuffer[start];
196 #ifdef COIN_EXTRA_DEBUG 197 assert(index >= 0 && index < this->numitems);
198 #endif // COIN_EXTRA_DEBUG 199 return this->itembuffer[index];
203 #ifdef COIN_EXTRA_DEBUG 204 assert(index >= 0 && index < this->numitems);
205 #endif // 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;
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];
259 #endif // !COIN_SBLIST_H SbList(const int sizehint=DEFAULTSIZE)
Definition: SbList.h:78
Type pop(void)
Definition: SbList.h:184
void push(const Type item)
Definition: SbList.h:180
int operator==(const SbList< Type > &l) const
Definition: SbList.h:209
void append(const Type item)
Definition: SbList.h:121
The SbList class is a template container class for lists.
Definition: SoType.h:55
int find(const Type item) const
Definition: SbList.h:126
void truncate(const int length, const int dofit=0)
Definition: SbList.h:172
int operator!=(const SbList< Type > &l) const
Definition: SbList.h:217
const Type * getArrayPtr(const int start=0) const
Definition: SbList.h:191
int getArraySize(void) const
Definition: SbList.h:235
void ensureCapacity(const int size)
Definition: SbList.h:221
Type operator[](const int index) const
Definition: SbList.h:195
void insert(const Type item, const int insertbefore)
Definition: SbList.h:132
Type & operator[](const int index)
Definition: SbList.h:202
SbList(const SbList< Type > &l)
Definition: SbList.h:83
void copy(const SbList< Type > &l)
Definition: SbList.h:92
void removeItem(const Type item)
Definition: SbList.h:144
void fit(void)
Definition: SbList.h:104
void removeFast(const int index)
Definition: SbList.h:161
~SbList()
Definition: SbList.h:88
SbList< Type > & operator=(const SbList< Type > &l)
Definition: SbList.h:99
void expand(const int size)
Definition: SbList.h:230
int getLength(void) const
Definition: SbList.h:168