Coin Logo 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
31class COIN_DLL_API SbPList {
32 enum { DEFAULTSIZE = 4 };
33
34public:
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
60protected:
61
62 void expand(const int size);
63 int getArraySize(void) const;
64
65private:
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
77inline void
78SbPList::append(void * item)
79{
80 if (this->numitems == this->itembuffersize) this->grow();
81 this->itembuffer[this->numitems++] = item;
82}
83
84inline void
85SbPList::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
93inline int
95{
96 return this->numitems;
97}
98
99inline void
100SbPList::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
109inline void **
110SbPList::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
118inline void *&
119SbPList::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
128inline int
130{
131 return !(*this == l);
132}
133
134inline void *
135SbPList::get(const int index) const
136{
137 return this->itembuffer[index];
138}
139
140inline void
141SbPList::set(const int index, void * item)
142{
143 this->itembuffer[index] = item;
144}
145
146inline void
147SbPList::expand(const int size)
148{
149 this->grow(size);
150 this->numitems = size;
151}
152
153inline int
155{
156 return this->itembuffersize;
157}
158
159
160#endif // !COIN_LISTS_SBPLIST_H
The SbPList class is a container class for void pointers.
Definition SbPList.h:31
void ** getArrayPtr(const int start=0) const
Definition SbPList.h:110
void set(const int index, void *item)
Definition SbPList.h:141
void expand(const int size)
Definition SbPList.h:147
void * get(const int index) const
Definition SbPList.h:135
int operator!=(const SbPList &l) const
Definition SbPList.h:129
void append(void *item)
Definition SbPList.h:78
int getLength(void) const
Definition SbPList.h:94
void fit(void)
Definition SbPList.cpp:189
void removeFast(const int index)
Definition SbPList.h:85
void *& operator[](const int index) const
Definition SbPList.h:119
int getArraySize(void) const
Definition SbPList.h:154
void truncate(const int length, const int fit=0)
Definition SbPList.h:100

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

Generated on Wed Jul 17 2024 for Coin by Doxygen 1.12.0.