29 #include <Inventor/SbBasic.h> 41 #ifdef _MSC_VER // Microsoft Visual C++ 42 #pragma warning(disable:4251) 43 #pragma warning(disable:4275) 51 enum { DEFAULTSIZE = 4 };
55 SbList(
const int sizehint = DEFAULTSIZE)
56 : itembuffersize(DEFAULTSIZE), numitems(0), itembuffer(builtinbuffer) {
57 if (sizehint > DEFAULTSIZE) this->grow(sizehint);
61 : itembuffersize(DEFAULTSIZE), numitems(0), itembuffer(builtinbuffer) {
66 if (this->itembuffer != builtinbuffer)
delete[] this->itembuffer;
70 if (
this == &l)
return;
71 const int n = l.numitems;
73 for (
int i = 0; i < n; i++) this->itembuffer[i] = l.itembuffer[i];
82 const int items = this->numitems;
84 if (items < this->itembuffersize) {
85 Type * newitembuffer = this->builtinbuffer;
86 if (items > DEFAULTSIZE) newitembuffer =
new Type[items];
88 if (newitembuffer != this->itembuffer) {
89 for (
int i = 0; i < items; i++) newitembuffer[i] = this->itembuffer[i];
92 if (this->itembuffer != this->builtinbuffer)
delete[] this->itembuffer;
93 this->itembuffer = newitembuffer;
94 this->itembuffersize = items > DEFAULTSIZE ? items : DEFAULTSIZE;
99 if (this->numitems == this->itembuffersize) this->grow();
100 this->itembuffer[this->numitems++] = item;
103 int find(
const Type item)
const {
104 for (
int i = 0; i < this->numitems; i++)
105 if (this->itembuffer[i] == item)
return i;
109 void insert(
const Type item,
const int insertbefore) {
110 #ifdef COIN_EXTRA_DEBUG 111 assert(insertbefore >= 0 && insertbefore <= this->numitems);
112 #endif // COIN_EXTRA_DEBUG 113 if (this->numitems == this->itembuffersize) this->grow();
115 for (
int i = this->numitems; i > insertbefore; i--)
116 this->itembuffer[i] = this->itembuffer[i-1];
117 this->itembuffer[insertbefore] = item;
122 int idx = this->
find(item);
123 #ifdef COIN_EXTRA_DEBUG 125 #endif // COIN_EXTRA_DEBUG 129 void remove(
const int index) {
130 #ifdef COIN_EXTRA_DEBUG 131 assert(index >= 0 && index < this->numitems);
132 #endif // COIN_EXTRA_DEBUG 134 for (
int i = index; i < this->numitems; i++)
135 this->itembuffer[i] = this->itembuffer[i + 1];
139 #ifdef COIN_EXTRA_DEBUG 140 assert(index >= 0 && index < this->numitems);
141 #endif // COIN_EXTRA_DEBUG 142 this->itembuffer[index] = this->itembuffer[--this->numitems];
146 return this->numitems;
149 void truncate(
const int length,
const int dofit = 0) {
150 #ifdef COIN_EXTRA_DEBUG 151 assert(length <= this->numitems);
152 #endif // COIN_EXTRA_DEBUG 153 this->numitems = length;
154 if (dofit) this->
fit();
162 #ifdef COIN_EXTRA_DEBUG 163 assert(this->numitems > 0);
164 #endif // COIN_EXTRA_DEBUG 165 return this->itembuffer[--this->numitems];
169 return &this->itembuffer[start];
173 #ifdef COIN_EXTRA_DEBUG 174 assert(index >= 0 && index < this->numitems);
175 #endif // COIN_EXTRA_DEBUG 176 return this->itembuffer[index];
180 #ifdef COIN_EXTRA_DEBUG 181 assert(index >= 0 && index < this->numitems);
182 #endif // COIN_EXTRA_DEBUG 183 return this->itembuffer[index];
187 if (
this == &l)
return TRUE;
188 if (this->numitems != l.numitems)
return FALSE;
189 for (
int i = 0; i < this->numitems; i++)
190 if (this->itembuffer[i] != l.itembuffer[i])
return FALSE;
195 return !(*
this == l);
202 this->numitems = size;
206 return this->itembuffersize;
210 void grow(
const int size = -1) {
212 if (size == -1) this->itembuffersize <<= 1;
213 else if (size <= this->itembuffersize)
return;
214 else { this->itembuffersize = size; }
216 Type * newbuffer =
new Type[this->itembuffersize];
217 const int n = this->numitems;
218 for (
int i = 0; i < n; i++) newbuffer[i] = this->itembuffer[i];
219 if (this->itembuffer != this->builtinbuffer)
delete[] this->itembuffer;
220 this->itembuffer = newbuffer;
226 Type builtinbuffer[DEFAULTSIZE];
229 #endif // !COIN_SBLIST_H SbList(const int sizehint=DEFAULTSIZE)
Definition: SbList.h:55
Type pop(void)
Definition: SbList.h:161
void push(const Type item)
Definition: SbList.h:157
int operator==(const SbList< Type > &l) const
Definition: SbList.h:186
void append(const Type item)
Definition: SbList.h:98
The SbList class is a template container class for lists.SbList is an extension of the Coin library v...
Definition: SoType.h:46
int find(const Type item) const
Definition: SbList.h:103
void truncate(const int length, const int dofit=0)
Definition: SbList.h:149
int operator!=(const SbList< Type > &l) const
Definition: SbList.h:194
const Type * getArrayPtr(const int start=0) const
Definition: SbList.h:168
int getArraySize(void) const
Definition: SbList.h:205
Type operator[](const int index) const
Definition: SbList.h:172
void insert(const Type item, const int insertbefore)
Definition: SbList.h:109
Type & operator[](const int index)
Definition: SbList.h:179
SbList(const SbList< Type > &l)
Definition: SbList.h:60
void copy(const SbList< Type > &l)
Definition: SbList.h:69
void removeItem(const Type item)
Definition: SbList.h:121
void fit(void)
Definition: SbList.h:81
void removeFast(const int index)
Definition: SbList.h:138
~SbList()
Definition: SbList.h:65
SbList< Type > & operator=(const SbList< Type > &l)
Definition: SbList.h:76
void expand(const int size)
Definition: SbList.h:200
int getLength(void) const
Definition: SbList.h:145