29 #include <Inventor/SbBasic.h>  
   55 #ifdef _MSC_VER // Microsoft Visual C++ 
   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);
 
  126 #endif // COIN_EXTRA_DEBUG 
  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 
  139 #endif // COIN_EXTRA_DEBUG 
  143   void remove(
const int index) {
 
  144 #ifdef COIN_EXTRA_DEBUG 
  145     assert(index >= 0 && index < this->numitems);
 
  146 #endif // COIN_EXTRA_DEBUG 
  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);
 
  155 #endif // COIN_EXTRA_DEBUG 
  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);
 
  166 #endif // COIN_EXTRA_DEBUG 
  167     this->numitems = length;
 
  168     if (dofit) this->
fit();
 
  176 #ifdef COIN_EXTRA_DEBUG 
  177     assert(this->numitems > 0);
 
  178 #endif // COIN_EXTRA_DEBUG 
  179     return this->itembuffer[--this->numitems];
 
  183     return &this->itembuffer[start];
 
  187 #ifdef COIN_EXTRA_DEBUG 
  188     assert(index >= 0 && index < this->numitems);
 
  189 #endif // COIN_EXTRA_DEBUG 
  190     return this->itembuffer[index];
 
  194 #ifdef COIN_EXTRA_DEBUG 
  195     assert(index >= 0 && index < this->numitems);
 
  196 #endif // COIN_EXTRA_DEBUG 
  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];
 
  250 #endif // !COIN_SBLIST_H 
const Type * getArrayPtr(const int start=0) const 
Definition: SbList.h:182
int getLength(void) const 
Definition: SbList.h:159
SbList(const int sizehint=DEFAULTSIZE)
Definition: SbList.h:69
Type pop(void)
Definition: SbList.h:175
void push(const Type item)
Definition: SbList.h:171
void append(const Type item)
Definition: SbList.h:112
int operator==(const SbList< Type > &l) const 
Definition: SbList.h:200
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:117
void truncate(const int length, const int dofit=0)
Definition: SbList.h:163
int getArraySize(void) const 
Definition: SbList.h:226
void ensureCapacity(const int size)
Definition: SbList.h:212
void insert(const Type item, const int insertbefore)
Definition: SbList.h:123
Type operator[](const int index) const 
Definition: SbList.h:186
Type & operator[](const int index)
Definition: SbList.h:193
int operator!=(const SbList< Type > &l) const 
Definition: SbList.h:208
SbList(const SbList< Type > &l)
Definition: SbList.h:74
void copy(const SbList< Type > &l)
Definition: SbList.h:83
void removeItem(const Type item)
Definition: SbList.h:135
void fit(void)
Definition: SbList.h:95
void removeFast(const int index)
Definition: SbList.h:152
~SbList()
Definition: SbList.h:79
SbList< Type > & operator=(const SbList< Type > &l)
Definition: SbList.h:90
void expand(const int size)
Definition: SbList.h:221