29#include <Inventor/SbBasic.h>
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);
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
130#ifdef COIN_EXTRA_DEBUG
131 assert(index >= 0 && index < this->numitems);
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);
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);
153 this->numitems = length;
154 if (dofit) this->
fit();
162#ifdef COIN_EXTRA_DEBUG
163 assert(this->numitems > 0);
165 return this->itembuffer[--this->numitems];
169 return &this->itembuffer[start];
173#ifdef COIN_EXTRA_DEBUG
174 assert(index >= 0 && index < this->numitems);
176 return this->itembuffer[index];
180#ifdef COIN_EXTRA_DEBUG
181 assert(index >= 0 && index < this->numitems);
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];
The SbList class is a template container class for lists.
Definition SbList.h:47
void truncate(const int length, const int dofit=0)
Definition SbList.h:149
int getLength(void) const
Definition SbList.h:145
SbList(const SbList< Type > &l)
Definition SbList.h:60
Type pop(void)
Definition SbList.h:161
int find(const Type item) const
Definition SbList.h:103
int operator!=(const SbList< Type > &l) const
Definition SbList.h:194
int operator==(const SbList< Type > &l) const
Definition SbList.h:186
SbList< Type > & operator=(const SbList< Type > &l)
Definition SbList.h:76
void removeFast(const int index)
Definition SbList.h:138
Type & operator[](const int index)
Definition SbList.h:179
int getArraySize(void) const
Definition SbList.h:205
const Type * getArrayPtr(const int start=0) const
Definition SbList.h:168
void remove(const int index)
Definition SbList.h:129
SbList(const int sizehint=DEFAULTSIZE)
Definition SbList.h:55
void removeItem(const Type item)
Definition SbList.h:121
void copy(const SbList< Type > &l)
Definition SbList.h:69
void fit(void)
Definition SbList.h:81
void insert(const Type item, const int insertbefore)
Definition SbList.h:109
~SbList()
Definition SbList.h:65
void append(const Type item)
Definition SbList.h:98
void expand(const int size)
Definition SbList.h:200
Type operator[](const int index) const
Definition SbList.h:172
void push(const Type item)
Definition SbList.h:157
Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.
Generated on Wed Jul 17 2024 for Coin by Doxygen. 1.12.0