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: cntnrsrt.hxx,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 ************************************************************************/
34 ***********************************************************************
36 * Hier folgt die Beschreibung fuer die exportierten Makros
:
38 * DECLARE_CONTAINER_SORT( ClassName
, Type
)
39 * IMPL_CONTAINER_SORT( ClassName
, Type
, SortFunc
)
41 * Definiert eine von Container abgeleitete Klasse
"ClassName",
42 * in der die Elemente des Typs
"Type" sortiert enthalten sind
.
43 * Dazu muss einer Funktion
"SortFunc" definiert sein
, die als
44 * Paramter zwei
"const Type&" erwartet und
0 zurueckgibt
, wenn
45 * beide gleich sind
, -1 wenn der erste Paramter kleiner ist als
46 * der zweite und
+1 wenn der erste Paramter groesser ist als
49 * Die Zugriffs
-Methoden entsprechen in etwa denen der Container
-
50 * Klasse
, mit Ausnahme von Insert
, DeleteAndDestroy und Seek_Entry
,
51 * der den SV
-Pointer
-Arrays entsprechen
.
53 * DECLARE_CONTAINER_SORT_DEL( ClassName
, Type
)
54 * IMPL_CONTAINER_SORT( ClassName
, Type
, SortFunc
)
56 * Wie DECLARE_CONTAINER_SORT
, nur dass beim Aufruf des Destruktors
57 * alle im Conatiner vorhandenen Objekte geloescht werden
.
61 #include <tools/contnr.hxx>
63 #define DECLARE_CONTAINER_SORT_COMMON( ClassName, Type ) \
64 ClassName( const ClassName& ); \
65 ClassName& operator =( const ClassName& ); \
67 using Container::Count; \
69 ClassName( USHORT InitSize, USHORT ReSize ) : \
70 Container( CONTAINER_MAXBLOCKSIZE, InitSize, ReSize ) {} \
72 BOOL Insert( Type* pObj ); \
74 Type *Remove( ULONG nPos ) \
75 { return (Type *)Container::Remove( nPos ); } \
77 Type *Remove( Type* pObj ); \
79 void DeleteAndDestroy( ULONG nPos ) \
81 Type *pObj = Remove( nPos ); \
86 void DeleteAndDestroy() \
87 { while( Count() ) DeleteAndDestroy( 0 ); } \
89 Type* GetObject( ULONG nPos ) const \
90 { return (Type *)Container::GetObject( nPos ); } \
92 Type* operator[]( ULONG nPos ) const \
93 { return GetObject(nPos); } \
95 BOOL Seek_Entry( const Type *pObj, ULONG* pPos ) const; \
97 ULONG GetPos( const Type* pObj ) const; \
100 #define DECLARE_CONTAINER_SORT( ClassName, Type ) \
101 class ClassName : private Container \
103 DECLARE_CONTAINER_SORT_COMMON( ClassName, Type ) \
108 #define DECLARE_CONTAINER_SORT_DEL( ClassName, Type ) \
109 class ClassName : private Container \
111 DECLARE_CONTAINER_SORT_COMMON( ClassName, Type ) \
112 ~ClassName() { DeleteAndDestroy(); } \
116 #define IMPL_CONTAINER_SORT( ClassName, Type, SortFunc ) \
117 BOOL ClassName::Insert( Type *pObj ) \
120 BOOL bExist = Seek_Entry( pObj, &nPos ); \
122 Container::Insert( pObj, nPos ); \
126 Type *ClassName::Remove( Type* pObj ) \
129 if( Seek_Entry( pObj, &nPos ) ) \
130 return Remove( nPos ); \
135 ULONG ClassName::GetPos( const Type* pObj ) const \
138 if( Seek_Entry( pObj, &nPos ) ) \
141 return CONTAINER_ENTRY_NOTFOUND; \
144 BOOL ClassName::Seek_Entry( const Type* pObj, ULONG* pPos ) const \
146 register ULONG nO = Count(), \
154 nM = nU + ( nO - nU ) / 2; \
155 int nCmp = SortFunc( *GetObject(nM), *pObj ); \
159 if( pPos ) *pPos = nM; \
162 else if( nCmp < 0 ) \
166 if( pPos ) *pPos = nU; \
173 if( pPos ) *pPos = nU; \