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: bucket.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 ************************************************************************/
31 #ifndef _B3D_BUCKET_HXX
32 #define _B3D_BUCKET_HXX
35 #include <bf_svtools/svarray.hxx>
40 /*************************************************************************
44 \************************************************************************/
46 #define BASE3D_DECL_BUCKET(TheClassName,TheExtension) \
47 SV_DECL_VARARR(TheClassName##TheExtension##MemArr, char*, 32, 32) \
48 class TheClassName##TheExtension { \
50 TheClassName##TheExtension##MemArr aMemArray; \
53 INT16 nFreeMemArray; \
58 UINT16 nEntriesPerArray; \
63 TheClassName##TheExtension(UINT16 TheSize); \
64 /* Zu verwendende Groesse der Speicherarrays setzen */ \
65 /* Bitte NUR verwenden, falls sich der Leerkonstruktor */ \
66 /* nicht vermeiden laesst! Nicht nachtraeglich anwenden! */ \
67 void InitializeSize(UINT16 TheSize); \
69 ~TheClassName##TheExtension(); \
70 /* Anhaengen und kopieren */ \
71 BOOL Append(TheClassName& rVec) \
72 { if(CareForSpace()) return ImplAppend(rVec); return FALSE; } \
73 /* nur neuen Eintrag anhaengen, ohne ausfuellen */ \
75 { if(CareForSpace()) return ImplAppend(); return FALSE; } \
76 /* Letzten Eintrag entfernen */ \
77 BOOL Remove() { if(nCount) return ImplRemove(); return FALSE; } \
78 /* leeren und Speicher freigeben */ \
80 /* leeren aber Speicher behalten */ \
82 TheClassName& operator[] (UINT32 nPos); \
83 UINT32 Count() { return nCount; } \
84 UINT32 GetNumAllocated() { return aMemArray.Count() * nEntriesPerArray; } \
85 void operator=(const TheClassName##TheExtension&); \
86 UINT16 GetBlockShift() { return nBlockShift; } \
87 UINT16 GetSlotSize() { return nSlotSize; } \
90 { if(nFreeEntry == nEntriesPerArray) \
91 return ImplCareForSpace(); return TRUE; } \
92 BOOL ImplCareForSpace(); \
93 /* Anhaengen und kopieren */ \
94 BOOL ImplAppend(TheClassName& rVec); \
95 /* nur neuen Eintrag anhaengen, ohne ausfuellen */ \
100 /*************************************************************************
102 |* Bucket implementor
104 \************************************************************************/
106 #define BASE3D_IMPL_BUCKET(TheClassName,TheExtension) \
107 SV_IMPL_VARARR(TheClassName##TheExtension##MemArr, char*) \
108 TheClassName##TheExtension::TheClassName##TheExtension(UINT16 TheSize) { \
109 InitializeSize(TheSize); \
111 void TheClassName##TheExtension::InitializeSize(UINT16 TheSize) { \
113 for(nShift=0,nSiz=1;nSiz<sizeof(TheClassName);nSiz<<=1,nShift++); \
114 nBlockShift = TheSize - nShift; \
115 nMask = (1L << nBlockShift)-1L; \
116 nSlotSize = 1<<nShift; \
117 nEntriesPerArray = (UINT16)((1L << TheSize) >> nShift); \
120 void TheClassName##TheExtension::operator=(const TheClassName##TheExtension& rObj) { \
122 TheClassName##TheExtension& rSrc = (TheClassName##TheExtension&)rObj; \
123 for(UINT32 a=0;a<rSrc.Count();a++) \
126 void TheClassName##TheExtension::Empty() { \
127 for(UINT16 i=0;i<aMemArray.Count();i++) \
128 /*#90353#*/ delete [] aMemArray[i]; \
129 if(aMemArray.Count()) \
130 aMemArray.Remove(0, aMemArray.Count()); \
135 void TheClassName##TheExtension::Erase() { \
136 nFreeEntry = nEntriesPerArray; \
140 TheClassName##TheExtension::~TheClassName##TheExtension() { \
143 BOOL TheClassName##TheExtension::ImplAppend(TheClassName& rVec) { \
144 *((TheClassName*)(aMemArray[nActMemArray] + (nFreeEntry++ << nShift))) = rVec; \
148 BOOL TheClassName##TheExtension::ImplAppend() { \
153 BOOL TheClassName##TheExtension::ImplRemove() { \
154 if(nFreeEntry == 1) { \
155 nFreeEntry = nEntriesPerArray + 1; \
156 if(nActMemArray == -1) \
164 BOOL TheClassName##TheExtension::ImplCareForSpace() { \
165 /* neues array bestimmem */ \
166 if(nActMemArray + 1 < nFreeMemArray) { \
167 /* ist scon allokiert, gehe auf naechstes */ \
170 /* neues muss allokiert werden */ \
171 char* pNew = new char[nEntriesPerArray << nShift]; \
174 aMemArray.Insert((const char*&) pNew, aMemArray.Count()); \
175 nActMemArray = nFreeMemArray++; \
180 TheClassName& TheClassName##TheExtension::operator[] (UINT32 nPos) { \
181 if(nPos >= nCount) { \
182 DBG_ERROR("Access to Bucket out of range!"); \
183 return *((TheClassName*)aMemArray[0]); \
185 return *((TheClassName*)(aMemArray[(UINT16)(nPos >> nBlockShift)] + ((nPos & nMask) << nShift))); \
189 }//end of namespace binfilter
191 #endif // _B3D_BUCKET_HXX