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