00001 #ifndef COIN_LISTS_SBPLIST_H
00002 #define COIN_LISTS_SBPLIST_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <Inventor/SbBasic.h>
00028 #include <assert.h>
00029 #include <stddef.h>
00030
00031 class COIN_DLL_API SbPList {
00032 enum { DEFAULTSIZE = 4 };
00033
00034 public:
00035 SbPList(const int sizehint = DEFAULTSIZE);
00036 SbPList(const SbPList & l);
00037 ~SbPList();
00038
00039 void copy(const SbPList & l);
00040 SbPList & operator=(const SbPList & l);
00041 void fit(void);
00042
00043 void append(void * item);
00044 int find(void * item) const;
00045 void insert(void * item, const int insertbefore);
00046 void removeItem(void * item);
00047 void remove(const int index);
00048 void removeFast(const int index);
00049 int getLength(void) const;
00050 void truncate(const int length, const int fit = 0);
00051
00052 void ** getArrayPtr(const int start = 0) const;
00053 void *& operator[](const int index) const;
00054
00055 int operator==(const SbPList & l) const;
00056 int operator!=(const SbPList & l) const;
00057 void * get(const int index) const;
00058 void set(const int index, void * item);
00059
00060 protected:
00061
00062 void expand(const int size);
00063 int getArraySize(void) const;
00064
00065 private:
00066 void expandlist(const int size) const;
00067 void grow(const int size = -1);
00068
00069 int itembuffersize;
00070 int numitems;
00071 void ** itembuffer;
00072 void * builtinbuffer[DEFAULTSIZE];
00073 };
00074
00075
00076
00077 inline void
00078 SbPList::append(void * item)
00079 {
00080 if (this->numitems == this->itembuffersize) this->grow();
00081 this->itembuffer[this->numitems++] = item;
00082 }
00083
00084 inline void
00085 SbPList::removeFast(const int index)
00086 {
00087 #ifdef COIN_EXTRA_DEBUG
00088 assert(index >= 0 && index < this->numitems);
00089 #endif // COIN_EXTRA_DEBUG
00090 this->itembuffer[index] = this->itembuffer[--this->numitems];
00091 }
00092
00093 inline int
00094 SbPList::getLength(void) const
00095 {
00096 return this->numitems;
00097 }
00098
00099 inline void
00100 SbPList::truncate(const int length, const int fit )
00101 {
00102 #ifdef COIN_EXTRA_DEBUG
00103 assert(length <= this->numitems);
00104 #endif // COIN_EXTRA_DEBUG
00105 this->numitems = length;
00106 if (fit) this->fit();
00107 }
00108
00109 inline void **
00110 SbPList::getArrayPtr(const int start) const
00111 {
00112 #ifdef COIN_EXTRA_DEBUG
00113 assert(index >= 0 && index < this->numitems);
00114 #endif // COIN_EXTRA_DEBUG
00115 return &this->itembuffer[start];
00116 }
00117
00118 inline void *&
00119 SbPList::operator[](const int index) const
00120 {
00121 #ifdef COIN_EXTRA_DEBUG
00122 assert(index >= 0);
00123 #endif // COIN_EXTRA_DEBUG
00124 if (index >= this->getLength()) this->expandlist(index + 1);
00125 return this->itembuffer[index];
00126 }
00127
00128 inline int
00129 SbPList::operator!=(const SbPList & l) const
00130 {
00131 return !(*this == l);
00132 }
00133
00134 inline void *
00135 SbPList::get(const int index) const
00136 {
00137 return this->itembuffer[index];
00138 }
00139
00140 inline void
00141 SbPList::set(const int index, void * item)
00142 {
00143 this->itembuffer[index] = item;
00144 }
00145
00146 inline void
00147 SbPList::expand(const int size)
00148 {
00149 this->grow(size);
00150 this->numitems = size;
00151 }
00152
00153 inline int
00154 SbPList::getArraySize(void) const
00155 {
00156 return this->itembuffersize;
00157 }
00158
00159
00160 #endif // !COIN_LISTS_SBPLIST_H