1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svarray.cxx,v $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
36 #define _SVSTDARR_BOOLS
37 #define _SVSTDARR_BYTES
38 #define _SVSTDARR_ULONGS
39 #define _SVSTDARR_ULONGSSORT
40 #define _SVSTDARR_USHORTS
41 #define _SVSTDARR_LONGS
42 #define _SVSTDARR_LONGSSORT
43 #define _SVSTDARR_SHORTS
44 #define _SVSTDARR_STRINGS
45 #define _SVSTDARR_STRINGSDTOR
46 #define _SVSTDARR_STRINGSSORT
47 #define _SVSTDARR_STRINGSSORTDTOR
48 #define _SVSTDARR_STRINGSISORT
49 #define _SVSTDARR_STRINGSISORTDTOR
50 #define _SVSTDARR_USHORTSSORT
52 #define _SVSTDARR_BYTESTRINGS
53 #define _SVSTDARR_BYTESTRINGSDTOR
54 #define _SVSTDARR_BYTESTRINGSSORT
55 #define _SVSTDARR_BYTESTRINGSSORTDTOR
56 #define _SVSTDARR_BYTESTRINGSISORT
57 #define _SVSTDARR_BYTESTRINGSISORTDTOR
59 #define _SVSTDARR_XUB_STRLEN
60 #define _SVSTDARR_XUB_STRLENSORT
62 #include <svtools/svstdarr.hxx>
63 #include <tools/string.hxx>
64 #include <tools/debug.hxx>
66 SV_IMPL_VARARR(SvPtrarr
,VoidPtr
)
67 SV_IMPL_VARARR_PLAIN(SvPtrarrPlain
,VoidPtr
)
69 USHORT
SvPtrarr::GetPos( const VoidPtr
& aElement
) const
71 for( n
=0; n
< nA
&& *(GetData()+n
) != aElement
; ) n
++;
72 return ( n
>= nA
? USHRT_MAX
: n
);
75 USHORT
SvPtrarrPlain::GetPos( const VoidPtr aElement
) const
77 for( n
=0; n
< nA
&& *(GetData()+n
) != aElement
; ) n
++;
78 return ( n
>= nA
? USHRT_MAX
: n
);
82 SV_IMPL_VARARR( SvBools
, BOOL
)
83 SV_IMPL_VARARR( SvBytes
, BYTE
)
84 SV_IMPL_VARARR( SvULongs
, ULONG
)
85 SV_IMPL_VARARR( SvUShorts
, USHORT
)
86 SV_IMPL_VARARR( SvLongs
, long)
87 SV_IMPL_VARARR( SvShorts
, short )
89 SV_IMPL_VARARR_SORT( SvULongsSort
, ULONG
)
90 SV_IMPL_VARARR_SORT( SvLongsSort
, long )
91 SV_IMPL_VARARR_SORT( SvXub_StrLensSort
, xub_StrLen
)
93 SV_IMPL_VARARR( SvXub_StrLens
, xub_StrLen
)
95 SV_IMPL_PTRARR( SvStrings
, StringPtr
)
96 SV_IMPL_PTRARR( SvStringsDtor
, StringPtr
)
97 SV_IMPL_OP_PTRARR_SORT( SvStringsSort
, StringPtr
)
98 SV_IMPL_OP_PTRARR_SORT( SvStringsSortDtor
, StringPtr
)
100 SV_IMPL_PTRARR( SvByteStrings
, ByteStringPtr
)
101 SV_IMPL_PTRARR( SvByteStringsDtor
, ByteStringPtr
)
102 SV_IMPL_OP_PTRARR_SORT( SvByteStringsSort
, ByteStringPtr
)
103 SV_IMPL_OP_PTRARR_SORT( SvByteStringsSortDtor
, ByteStringPtr
)
107 // ---------------- strings -------------------------------------
109 // Array mit anderer Seek-Methode!
110 _SV_IMPL_SORTAR_ALG( SvStringsISort
, StringPtr
)
111 void SvStringsISort::DeleteAndDestroy( USHORT nP
, USHORT nL
)
115 DBG_ASSERT( nP
< nA
&& nP
+ nL
<= nA
, "ERR_VAR_DEL" );
116 for( USHORT n
=nP
; n
< nP
+ nL
; n
++ )
117 delete *((StringPtr
*)pData
+n
);
118 SvPtrarr::Remove( nP
, nL
);
121 BOOL
SvStringsISort::Seek_Entry( const StringPtr aE
, USHORT
* pP
) const
123 register USHORT nO
= SvStringsISort_SAR::Count(),
131 nM
= nU
+ ( nO
- nU
) / 2;
132 StringCompare eCmp
= (*((StringPtr
*)pData
+ nM
))->
133 CompareIgnoreCaseToAscii( *(aE
) );
134 if( COMPARE_EQUAL
== eCmp
)
139 else if( COMPARE_LESS
== eCmp
)
154 // ---------------- strings -------------------------------------
156 // Array mit anderer Seek-Methode!
157 _SV_IMPL_SORTAR_ALG( SvStringsISortDtor
, StringPtr
)
158 void SvStringsISortDtor::DeleteAndDestroy( USHORT nP
, USHORT nL
)
162 DBG_ASSERT( nP
< nA
&& nP
+ nL
<= nA
, "ERR_VAR_DEL" );
163 for( USHORT n
=nP
; n
< nP
+ nL
; n
++ )
164 delete *((StringPtr
*)pData
+n
);
165 SvPtrarr::Remove( nP
, nL
);
168 BOOL
SvStringsISortDtor::Seek_Entry( const StringPtr aE
, USHORT
* pP
) const
170 register USHORT nO
= SvStringsISortDtor_SAR::Count(),
178 nM
= nU
+ ( nO
- nU
) / 2;
179 StringCompare eCmp
= (*((StringPtr
*)pData
+ nM
))->
180 CompareIgnoreCaseToAscii( *(aE
) );
181 if( COMPARE_EQUAL
== eCmp
)
186 else if( COMPARE_LESS
== eCmp
)
201 // ---------------- Ushorts -------------------------------------
203 /* SortArray fuer UShorts */
204 BOOL
SvUShortsSort::Seek_Entry( const USHORT aE
, USHORT
* pP
) const
206 register USHORT nO
= SvUShorts::Count(),
214 nM
= nU
+ ( nO
- nU
) / 2;
215 if( *(pData
+ nM
) == aE
)
220 else if( *(pData
+ nM
) < aE
)
235 void SvUShortsSort::Insert( const SvUShortsSort
* pI
, USHORT nS
, USHORT nE
)
237 if( USHRT_MAX
== nE
)
240 const USHORT
* pIArr
= pI
->GetData();
241 for( ; nS
< nE
; ++nS
)
243 if( ! Seek_Entry( *(pIArr
+nS
), &nP
) )
244 SvUShorts::Insert( *(pIArr
+nS
), nP
);
245 if( ++nP
>= Count() )
247 SvUShorts::Insert( pI
, nP
, nS
+1, nE
);
253 BOOL
SvUShortsSort::Insert( const USHORT aE
)
256 BOOL bExist
= Seek_Entry( aE
, &nP
);
258 SvUShorts::Insert( aE
, nP
);
262 BOOL
SvUShortsSort::Insert( const USHORT aE
, USHORT
& rP
)
264 BOOL bExist
= Seek_Entry( aE
, &rP
);
266 SvUShorts::Insert( aE
, rP
);
270 void SvUShortsSort::Insert( const USHORT
* pE
, USHORT nL
)
273 for( USHORT n
= 0; n
< nL
; ++n
)
274 if( ! Seek_Entry( *(pE
+n
), &nP
))
275 SvUShorts::Insert( *(pE
+n
), nP
);
279 void SvUShortsSort::RemoveAt( const USHORT nP
, USHORT nL
)
282 SvUShorts::Remove( nP
, nL
);
285 // remove ab dem Eintrag
286 void SvUShortsSort::Remove( const USHORT aE
, USHORT nL
)
289 if( nL
&& Seek_Entry( aE
, &nP
) )
290 SvUShorts::Remove( nP
, nL
);
293 // ---------------- bytestrings -------------------------------------
295 // Array mit anderer Seek-Methode!
296 _SV_IMPL_SORTAR_ALG( SvByteStringsISort
, ByteStringPtr
)
297 void SvByteStringsISort::DeleteAndDestroy( USHORT nP
, USHORT nL
)
301 DBG_ASSERT( nP
< nA
&& nP
+ nL
<= nA
, "ERR_VAR_DEL" );
302 for( USHORT n
=nP
; n
< nP
+ nL
; n
++ )
303 delete *((ByteStringPtr
*)pData
+n
);
304 SvPtrarr::Remove( nP
, nL
);
307 BOOL
SvByteStringsISort::Seek_Entry( const ByteStringPtr aE
, USHORT
* pP
) const
309 register USHORT nO
= SvByteStringsISort_SAR::Count(),
317 nM
= nU
+ ( nO
- nU
) / 2;
318 StringCompare eCmp
= (*((ByteStringPtr
*)pData
+ nM
))->
319 CompareIgnoreCaseToAscii( *(aE
) );
320 if( COMPARE_EQUAL
== eCmp
)
325 else if( COMPARE_LESS
== eCmp
)
341 // Array mit anderer Seek-Methode!
342 _SV_IMPL_SORTAR_ALG( SvByteStringsISortDtor
, ByteStringPtr
)
343 void SvByteStringsISortDtor::DeleteAndDestroy( USHORT nP
, USHORT nL
)
347 DBG_ASSERT( nP
< nA
&& nP
+ nL
<= nA
, "ERR_VAR_DEL" );
348 for( USHORT n
=nP
; n
< nP
+ nL
; n
++ )
349 delete *((ByteStringPtr
*)pData
+n
);
350 SvPtrarr::Remove( nP
, nL
);
353 BOOL
SvByteStringsISortDtor::Seek_Entry( const ByteStringPtr aE
, USHORT
* pP
) const
355 register USHORT nO
= SvByteStringsISortDtor_SAR::Count(),
363 nM
= nU
+ ( nO
- nU
) / 2;
364 StringCompare eCmp
= (*((ByteStringPtr
*)pData
+ nM
))->
365 CompareIgnoreCaseToAscii( *(aE
) );
366 if( COMPARE_EQUAL
== eCmp
)
371 else if( COMPARE_LESS
== eCmp
)