27 #ifndef ICB_LIBRARY_CMYACTARRAY 28 #define ICB_LIBRARY_CMYACTARRAY 30 #include "engines/icb/common/px_rcutypes.h" 34 #define MY_TEMPLATE template <class Type> 35 #define T_MYACTARRAY rcActArray<Type> 36 #define T_MYPTRARRAY rcAutoPtrArray<Type> 41 m_userPosition = m_allocatedSize = 0;
45 m_userPosition = m_allocatedSize = 0;
54 uint32 GetNoItems()
const {
return (m_userPosition); }
56 uint32 Add(
const Type &f);
58 Type &operator[](uint32);
59 const Type &operator[](uint32 i)
const;
61 void SetSize(uint32 n) { ResizeArray(n); }
65 uint32 m_userPosition;
66 uint32 m_allocatedSize;
70 void ResizeArray(uint32);
74 void T_MYACTARRAY::operator=(
const rcActArray &a) {
77 m_userPosition = a.m_userPosition;
78 m_allocatedSize = a.m_allocatedSize;
83 m_contents =
new Type *[m_allocatedSize];
84 for (uint32 count = 0; count < m_allocatedSize; count++)
85 m_contents[count] =
new Type(*(a.m_contents[count]));
90 Type &T_MYACTARRAY::operator[](uint32 n) {
91 if (n >= m_userPosition) {
93 m_userPosition = n + 1;
95 return (*(m_contents[n]));
99 const Type &T_MYACTARRAY::operator[](uint32 n)
const {
102 if (n >= m_userPosition) {
108 return (*(m_contents[n]));
111 MY_TEMPLATE T_MYACTARRAY::~rcActArray() { Reset(); }
113 MY_TEMPLATE
void T_MYACTARRAY::Reset() {
114 for (uint32 count = 0; count < m_allocatedSize; count++)
115 delete m_contents[count];
123 MY_TEMPLATE
void T_MYACTARRAY::ResizeArray(uint32 n2) {
125 if (n2 >= m_allocatedSize) {
127 uint32 nextSize = m_allocatedSize ? m_allocatedSize + m_allocatedSize : 1;
128 while (nextSize <= n2)
129 nextSize += nextSize;
132 Type **newArray =
new Type *[nextSize];
133 if (m_allocatedSize > 0) {
135 memcpy((
unsigned char *)newArray, (
unsigned char *)m_contents, m_allocatedSize *
sizeof(
Type *));
138 for (uint32 newObjects = m_allocatedSize; newObjects < nextSize; newObjects++)
139 newArray[newObjects] =
new Type;
143 m_contents = newArray;
144 m_allocatedSize = nextSize;
148 MY_TEMPLATE uint32 T_MYACTARRAY::Add(
const Type &f) {
149 operator[](m_userPosition) = f;
150 return (m_userPosition - 1);
155 uint32 m_userPosition;
159 void ResizeArray(uint32);
162 m_noContents = m_userPosition = 0;
167 uint32 GetNoItems()
const {
return (m_userPosition); }
169 uint32 Add(
Type *f) {
170 operator[](m_userPosition) = f;
171 return (m_userPosition - 1);
174 Type *&operator[](uint32);
175 const Type *&operator[](uint32)
const;
178 void RemoveAndShuffle(uint32);
179 void SetSize(uint32 n) { ResizeArray(n); }
182 Type *GetRawArray() {
return (*m_contents); }
191 Type *&T_MYPTRARRAY::operator[](uint32 n) {
192 if (n >= m_userPosition) {
194 m_userPosition = n + 1;
196 return (m_contents[n]);
200 const Type *&T_MYPTRARRAY::operator[](uint32 n)
const {
202 if (n >= m_userPosition) {
207 return const_cast<const Type *&
>(m_contents[n]);
210 MY_TEMPLATE T_MYPTRARRAY::~rcAutoPtrArray() { Reset(); }
212 MY_TEMPLATE
void T_MYPTRARRAY::Reset() {
214 for (uint32 count = 0; count < m_userPosition; count++)
215 if (m_contents[count])
216 delete m_contents[count];
219 m_noContents = m_userPosition = 0;
222 MY_TEMPLATE
void T_MYPTRARRAY::ResizeArray(uint32 n2) {
223 if (n2 >= m_noContents) {
225 uint32 nextSize = m_noContents > 0 ? m_noContents + m_noContents : 1;
226 while (n2 >= nextSize)
227 nextSize = nextSize + nextSize;
229 Type **newArray =
new Type *[nextSize];
231 if (m_noContents > 0)
232 memcpy((
unsigned char *)newArray, (
unsigned char *)m_contents, m_noContents *
sizeof(
Type *));
234 memset((
unsigned char *)(newArray + m_noContents), 0, (nextSize - m_noContents) *
sizeof(
Type *));
238 m_contents = newArray;
239 m_noContents = nextSize;
243 MY_TEMPLATE
void T_MYPTRARRAY::RemoveAndShuffle(uint32 n) {
248 delete m_contents[n];
250 memcpy(m_contents + n, m_contents + n + 1, (m_noContents - n - 1) *
sizeof(
Type *));
255 uint32 m_userPosition;
258 void ResizeArray(uint32);
262 m_noContents = m_userPosition = 0;
271 m_noContents = m_userPosition = 0;
276 rcIntArray(uint32 initialSize) { ResizeArray(initialSize); }
281 uint32 GetNoItems()
const {
return (m_userPosition); }
285 Type &operator[](uint32);
286 const Type operator[](uint32)
const;
289 void SetSize(uint32 n) { ResizeArray(n); }
291 Type *GetRawArray() {
return (m_contents); }
295 if (index >= m_userPosition) {
297 m_userPosition = index + 1;
299 return m_contents[index];
305 if (index >= m_userPosition) {
311 return m_contents[index];
316 if (accessedSize >= m_noContents) {
317 uint32 newSize = m_noContents > 0 ? m_noContents * 2 : 1;
318 while (newSize <= accessedSize)
319 newSize = newSize + newSize;
321 IntType *newArray =
new IntType[newSize];
323 memcpy(newArray, m_contents, m_noContents *
sizeof(IntType));
325 memset(newArray + m_noContents, 0, (newSize - m_noContents) *
sizeof(IntType));
329 m_contents = newArray;
330 m_noContents = newSize;
339 m_userPosition = obOpB.m_userPosition;
340 m_noContents = obOpB.m_noContents;
343 m_contents =
new IntType[m_noContents];
344 for (nCount = 0; nCount < m_noContents; nCount++)
345 m_contents[nCount] = obOpB.m_contents[nCount];
355 m_noContents = m_userPosition = 0;
361 operator[](m_userPosition) = f;
362 return (m_userPosition - 1);
367 #endif // ndef _LIBRARY_CMYACTARRAY Definition: px_array.h:253
Definition: px_array.h:153
Definition: px_array.h:38