33 #ifndef SMALLCHANGE_SBLIST_H 34 #define SMALLCHANGE_SBLIST_H 36 #include <Inventor/SbBasic.h> 45 enum { DEFAULTSIZE = 4 };
48 SbList(
const int sizehint = DEFAULTSIZE);
57 void append(
const Type item);
58 int find(
const Type item)
const;
59 void insert(
const Type item,
const int insertbefore);
60 void remove(
const int index);
69 void push(
const Type item);
74 const Type *
getArrayPtr(
const int start = 0)
const;
85 void expand(
const int size);
89 void grow(
const int size = -1);
94 Type builtinbuffer[DEFAULTSIZE];
100 template <
class Type>
inline 102 : itembuffersize(DEFAULTSIZE), numitems(0), itembuffer(builtinbuffer)
104 if (sizehint > DEFAULTSIZE) this->grow(sizehint);
107 template <
class Type>
inline 109 : itembuffersize(DEFAULTSIZE), numitems(0), itembuffer(builtinbuffer)
114 template <
class Type>
inline 117 if (this->itembuffer != builtinbuffer)
delete [] this->itembuffer;
122 template <
class Type>
inline void 126 if (size == -1) this->itembuffersize <<= 1;
127 else if (size <= this->itembuffersize)
return;
128 else { this->itembuffersize = size; }
130 Type * newbuffer =
new Type[this->itembuffersize];
131 const int n = this->numitems;
132 for (
int i = 0; i < n; i++) newbuffer[i] = this->itembuffer[i];
133 if (this->itembuffer != this->builtinbuffer)
delete [] this->itembuffer;
134 this->itembuffer = newbuffer;
137 template <
class Type>
inline void 141 this->numitems = size;
144 template <
class Type>
inline int 147 return this->itembuffersize;
150 template <
class Type>
inline void 153 if (
this == &l)
return;
155 const int n = l.numitems;
157 for (
int i = 0; i < n; i++) this->itembuffer[i] = l.itembuffer[i];
167 template <
class Type>
inline void 170 const int items = this->numitems;
172 if (items < this->itembuffersize) {
173 Type * newitembuffer = this->builtinbuffer;
174 if (items > DEFAULTSIZE) newitembuffer =
new Type[items];
176 if (newitembuffer != this->itembuffer) {
177 for (
int i = 0; i < items; i++) newitembuffer[i] = this->itembuffer[i];
180 if (this->itembuffer != this->builtinbuffer)
delete [] this->itembuffer;
181 this->itembuffer = newitembuffer;
182 this->itembuffersize = items > DEFAULTSIZE ? items : DEFAULTSIZE;
186 template <
class Type>
inline void 189 if (this->numitems == this->itembuffersize) this->grow();
190 this->itembuffer[this->numitems++] = item;
193 template <
class Type>
inline int 196 for (
int i = 0; i < this->numitems; i++)
197 if (this->itembuffer[i] == item)
return i;
201 template <
class Type>
inline void 204 #ifdef COIN_EXTRA_DEBUG 205 assert(insertbefore >= 0 && insertbefore <= this->numitems);
206 #endif // COIN_EXTRA_DEBUG 207 if (this->numitems == this->itembuffersize) this->grow();
209 for (
int i = this->numitems; i > insertbefore; i--)
210 this->itembuffer[i] = this->itembuffer[i-1];
211 this->itembuffer[insertbefore] = item;
215 template <
class Type>
inline void 218 int idx = this->find(item);
219 #ifdef COIN_EXTRA_DEBUG 221 #endif // COIN_EXTRA_DEBUG 225 template <
class Type>
inline void 228 #ifdef COIN_EXTRA_DEBUG 229 assert(index >= 0 && index < this->numitems);
230 #endif // COIN_EXTRA_DEBUG 232 for (
int i = index; i < this->numitems; i++)
233 this->itembuffer[i] = this->itembuffer[i + 1];
236 template <
class Type>
inline void 239 #ifdef COIN_EXTRA_DEBUG 240 assert(index >= 0 && index < this->numitems);
241 #endif // COIN_EXTRA_DEBUG 242 this->itembuffer[index] = this->itembuffer[--this->numitems];
245 template <
class Type>
inline int 248 return this->numitems;
251 template <
class Type>
inline void 254 #ifdef COIN_EXTRA_DEBUG 255 assert(length <= this->numitems);
256 #endif // COIN_EXTRA_DEBUG 257 this->numitems = length;
258 if (fit) this->fit();
261 template <
class Type>
inline void 267 template <
class Type>
inline Type
270 #ifdef COIN_EXTRA_DEBUG 271 assert(this->numitems > 0);
272 #endif // COIN_EXTRA_DEBUG 273 return this->itembuffer[--this->numitems];
276 template <
class Type>
inline const Type *
279 return &this->itembuffer[start];
282 template <
class Type>
inline Type
285 #ifdef COIN_EXTRA_DEBUG 286 assert(index >= 0 && index < this->numitems);
287 #endif // COIN_EXTRA_DEBUG 288 return this->itembuffer[index];
291 template <
class Type>
inline Type &
294 #ifdef COIN_EXTRA_DEBUG 295 assert(index >= 0 && index < this->numitems);
296 #endif // COIN_EXTRA_DEBUG 297 return this->itembuffer[index];
300 template <
class Type>
inline int 303 if (
this == &l)
return TRUE;
304 if (this->numitems != l.numitems)
return FALSE;
305 for (
int i = 0; i < this->numitems; i++)
306 if (this->itembuffer[i] != l.itembuffer[i])
return FALSE;
310 template <
class Type>
inline int 313 return !(*
this == l);
316 #endif // !SMALLCHANGE_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
void remove(const int index)
Definition: SbList.h:226
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