Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SbPList.h
Go to the documentation of this file.
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Paul S. Strauss (MMM yyyy)
25** Modified by : Nick Thompson (MMM yyyy)
26** Modified by : Gavin Bell (MMM yyyy)
27**=======================================================================*/
28/*=======================================================================
29 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
30 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
31 *** ***
32 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
33 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
34 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
35 *** ***
36 *** RESTRICTED RIGHTS LEGEND ***
37 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
38 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
39 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
40 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
41 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
42 *** ***
43 *** COPYRIGHT (C) 1996-2014 BY FEI S.A.S, ***
44 *** BORDEAUX, FRANCE ***
45 *** ALL RIGHTS RESERVED ***
46**=======================================================================*/
47/*=======================================================================
48** Modified by : VSG (MMM YYYY)
49**=======================================================================*/
50
51
52#ifndef _SB_PLIST_
53#define _SB_PLIST_
54
55#include <Inventor/SbBase.h>
56#include <Inventor/STL/cassert>
57
58class SbVec3f;
59
77{
78 public:
79
84
90 SbPList(int initSize);
91
95 SbPList(const SbPList &pl);
96
100 virtual ~SbPList();
101
105 void append(void* ptr);
106
110 int find(const void* ptr) const;
111
115 void insert(void* ptr, int addBefore);
116
120 virtual void remove(int which);
121
125 inline int getLength() const
126 { return nPtrs; }
127
131 virtual void truncate(int start);
132
136 void copy(const SbPList &pl);
137
142
147 void *&operator [](const int index) const;
148
152 int operator ==(const SbPList &pl) const;
153
157 int operator !=(const SbPList &pl) const;
158
162 void swap( int index1, int index2 );
163
164 private:
165
167 void *get(int i) const;
168 void set(int i, void *j);
169
170 void **getArray()
171 { return ptrs; }
172
173 // internal public call to expand function (see below) in order to reserve more memory in the list.
174 // same name than stl reserve function
175 void reserve(int size)
176 { expand(size); }
177
178private:
179 // Number of pointers used
180 int nPtrs;
181
182 // There are three(!) methods to expand the list. grow() is used
183 // when space is dynamically created, and needs to be initialized
184 // to NULL:
185 void grow(int max) const;
186
187 // setSize is used by grow and in other places internally where we
188 // know that nothing needs to be initialized to NULL.
189 void setSize(int size);
190
191 private:
192
193 // NOTE: this must be called only if the number of elements in the two
194 // lists is the same, otherwise badness could result
195 int compare(const SbPList &pl) const;
196
197 // The collection of pointers
198 void **ptrs;
199
200 // Number of pointers allocated
201 int ptrsSize;
202
203 // expand is the lowest level routine. It just reallocates the
204 // array and copies over the old values.
205 void expand(int size);
206
207};
208
209inline void* SbPList::get(int i) const
210{
211 assert(i>=0);
212 return ((i>=0)&&(i<nPtrs))?ptrs[i]:NULL;
213}
214
215inline void SbPList::truncate(int start)
216{
217 assert(start>=0);
218 nPtrs = (start>=0)?start:0;
219}
220
221inline void SbPList::append(void * ptr)
222{
223 if (nPtrs + 1 > ptrsSize)
224 expand(nPtrs + 1);
225 ptrs[nPtrs++] = ptr;
226}
227
228inline void*& SbPList::operator[](const int index) const
229{
230 assert(index>=0);
231 if (index>= nPtrs)
232 grow(index);
233 return ptrs[index];
234}
235
236
237// Keep include for compatibility
241
242#endif
void start()
List of generic (void *) pointers.
Definition SbPList.h:77
void append(void *ptr)
Adds given pointer to end of list.
Definition SbPList.h:221
virtual void truncate(int start)
Removes all pointers after one with given index, inclusive.
Definition SbPList.h:215
int find(const void *ptr) const
Returns index of given pointer in list, or -1 if not found.
void swap(int index1, int index2)
Swaps element having index1 with the one having index2.
SbPList & operator=(const SbPList &pl)
Assignment operator: copies list into this list.
void copy(const SbPList &pl)
Copies a list.
void *& operator[](const int index) const
Returns pointer with given index.
Definition SbPList.h:228
int operator!=(const SbPList &pl) const
Inequality operator.
SbPList(int initSize)
Constructor.
int operator==(const SbPList &pl) const
Equality operator.
virtual ~SbPList()
Destructor.
void insert(void *ptr, int addBefore)
Inserts given pointer in list before pointer with given index.
virtual void remove(int which)
Removes pointer with given index.
SbPList(const SbPList &pl)
Constructor.
SbPList()
Default constructor.
int getLength() const
Returns number of pointers in list.
Definition SbPList.h:125
3D vector class.
Definition SbVec.h:932
size_t size() const