summaryrefslogtreecommitdiff
path: root/svl/inc/svl/svarray.hxx
blob: 2a2c6a84e40ec28f81f0956fba75235e305fc025 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _SVARRAY_HXX
#define _SVARRAY_HXX

/***********************************************************************
*
*   Hier folgt die Beschreibung fuer die exportierten Makros:
*
*       SV_DECL_VARARR(nm, AE, IS, GS)
*       SV_IMPL_VARARR( nm, AE )
*           definiere/implementiere ein Array das einfache Objecte
*           enthaelt. (Sie werden im Speicher verschoben, koennen also
*           z.B. keine String sein)
*
*       SV_DECL_PTRARR(nm, AE, IS, GS)
*       SV_IMPL_PTRARR(nm, AE)
*           definiere/implementiere ein Array das Pointer haelt. Diese
*           werden von aussen angelegt und zerstoert. Das IMPL-Makro
*           wird nur benoetigt, wenn die DeleteAndDestroy Methode genutzt
*           wird, diese loescht dann die Pointer und ruft deren Destruktoren
*
*       SV_DECL_PTRARR_DEL(nm, AE, IS, GS)
*       SV_IMPL_PTRARR(nm, AE)
*           definiere/implementiere ein Array das Pointer haelt. Diese
*           werden von aussen angelegt und im Destructor zerstoert.
*
*
*       SV_DECL_PTRARR_SORT(nm, AE, IS, GS)
*       SV_IMPL_PTRARR_SORT( nm,AE )
*           defieniere/implementiere ein Sort-Array mit Pointern, das nach
*           Pointern sortiert ist. Basiert auf einem PTRARR
*
*       SV_DECL_PTRARR_SORT_DEL(nm, AE, IS, GS)
*       SV_IMPL_PTRARR_SORT( nm,AE )
*           defieniere/implementiere ein Sort-Array mit Pointern, das nach
*           Pointern sortiert ist. Basiert auf einem PTRARR_DEL
*
*       SV_DECL_PTRARR_SORT(nm, AE, IS, GS)
*       SV_IMPL_OP_PTRARR_SORT( nm,AE )
*           defieniere/implementiere ein Sort-Array mit Pointern, das nach
*           Objecten sortiert ist. Basiert auf einem PTRARR.
*           Sortierung mit Hilfe der Object-operatoren "<" und "=="
*
*       SV_DECL_PTRARR_SORT_DEL(nm, AE, IS, GS)
*       SV_IMPL_OP_PTRARR_SORT( nm,AE )
*           defieniere/implementiere ein Sort-Array mit Pointern, das nach
*           Objecten sortiert ist. Basiert auf einem PTRARR_DEL.
*           Sortierung mit Hilfe der Object-operatoren "<" und "=="
*
*       SV_DECL_VARARR_SORT(nm, AE, IS, GS)
*       SV_IMPL_VARARR_SORT( nm,AE )
*           defieniere/implementiere ein Sort-Array mit einfachen Objecten.
*           Basiert auf einem VARARR.
*           Sortierung mit Hilfe der Object-operatoren "<" und "=="
*
* JP 09.10.96:  vordefinierte Arrays:
*   SortArr:    SvStringsSort, SvStringsSortDtor,
*               SvStringsISort, SvStringsISortDtor
***********************************************************************/

#include "svl/svldllapi.h"

#ifndef INCLUDED_STRING_H
#include <string.h>     // memmove()
#define INCLUDED_STRING_H
#endif

#ifndef INCLUDED_LIMITS_H
#include <limits.h>     // USHRT_MAX
#define INCLUDED_LIMITS_H
#endif
#include <rtl/alloc.h>
#include <tools/solar.h>

class String;

#ifndef CONCAT
#define CONCAT(x,y) x##y
#endif

class DummyType;
inline void* operator new( size_t, DummyType* pPtr )
{
    return pPtr;
}
inline void operator delete( void*, DummyType* ) {}

#ifndef DBG_UTIL

#define _SVVARARR_DEF_GET_OP_INLINE( nm, ArrElem ) \
ArrElem& operator[](sal_uInt16 nP) const { return *(pData+nP); }\
\
void Insert( const nm * pI, sal_uInt16 nP,\
             sal_uInt16 nS = 0, sal_uInt16 nE = USHRT_MAX )\
{\
    if( USHRT_MAX == nE ) \
        nE = pI->nA; \
    if( nS < nE ) \
        Insert( (const ArrElem*)pI->pData+nS, (sal_uInt16)nE-nS, nP );\
}

