Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SW_BPARR_HXX
30 : : #define SW_BPARR_HXX
31 : :
32 : : #include <assert.h>
33 : :
34 : : #include <tools/solar.h>
35 : : #include <osl/diagnose.h>
36 : : #include <swdllapi.h>
37 : :
38 : : struct BlockInfo;
39 : : class BigPtrArray;
40 : :
41 : : class BigPtrEntry
42 : : {
43 : : friend class BigPtrArray;
44 : : BlockInfo* pBlock;
45 : : sal_uInt16 nOffset;
46 : : public:
47 [ - + ]: 57532 : virtual ~BigPtrEntry() {}
48 : : protected:
49 : 59953 : BigPtrEntry() : pBlock(0), nOffset(0) {}
50 : :
51 : : inline sal_uLong GetPos() const;
52 : : inline BigPtrArray& GetArray() const;
53 : : };
54 : : typedef BigPtrEntry* ElementPtr;
55 : :
56 : :
57 : : typedef sal_Bool (*FnForEach)( const ElementPtr&, void* pArgs );
58 : :
59 : : // 1000 entries per Block = a bit less then 4K
60 : : #define MAXENTRY 1000
61 : :
62 : :
63 : : // number of entries that may remain free during compression
64 : : // this value is for the worst case; because we defined MAXBLOCK with ca 25%
65 : : // overhead, 80% = 800 entries are enough
66 : : // if complete compression is desired, 100 has to be specified
67 : : #define COMPRESSLVL 80
68 : :
69 : : struct BlockInfo { // block info:
70 : : BigPtrArray* pBigArr; ///< in this array the block is located
71 : : ElementPtr* pData; ///< data block
72 : : sal_uLong nStart, nEnd; ///< start- and end index
73 : : sal_uInt16 nElem; ///< number of elements
74 : : };
75 : :
76 : : class SW_DLLPUBLIC BigPtrArray
77 : : {
78 : : BlockInfo** ppInf; // block info
79 : : sal_uLong nSize; ///< number of elements
80 : : sal_uInt16 nMaxBlock; ///< current max. number of blocks
81 : : sal_uInt16 nBlock; ///< number of blocks
82 : : sal_uInt16 nCur; ///< last block
83 : :
84 : : sal_uInt16 Index2Block( sal_uLong ) const; ///< block search
85 : : BlockInfo* InsBlock( sal_uInt16 ); ///< insert block
86 : : void BlockDel( sal_uInt16 ); ///< some blocks were deleted
87 : : void UpdIndex( sal_uInt16 ); ///< recalculate indices
88 : :
89 : : protected:
90 : : // fill all blocks
91 : : // the short parameter specifies in percent, how full the blocks should be
92 : : // made
93 : : sal_uInt16 Compress( short = COMPRESSLVL );
94 : :
95 : : public:
96 : : BigPtrArray();
97 : : ~BigPtrArray();
98 : :
99 : 200774 : sal_uLong Count() const { return nSize; }
100 : :
101 : : void Insert( const ElementPtr& r, sal_uLong pos );
102 : : void Remove( sal_uLong pos, sal_uLong n = 1 );
103 : : void Move( sal_uLong from, sal_uLong to );
104 : : void Replace( sal_uLong pos, const ElementPtr& r);
105 : :
106 : : ElementPtr operator[]( sal_uLong ) const;
107 : 5 : void ForEach( FnForEach fn, void* pArgs = NULL )
108 : : {
109 : 5 : ForEach( 0, nSize, fn, pArgs );
110 : 5 : }
111 : : void ForEach( sal_uLong nStart, sal_uLong nEnd, FnForEach fn, void* pArgs = NULL );
112 : : };
113 : :
114 : :
115 : :
116 : 21728188 : inline sal_uLong BigPtrEntry::GetPos() const
117 : : {
118 : : assert(this == pBlock->pData[ nOffset ]); // element not in the block
119 : 21728188 : return pBlock->nStart + nOffset;
120 : : }
121 : :
122 : 9309732 : inline BigPtrArray& BigPtrEntry::GetArray() const
123 : : {
124 : 9309732 : return *pBlock->pBigArr;
125 : : }
126 : :
127 : :
128 : : #endif
129 : :
130 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|