63 #ifdef _MSC_VER // Microsoft Visual C++ 64 #pragma warning(disable:4251) 65 #pragma warning(disable:4275) 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;
106 if (items < this->itembuffersize) {
107 Type * newitembuffer = this->builtinbuffer;
108 if (items > DEFAULTSIZE) newitembuffer =
new Type[items];
110 if (newitembuffer != this->itembuffer) {
111 for (
int i = 0; i < items; i++) newitembuffer[i] = this->itembuffer[i];
114 if (this->itembuffer != this->builtinbuffer)
delete[] this->itembuffer;
115 this->itembuffer = newitembuffer;
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;
131 void insert(
const Type item,
const int insertbefore) {
132 #ifdef COIN_EXTRA_DEBUG 133 assert(insertbefore >= 0 && insertbefore <= this->numitems);
134 #endif // COIN_EXTRA_DEBUG 135 if (this->numitems == this->itembuffersize) this->grow();
137 for (
int i = this->numitems; i > insertbefore; i--)
138 this->itembuffer[i] = this->itembuffer[i-1];
139 this->itembuffer[insertbefore] = item;
144 int idx = this->
find(item);
145 #ifdef COIN_EXTRA_DEBUG 147 #endif // COIN_EXTRA_DEBUG 151 void remove(
const int index) {
152 #ifdef COIN_EXTRA_DEBUG 153 assert(index >= 0 && index < this->numitems);
154 #endif // COIN_EXTRA_DEBUG 156 for (
int i = index; i < this->numitems; i++)
157 this->itembuffer[i] = this->itembuffer[i + 1];
161 #ifdef COIN_EXTRA_DEBUG 162 assert(index >= 0 && index < this->numitems);
163 #endif // COIN_EXTRA_DEBUG 164 this->itembuffer[index] = this->itembuffer[--this->numitems];
168 return this->numitems;
171 void truncate(
const int length,
const int fit = 0) {
172 #ifdef COIN_EXTRA_DEBUG 173 assert(length <= this->numitems);
174 #endif // COIN_EXTRA_DEBUG 175 this->numitems = length;
179 void push(
const Type item) {
184 #ifdef COIN_EXTRA_DEBUG 185 assert(this->numitems > 0);
186 #endif // COIN_EXTRA_DEBUG 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];
200 #ifdef COIN_EXTRA_DEBUG 201 assert(index >= 0 && index < this->numitems);
202 #endif // COIN_EXTRA_DEBUG 203 return this->itembuffer[index];
207 #ifdef COIN_EXTRA_DEBUG 208 assert(index >= 0 && index < this->numitems);
209 #endif // 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;
233 return this->itembuffersize;
237 void grow(
const int size = -1) {
239 if (size == -1) this->itembuffersize <<= 1;
240 else if (size <= this->itembuffersize)
return;
241 else { this->itembuffersize = size; }
243 Type * newbuffer =
new Type[this->itembuffersize];
244 const int n = this->numitems;
245 for (
int i = 0; i < n; i++) newbuffer[i] = this->itembuffer[i];
246 if (this->itembuffer != this->builtinbuffer)
delete[] this->itembuffer;
247 this->itembuffer = newbuffer;
253 Type builtinbuffer[DEFAULTSIZE];
256 #endif // !COIN_SBLIST_H SbList(const int sizehint=DEFAULTSIZE)
Definition: SbList.h:101
Type pop(void)
Definition: SbList.h:268
void push(const Type item)
Definition: SbList.h:262
int operator==(const SbList< Type > &l) const
Definition: SbList.h:301
void append(const Type item)
Definition: SbList.h:187
int find(const Type item) const
Definition: SbList.h:194
void truncate(const int length, const int dofit=0)
Definition: SbList.h:252
int operator!=(const SbList< Type > &l) const
Definition: SbList.h:311
const Type * getArrayPtr(const int start=0) const
Definition: SbList.h:277
int getArraySize(void) const
Definition: SbList.h:145
Type operator[](const int index) const
Definition: SbList.h:283
void insert(const Type item, const int insertbefore)
Definition: SbList.h:202
void copy(const SbList< Type > &l)
Definition: SbList.h:151
void removeItem(const Type item)
Definition: SbList.h:216
void fit(void)
Definition: SbList.h:168
void removeFast(const int index)
Definition: SbList.h:237
~SbList()
Definition: SbList.h:115
SbList< Type > & operator=(const SbList< Type > &l)
Definition: SbList.h:161
void expand(const int size)
Definition: SbList.h:138
int getLength(void) const
Definition: SbList.h:246