lok: Hide file linking in section
[LibreOffice.git] / sw / inc / bparr.hxx
blob2c990259d11ac873a980c8b6d43ca15f2e296b1d
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 INCLUDED_SW_INC_BPARR_HXX
21 #define INCLUDED_SW_INC_BPARR_HXX
23 #include <assert.h>
25 #include <tools/solar.h>
26 #include "swdllapi.h"
27 #include <array>
28 #include <memory>
30 struct BlockInfo;
31 class BigPtrArray;
33 class BigPtrEntry
35 friend class BigPtrArray;
36 BlockInfo* m_pBlock;
37 sal_uInt16 m_nOffset;
38 public:
39 BigPtrEntry() : m_pBlock(nullptr), m_nOffset(0) {}
40 virtual ~BigPtrEntry() {}
42 inline sal_uLong GetPos() const;
43 inline BigPtrArray& GetArray() const;
46 // 1000 entries per Block = a bit less than 4K
47 #define MAXENTRY 1000
49 // number of entries that may remain free during compression
50 // this value is for the worst case; because we defined MAXBLOCK with ca 25%
51 // overhead, 80% = 800 entries are enough
52 // if complete compression is desired, 100 has to be specified
53 #define COMPRESSLVL 80
55 struct BlockInfo final
57 BigPtrArray* pBigArr; ///< in this array the block is located
58 std::array<BigPtrEntry*, MAXENTRY>
59 mvData; ///< data block
60 sal_uLong nStart, nEnd; ///< start- and end index
61 sal_uInt16 nElem; ///< number of elements
64 class SW_DLLPUBLIC BigPtrArray
66 protected:
67 std::unique_ptr<BlockInfo*[]>
68 m_ppInf; ///< block info
69 sal_uLong m_nSize; ///< number of elements
70 sal_uInt16 m_nMaxBlock; ///< current max. number of blocks
71 sal_uInt16 m_nBlock; ///< number of blocks
72 mutable
73 sal_uInt16 m_nCur; ///< last used block
75 sal_uInt16 Index2Block( sal_uLong ) const; ///< block search
76 BlockInfo* InsBlock( sal_uInt16 ); ///< insert block
77 void BlockDel( sal_uInt16 ); ///< some blocks were deleted
78 void UpdIndex( sal_uInt16 ); ///< recalculate indices
80 // fill all blocks
81 sal_uInt16 Compress();
83 public:
84 BigPtrArray();
85 ~BigPtrArray();
87 sal_uLong Count() const { return m_nSize; }
89 void Insert( BigPtrEntry* p, sal_uLong pos );
90 void Remove( sal_uLong pos, sal_uLong n = 1 );
91 void Move( sal_uLong from, sal_uLong to );
92 void Replace( sal_uLong pos, BigPtrEntry* p);
94 BigPtrEntry* operator[]( sal_uLong ) const;
97 inline sal_uLong BigPtrEntry::GetPos() const
99 assert(this == m_pBlock->mvData[ m_nOffset ]); // element not in the block
100 return m_pBlock->nStart + m_nOffset;
103 inline BigPtrArray& BigPtrEntry::GetArray() const
105 return *m_pBlock->pBigArr;
108 #endif
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */