| http://www.sim.no/ http://www.coin3d.org/

SbPList.h
1 #ifndef COIN_LISTS_SBPLIST_H
2 #define COIN_LISTS_SBPLIST_H
3
4 /**************************************************************************\
5 *
6 * This file is part of the Coin 3D visualization library.
7 * Copyright (C) by Kongsberg Oil & Gas Technologies.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * ("GPL") version 2 as published by the Free Software Foundation.
12 * See the file LICENSE.GPL at the root directory of this source
13 * distribution for additional information about the GNU GPL.
14 *
15 * For using Coin with software that can not be combined with the GNU
16 * GPL, and for taking advantage of the additional benefits of our
17 * support services, please contact Kongsberg Oil & Gas Technologies
18 * about acquiring a Coin Professional Edition License.
19 *
20 * See http://www.coin3d.org/ for more information.
21 *
22 * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
23 * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24 *
25 \**************************************************************************/
26
27 #include <Inventor/SbBasic.h>
28 #include <assert.h>
29 #include <stddef.h> // NULL definition
30
31 class COIN_DLL_API SbPList {
32 enum { DEFAULTSIZE = 4 };
33
34 public:
35 SbPList(const int sizehint = DEFAULTSIZE);
36 SbPList(const SbPList & l);
37 ~SbPList();
38
39 void copy(const SbPList & l);
40 SbPList & operator=(const SbPList & l);
41 void fit(void);
42
43 void append(void * item);
44 int find(void * item) const;
45 void insert(void * item, const int insertbefore);
46 void removeItem(void * item);
47 void remove(const int index);
48 void removeFast(const int index);
49 int getLength(void) const;
50 void truncate(const int length, const int fit = 0);
51
52 void ** getArrayPtr(const int start = 0) const;
53 void *& operator[](const int index) const;
54
55 int operator==(const SbPList & l) const;
56 int operator!=(const SbPList & l) const;
57 void * get(const int index) const;
58 void set(const int index, void * item);
59
60 protected:
61
62 void expand(const int size);
63 int getArraySize(void) const;
64
65 private:
66 void expandlist(const int size) const;
67 void grow(const int size = -1);
68
69 int itembuffersize;
70 int numitems;
71 void ** itembuffer;
72 void * builtinbuffer[DEFAULTSIZE];
73 };
74
75 /* inlined methods ********************************************************/
76
77 inline void
78 SbPList::append(void * item)
79 {
80 if (this->numitems == this->itembuffersize) this->grow();
81 this->itembuffer[this->numitems++] = item;
82 }
83
84 inline void
85 SbPList::removeFast(const int index)
86 {
87 #ifdef COIN_EXTRA_DEBUG
88 assert(index >= 0 && index < this->numitems);
89 #endif // COIN_EXTRA_DEBUG
90 this->itembuffer[index] = this->itembuffer[--this->numitems];
91 }
92
93 inline int
94 SbPList::getLength(void) const
95 {
96 return this->numitems;
97 }
98
99 inline void
100 SbPList::truncate(const int length, const int dofit)
101 {
102 #ifdef COIN_EXTRA_DEBUG
103 assert(length <= this->numitems);
104 #endif // COIN_EXTRA_DEBUG
105 this->numitems = length;
106 if (dofit) this->fit();
107 }
108
109 inline void **
110 SbPList::getArrayPtr(const int start) const
111 {
112 #ifdef COIN_EXTRA_DEBUG
113 assert(start >= 0 && start < this->numitems);
114 #endif // COIN_EXTRA_DEBUG
115 return &this->itembuffer[start];
116 }
117
118 inline void *&
119 SbPList::operator[](const int index) const
120 {
121 #ifdef COIN_EXTRA_DEBUG
122 assert(index >= 0);
123 #endif // COIN_EXTRA_DEBUG
124 if (index >= this->getLength()) this->expandlist(index + 1);
125 return this->itembuffer[index];
126 }
127
128 inline int
129 SbPList::operator!=(const SbPList & l) const
130 {
131 return !(*this == l);
132 }
133
134 inline void *
135 SbPList::get(const int index) const
136 {
137 return this->itembuffer[index];
138 }
139
140 inline void
141 SbPList::set(const int index, void * item)
142 {
143 this->itembuffer[index] = item;
144 }
145
146 inline void
147 SbPList::expand(const int size)
148 {
149 this->grow(size);
150 this->numitems = size;
151 }
152
153 inline int
154 SbPList::getArraySize(void) const
155 {
156 return this->itembuffersize;
157 }
158
159
160 #endif // !COIN_LISTS_SBPLIST_H
SbPList::fit
void fit(void)
Definition: SbPList.cpp:189
SbPList::removeFast
void removeFast(const int index)
Definition: SbPList.h:85
SbPList::getArrayPtr
void ** getArrayPtr(const int start=0) const
Definition: SbPList.h:110
SbPList::get
void * get(const int index) const
Definition: SbPList.h:135
SbPList
The SbPList class is a container class for void pointers.
Definition: SbPList.h:31
SbPList::append
void append(void *item)
Definition: SbPList.h:78
SbPList::operator!=
int operator!=(const SbPList &l) const
Definition: SbPList.h:129
SbPList::operator[]
void *& operator[](const int index) const
Definition: SbPList.h:119
SbPList::set
void set(const int index, void *item)
Definition: SbPList.h:141
SbPList::expand
void expand(const int size)
Definition: SbPList.h:147
SbPList::truncate
void truncate(const int length, const int fit=0)
Definition: SbPList.h:100
SbPList::getLength
int getLength(void) const
Definition: SbPList.h:94
SbPList::getArraySize
int getArraySize(void) const
Definition: SbPList.h:154

Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.