Update ooo320-m1
[ooovba.git] / binfilter / inc / bf_svtools / svarray.hxx
blobbfad97bfc4d2edc71c031b19015933b7120535be
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svarray.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _SVARRAY_HXX
32 #define _SVARRAY_HXX
34 #ifndef INCLUDED_STRING_H
35 #include <string.h> // memmove()
36 #define INCLUDED_STRING_H
37 #endif
39 #ifndef INCLUDED_LIMITS_H
40 #include <limits.h> // USHRT_MAX
41 #define INCLUDED_LIMITS_H
42 #endif
44 #ifndef _RTL_ALLOC_H_
45 #include <rtl/alloc.h>
46 #endif
48 #ifndef _SOLAR_H
49 #include <tools/solar.h>
50 #endif
52 class String;
54 #ifndef CONCAT
55 #define CONCAT(x,y) x##y
56 #endif
58 class DummyType;
59 inline void* operator new( size_t, DummyType* pPtr )
61 return pPtr;
63 inline void operator delete( void*, DummyType* ) {}
65 namespace binfilter {
67 #if defined(PRODUCT)
69 #define _SVVARARR_DEF_GET_OP_INLINE( nm, ArrElem ) \
70 ArrElem& operator[](USHORT nP) const { return *(pData+nP); }\
72 void Insert( const nm * pI, USHORT nP,\
73 USHORT nS = 0, USHORT nE = USHRT_MAX )\
75 if( USHRT_MAX == nE ) \
76 nE = pI->nA; \
77 if( nS < nE ) \
78 Insert( (const ArrElem*)pI->pData+nS, (USHORT)nE-nS, nP );\
81 #define _SVVARARR_IMPL_GET_OP_INLINE( nm, ArrElem )
83 #else
85 #define _SVVARARR_DEF_GET_OP_INLINE( nm,ArrElem )\
86 ArrElem& operator[](USHORT nP) const;\
87 void Insert( const nm *pI, USHORT nP,\
88 USHORT nS = 0, USHORT nE = USHRT_MAX );
90 #define _SVVARARR_IMPL_GET_OP_INLINE( nm, ArrElem )\
91 ArrElem& nm::operator[](USHORT nP) const\
93 DBG_ASSERT( pData && nP < nA,"Op[]");\
94 return *(pData+nP);\
96 void nm::Insert( const nm *pI, USHORT nP, USHORT nStt, USHORT nE)\
98 DBG_ASSERT(nP<=nA,"Ins,Ar[Start.End]");\
99 if( USHRT_MAX == nE ) \
100 nE = pI->nA; \
101 if( nStt < nE ) \
102 Insert( (const ArrElem*)pI->pData+nStt, (USHORT)nE-nStt, nP );\
105 #endif
107 #define _SV_DECL_VARARR_GEN(nm, AE, IS, GS, AERef, vis )\
108 typedef BOOL (*FnForEach_##nm)( const AERef, void* );\
109 class vis nm\
111 protected:\
112 AE *pData;\
113 USHORT nFree;\
114 USHORT nA;\
116 void _resize(size_t n);\
118 public:\
119 nm( USHORT= IS, BYTE= GS );\
120 ~nm() { rtl_freeMemory( pData ); }\
122 _SVVARARR_DEF_GET_OP_INLINE(nm, AE )\
123 AERef GetObject(USHORT nP) const { return (*this)[nP]; } \
125 void Insert( const AERef aE, USHORT nP );\
126 void Insert( const AE *pE, USHORT nL, USHORT nP );\
127 void Remove( USHORT nP, USHORT nL = 1 );\
128 void Replace( const AERef aE, USHORT nP );\
129 void Replace( const AE *pE, USHORT nL, USHORT nP );\
130 USHORT Count() const { return nA; }\
131 const AE* GetData() const { return (const AE*)pData; }\
133 void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
135 _ForEach( 0, nA, fnForEach, pArgs );\
137 void ForEach( USHORT nS, USHORT nE, \
138 CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
140 _ForEach( nS, nE, fnForEach, pArgs );\
143 void _ForEach( USHORT nStt, USHORT nE, \
144 CONCAT( FnForEach_, nm ) fnCall, void* pArgs = 0 );\
147 #define _SV_DECL_VARARR(nm, AE, IS, GS ) \
148 _SV_DECL_VARARR_GEN(nm, AE, IS, GS, AE & )
150 #define SV_DECL_VARARR_GEN(nm, AE, IS, GS, AERef, vis )\
151 _SV_DECL_VARARR_GEN(nm, AE, IS, GS, AERef, vis )\
152 private:\
153 nm( const nm& );\
154 nm& operator=( const nm& );\
157 #define SV_DECL_VARARR(nm, AE, IS, GS ) \
158 SV_DECL_VARARR_GEN(nm, AE, IS, GS, AE &, )
160 #define SV_DECL_VARARR_VISIBILITY(nm, AE, IS, GS, vis ) \
161 SV_DECL_VARARR_GEN(nm, AE, IS, GS, AE &, vis )
163 #define SV_IMPL_VARARR_GEN( nm, AE, AERef )\
164 nm::nm( USHORT nInit, BYTE )\
165 : pData (0),\
166 nFree (nInit),\
167 nA (0)\
169 if( nInit )\
171 pData = (AE*)(rtl_allocateMemory(sizeof(AE) * nInit));\
172 DBG_ASSERT( pData, "CTOR, allocate");\
176 void nm::_resize (size_t n)\
178 USHORT nL = ((n < USHRT_MAX) ? USHORT(n) : USHRT_MAX);\
179 AE* pE = (AE*)(rtl_reallocateMemory (pData, sizeof(AE) * nL));\
180 if ((pE != 0) || (nL == 0))\
182 pData = pE;\
183 nFree = nL - nA;\
187 void nm::Insert( const AERef aE, USHORT nP )\
189 DBG_ASSERT(nP <= nA && nA < USHRT_MAX, "Ins 1");\
190 if (nFree < 1)\
191 _resize (nA + ((nA > 1) ? nA : 1));\
192 if( pData && nP < nA )\
193 memmove( pData+nP+1, pData+nP, (nA-nP) * sizeof( AE ));\
194 *(pData+nP) = (AE&)aE;\
195 ++nA; --nFree;\
198 void nm::Insert( const AE* pE, USHORT nL, USHORT nP )\
200 DBG_ASSERT(nP<=nA && ((long)nA+nL)<USHRT_MAX,"Ins n");\
201 if (nFree < nL)\
202 _resize (nA + ((nA > nL) ? nA : nL));\
203 if( pData && nP < nA )\
204 memmove( pData+nP+nL, pData+nP, (nA-nP) * sizeof( AE ));\
205 if( pE )\
206 memcpy( pData+nP, pE, nL * sizeof( AE ));\
207 nA = nA + nL; nFree = nFree - nL;\
210 void nm::Replace( const AERef aE, USHORT nP )\
212 if( nP < nA )\
213 *(pData+nP) = (AE&)aE;\
216 void nm::Replace( const AE *pE, USHORT nL, USHORT nP )\
218 if( pE && nP < nA )\
220 if( nP + nL < nA )\
221 memcpy( pData + nP, pE, nL * sizeof( AE ));\
222 else if( nP + nL < nA + nFree )\
224 memcpy( pData + nP, pE, nL * sizeof( AE ));\
225 nP = nP + (nL - nA); \
226 nFree = nP;\
228 else \
230 USHORT nTmpLen = nA + nFree - nP; \
231 memcpy( pData + nP, pE, nTmpLen * sizeof( AE ));\
232 nA = nA + nFree; \
233 nFree = 0; \
234 Insert( pE + nTmpLen, nL - nTmpLen, nA );\
239 void nm::Remove( USHORT nP, USHORT nL )\
241 if( !nL )\
242 return;\
243 DBG_ASSERT( nP < nA && nP + nL <= nA,"Del");\
244 if( pData && nP+1 < nA )\
245 memmove( pData+nP, pData+nP+nL, (nA-nP-nL) * sizeof( AE ));\
246 nA = nA - nL; nFree = nFree + nL;\
247 if (nFree > nA)\
248 _resize (nA);\
251 void nm::_ForEach( USHORT nStt, USHORT nE, \
252 CONCAT( FnForEach_, nm ) fnCall, void* pArgs )\
254 if( nStt >= nE || nE > nA )\
255 return;\
256 for( ; nStt < nE && (*fnCall)( *(const AE*)(pData+nStt), pArgs ); nStt++)\
260 _SVVARARR_IMPL_GET_OP_INLINE(nm, AE )\
262 #define SV_IMPL_VARARR( nm, AE ) \
263 SV_IMPL_VARARR_GEN( nm, AE, AE & )
265 #if defined(PRODUCT)
267 #define _SVOBJARR_DEF_GET_OP_INLINE( nm,ArrElem )\
268 ArrElem& operator[](USHORT nP) const { return *(pData+nP); }\
270 void Insert( const nm *pI, USHORT nP,\
271 USHORT nS = 0, USHORT nE = USHRT_MAX )\
273 if( USHRT_MAX == nE ) \
274 nE = pI->nA; \
275 if( nS < nE ) \
276 Insert( (const ArrElem*)pI->pData+nS, (USHORT)nE-nS, nP );\
279 #define _SVOBJARR_IMPL_GET_OP_INLINE( nm, ArrElem )
281 #else
283 #define _SVOBJARR_DEF_GET_OP_INLINE( nm,ArrElem ) \
284 ArrElem& operator[](USHORT nP) const;\
285 void Insert( const nm *pI, USHORT nP,\
286 USHORT nS = 0, USHORT nE = USHRT_MAX );
288 #define _SVOBJARR_IMPL_GET_OP_INLINE( nm, ArrElem )\
289 ArrElem& nm::operator[](USHORT nP) const\
291 DBG_ASSERT( pData && nP < nA,"Op[]");\
292 return *(pData+nP);\
294 void nm::Insert( const nm *pI, USHORT nP, USHORT nStt, USHORT nE )\
296 DBG_ASSERT( nP <= nA,"Ins,Ar[Start.End]");\
297 if( USHRT_MAX == nE ) \
298 nE = pI->nA; \
299 if( nStt < nE ) \
300 Insert( (const ArrElem*)pI->pData+nStt, (USHORT)nE-nStt, nP );\
303 #endif
305 #define _SV_DECL_OBJARR(nm, AE, IS, GS)\
306 typedef BOOL (*FnForEach_##nm)( const AE&, void* );\
307 class nm\
309 protected:\
310 AE *pData;\
311 USHORT nFree;\
312 USHORT nA;\
314 void _resize(size_t n);\
315 void _destroy();\
317 public:\
318 nm( USHORT= IS, BYTE= GS );\
319 ~nm() { _destroy(); }\
321 _SVOBJARR_DEF_GET_OP_INLINE(nm,AE)\
322 AE& GetObject(USHORT nP) const { return (*this)[nP]; } \
324 void Insert( const AE &aE, USHORT nP );\
325 void Insert( const AE *pE, USHORT nL, USHORT nP );\
326 void Remove( USHORT nP, USHORT nL = 1 );\
327 USHORT Count() const { return nA; }\
328 const AE* GetData() const { return (const AE*)pData; }\
330 void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
332 _ForEach( 0, nA, fnForEach, pArgs );\
334 void ForEach( USHORT nS, USHORT nE, \
335 CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
337 _ForEach( nS, nE, fnForEach, pArgs );\
340 void _ForEach( USHORT nStt, USHORT nE, \
341 CONCAT( FnForEach_, nm ) fnCall, void* pArgs = 0 );\
344 #define SV_DECL_OBJARR(nm, AE, IS, GS)\
345 _SV_DECL_OBJARR(nm, AE, IS, GS)\
346 private:\
347 nm( const nm& );\
348 nm& operator=( const nm& );\
351 #define SV_IMPL_OBJARR( nm, AE )\
352 nm::nm( USHORT nInit, BYTE )\
353 : pData (0),\
354 nFree (nInit),\
355 nA (0)\
357 if( nInit )\
359 pData = (AE*)(rtl_allocateMemory(sizeof(AE) * nInit));\
360 DBG_ASSERT( pData, "CTOR, allocate");\
364 void nm::_destroy()\
366 if(pData)\
368 AE* pTmp=pData;\
369 for(USHORT n=0; n < nA; n++,pTmp++ )\
371 pTmp->~AE();\
373 rtl_freeMemory(pData);\
374 pData = 0;\
378 void nm::_resize (size_t n)\
380 USHORT nL = ((n < USHRT_MAX) ? USHORT(n) : USHRT_MAX);\
381 AE* pE = (AE*)(rtl_reallocateMemory (pData, sizeof(AE) * nL));\
382 if ((pE != 0) || (nL == 0))\
384 pData = pE;\
385 nFree = nL - nA;\
389 void nm::Insert( const AE &aE, USHORT nP )\
391 DBG_ASSERT( nP <= nA && nA < USHRT_MAX,"Ins 1");\
392 if (nFree < 1)\
393 _resize (nA + ((nA > 1) ? nA : 1));\
394 if( pData && nP < nA )\
395 memmove( pData+nP+1, pData+nP, (nA-nP) * sizeof( AE ));\
396 AE* pTmp = pData+nP;\
397 new( (DummyType*) pTmp ) AE( (AE&)aE );\
398 ++nA; --nFree;\
401 void nm::Insert( const AE* pE, USHORT nL, USHORT nP )\
403 DBG_ASSERT(nP<=nA && ((long)nA+nL) < USHRT_MAX, "Ins n");\
404 if (nFree < nL)\
405 _resize (nA + ((nA > nL) ? nA : nL));\
406 if( pData && nP < nA )\
407 memmove( pData+nP+nL, pData+nP, (nA-nP) * sizeof( AE ));\
408 if( pE )\
410 AE* pTmp = pData+nP;\
411 for( USHORT n = 0; n < nL; n++, pTmp++, pE++)\
413 new( (DummyType*) pTmp ) AE( (AE&)*pE );\
416 nA = nA + nL; nFree = nFree - nL;\
419 void nm::Remove( USHORT nP, USHORT nL )\
421 if( !nL )\
422 return;\
423 DBG_ASSERT( nP < nA && nP + nL <= nA,"Del");\
424 AE* pTmp=pData+nP;\
425 USHORT nCtr = nP;\
426 for(USHORT n=0; n < nL; n++,pTmp++,nCtr++)\
428 if( nCtr < nA )\
429 pTmp->~AE();\
431 if( pData && nP+1 < nA )\
432 memmove( pData+nP, pData+nP+nL, (nA-nP-nL) * sizeof( AE ));\
433 nA = nA - nL; nFree = nFree + nL;\
434 if (nFree > nA) \
435 _resize (nA);\
438 void nm::_ForEach( USHORT nStt, USHORT nE, \
439 CONCAT( FnForEach_, nm ) fnCall, void* pArgs )\
441 if( nStt >= nE || nE > nA )\
442 return;\
443 for( ; nStt < nE && (*fnCall)( *(pData+nStt), pArgs ); nStt++)\
447 _SVOBJARR_IMPL_GET_OP_INLINE(nm, AE)\
449 #define _SV_DECL_PTRARR_DEF_GEN( nm, AE, IS, GS, AERef, vis )\
450 _SV_DECL_VARARR_GEN( nm, AE, IS, GS, AERef, vis)\
451 USHORT GetPos( const AERef aE ) const;\
454 #define _SV_DECL_PTRARR_DEF( nm, AE, IS, GS, vis )\
455 _SV_DECL_PTRARR_DEF_GEN( nm, AE, IS, GS, AE &, vis )
457 #define SV_DECL_PTRARR_GEN(nm, AE, IS, GS, Base, AERef, VPRef, vis )\
458 typedef BOOL (*FnForEach_##nm)( const AERef, void* );\
459 class vis nm: public Base \
461 public:\
462 nm( USHORT nIni=IS, BYTE nG=GS )\
463 : Base(nIni,nG) {}\
464 void Insert( const nm *pI, USHORT nP, \
465 USHORT nS = 0, USHORT nE = USHRT_MAX ) {\
466 Base::Insert((const Base*)pI, nP, nS, nE);\
468 void Insert( const AERef aE, USHORT nP ) {\
469 Base::Insert( (const VPRef )aE, nP );\
471 void Insert( const AE *pE, USHORT nL, USHORT nP ) {\
472 Base::Insert( (const VoidPtr*)pE, nL, nP );\
474 void Replace( const AERef aE, USHORT nP ) {\
475 Base::Replace( (const VPRef)aE, nP );\
477 void Replace( const AE *pE, USHORT nL, USHORT nP ) {\
478 Base::Replace( (const VoidPtr*)pE, nL, nP );\
480 void Remove( USHORT nP, USHORT nL = 1) {\
481 Base::Remove(nP,nL);\
483 const AE* GetData() const {\
484 return (const AE*)Base::GetData();\
486 void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
488 _ForEach( 0, nA, (FnForEach_##Base)fnForEach, pArgs );\
490 void ForEach( USHORT nS, USHORT nE, \
491 CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
493 _ForEach( nS, nE, (FnForEach_##Base)fnForEach, pArgs );\
495 AE operator[]( USHORT nP )const { \
496 return (AE)Base::operator[](nP); }\
497 AE GetObject(USHORT nP) const { \
498 return (AE)Base::GetObject(nP); }\
500 USHORT GetPos( const AERef aE ) const { \
501 return Base::GetPos((const VPRef)aE);\
503 void DeleteAndDestroy( USHORT nP, USHORT nL=1 );\
504 private:\
505 nm( const nm& );\
506 nm& operator=( const nm& );\
509 #define SV_DECL_PTRARR(nm, AE, IS, GS )\
510 SV_DECL_PTRARR_GEN(nm, AE, IS, GS, SvPtrarr, AE &, VoidPtr &, )
512 #define SV_DECL_PTRARR_VISIBILITY(nm, AE, IS, GS, vis )\
513 SV_DECL_PTRARR_GEN(nm, AE, IS, GS, SvPtrarr, AE &, VoidPtr &, vis )
515 #define SV_DECL_PTRARR_DEL_GEN(nm, AE, IS, GS, Base, AERef, VPRef, vis )\
516 typedef BOOL (*FnForEach_##nm)( const AERef, void* );\
517 class vis nm: public Base \
519 public:\
520 nm( USHORT nIni=IS, BYTE nG=GS )\
521 : Base(nIni,nG) {}\
522 ~nm() { DeleteAndDestroy( 0, Count() ); }\
523 void Insert( const nm *pI, USHORT nP, \
524 USHORT nS = 0, USHORT nE = USHRT_MAX ) {\
525 Base::Insert((const Base*)pI, nP, nS, nE);\
527 void Insert( const AERef aE, USHORT nP ) {\
528 Base::Insert((const VPRef)aE, nP );\
530 void Insert( const AE *pE, USHORT nL, USHORT nP ) {\
531 Base::Insert( (const VoidPtr *)pE, nL, nP );\
533 void Replace( const AERef aE, USHORT nP ) {\
534 Base::Replace( (const VPRef)aE, nP );\
536 void Replace( const AE *pE, USHORT nL, USHORT nP ) {\
537 Base::Replace( (const VoidPtr*)pE, nL, nP );\
539 void Remove( USHORT nP, USHORT nL = 1) {\
540 Base::Remove(nP,nL);\
542 const AE* GetData() const {\
543 return (const AE*)Base::GetData();\
545 void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
547 _ForEach( 0, nA, (FnForEach_##Base)fnForEach, pArgs );\
549 void ForEach( USHORT nS, USHORT nE, \
550 CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
552 _ForEach( nS, nE, (FnForEach_##Base)fnForEach, pArgs );\
554 AE operator[]( USHORT nP )const { \
555 return (AE)Base::operator[](nP); }\
556 AE GetObject( USHORT nP )const { \
557 return (AE)Base::GetObject(nP); }\
559 USHORT GetPos( const AERef aE ) const { \
560 return Base::GetPos((const VPRef)aE);\
562 void DeleteAndDestroy( USHORT nP, USHORT nL=1 );\
563 private:\
564 nm( const nm& );\
565 nm& operator=( const nm& );\
568 #define SV_DECL_PTRARR_DEL(nm, AE, IS, GS )\
569 SV_DECL_PTRARR_DEL_GEN(nm, AE, IS, GS, SvPtrarr, AE &, VoidPtr &, )
571 #define SV_DECL_PTRARR_DEL_VISIBILITY(nm, AE, IS, GS, vis )\
572 SV_DECL_PTRARR_DEL_GEN(nm, AE, IS, GS, SvPtrarr, AE &, VoidPtr &, vis)
574 #define SV_IMPL_PTRARR_GEN(nm, AE, Base)\
575 void nm::DeleteAndDestroy( USHORT nP, USHORT nL )\
577 if( nL ) {\
578 DBG_ASSERT( nP < nA && nP + nL <= nA,"Del");\
579 for( USHORT n=nP; n < nP + nL; n++ ) \
580 delete *((AE*)pData+n); \
581 Base::Remove( nP, nL ); \
585 #define SV_IMPL_PTRARR(nm, AE )\
586 SV_IMPL_PTRARR_GEN(nm, AE, SvPtrarr )
588 typedef void* VoidPtr;
589 _SV_DECL_PTRARR_DEF( SvPtrarr, VoidPtr, 0, 1, )
591 // SORTARR - Begin
593 #ifdef __MWERKS__
594 #define __MWERKS__PRIVATE public
595 #else
596 #define __MWERKS__PRIVATE private
597 #endif
599 #define _SORT_CLASS_DEF(nm, AE, IS, GS, vis)\
600 typedef BOOL (*FnForEach_##nm)( const AE&, void* );\
601 class vis nm : __MWERKS__PRIVATE nm##_SAR \
603 public:\
604 nm(USHORT nSize = IS, BYTE nG = GS)\
605 : nm##_SAR(nSize,nG) {}\
606 void Insert( const nm *pI, USHORT nS=0, USHORT nE=USHRT_MAX );\
607 BOOL Insert( const AE& aE );\
608 BOOL Insert( const AE& aE, USHORT& rP );\
609 void Insert( const AE *pE, USHORT nL );\
610 void Remove( USHORT nP, USHORT nL = 1 );\
611 void Remove( const AE& aE, USHORT nL = 1 );\
612 USHORT Count() const { return nm##_SAR::Count(); }\
613 const AE* GetData() const { return (const AE*)pData; }\
615 /* Das Ende stehe im DECL-Makro !!! */
617 #define _SV_SEEK_PTR(nm,AE)\
618 BOOL nm::Seek_Entry( const AE aE, USHORT* pP ) const\
620 register USHORT nO = nm##_SAR::Count(),\
621 nM, \
622 nU = 0;\
623 if( nO > 0 )\
625 nO--;\
626 register long rCmp = (long)aE;\
627 while( nU <= nO )\
629 nM = nU + ( nO - nU ) / 2;\
630 if( (long)*(pData + nM) == rCmp )\
632 if( pP ) *pP = nM;\
633 return TRUE;\
635 else if( (long)*(pData+ nM) < (long)aE )\
636 nU = nM + 1;\
637 else if( nM == 0 )\
639 if( pP ) *pP = nU;\
640 return FALSE;\
642 else\
643 nO = nM - 1;\
646 if( pP ) *pP = nU;\
647 return FALSE;\
650 #define _SV_SEEK_PTR_TO_OBJECT( nm,AE )\
651 BOOL nm::Seek_Entry( const AE aE, USHORT* pP ) const\
653 register USHORT nO = nm##_SAR::Count(),\
654 nM, \
655 nU = 0;\
656 if( nO > 0 )\
658 nO--;\
659 while( nU <= nO )\
661 nM = nU + ( nO - nU ) / 2;\
662 if( *(*((AE*)pData + nM)) == *(aE) )\
664 if( pP ) *pP = nM;\
665 return TRUE;\
667 else if( *(*((AE*)pData + nM)) < *(aE) )\
668 nU = nM + 1;\
669 else if( nM == 0 )\
671 if( pP ) *pP = nU;\
672 return FALSE;\
674 else\
675 nO = nM - 1;\
678 if( pP ) *pP = nU;\
679 return FALSE;\
682 #define _SV_SEEK_OBJECT( nm,AE )\
683 BOOL nm::Seek_Entry( const AE & aE, USHORT* pP ) const\
685 register USHORT nO = nm##_SAR::Count(),\
686 nM, \
687 nU = 0;\
688 if( nO > 0 )\
690 nO--;\
691 while( nU <= nO )\
693 nM = nU + ( nO - nU ) / 2;\
694 if( *(pData + nM) == aE )\
696 if( pP ) *pP = nM;\
697 return TRUE;\
699 else if( *(pData + nM) < aE )\
700 nU = nM + 1;\
701 else if( nM == 0 )\
703 if( pP ) *pP = nU;\
704 return FALSE;\
706 else\
707 nO = nM - 1;\
710 if( pP ) *pP = nU;\
711 return FALSE;\
714 #define _SV_IMPL_SORTAR_ALG(nm, AE)\
715 void nm::Insert( const nm * pI, USHORT nS, USHORT nE )\
717 if( USHRT_MAX == nE )\
718 nE = pI->Count();\
719 USHORT nP;\
720 const AE * pIArr = pI->GetData();\
721 for( ; nS < nE; ++nS )\
723 if( ! Seek_Entry( *(pIArr+nS), &nP) )\
724 nm##_SAR::Insert( *(pIArr+nS), nP );\
725 if( ++nP >= Count() )\
727 nm##_SAR::Insert( pI, nP, nS+1, nE );\
728 nS = nE;\
733 BOOL nm::Insert( const AE & aE )\
735 USHORT nP;\
736 BOOL bExist;\
737 bExist = Seek_Entry( aE, &nP );\
738 if( ! bExist )\
739 nm##_SAR::Insert( aE, nP );\
740 return !bExist;\
742 BOOL nm::Insert( const AE & aE, USHORT& rP )\
744 BOOL bExist;\
745 bExist = Seek_Entry( aE, &rP );\
746 if( ! bExist )\
747 nm##_SAR::Insert( aE, rP );\
748 return !bExist;\
750 void nm::Insert( const AE* pE, USHORT nL)\
752 USHORT nP;\
753 for( USHORT n = 0; n < nL; ++n )\
754 if( ! Seek_Entry( *(pE+n), &nP ))\
755 nm##_SAR::Insert( *(pE+n), nP );\
757 void nm::Remove( USHORT nP, USHORT nL )\
759 if( nL )\
760 nm##_SAR::Remove( nP, nL);\
763 void nm::Remove( const AE &aE, USHORT nL )\
765 USHORT nP;\
766 if( nL && Seek_Entry( aE, &nP ) ) \
767 nm##_SAR::Remove( nP, nL);\
770 #if defined(TCPP)
772 #define _SORTARR_BLC_CASTS(nm, AE )\
773 BOOL Insert( AE &aE ) {\
774 return Insert( (const AE&)aE );\
776 USHORT GetPos( AE& aE ) const { \
777 return SvPtrarr::GetPos((const VoidPtr&)aE);\
779 void Remove( AE& aE, USHORT nL = 1 ) { \
780 Remove( (const AE&) aE, nL );\
783 #else
785 #define _SORTARR_BLC_CASTS(nm, AE )\
786 USHORT GetPos( const AE& aE ) const { \
787 return SvPtrarr::GetPos((const VoidPtr&)aE);\
790 #endif
792 #define _SV_DECL_PTRARR_SORT_ALG(nm, AE, IS, GS, vis)\
793 SV_DECL_PTRARR_VISIBILITY(nm##_SAR, AE, IS, GS, vis)\
794 _SORT_CLASS_DEF(nm, AE, IS, GS, vis)\
795 AE operator[](USHORT nP) const {\
796 return nm##_SAR::operator[]( nP );\
798 AE GetObject(USHORT nP) const {\
799 return nm##_SAR::GetObject( nP );\
801 BOOL Seek_Entry( const AE aE, USHORT* pP = 0 ) const;\
802 void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
804 _ForEach( 0, nA, (FnForEach_SvPtrarr)fnForEach, pArgs );\
806 void ForEach( USHORT nS, USHORT nE, \
807 CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
809 _ForEach( nS, nE, (FnForEach_SvPtrarr)fnForEach, pArgs );\
811 void DeleteAndDestroy( USHORT nP, USHORT nL=1 ); \
812 _SORTARR_BLC_CASTS(nm, AE )\
814 /* Das Ende stehe im DECL-Makro !!! */
816 #define _SV_DECL_PTRARR_SORT(nm, AE, IS, GS, vis)\
817 _SV_DECL_PTRARR_SORT_ALG(nm, AE, IS, GS, vis)\
818 private:\
819 nm( const nm& );\
820 nm& operator=( const nm& );\
823 #define SV_DECL_PTRARR_SORT(nm, AE, IS, GS)\
824 _SV_DECL_PTRARR_SORT(nm, AE, IS, GS, )
826 #define SV_DECL_PTRARR_SORT_VISIBILITY(nm, AE, IS, GS, vis)\
827 _SV_DECL_PTRARR_SORT(nm, AE, IS, GS, vis)
830 #define _SV_DECL_PTRARR_SORT_DEL(nm, AE, IS, GS, vis)\
831 _SV_DECL_PTRARR_SORT_ALG(nm, AE, IS, GS, vis)\
832 ~nm() { DeleteAndDestroy( 0, Count() ); }\
833 private:\
834 nm( const nm& );\
835 nm& operator=( const nm& );\
838 #define SV_DECL_PTRARR_SORT_DEL(nm, AE, IS, GS)\
839 _SV_DECL_PTRARR_SORT_DEL(nm, AE, IS, GS, )
841 #define SV_DECL_PTRARR_SORT_DEL_VISIBILITY(nm, AE, IS, GS, vis)\
842 _SV_DECL_PTRARR_SORT_DEL(nm, AE, IS, GS, vis)
844 #define _SV_DECL_VARARR_SORT(nm, AE, IS, GS, vis)\
845 SV_DECL_VARARR_VISIBILITY(nm##_SAR, AE, IS, GS, vis)\
846 _SORT_CLASS_DEF(nm, AE, IS, GS, vis) \
847 const AE& operator[](USHORT nP) const {\
848 return nm##_SAR::operator[]( nP );\
850 const AE& GetObject(USHORT nP) const {\
851 return nm##_SAR::GetObject( nP );\
853 BOOL Seek_Entry( const AE & aE, USHORT* pP = 0 ) const;\
854 void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
856 _ForEach( 0, nA, (FnForEach_##nm##_SAR)fnForEach, pArgs );\
858 void ForEach( USHORT nS, USHORT nE, \
859 CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
861 _ForEach( nS, nE, (FnForEach_##nm##_SAR)fnForEach, pArgs );\
863 private:\
864 nm( const nm& );\
865 nm& operator=( const nm& );\
868 #define SV_DECL_VARARR_SORT(nm, AE, IS, GS)\
869 _SV_DECL_VARARR_SORT(nm, AE, IS, GS,)
871 #define SV_DECL_VARARR_SORT_VISIBILITY(nm, AE, IS, GS, vis)\
872 _SV_DECL_VARARR_SORT(nm, AE, IS, GS, vis)
874 #define SV_IMPL_PTRARR_SORT( nm,AE )\
875 _SV_IMPL_SORTAR_ALG( nm,AE )\
876 void nm::DeleteAndDestroy( USHORT nP, USHORT nL ) { \
877 if( nL ) {\
878 DBG_ASSERT( nP < nA && nP + nL <= nA, "ERR_VAR_DEL" );\
879 for( USHORT n=nP; n < nP + nL; n++ ) \
880 delete *((AE*)pData+n); \
881 SvPtrarr::Remove( nP, nL ); \
884 _SV_SEEK_PTR( nm, AE )
886 #define SV_IMPL_OP_PTRARR_SORT( nm,AE )\
887 _SV_IMPL_SORTAR_ALG( nm,AE )\
888 void nm::DeleteAndDestroy( USHORT nP, USHORT nL ) { \
889 if( nL ) {\
890 DBG_ASSERT( nP < nA && nP + nL <= nA, "ERR_VAR_DEL" );\
891 for( USHORT n=nP; n < nP + nL; n++ ) \
892 delete *((AE*)pData+n); \
893 SvPtrarr::Remove( nP, nL ); \
896 _SV_SEEK_PTR_TO_OBJECT( nm,AE )
898 #define SV_IMPL_VARARR_SORT( nm,AE )\
899 SV_IMPL_VARARR(nm##_SAR, AE)\
900 _SV_IMPL_SORTAR_ALG( nm,AE )\
901 _SV_SEEK_OBJECT( nm,AE )
903 #define SV_DECL_PTRARR_STACK(nm, AE, IS, GS)\
904 class nm: private SvPtrarr \
906 public:\
907 nm( USHORT nIni=IS, BYTE nG=GS )\
908 : SvPtrarr(nIni,nG) {}\
909 void Insert( const nm *pI, USHORT nP,\
910 USHORT nS = 0, USHORT nE = USHRT_MAX ) {\
911 SvPtrarr::Insert( pI, nP, nS, nE ); \
913 void Remove( USHORT nP, USHORT nL = 1 ) {\
914 SvPtrarr::Remove( nP, nL ); \
916 void Push( const AE &aE ) {\
917 SvPtrarr::Insert( (const VoidPtr &)aE, SvPtrarr::Count() );\
919 USHORT Count() const { return SvPtrarr::Count(); }\
920 AE operator[](USHORT nP) const {\
921 return (AE)SvPtrarr::operator[]( nP );\
923 AE GetObject(USHORT nP) const {\
924 return (AE)SvPtrarr::GetObject( nP );\
926 AE Pop(){\
927 AE pRet = 0;\
928 if( SvPtrarr::Count() ){\
929 pRet = GetObject( SvPtrarr::Count()-1 );\
930 SvPtrarr::Remove(Count()-1);\
932 return pRet;\
934 AE Top() const {\
935 AE pRet = 0;\
936 if( SvPtrarr::Count() )\
937 pRet = GetObject( SvPtrarr::Count()-1 ); \
938 return pRet;\
942 #if defined (C40) || defined (C41) || defined (C42) || defined(C50) || defined(C52)
943 #define C40_INSERT( c, p, n) Insert( (c const *) p, n )
944 #define C40_PUSH( c, p) Push( (c const *) p )
945 #define C40_PTR_INSERT( c, p) Insert( (c const *) p )
946 #define C40_REMOVE( c, p ) Remove( (c const *) p )
947 #define C40_REPLACE( c, p, n) Replace( (c const *) p, n )
948 #define C40_PTR_REPLACE( c, p) Replace( (c const *) p )
949 #define C40_GETPOS( c, r) GetPos( (c const *)r )
950 #else
951 #if defined WTC || defined IRIX || defined ICC || defined HPUX || (defined GCC && __GNUC__ >= 3) || (defined(WNT) && _MSC_VER >= 1400)
952 #define C40_INSERT( c, p, n ) Insert( (c const *&) p, n )
953 #define C40_PUSH( c, p) Push( (c const *&) p )
954 #define C40_PTR_INSERT( c, p ) Insert( (c const *&) p )
955 #define C40_REMOVE( c, p ) Remove( (c const *&) p )
956 #define C40_REPLACE( c, p, n ) Replace( (c const *&) p, n )
957 #define C40_PTR_REPLACE( c, p ) Replace( (c const *&) p )
958 #define C40_GETPOS( c, r) GetPos( (c const *&) r )
959 #else
960 #define C40_INSERT( c, p, n ) Insert( p, n )
961 #define C40_PUSH( c, p) Push( p )
962 #define C40_PTR_INSERT( c, p ) Insert( p )
963 #define C40_REMOVE( c, p) Remove( p )
964 #define C40_REPLACE( c, p, n ) Replace( p, n )
965 #define C40_PTR_REPLACE( c, p ) Replace( p )
966 #define C40_GETPOS( c, r) GetPos( r )
967 #endif
968 #endif
972 #endif //_SVARRAY_HXX