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 ************************************************************************/
33 #ifndef _CONTNR_HXX //autogen
34 #include <tools/contnr.hxx>
39 #define DECLARE_CONTAINER_SORT_COMMON( ClassName, Type ) \
40 ClassName( const ClassName& ); \
41 ClassName& operator =( const ClassName& ); \
43 using Container::Count; \
45 ClassName( USHORT InitSize, USHORT ReSize ) : \
46 Container( CONTAINER_MAXBLOCKSIZE, InitSize, ReSize ) {} \
48 BOOL Insert( Type* pObj ); \
50 Type *Remove( ULONG nPos ) \
51 { return (Type *)Container::Remove( nPos ); } \
53 Type *Remove( Type* pObj ); \
55 void DeleteAndDestroy( ULONG nPos ) \
57 Type *pObj = Remove( nPos ); \
62 void DeleteAndDestroy() \
63 { while( Count() ) DeleteAndDestroy( 0 ); } \
65 Type* GetObject( ULONG nPos ) const \
66 { return (Type *)Container::GetObject( nPos ); } \
68 Type* operator[]( ULONG nPos ) const \
69 { return GetObject(nPos); } \
71 BOOL Seek_Entry( const Type *pObj, ULONG* pPos ) const; \
73 ULONG GetPos( const Type* pObj ) const; \
76 #define DECLARE_CONTAINER_SORT( ClassName, Type ) \
77 class ClassName : private Container \
79 DECLARE_CONTAINER_SORT_COMMON( ClassName, Type ) \
84 #define DECLARE_CONTAINER_SORT_DEL( ClassName, Type ) \
85 class ClassName : private Container \
87 DECLARE_CONTAINER_SORT_COMMON( ClassName, Type ) \
88 ~ClassName() { DeleteAndDestroy(); } \
92 #define IMPL_CONTAINER_SORT( ClassName, Type, SortFunc ) \
93 BOOL ClassName::Insert( Type *pObj ) \
96 BOOL bExist = Seek_Entry( pObj, &nPos ); \
98 Container::Insert( pObj, nPos ); \
102 Type *ClassName::Remove( Type* pObj ) \
105 if( Seek_Entry( pObj, &nPos ) ) \
106 return Remove( nPos ); \
111 ULONG ClassName::GetPos( const Type* pObj ) const \
114 if( Seek_Entry( pObj, &nPos ) ) \
117 return CONTAINER_ENTRY_NOTFOUND; \
120 BOOL ClassName::Seek_Entry( const Type* pObj, ULONG* pPos ) const \
122 register ULONG nO = Count(), \
130 nM = nU + ( nO - nU ) / 2; \
131 int nCmp = SortFunc( *GetObject(nM), *pObj ); \
135 if( pPos ) *pPos = nM; \
138 else if( nCmp < 0 ) \
142 if( pPos ) *pPos = nU; \
149 if( pPos ) *pPos = nU; \