Open Inventor Release 2024.1.0
 
Loading...
Searching...
No Matches
PbArray.h
Go to the documentation of this file.
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : VSG (MMM YYYY)
22**=======================================================================*/
23
24#ifndef _PB_ARRAY_
25#define _PB_ARRAY_
26#include <string.h>
27
28#include <Inventor/SbBasic.h>
29
30#include <Inventor/STL/vector>
31
32#define PO_ARRAY_HEADER(className,valueType) \
33 \
34 \
35 \
36 \
37 \
38
39class className { \
40public: \
41 className(): \
42 m_array(0), \
43 m_allocatedSize(0), \
44 m_lastInd(-1), \
45 m_extend(10) \
46 {}; \ \
48 className(int init_size, int extend=10); \
49 className(const className& other_array); \
50 ~className(); \
51\
52 /* access/insertion methods */ \ \
54 const valueType* get() const; \
55\ \
57 valueType get(int index) const; \
58\ \
60 int find(valueType val) const; \
61\ \
63 void set(int index, valueType val); \
64\ \
66 int add(valueType val); \
67\ \
69 int add(int num_val, const valueType* val); \
70\
71 /* special operators */ \ \
73 className &operator=(const className& other_array); \
74\ \
76 className &operator=(const std::vector<valueType>& other_array); \
77\ \
79 void operator+=(const className& other_array); \
80\ \
82 void operator+=(valueType val); \
83\
84 valueType& operator[](int index); \
85 const valueType& operator[](int index) const; \
86\ \
88 friend int operator ==(const className &array_1, const className &array_2); \
89\ \
91 friend int operator !=(const className &array_1, const className &array_2) \
92 { return !(array_1 == array_2); } \
93\ \
95 void setCapacity(int capacity, int extend); \
96\
97 /* miscellaneous methods */ \
98 void squeeze(); \
99\ \
101 int getCapacity() const; \
102\ \
104 int getNum() const; \
105\ \
108\ \
111\ \
113\
114 void empty(); \
115 /* friend ostream& operator<<(ostream &stream, const className &array); */ \
116\
117private: \
118 valueType *m_array; \
119 int m_allocatedSize; \
120 int m_lastInd; \
121 int m_extend; \
122 valueType *resize(int sz); \
123}; \
124/*---------------------------------------------------------------------------*/ \
125\
126\
127/* Get the adress of the internal array */ \
128inline const valueType* \
129className::get() const {return m_array;} \
130 \
131/* Get the valueType value at a particular index. */ \
132inline valueType \
133className::get(int index) const {return m_array[index];} \
134 \
135/* Find the first index in the array of a given valueType value (-1 if not found) */ \
136inline int \
137className::find(valueType val) const { \
138 for ( int i=0; i<=m_lastInd; i++) if (m_array[i]==val) return i; \
139 return -1; \
140}/*---------------------------------------------------------------------------*/ \
141 \
142 \
143/* Insert valueType value at a specified position in the array. */ \
144inline void \
145className::set(int index, valueType val) \
146{ \
147 if ( index >= m_allocatedSize ) resize(index+1); \
148 m_array[index] = val; \
149 if ( index > m_lastInd ) m_lastInd = index; \
150}/*---------------------------------------------------------------------------*/ \
151 \
152 \
153/* Insert valueType value at the end of the array. Return its location in the array. */ \
154inline int \
155className::add(valueType val) \
156{ \
157 m_lastInd++; \
158 if ( m_lastInd >= m_allocatedSize ) resize(m_lastInd+1); \
159 m_array[m_lastInd] = val; \
160 \
161 return m_lastInd; \
162}/*---------------------------------------------------------------------------*/ \
163 \
164 \
165inline void \
166className::operator+=(valueType val) \
167{ \
168 add(val); \
169}/*---------------------------------------------------------------------------*/ \
170 \
171 \
172/* Get valueType value in a const array (location on rhs statement). */ \
173inline const valueType& \
174className::operator[](int index) const \
175{ \
176 return m_array[index]; \
177}/*---------------------------------------------------------------------------*/ \
178 \
179 \
180/* Does insert or get (depending on location on lhs or rhs of statement). Does */ \
181/* not do automatic resizing - user's responsibility to range check. */ \
182inline valueType& \
184{ \
185 if (index > m_lastInd) m_lastInd = index; \
186 return m_array[index]; \
187}/*---------------------------------------------------------------------------*/ \
188 \
189 \
190/* Get the allocated size of the array */ \
191inline int \
192className::getCapacity() const {return m_allocatedSize;} \
193 \
194 \
195/* Returning the maximum index of valueType values inserted so far. */ \
196inline int \
197className::getNum() const {return m_lastInd+1;} \
198 \
199 \
200/* Reuse the memory allocated by this array. It appears like */ \
201/* no valueType value has been previously inserted. */ \
202inline void \
203className::empty() {m_lastInd = -1;}
204
205
206#endif /* _PB_ARRAY_ */
207
208
209
210
211
212
213
virtual void resize(const size_t newSize)
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> CPUBufferObject ...
int add(valueType val)
Inserts valueType value at the end of the array.
Definition PbArray.h:155
void setCapacity(int capacity, int extend)
set the capacity and allocate this capacity if necessary
int getNum() const
Gets the number of values in the array.
Definition PbArray.h:197
const valueType * get() const
Gets the adress of the internal array.
Definition PbArray.h:129
void increasingSort()
Sorts array by increasing order.
void empty()
After empty, the array appears like no valueType value has been previously inserted.
Definition PbArray.h:203
void squeeze()
int getCapacity() const
Gets the allocated size of the array.
Definition PbArray.h:192
friend int operator==(const className &array_1, const className &array_2)
Equality comparison operator.
className & operator=(const className &other_array)
Copy from other_array.
friend int operator!=(const className &array_1, const className &array_2)
Inequality comparison operator.
Definition PbArray.h:91
int find(valueType val) const
Finds the first index in the array of a given valueType value (-1 if not found).
Definition PbArray.h:137
className & operator=(const std::vector< valueType > &other_array)
Copy from an STL vector.
void decreasingSort()
Sorts array by decreasing order.
void operator+=(const className &other_array)
Appends other_array to the end of the array.
int add(int num_val, const valueType *val)
Inserts a list of valueType values at the end of the array.
void set(int index, valueType val)
Inserts valueType value at a specified position in the array.
Definition PbArray.h:145
valueType & operator[](int index)
Definition PbArray.h:183