1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _BPARR_HXX 29*cdf0e10cSrcweir #define _BPARR_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <tools/solar.h> 32*cdf0e10cSrcweir #include <tools/debug.hxx> 33*cdf0e10cSrcweir #include <swdllapi.h> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir struct BlockInfo; 36*cdf0e10cSrcweir class BigPtrArray; 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir class BigPtrEntry 39*cdf0e10cSrcweir { 40*cdf0e10cSrcweir friend class BigPtrArray; 41*cdf0e10cSrcweir BlockInfo* pBlock; 42*cdf0e10cSrcweir sal_uInt16 nOffset; 43*cdf0e10cSrcweir public: 44*cdf0e10cSrcweir virtual ~BigPtrEntry() {} 45*cdf0e10cSrcweir protected: 46*cdf0e10cSrcweir BigPtrEntry() : pBlock(0), nOffset(0) {} 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir inline sal_uLong GetPos() const; 49*cdf0e10cSrcweir inline BigPtrArray& GetArray() const; 50*cdf0e10cSrcweir }; 51*cdf0e10cSrcweir typedef BigPtrEntry* ElementPtr; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir typedef sal_Bool (*FnForEach)( const ElementPtr&, void* pArgs ); 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir // 1000 Eintr�ge pro Block = etwas weniger als 4K 57*cdf0e10cSrcweir #define MAXENTRY 1000 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir // Anzahl Eintraege, die bei der Kompression frei bleiben duerfen 61*cdf0e10cSrcweir // dieser Wert ist fuer den Worst Case, da wir MAXBLOCK mit ca 25% 62*cdf0e10cSrcweir // Overhead definiert haben, reichen 80% = 800 Eintraege vollkommen aus 63*cdf0e10cSrcweir // Will mann voellige Kompression haben, muss eben 100 angegeben werden. 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir #define COMPRESSLVL 80 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir struct BlockInfo { // Block-Info: 68*cdf0e10cSrcweir BigPtrArray* pBigArr; // in diesem Array steht der Block 69*cdf0e10cSrcweir ElementPtr* pData; // Datenblock 70*cdf0e10cSrcweir sal_uLong nStart, nEnd; // Start- und EndIndex 71*cdf0e10cSrcweir sal_uInt16 nElem; // Anzahl Elemente 72*cdf0e10cSrcweir }; 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir class SW_DLLPUBLIC BigPtrArray 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir BlockInfo** ppInf; // Block-Infos 77*cdf0e10cSrcweir sal_uLong nSize; // Anzahl Elemente 78*cdf0e10cSrcweir sal_uInt16 nMaxBlock; // akt. max Anzahl Bloecke 79*cdf0e10cSrcweir sal_uInt16 nBlock; // Anzahl Bloecke 80*cdf0e10cSrcweir sal_uInt16 nCur; // letzter Block 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir sal_uInt16 Index2Block( sal_uLong ) const; // Blocksuche 83*cdf0e10cSrcweir BlockInfo* InsBlock( sal_uInt16 ); // Block einfuegen 84*cdf0e10cSrcweir void BlockDel( sal_uInt16 ); // es wurden Bloecke geloescht 85*cdf0e10cSrcweir void UpdIndex( sal_uInt16 ); // Indexe neu berechnen 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir protected: 88*cdf0e10cSrcweir // fuelle alle Bloecke auf. 89*cdf0e10cSrcweir // Der short gibt in Prozent an, wie voll die Bloecke werden sollen. 90*cdf0e10cSrcweir // Der ReturnWert besagt, das irgendetwas "getan" wurde 91*cdf0e10cSrcweir sal_uInt16 Compress( short = COMPRESSLVL ); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir public: 94*cdf0e10cSrcweir BigPtrArray(); 95*cdf0e10cSrcweir ~BigPtrArray(); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir sal_uLong Count() const { return nSize; } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir void Insert( const ElementPtr& r, sal_uLong pos ); 100*cdf0e10cSrcweir void Remove( sal_uLong pos, sal_uLong n = 1 ); 101*cdf0e10cSrcweir void Move( sal_uLong from, sal_uLong to ); 102*cdf0e10cSrcweir void Replace( sal_uLong pos, const ElementPtr& r); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir ElementPtr operator[]( sal_uLong ) const; 105*cdf0e10cSrcweir void ForEach( FnForEach fn, void* pArgs = NULL ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir ForEach( 0, nSize, fn, pArgs ); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir void ForEach( sal_uLong nStart, sal_uLong nEnd, FnForEach fn, void* pArgs = NULL ); 110*cdf0e10cSrcweir }; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir inline sal_uLong BigPtrEntry::GetPos() const 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir DBG_ASSERT( this == pBlock->pData[ nOffset ], "Element nicht im Block" ); 117*cdf0e10cSrcweir return pBlock->nStart + nOffset; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir inline BigPtrArray& BigPtrEntry::GetArray() const 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir return *pBlock->pBigArr; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir #endif 127