29#include <Inventor/SbBasic.h>
56#pragma warning(disable:4251)
57#pragma warning(disable:4275)
65 enum { DEFAULTSIZE = 4 };
69 SbList(
const int sizehint = DEFAULTSIZE)
70 : itembuffersize(DEFAULTSIZE), numitems(0), itembuffer(builtinbuffer) {
71 if (sizehint > DEFAULTSIZE) this->grow(sizehint);
75 : itembuffersize(DEFAULTSIZE), numitems(0), itembuffer(builtinbuffer) {
80 if (this->itembuffer != builtinbuffer)
delete[] this->itembuffer;
84 if (
this == &l)
return;
85 const int n = l.numitems;
87 for (
int i = 0; i < n; i++) this->itembuffer[i] = l.itembuffer[i];
96 const int items = this->numitems;
98 if (items < this->itembuffersize) {
99 Type * newitembuffer = this->builtinbuffer;
100 if (items > DEFAULTSIZE) newitembuffer =
new Type[items];
102 if (newitembuffer != this->itembuffer) {
103 for (
int i = 0; i < items; i++) newitembuffer[i] = this->itembuffer[i];
106 if (this->itembuffer != this->builtinbuffer)
delete[] this->itembuffer;
107 this->itembuffer = newitembuffer;
108 this->itembuffersize = items > DEFAULTSIZE ? items : DEFAULTSIZE;
113 if (this->numitems == this->itembuffersize) this->grow();
114 this->itembuffer[this->numitems++] = item;
117 int find(
const Type item)
const {
118 for (
int i = 0; i < this->numitems; i++)
119 if (this->itembuffer[i] == item)
return i;
123 void insert(
const Type item,
const int insertbefore) {
124#ifdef COIN_EXTRA_DEBUG
125 assert(insertbefore >= 0 && insertbefore <= this->numitems);
127 if (this->numitems == this->itembuffersize) this->grow();
129 for (
int i = this->numitems; i > insertbefore; i--)
130 this->itembuffer[i] = this->itembuffer[i-1];
131 this->itembuffer[insertbefore] = item;
136 int idx = this->
find(item);
137#ifdef COIN_EXTRA_DEBUG
144#ifdef COIN_EXTRA_DEBUG
145 assert(index >= 0 && index < this->numitems);
148 for (
int i = index; i < this->numitems; i++)
149 this->itembuffer[i] = this->itembuffer[i + 1];
153#ifdef COIN_EXTRA_DEBUG
154 assert(index >= 0 && index < this->numitems);
156 this->itembuffer[index] = this->itembuffer[--this->numitems];
160 return this->numitems;
163 void truncate(
const int length,
const int dofit = 0) {
164#ifdef COIN_EXTRA_DEBUG
165 assert(length <= this->numitems);
167 this->numitems = length;
168 if (dofit) this->
fit();
176#ifdef COIN_EXTRA_DEBUG
177 assert(this->numitems > 0);
179 return this->itembuffer[--this->numitems];
183 return &this->itembuffer[start];
187#ifdef COIN_EXTRA_DEBUG
188 assert(index >= 0 && index < this->numitems);
190 return this->itembuffer[index];
194#ifdef COIN_EXTRA_DEBUG
195 assert(index >= 0 && index < this->numitems);
197 return this->itembuffer[index];
201 if (
this == &l)
return TRUE;
202 if (this->numitems != l.numitems)
return FALSE;
203 for (
int i = 0; i < this->numitems; i++)
204 if (this->itembuffer[i] != l.itembuffer[i])
return FALSE;
209 return !(*
this == l);
213 if ((size > itembuffersize) &&
214 (size > DEFAULTSIZE)) {
223 this->numitems = size;
227 return this->itembuffersize;
231 void grow(
const int size = -1) {
233 if (size == -1) this->itembuffersize <<= 1;
234 else if (size <= this->itembuffersize)
return;
235 else { this->itembuffersize = size; }
237 Type * newbuffer =
new Type[this->itembuffersize];
238 const int n = this->numitems;
239 for (
int i = 0; i < n; i++) newbuffer[i] = this->itembuffer[i];
240 if (this->itembuffer != this->builtinbuffer)
delete[] this->itembuffer;
241 this->itembuffer = newbuffer;
247 Type builtinbuffer[DEFAULTSIZE];
The SbList class is a template container class for lists.
Definition SbList.h:61
void truncate(const int length, const int dofit=0)
Definition SbList.h:163
int getLength(void) const
Definition SbList.h:159
SbList(const SbList< Type > &l)
Definition SbList.h:74
Type pop(void)
Definition SbList.h:175
int find(const Type item) const
Definition SbList.h:117
int operator!=(const SbList< Type > &l) const
Definition SbList.h:208
int operator==(const SbList< Type > &l) const
Definition SbList.h:200
SbList< Type > & operator=(const SbList< Type > &l)
Definition SbList.h:90
void removeFast(const int index)
Definition SbList.h:152
Type & operator[](const int index)
Definition SbList.h:193
int getArraySize(void) const
Definition SbList.h:226
const Type * getArrayPtr(const int start=0) const
Definition SbList.h:182
void remove(const int index)
Definition SbList.h:143
SbList(const int sizehint=DEFAULTSIZE)
Definition SbList.h:69
void removeItem(const Type item)
Definition SbList.h:135
void copy(const SbList< Type > &l)
Definition SbList.h:83
void fit(void)
Definition SbList.h:95
void insert(const Type item, const int insertbefore)
Definition SbList.h:123
~SbList()
Definition SbList.h:79
void append(const Type item)
Definition SbList.h:112
void expand(const int size)
Definition SbList.h:221
void ensureCapacity(const int size)
Definition SbList.h:212
Type operator[](const int index) const
Definition SbList.h:186
void push(const Type item)
Definition SbList.h:171
Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.
Generated on Wed Jul 17 2024 for Coin by Doxygen 1.12.0.