LibreOffice Module sw (master) 1
bparr.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_SW_INC_BPARR_HXX
21#define INCLUDED_SW_INC_BPARR_HXX
22
23#include <assert.h>
24
25#include "swdllapi.h"
26#include <array>
27#include <memory>
28
29struct BlockInfo;
30class BigPtrArray;
31
33{
34 friend class BigPtrArray;
36 sal_uInt16 m_nOffset;
37public:
38 BigPtrEntry() : m_pBlock(nullptr), m_nOffset(0) {}
39 BigPtrEntry(BigPtrEntry const &) = default;
40 virtual ~BigPtrEntry() = default;
41 BigPtrEntry & operator =(BigPtrEntry const &) = default;
42
43 inline sal_Int32 GetPos() const;
44 inline BigPtrArray& GetArray() const;
45};
46
47// 1000 entries per Block = a bit less than 4K
48#define MAXENTRY 1000
49
50// number of entries that may remain free during compression
51// this value is for the worst case; because we defined MAXBLOCK with ca 25%
52// overhead, 80% = 800 entries are enough
53// if complete compression is desired, 100 has to be specified
54#define COMPRESSLVL 80
55
56struct BlockInfo final
57{
59 sal_Int32 nStart, nEnd;
60 sal_uInt16 nElem;
61 std::array<BigPtrEntry*, MAXENTRY>
63};
64
66{
67protected:
68 std::unique_ptr<BlockInfo*[]>
70 sal_Int32 m_nSize;
71 sal_uInt16 m_nMaxBlock;
72 sal_uInt16 m_nBlock;
73 mutable
74 sal_uInt16 m_nCur;
75
76 sal_uInt16 Index2Block( sal_Int32 ) const;
77 BlockInfo* InsBlock( sal_uInt16 );
78 void BlockDel( sal_uInt16 );
79 void UpdIndex( sal_uInt16 );
80
81 // fill all blocks
82 sal_uInt16 Compress();
83
84public:
87
88 sal_Int32 Count() const { return m_nSize; }
89
90 void Insert( BigPtrEntry* p, sal_Int32 pos );
91 void Remove( sal_Int32 pos, sal_Int32 n = 1 );
92 void Move( sal_Int32 from, sal_Int32 to );
93 void Replace( sal_Int32 pos, BigPtrEntry* p);
94
95 BigPtrEntry* operator[]( sal_Int32 ) const;
96};
97
98inline sal_Int32 BigPtrEntry::GetPos() const
99{
100 assert(this == m_pBlock->mvData[ m_nOffset ]); // element not in the block
101 return m_pBlock->nStart + m_nOffset;
102}
103
105{
106 return *m_pBlock->pBigArr;
107}
108
109#endif
110
111/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 m_nBlock
number of blocks
Definition: bparr.hxx:72
sal_Int32 Count() const
Definition: bparr.hxx:88
std::unique_ptr< BlockInfo *[]> m_ppInf
block info
Definition: bparr.hxx:69
sal_uInt16 m_nMaxBlock
current max. number of blocks
Definition: bparr.hxx:71
sal_Int32 m_nSize
number of elements
Definition: bparr.hxx:70
sal_uInt16 m_nCur
last used block
Definition: bparr.hxx:74
sal_uInt16 m_nOffset
Definition: bparr.hxx:36
sal_Int32 GetPos() const
Definition: bparr.hxx:98
BigPtrEntry(BigPtrEntry const &)=default
BigPtrEntry()
Definition: bparr.hxx:38
virtual ~BigPtrEntry()=default
BigPtrEntry & operator=(BigPtrEntry const &)=default
BigPtrArray & GetArray() const
Definition: bparr.hxx:104
BlockInfo * m_pBlock
Definition: bparr.hxx:35
virtual void Insert(SotClipboardFormatId nFormat, const OUString &rFormatName) override
sal_uInt32 m_nSize
sal_uInt16 nElem
number of elements
Definition: bparr.hxx:60
BigPtrArray * pBigArr
in this array the block is located
Definition: bparr.hxx:58
std::array< BigPtrEntry *, MAXENTRY > mvData
data block
Definition: bparr.hxx:62
sal_Int32 nEnd
start- and end index
Definition: bparr.hxx:59
sal_Int32 nStart
Definition: bparr.hxx:59
#define SW_DLLPUBLIC
Definition: swdllapi.h:28