bump product version to 4.1.6.2
[LibreOffice.git] / sw / inc / bparr.hxx
blob6cac07cf3d4f54d48bfdf0640e1f80091a28f601
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef SW_BPARR_HXX
21 #define SW_BPARR_HXX
23 #include <assert.h>
25 #include <tools/solar.h>
26 #include <osl/diagnose.h>
27 #include <swdllapi.h>
29 struct BlockInfo;
30 class BigPtrArray;
32 class BigPtrEntry
34 friend class BigPtrArray;
35 BlockInfo* pBlock;
36 sal_uInt16 nOffset;
37 public:
38 virtual ~BigPtrEntry() {}
39 protected:
40 BigPtrEntry() : pBlock(0), nOffset(0) {}
42 inline sal_uLong GetPos() const;
43 inline BigPtrArray& GetArray() const;
45 typedef BigPtrEntry* ElementPtr;
48 typedef bool (*FnForEach)( const ElementPtr&, void* pArgs );
50 // 1000 entries per Block = a bit less then 4K
51 #define MAXENTRY 1000
54 // number of entries that may remain free during compression
55 // this value is for the worst case; because we defined MAXBLOCK with ca 25%
56 // overhead, 80% = 800 entries are enough
57 // if complete compression is desired, 100 has to be specified
58 #define COMPRESSLVL 80
60 struct BlockInfo { // block info:
61 BigPtrArray* pBigArr; ///< in this array the block is located
62 ElementPtr* pData; ///< data block
63 sal_uLong nStart, nEnd; ///< start- and end index
64 sal_uInt16 nElem; ///< number of elements
67 class SW_DLLPUBLIC BigPtrArray
69 BlockInfo** ppInf; // block info
70 sal_uLong nSize; ///< number of elements
71 sal_uInt16 nMaxBlock; ///< current max. number of blocks
72 sal_uInt16 nBlock; ///< number of blocks
73 mutable
74 sal_uInt16 nCur; ///< last used block
76 sal_uInt16 Index2Block( sal_uLong ) const; ///< block search
77 BlockInfo* InsBlock( sal_uInt16 ); ///< insert block
78 void BlockDel( sal_uInt16 ); ///< some blocks were deleted
79 void UpdIndex( sal_uInt16 ); ///< recalculate indices
81 protected:
82 // fill all blocks
83 // the short parameter specifies in percent, how full the blocks should be
84 // made
85 sal_uInt16 Compress( short = COMPRESSLVL );
87 public:
88 BigPtrArray();
89 ~BigPtrArray();
91 sal_uLong Count() const { return nSize; }
93 void Insert( const ElementPtr& r, sal_uLong pos );
94 void Remove( sal_uLong pos, sal_uLong n = 1 );
95 void Move( sal_uLong from, sal_uLong to );
96 void Replace( sal_uLong pos, const ElementPtr& r);
98 ElementPtr operator[]( sal_uLong ) const;
99 void ForEach( FnForEach fn, void* pArgs = NULL )
101 ForEach( 0, nSize, fn, pArgs );
103 void ForEach( sal_uLong nStart, sal_uLong nEnd, FnForEach fn, void* pArgs = NULL );
108 inline sal_uLong BigPtrEntry::GetPos() const
110 assert(this == pBlock->pData[ nOffset ]); // element not in the block
111 return pBlock->nStart + nOffset;
114 inline BigPtrArray& BigPtrEntry::GetArray() const
116 return *pBlock->pBigArr;
120 #endif
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */