Update ooo320-m1
[ooovba.git] / sw / inc / bparr.hxx
blob0fbdaef7694d71db562b11ce74f994d2ecaaf949
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bparr.hxx,v $
10 * $Revision: 1.5 $
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 _BPARR_HXX
32 #define _BPARR_HXX
34 #include <tools/solar.h>
35 #include <tools/debug.hxx>
36 #include <swdllapi.h>
38 struct BlockInfo;
39 class BigPtrArray;
41 class BigPtrEntry
43 friend class BigPtrArray;
44 BlockInfo* pBlock;
45 USHORT nOffset;
46 public:
47 virtual ~BigPtrEntry() {}
48 protected:
49 BigPtrEntry() : pBlock(0), nOffset(0) {}
51 inline ULONG GetPos() const;
52 inline BigPtrArray& GetArray() const;
54 typedef BigPtrEntry* ElementPtr;
57 typedef BOOL (*FnForEach)( const ElementPtr&, void* pArgs );
59 // 1000 Eintr„ge pro Block = etwas weniger als 4K
60 #define MAXENTRY 1000
63 // Anzahl Eintraege, die bei der Kompression frei bleiben duerfen
64 // dieser Wert ist fuer den Worst Case, da wir MAXBLOCK mit ca 25%
65 // Overhead definiert haben, reichen 80% = 800 Eintraege vollkommen aus
66 // Will mann voellige Kompression haben, muss eben 100 angegeben werden.
68 #define COMPRESSLVL 80
70 struct BlockInfo { // Block-Info:
71 BigPtrArray* pBigArr; // in diesem Array steht der Block
72 ElementPtr* pData; // Datenblock
73 ULONG nStart, nEnd; // Start- und EndIndex
74 USHORT nElem; // Anzahl Elemente
77 class SW_DLLPUBLIC BigPtrArray
79 BlockInfo** ppInf; // Block-Infos
80 ULONG nSize; // Anzahl Elemente
81 USHORT nMaxBlock; // akt. max Anzahl Bloecke
82 USHORT nBlock; // Anzahl Bloecke
83 USHORT nCur; // letzter Block
85 USHORT Index2Block( ULONG ) const; // Blocksuche
86 BlockInfo* InsBlock( USHORT ); // Block einfuegen
87 void BlockDel( USHORT ); // es wurden Bloecke geloescht
88 void UpdIndex( USHORT ); // Indexe neu berechnen
90 protected:
91 // fuelle alle Bloecke auf.
92 // Der short gibt in Prozent an, wie voll die Bloecke werden sollen.
93 // Der ReturnWert besagt, das irgendetwas "getan" wurde
94 USHORT Compress( short = COMPRESSLVL );
96 public:
97 BigPtrArray();
98 ~BigPtrArray();
100 ULONG Count() const { return nSize; }
102 void Insert( const ElementPtr& r, ULONG pos );
103 void Remove( ULONG pos, ULONG n = 1 );
104 void Move( ULONG from, ULONG to );
105 void Replace( ULONG pos, const ElementPtr& r);
107 ElementPtr operator[]( ULONG ) const;
108 void ForEach( FnForEach fn, void* pArgs = NULL )
110 ForEach( 0, nSize, fn, pArgs );
112 void ForEach( ULONG nStart, ULONG nEnd, FnForEach fn, void* pArgs = NULL );
117 inline ULONG BigPtrEntry::GetPos() const
119 DBG_ASSERT( this == pBlock->pData[ nOffset ], "Element nicht im Block" );
120 return pBlock->nStart + nOffset;
123 inline BigPtrArray& BigPtrEntry::GetArray() const
125 return *pBlock->pBigArr;
129 #endif