#define _SVVARARR_IMPL_GET_OP_INLINE( nm, ArrElem )

#else // DBG_UTIL

#define _SVVARARR_DEF_GET_OP_INLINE( nm,ArrElem )\
ArrElem& operator[](sal_uInt16 nP) const;\
void Insert( const nm *pI, sal_uInt16 nP,\
                sal_uInt16 nS = 0, sal_uInt16 nE = USHRT_MAX );

#define _SVVARARR_IMPL_GET_OP_INLINE( nm, ArrElem )\
ArrElem& nm::operator[](sal_uInt16 nP) const\
{\
    OSL_ENSURE( pData && nP < nA,"Op[]");\
    return *(pData+nP);\
}\
void nm::Insert( const nm *pI, sal_uInt16 nP, sal_uInt16 nStt, sal_uInt16 nE)\
{\
    OSL_ENSURE(nP<=nA,"Ins,Ar[Start.End]");\
    if( USHRT_MAX == nE ) \
        nE = pI->nA; \
    if( nStt < nE ) \
        Insert( (const ArrElem*)pI->pData+nStt, (sal_uInt16)nE-nStt, nP );\
}

#endif // DBG_UTIL

#define _SV_DECL_VARARR_GEN(nm, AE, IS, AERef, vis )\
typedef sal_Bool (*FnForEach_##nm)( const AERef, void* );\
class vis nm\
{\
protected:\
    AE    *pData;\
    sal_uInt16 nFree;\
    sal_uInt16 nA;\
\
    void _resize(size_t n);\
\
public:\
    nm( sal_uInt16= IS );\
    ~nm() { rtl_freeMemory( pData ); }\
\
    _SVVARARR_DEF_GET_OP_INLINE(nm, AE )\
    AERef GetObject(sal_uInt16 nP) const { return (*this)[nP]; } \
\
    void Insert( const AERef aE, sal_uInt16 nP );\
    void Insert( const AE *pE, sal_uInt16 nL, sal_uInt16 nP );\
    void Remove( sal_uInt16 nP, sal_uInt16 nL = 1 );\
    void Replace( const AERef aE, sal_uInt16 nP );\
    void Replace( const AE *pE, sal_uInt16 nL, sal_uInt16 nP );\
    sal_uInt16 Count() const { return nA; }\
    const AE* GetData() const { return (const AE*)pData; }\
\
    void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
    {\
        _ForEach( 0, nA, fnForEach, pArgs );\
    }\
    void ForEach( sal_uInt16 nS, sal_uInt16 nE, \
                    CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
    {\
        _ForEach( nS, nE, fnForEach, pArgs );\
    }\
\
    void _ForEach( sal_uInt16 nStt, sal_uInt16 nE, \
            CONCAT( FnForEach_, nm ) fnCall, void* pArgs = 0 );\
\

#define SV_DECL_VARARR_GEN(nm, AE, IS, AERef, vis )\
_SV_DECL_VARARR_GEN(nm, AE, IS, AERef, vis )\
private:\
nm( const nm& );\
nm& operator=( const nm& );\
};

#define SV_DECL_VARARR(nm, AE, IS) \
SV_DECL_VARARR_GEN(nm, AE, IS, AE &, )

#define SV_DECL_VARARR_VISIBILITY(nm, AE, IS, vis ) \
SV_DECL_VARARR_GEN(nm, AE, IS, AE &, vis )

#define SV_IMPL_VARARR_GEN( nm, AE, AERef )\
nm::nm( sal_uInt16 nInit )\
    : pData (0),\
      nFree (nInit),\
      nA    (0)\
{\
    if( nInit )\
    {\
        pData = (AE*)(rtl_allocateMemory(sizeof(AE) * nInit));\
        OSL_ENSURE( pData, "CTOR, allocate");\
    }\
}\
\
void nm::_resize (size_t n)\
{\
    sal_uInt16 nL = ((n < USHRT_MAX) ? sal_uInt16(n) : USHRT_MAX);\
    AE* pE = (AE*)(rtl_reallocateMemory (pData, sizeof(AE) * nL));\
    if ((pE != 0) || (nL == 0))\
    {\
        pData = pE;\
        nFree = nL - nA;\
    }\
}\
\
void nm::Insert( const AERef aE, sal_uInt16 nP )\
{\
    OSL_ENSURE(nP <= nA && nA < USHRT_MAX, "Ins 1");\
    if (nFree < 1)\
        _resize (nA + ((nA > 1) ? nA : 1));\
    if( pData && nP < nA )\
        memmove( pData+nP+1, pData+nP, (nA-nP) * sizeof( AE ));\
    *(pData+nP) = (AE&)aE;\
    ++nA; --nFree;\
}\
\
void nm::Insert( const AE* pE, sal_uInt16 nL, sal_uInt16 nP )\
{\
    OSL_ENSURE(nP<=nA && ((long)nA+nL)<USHRT_MAX,"Ins n");\
    if (nFree < nL)\
        _resize (nA + ((nA > nL) ? nA : nL));\
    if( pData && nP < nA )\
        memmove( pData+nP+nL, pData+nP, (nA-nP) * sizeof( AE ));\
    if( pE )\
        memcpy( pData+nP, pE, nL * sizeof( AE ));\
    nA = nA + nL; nFree = nFree - nL;\
}\
\
void nm::Replace( const AERef aE, sal_uInt16 nP )\
{\
    if( nP < nA )\
        *(pData+nP) = (AE&)aE;\
}\
\
void nm::Replace( const AE *pE, sal_uInt16 nL, sal_uInt16 nP )\
{\
    if( pE && nP < nA )\
    {\
        if( nP + nL < nA )\
            memcpy( pData + nP, pE, nL * sizeof( AE ));\
        else if( nP + nL < nA + nFree )\
        {\
            memcpy( pData + nP, pE, nL * sizeof( AE ));\
            nP = nP + (nL - nA); \
            nFree = nP;\
        }\
        else \
        {\
            sal_uInt16 nTmpLen = nA + nFree - nP; \
            memcpy( pData + nP, pE, nTmpLen * sizeof( AE ));\
            nA = nA + nFree; \
            nFree = 0; \
            Insert( pE + nTmpLen, nL - nTmpLen, nA );\
        }\
    }\
}\
\
void nm::Remove( sal_uInt16 nP, sal_uInt16 nL )\
{\
    if( !nL )\
        return;\
    OSL_ENSURE( nP < nA && nP + nL <= nA,"Del");\
    if( pData && nP+1 < nA )\
        memmove( pData+nP, pData+nP+nL, (nA-nP-nL) * sizeof( AE ));\
    nA = nA - nL; nFree = nFree + nL;\
    if (nFree > nA)\
        _resize (nA);\
}\
\
void nm::_ForEach( sal_uInt16 nStt, sal_uInt16 nE, \
            CONCAT( FnForEach_, nm ) fnCall, void* pArgs )\
{\
    if( nStt >= nE || nE > nA )\
        return;\
    for( ; nStt < nE && (*fnCall)( *(const AE*)(pData+nStt), pArgs ); nStt++)\
        ;\
}\
\
_SVVARARR_IMPL_GET_OP_INLINE(nm, AE )\

#define SV_IMPL_VARARR( nm, AE ) \
SV_IMPL_VARARR_GEN( nm, AE, AE & )

#define _SV_DECL_PTRARR_DEF_GEN( nm, AE, IS, AERef, vis )\
_SV_DECL_VARARR_GEN( nm, AE, IS, AERef, vis)\
sal_uInt16 GetPos( const AERef aE ) const;\
};

#define _SV_DECL_PTRARR_DEF( nm, AE, IS, vis )\
_SV_DECL_PTRARR_DEF_GEN( nm, AE, IS, AE &, vis )

#define SV_DECL_PTRARR_GEN(nm, AE, IS, Base, AERef, VPRef, vis )\
typedef sal_Bool (*FnForEach_##nm)( const AERef, void* );\
class vis nm: public Base \
{\
public:\
    nm( sal_uInt16 nIni=IS )\
        : Base(nIni) {}\
    void Insert( const nm *pI, sal_uInt16 nP, \
            sal_uInt16 nS = 0, sal_uInt16 nE = USHRT_MAX ) {\
        Base::Insert((const Base*)pI, nP, nS, nE);\
    }\
    void Insert( const AERef aE, sal_uInt16 nP ) {\
        Base::Insert( (const VPRef )aE, nP );\
    }\
    void Insert( const AE *pE, sal_uInt16 nL, sal_uInt16 nP ) {\
        Base::Insert( (const VoidPtr*)pE, nL, nP );\
    }\
    void Replace( const AERef aE, sal_uInt16 nP ) {\
        Base::Replace( (const VPRef)aE, nP );\
    }\
    void Replace( const AE *pE, sal_uInt16 nL, sal_uInt16 nP ) {\
        Base::Replace( (const VoidPtr*)pE, nL, nP );\
    }\
    void Remove( sal_uInt16 nP, sal_uInt16 nL = 1) {\
        Base::Remove(nP,nL);\
    }\
    const AE* GetData() const {\
        return (const AE*)Base::GetData();\
    }\
    void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
    {\
        _ForEach( 0, nA, (FnForEach_##Base)fnForEach, pArgs );\
    }\
    void ForEach( sal_uInt16 nS, sal_uInt16 nE, \
                    CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
    {\
        _ForEach( nS, nE, (FnForEach_##Base)fnForEach, pArgs );\
    }\
    AE operator[]( sal_uInt16 nP )const  { \
        return (AE)Base::operator[](nP); }\
    AE GetObject(sal_uInt16 nP) const { \
        return (AE)Base::GetObject(nP); }\
    \
    sal_uInt16 GetPos( const AERef aE ) const { \
        return Base::GetPos((const VPRef)aE);\
    }\
    void DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL=1 );\
private:\
    nm( const nm& );\
    nm& operator=( const nm& );\
};

#define SV_DECL_PTRARR(nm, AE, IS)\
SV_DECL_PTRARR_GEN(nm, AE, IS, SvPtrarr, AE &, VoidPtr &, )

#define SV_DECL_PTRARR_VISIBILITY(nm, AE, IS, vis)\
SV_DECL_PTRARR_GEN(nm, AE, IS, SvPtrarr, AE &, VoidPtr &, vis )

#define SV_DECL_PTRARR_DEL_GEN(nm, AE, IS, Base, AERef, VPRef, vis )\
typedef sal_Bool (*FnForEach_##nm)( const AERef, void* );\
class vis nm: public Base \
{\
public:\
    nm( sal_uInt16 nIni=IS )\
        : Base(nIni) {}\
    ~nm() { DeleteAndDestroy( 0, Count() ); }\
    void Insert( const nm *pI, sal_uInt16 nP, \
            sal_uInt16 nS = 0, sal_uInt16 nE = USHRT_MAX ) {\
        Base::Insert((const Base*)pI, nP, nS, nE);\
    }\
    void Insert( const AERef aE, sal_uInt16 nP ) {\
        Base::Insert((const VPRef)aE, nP );\
    }\
    void Insert( const AE *pE, sal_uInt16 nL, sal_uInt16 nP ) {\
        Base::Insert( (const VoidPtr *)pE, nL, nP );\
    }\
    void Replace( const AERef aE, sal_uInt16 nP ) {\
        Base::Replace( (const VPRef)aE, nP );\
    }\
    void Replace( const AE *pE, sal_uInt16 nL, sal_uInt16 nP ) {\
        Base::Replace( (const VoidPtr*)pE, nL, nP );\
    }\
    void Remove( sal_uInt16 nP, sal_uInt16 nL = 1) {\
        Base::Remove(nP,nL);\
    }\
    const AE* GetData() const {\
        return (const AE*)Base::GetData();\
    }\
    void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
    {\
        _ForEach( 0, nA, (FnForEach_##Base)fnForEach, pArgs );\
    }\
    void ForEach( sal_uInt16 nS, sal_uInt16 nE, \
                    CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
    {\
        _ForEach( nS, nE, (FnForEach_##Base)fnForEach, pArgs );\
    }\
    AE operator[]( sal_uInt16 nP )const  { \
        return (AE)Base::operator[](nP); }\
    AE GetObject( sal_uInt16 nP )const  { \
        return (AE)Base::GetObject(nP); }\
    \
    sal_uInt16 GetPos( const AERef aE ) const { \
        return Base::GetPos((const VPRef)aE);\
    } \
    void DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL=1 );\
private:\
    nm( const nm& );\
    nm& operator=( const nm& );\
};

#define SV_DECL_PTRARR_DEL(nm, AE, IS)\
SV_DECL_PTRARR_DEL_GEN(nm, AE, IS, SvPtrarr, AE &, VoidPtr &, )

#define SV_DECL_PTRARR_DEL_VISIBILITY(nm, AE, IS, vis)\
SV_DECL_PTRARR_DEL_GEN(nm, AE, IS, SvPtrarr, AE &, VoidPtr &, vis)

#define SV_IMPL_PTRARR_GEN(nm, AE, Base)\
void nm::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL )\
{ \
    if( nL ) {\
        OSL_ENSURE( nP < nA && nP + nL <= nA,"Del");\
        for( sal_uInt16 n=nP; n < nP + nL; n++ ) \
            delete *((AE*)pData+n); \
        Base::Remove( nP, nL ); \
    } \
}

#define SV_IMPL_PTRARR(nm, AE )\
SV_IMPL_PTRARR_GEN(nm, AE, SvPtrarr )

typedef void* VoidPtr;
_SV_DECL_PTRARR_DEF( SvPtrarr, VoidPtr, 0, SVL_DLLPUBLIC )

// SORTARR - Begin

#define _SORT_CLASS_DEF(nm, AE, IS, vis)\
typedef sal_Bool (*FnForEach_##nm)( const AE&, void* );\
class vis nm : private nm##_SAR \
{\
public:\
    nm(sal_uInt16 nSize = IS)\
        : nm##_SAR(nSize) {}\
    void Insert( const nm *pI, sal_uInt16 nS=0, sal_uInt16 nE=USHRT_MAX );\
    sal_Bool Insert( const AE& aE );\
    sal_Bool Insert( const AE& aE, sal_uInt16& rP );\
    void Insert( const AE *pE, sal_uInt16 nL );\
    void Remove( sal_uInt16 nP, sal_uInt16 nL = 1 );\
    void Remove( const AE& aE, sal_uInt16 nL = 1 );\
    sal_uInt16 Count() const  {   return nm##_SAR::Count(); }\
    const AE* GetData() const { return (const AE*)pData; }\
\
/* Das Ende stehe im DECL-Makro !!! */

#define _SV_SEEK_PTR(nm,AE)\
sal_Bool nm::Seek_Entry( const AE aE, sal_uInt16* pP ) const\
{\
    register sal_uInt16 nO  = nm##_SAR::Count(),\
            nM, \
            nU = 0;\
    if( nO > 0 )\
    {\
        nO--;\
        register long rCmp = (long)aE;\
        while( nU <= nO )\
        {\
            nM = nU + ( nO - nU ) / 2;\
            if( (long)*(pData + nM) == rCmp )\
            {\
                if( pP ) *pP = nM;\
                return sal_True;\
            }\
            else if( (long)*(pData+ nM) < (long)aE  )\
                nU = nM + 1;\
            else if( nM == 0 )\
            {\
                if( pP ) *pP = nU;\
                return sal_False;\
            }\
            else\
                nO = nM - 1;\
        }\
    }\
    if( pP ) *pP = nU;\
    return sal_False;\
}

#define _SV_SEEK_PTR_TO_OBJECT( nm,AE )\
sal_Bool nm::Seek_Entry( const AE aE, sal_uInt16* pP ) const\
{\
    register sal_uInt16 nO  = nm##_SAR::Count(),\
            nM, \
            nU = 0;\
    if( nO > 0 )\
    {\
        nO--;\
        while( nU <= nO )\
        {\
            nM = nU + ( nO - nU ) / 2;\
            if( *(*((AE*)pData + nM)) == *(aE) )\
            {\
                if( pP ) *pP = nM;\
                return sal_True;\
            }\
            else if( *(*((AE*)pData + nM)) < *(aE) )\
                nU = nM + 1;\
            else if( nM == 0 )\
            {\
                if( pP ) *pP = nU;\
                return sal_False;\
            }\
            else\
                nO = nM - 1;\
        }\
    }\
    if( pP ) *pP = nU;\
    return sal_False;\
}

#define _SV_SEEK_OBJECT( nm,AE )\
sal_Bool nm::Seek_Entry( const AE & aE, sal_uInt16* pP ) const\
{\
    register sal_uInt16 nO  = nm##_SAR::Count(),\
            nM, \
            nU = 0;\
    if( nO > 0 )\
    {\
        nO--;\
        while( nU <= nO )\
        {\
            nM = nU + ( nO - nU ) / 2;\
            if( *(pData + nM) == aE )\
            {\
                if( pP ) *pP = nM;\
                return sal_True;\
            }\
            else if( *(pData + nM) < aE )\
                nU = nM + 1;\
            else if( nM == 0 )\
            {\
                if( pP ) *pP = nU;\
                return sal_False;\
            }\
            else\
                nO = nM - 1;\
        }\
    }\
    if( pP ) *pP = nU;\
    return sal_False;\
}

#define _SV_IMPL_SORTAR_ALG(nm, AE)\
void nm::Insert( const nm * pI, sal_uInt16 nS, sal_uInt16 nE )\
{\
    if( USHRT_MAX == nE )\
        nE = pI->Count();\
    sal_uInt16 nP;\
    const AE * pIArr = pI->GetData();\
    for( ; nS < nE; ++nS )\
    {\
        if( ! Seek_Entry( *(pIArr+nS), &nP) )\
                nm##_SAR::Insert( *(pIArr+nS), nP );\
        if( ++nP >= Count() )\
        {\
            nm##_SAR::Insert( pI, nP, nS+1, nE );\
            nS = nE;\
        }\
    }\
}\
\
sal_Bool nm::Insert( const AE & aE )\
{\
    sal_uInt16 nP;\
    sal_Bool bExist;\
    bExist = Seek_Entry( aE, &nP );\
    if( ! bExist )\
        nm##_SAR::Insert( aE, nP );\
    return !bExist;\
}\
sal_Bool nm::Insert( const AE & aE, sal_uInt16& rP )\
{\
    sal_Bool bExist;\
    bExist = Seek_Entry( aE, &rP );\
    if( ! bExist )\
        nm##_SAR::Insert( aE, rP );\
    return !bExist;\
}\
void nm::Insert( const AE* pE, sal_uInt16 nL)\
{\
    sal_uInt16 nP;\
    for( sal_uInt16 n = 0; n < nL; ++n )\
        if( ! Seek_Entry( *(pE+n), &nP ))\
            nm##_SAR::Insert( *(pE+n), nP );\
}\
void nm::Remove( sal_uInt16 nP, sal_uInt16 nL )\
{\
    if( nL )\
        nm##_SAR::Remove( nP, nL);\
}\
\
void nm::Remove( const AE &aE, sal_uInt16 nL )\
{\
    sal_uInt16 nP;\
    if( nL && Seek_Entry( aE, &nP ) )   \
        nm##_SAR::Remove( nP, nL);\
}\

#define _SORTARR_BLC_CASTS(nm, AE )\
    sal_uInt16 GetPos( const AE& aE ) const { \
        return SvPtrarr::GetPos((const VoidPtr&)aE);\
    }

#define _SV_DECL_PTRARR_SORT_ALG(nm, AE, IS, vis)\
SV_DECL_PTRARR_VISIBILITY(nm##_SAR, AE, IS, vis)\
_SORT_CLASS_DEF(nm, AE, IS, vis)\
    AE operator[](sal_uInt16 nP) const {\
        return nm##_SAR::operator[]( nP );\
    }\
    AE GetObject(sal_uInt16 nP) const {\
        return nm##_SAR::GetObject( nP );\
    }\
    sal_Bool Seek_Entry( const AE aE, sal_uInt16* pP = 0 ) const;\
    void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
    {\
        _ForEach( 0, nA, (FnForEach_SvPtrarr)fnForEach, pArgs );\
    }\
    void ForEach( sal_uInt16 nS, sal_uInt16 nE, \
                    CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
    {\
        _ForEach( nS, nE, (FnForEach_SvPtrarr)fnForEach, pArgs );\
    }\
    void DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL=1 ); \
    _SORTARR_BLC_CASTS(nm, AE )\
\
/* Das Ende stehe im DECL-Makro !!! */

#define _SV_DECL_PTRARR_SORT(nm, AE, IS, vis)\
_SV_DECL_PTRARR_SORT_ALG(nm, AE, IS, vis)\
private:\
    nm( const nm& );\
    nm& operator=( const nm& );\
};

#define SV_DECL_PTRARR_SORT(nm, AE, IS)\
_SV_DECL_PTRARR_SORT(nm, AE, IS,)

#define SV_DECL_PTRARR_SORT_VISIBILITY(nm, AE, IS, vis)\
_SV_DECL_PTRARR_SORT(nm, AE, IS, vis)


#define _SV_DECL_PTRARR_SORT_DEL(nm, AE, IS, vis)\
_SV_DECL_PTRARR_SORT_ALG(nm, AE, IS, vis)\
    ~nm() { DeleteAndDestroy( 0, Count() ); }\
private:\
    nm( const nm& );\
    nm& operator=( const nm& );\
};

#define SV_DECL_PTRARR_SORT_DEL(nm, AE, IS)\
_SV_DECL_PTRARR_SORT_DEL(nm, AE, IS,)

#define SV_DECL_PTRARR_SORT_DEL_VISIBILITY(nm, AE, IS, vis)\
_SV_DECL_PTRARR_SORT_DEL(nm, AE, IS, vis)

#define _SV_DECL_VARARR_SORT(nm, AE, IS, vis)\
SV_DECL_VARARR_VISIBILITY(nm##_SAR, AE, IS, vis)\
_SORT_CLASS_DEF(nm, AE, IS, vis) \
    const AE& operator[](sal_uInt16 nP) const {\
        return nm##_SAR::operator[]( nP );\
    }\
    const AE& GetObject(sal_uInt16 nP) const {\
        return nm##_SAR::GetObject( nP );\
    }\
    sal_Bool Seek_Entry( const AE & aE, sal_uInt16* pP = 0 ) const;\
    void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
    {\
        _ForEach( 0, nA, (FnForEach_##nm##_SAR)fnForEach, pArgs );\
    }\
    void ForEach( sal_uInt16 nS, sal_uInt16 nE, \
                    CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\
    {\
        _ForEach( nS, nE, (FnForEach_##nm##_SAR)fnForEach, pArgs );\
    }\
private:\
    nm( const nm& );\
    nm& operator=( const nm& );\
};

#define SV_DECL_VARARR_SORT(nm, AE, IS)\
_SV_DECL_VARARR_SORT(nm, AE, IS,)

#define SV_DECL_VARARR_SORT_VISIBILITY(nm, AE, IS, vis)\
_SV_DECL_VARARR_SORT(nm, AE, IS, vis)

#define SV_IMPL_PTRARR_SORT( nm,AE )\
_SV_IMPL_SORTAR_ALG( nm,AE )\
    void nm::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL ) { \
        if( nL ) {\
            OSL_ENSURE( nP < nA && nP + nL <= nA, "ERR_VAR_DEL" );\
            for( sal_uInt16 n=nP; n < nP + nL; n++ ) \
                delete *((AE*)pData+n); \
            SvPtrarr::Remove( nP, nL ); \
        } \
    } \
_SV_SEEK_PTR( nm, AE )

#define SV_IMPL_OP_PTRARR_SORT( nm,AE )\
_SV_IMPL_SORTAR_ALG( nm,AE )\
    void nm::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL ) { \
        if( nL ) {\
            OSL_ENSURE( nP < nA && nP + nL <= nA, "ERR_VAR_DEL" );\
            for( sal_uInt16 n=nP; n < nP + nL; n++ ) \
                delete *((AE*)pData+n); \
            SvPtrarr::Remove( nP, nL ); \
        } \
    } \
_SV_SEEK_PTR_TO_OBJECT( nm,AE )

#define SV_IMPL_VARARR_SORT( nm,AE )\
SV_IMPL_VARARR(nm##_SAR, AE)\
_SV_IMPL_SORTAR_ALG( nm,AE )\
_SV_SEEK_OBJECT( nm,AE )

#if defined(ICC) || defined(GCC) || (defined(WNT) && _MSC_VER >= 1400)
#define C40_INSERT( c, p, n ) Insert( (c const *&) p, n )
#define C40_PTR_INSERT( c, p ) Insert( (c const *&) p )
#define C40_REPLACE( c, p, n ) Replace( (c const *&) p, n )
#define C40_GETPOS( c, r) GetPos( (c const *&) r )
#else
#define C40_INSERT( c, p, n ) Insert( p, n )
#define C40_PTR_INSERT( c, p ) Insert( p )
#define C40_REPLACE( c, p, n ) Replace( p, n )
#define C40_GETPOS( c, r) GetPos( r )
#endif

#endif  //_SVARRAY_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */