Open Inventor Reference
SbPList.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * Further, this software is distributed without any warranty that it is
16  * free of the rightful claim of any third person regarding infringement
17  * or the like. Any license provided herein, whether implied or
18  * otherwise, applies only to this software file. Patent licenses, if
19  * any, provided herein do not apply to combinations of this program with
20  * other software, or any other product whatsoever.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25  *
26  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27  * Mountain View, CA 94043, or:
28  *
29  * http://www.sgi.com
30  *
31  * For further information regarding this notice, see:
32  *
33  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34  *
35  */
36 
37 
38 /*
39  * Copyright (C) 1990,91 Silicon Graphics, Inc.
40  *
41  _______________________________________________________________________
42  ______________ S I L I C O N G R A P H I C S I N C . ____________
43  |
44  | $Revision: 1.3 $
45  |
46  | Description:
47  | This contains the definition of the SbPList generic pointer
48  | list class. An SbPList is a list of (void *) pointers that
49  | allows easy insertion, removal, and other operations.
50  |
51  | The SbIntList class allows lists of integers to be created.
52  |
53  | Author(s) : Paul S. Strauss, Nick Thompson, Gavin Bell
54  |
55  ______________ S I L I C O N G R A P H I C S I N C . ____________
56  _______________________________________________________________________
57  */
58 
59 #ifndef _SB_PLIST_
60 #define _SB_PLIST_
61 
63 #include <Inventor/SbBasic.h>
64 #include <Inventor/SbLinear.h>
65 
66 
69 
77 
79  public:
80 
83 
87  SbPList(int initSize);
88 
90  SbPList(const SbPList &pl);
91 
94 
96  void append(void * ptr)
97  { if (nPtrs + 1 > ptrsSize) expand(nPtrs + 1);
98  ptrs[nPtrs++] = ptr; }
99 
101  int find(const void *ptr) const;
102 
104  void insert(void *ptr, int addBefore);
105 
107  void remove(int which);
108 
110  int getLength() const { return nPtrs; }
111 
113  void truncate(int start)
114  { nPtrs = start; }
115 
117  void copy(const SbPList &pl);
118 
120  SbPList & operator =(const SbPList &pl) { copy(pl); return *this; }
121 
123  void *& operator [](int i) const
124  { if (i >= nPtrs) grow(i); return ptrs[i]; }
125 
127  bool operator ==(const SbPList &pl) const
128  { return pl.nPtrs == nPtrs ? compare(pl) : FALSE; }
130  bool operator !=(const SbPList &pl) const
131  { return pl.nPtrs == nPtrs ? ! compare(pl) : TRUE; }
132 
134  SoINTERNAL public:
135  void * get(int i) const { return ptrs[i]; }
136  void set(int i, void *j) { ptrs[i] = j; }
137 
138  private:
139 
142  bool compare(const SbPList &pl) const;
143 
144  void ** ptrs;
145  int nPtrs;
146  int ptrsSize;
147 
151  void grow(int max) const;
152 
155  void setSize(int size)
156  { if (size > ptrsSize) expand(size); nPtrs = size; }
157 
160  void expand(int size);
161 };
162 
171 
172 
174 
175  public:
178  SbIntList(int initSize) : SbPList(initSize) {}
179 
181  void append(int integer)
182  { ((SbPList *) this)->append((void *) (size_t) integer); }
183 
185  int find(int integer)
186  { return ((SbPList *) this)->find((void *) (size_t) integer); }
187 
189  void insert(int integer, int addBefore)
190  { ((SbPList *) this)->insert((void *) (size_t) integer, addBefore); }
191 
192  int & operator [](int i) const
193  { return ( (int &) ( (*(const SbPList *) this) [i] ) ); }
194  // support for 64bit, big-endian:
195  // An ugly cast that makes sure that when we cast from void* to
196  // int&, we get the rightmost four bytes, rather than the upper
197  // bytes.
198  // { return ((int &)*(((char*)&((*(const SbPList *) this) [i]) ) + 4 ));}
199 };
200 
208 
210 
211  public:
214 
216  void append(SbVec3f *vec)
217  { ((SbPList *) this)->append((void *) new SbVec3f(vec->getValue())); }
218 
220  void insert(SbVec3f *vec, int addBefore)
221  { ((SbPList *) this)->insert((void *) new SbVec3f(vec->getValue()),
222  addBefore); }
223 
224  SbVec3f * operator [](int i) const
225  { return ( (SbVec3f *) ( (*(const SbPList *) this) [i] ) ); }
226 };
227 
236 
237 class SbString;
238 
240  public:
242  void append(SbString *string)
243  { ((SbPList *) this)->append((void *) string); }
244 
246  int find(SbString *string)
247  { return ((SbPList *) this)->find((void *) string); }
248 
250  void insert(SbString *string, int addBefore)
251  { ((SbPList *) this)->insert((void *) string, addBefore); }
252 
253  SbString *& operator [](int i) const
254  { return ( (SbString *&) ( (*(const SbPList *) this) [i] ) ); }
255 };
256 
257 #endif /* _SB_PLIST_ */
#define SoEXTENDER
Provide inline template functions for abs, swap, min, max, and clamp.
Definition: SbBasic.h:154
#define TRUE
Definition: SbBasic.h:76
#define FALSE
Definition: SbBasic.h:79
#define SoINTERNAL
Definition: SbBasic.h:155
INVENTOR_API bool operator!=(const SbBox3f &b1, const SbBox3f &b2)
Definition: SbBox.h:207
INVENTOR_API bool operator==(const SbBox3f &b1, const SbBox3f &b2)
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition: SbSystem.h:81
List of generic (void *) pointers.
Definition: SbPList.h:173
void append(int integer)
Adds given pointer to end of list.
Definition: SbPList.h:181
SbIntList(int initSize)
Definition: SbPList.h:178
int find(int integer)
Returns index of given pointer in list, or -1 if not found.
Definition: SbPList.h:185
SbIntList()
Constructors, similar to SbPList.
Definition: SbPList.h:177
void insert(int integer, int addBefore)
Inserts given pointer in list before pointer with given index.
Definition: SbPList.h:189
List of generic (void *) pointers.
Definition: SbPList.h:78
void append(void *ptr)
Adds given pointer to end of list.
Definition: SbPList.h:96
void * get(int i) const
Internal versions of [] that do not check for bounds:
Definition: SbPList.h:135
void truncate(int start)
Removes all pointers after one with given index, inclusive.
Definition: SbPList.h:113
void remove(int which)
Removes pointer with given index.
int find(const void *ptr) const
Returns index of given pointer in list, or -1 if not found.
void set(int i, void *j)
Definition: SbPList.h:136
void copy(const SbPList &pl)
Copy a list.
SbPList(int initSize)
initSize specifies an initial size for the list, which is useful as an optimization if you can estima...
~SbPList()
Destructor.
void insert(void *ptr, int addBefore)
Inserts given pointer in list before pointer with given index.
SbPList(const SbPList &pl)
Copy constructor.
SbPList()
Constructor.
int getLength() const
Returns number of pointers in list.
Definition: SbPList.h:110
A list of strings.
Definition: SbPList.h:239
int find(SbString *string)
Returns index of given pointer in list, or -1 if not found.
Definition: SbPList.h:246
void insert(SbString *string, int addBefore)
Inserts given pointer in list before pointer with given index.
Definition: SbPList.h:250
void append(SbString *string)
Adds given pointer to end of list.
Definition: SbPList.h:242
Class for smart character strings.
Definition: SbString.h:85
List of vectors.
Definition: SbPList.h:209
void append(SbVec3f *vec)
Adds given pointer to end of list.
Definition: SbPList.h:216
SbVec3fList()
Definition: SbPList.h:212
void insert(SbVec3f *vec, int addBefore)
Inserts given pointer in list before pointer with given index.
Definition: SbPList.h:220
3D vector class.
Definition: SbLinear.h:120
const float * getValue() const
Returns vector components.
Definition: SbLinear.h:144