1*1d2dbeb0SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*1d2dbeb0SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*1d2dbeb0SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*1d2dbeb0SAndrew Rist * distributed with this work for additional information 6*1d2dbeb0SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*1d2dbeb0SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*1d2dbeb0SAndrew Rist * "License"); you may not use this file except in compliance 9*1d2dbeb0SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*1d2dbeb0SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*1d2dbeb0SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*1d2dbeb0SAndrew Rist * software distributed under the License is distributed on an 15*1d2dbeb0SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*1d2dbeb0SAndrew Rist * KIND, either express or implied. See the License for the 17*1d2dbeb0SAndrew Rist * specific language governing permissions and limitations 18*1d2dbeb0SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*1d2dbeb0SAndrew Rist *************************************************************/ 21*1d2dbeb0SAndrew Rist 22*1d2dbeb0SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _BPARR_HXX 25cdf0e10cSrcweir #define _BPARR_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <tools/solar.h> 28cdf0e10cSrcweir #include <tools/debug.hxx> 29cdf0e10cSrcweir #include <swdllapi.h> 30cdf0e10cSrcweir 31cdf0e10cSrcweir struct BlockInfo; 32cdf0e10cSrcweir class BigPtrArray; 33cdf0e10cSrcweir 34cdf0e10cSrcweir class BigPtrEntry 35cdf0e10cSrcweir { 36cdf0e10cSrcweir friend class BigPtrArray; 37cdf0e10cSrcweir BlockInfo* pBlock; 38cdf0e10cSrcweir sal_uInt16 nOffset; 39cdf0e10cSrcweir public: 40cdf0e10cSrcweir virtual ~BigPtrEntry() {} 41cdf0e10cSrcweir protected: 42cdf0e10cSrcweir BigPtrEntry() : pBlock(0), nOffset(0) {} 43cdf0e10cSrcweir 44cdf0e10cSrcweir inline sal_uLong GetPos() const; 45cdf0e10cSrcweir inline BigPtrArray& GetArray() const; 46cdf0e10cSrcweir }; 47cdf0e10cSrcweir typedef BigPtrEntry* ElementPtr; 48cdf0e10cSrcweir 49cdf0e10cSrcweir 50cdf0e10cSrcweir typedef sal_Bool (*FnForEach)( const ElementPtr&, void* pArgs ); 51cdf0e10cSrcweir 52cdf0e10cSrcweir // 1000 Eintr�ge pro Block = etwas weniger als 4K 53cdf0e10cSrcweir #define MAXENTRY 1000 54cdf0e10cSrcweir 55cdf0e10cSrcweir 56cdf0e10cSrcweir // Anzahl Eintraege, die bei der Kompression frei bleiben duerfen 57cdf0e10cSrcweir // dieser Wert ist fuer den Worst Case, da wir MAXBLOCK mit ca 25% 58cdf0e10cSrcweir // Overhead definiert haben, reichen 80% = 800 Eintraege vollkommen aus 59cdf0e10cSrcweir // Will mann voellige Kompression haben, muss eben 100 angegeben werden. 60cdf0e10cSrcweir 61cdf0e10cSrcweir #define COMPRESSLVL 80 62cdf0e10cSrcweir 63cdf0e10cSrcweir struct BlockInfo { // Block-Info: 64cdf0e10cSrcweir BigPtrArray* pBigArr; // in diesem Array steht der Block 65cdf0e10cSrcweir ElementPtr* pData; // Datenblock 66cdf0e10cSrcweir sal_uLong nStart, nEnd; // Start- und EndIndex 67cdf0e10cSrcweir sal_uInt16 nElem; // Anzahl Elemente 68cdf0e10cSrcweir }; 69cdf0e10cSrcweir 70cdf0e10cSrcweir class SW_DLLPUBLIC BigPtrArray 71cdf0e10cSrcweir { 72cdf0e10cSrcweir BlockInfo** ppInf; // Block-Infos 73cdf0e10cSrcweir sal_uLong nSize; // Anzahl Elemente 74cdf0e10cSrcweir sal_uInt16 nMaxBlock; // akt. max Anzahl Bloecke 75cdf0e10cSrcweir sal_uInt16 nBlock; // Anzahl Bloecke 76cdf0e10cSrcweir sal_uInt16 nCur; // letzter Block 77cdf0e10cSrcweir 78cdf0e10cSrcweir sal_uInt16 Index2Block( sal_uLong ) const; // Blocksuche 79cdf0e10cSrcweir BlockInfo* InsBlock( sal_uInt16 ); // Block einfuegen 80cdf0e10cSrcweir void BlockDel( sal_uInt16 ); // es wurden Bloecke geloescht 81cdf0e10cSrcweir void UpdIndex( sal_uInt16 ); // Indexe neu berechnen 82cdf0e10cSrcweir 83cdf0e10cSrcweir protected: 84cdf0e10cSrcweir // fuelle alle Bloecke auf. 85cdf0e10cSrcweir // Der short gibt in Prozent an, wie voll die Bloecke werden sollen. 86cdf0e10cSrcweir // Der ReturnWert besagt, das irgendetwas "getan" wurde 87cdf0e10cSrcweir sal_uInt16 Compress( short = COMPRESSLVL ); 88cdf0e10cSrcweir 89cdf0e10cSrcweir public: 90cdf0e10cSrcweir BigPtrArray(); 91cdf0e10cSrcweir ~BigPtrArray(); 92cdf0e10cSrcweir 93cdf0e10cSrcweir sal_uLong Count() const { return nSize; } 94cdf0e10cSrcweir 95cdf0e10cSrcweir void Insert( const ElementPtr& r, sal_uLong pos ); 96cdf0e10cSrcweir void Remove( sal_uLong pos, sal_uLong n = 1 ); 97cdf0e10cSrcweir void Move( sal_uLong from, sal_uLong to ); 98cdf0e10cSrcweir void Replace( sal_uLong pos, const ElementPtr& r); 99cdf0e10cSrcweir 100cdf0e10cSrcweir ElementPtr operator[]( sal_uLong ) const; 101cdf0e10cSrcweir void ForEach( FnForEach fn, void* pArgs = NULL ) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir ForEach( 0, nSize, fn, pArgs ); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir void ForEach( sal_uLong nStart, sal_uLong nEnd, FnForEach fn, void* pArgs = NULL ); 106cdf0e10cSrcweir }; 107cdf0e10cSrcweir 108cdf0e10cSrcweir 109cdf0e10cSrcweir 110cdf0e10cSrcweir inline sal_uLong BigPtrEntry::GetPos() const 111cdf0e10cSrcweir { 112cdf0e10cSrcweir DBG_ASSERT( this == pBlock->pData[ nOffset ], "Element nicht im Block" ); 113cdf0e10cSrcweir return pBlock->nStart + nOffset; 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir inline BigPtrArray& BigPtrEntry::GetArray() const 117cdf0e10cSrcweir { 118cdf0e10cSrcweir return *pBlock->pBigArr; 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir 122cdf0e10cSrcweir #endif 123