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