2010-10-14 08:30:41 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2011-03-31 10:05:04 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2013-11-05 02:17:53 +01:00
|
|
|
#ifndef INCLUDED_SW_INC_BPARR_HXX
|
|
|
|
#define INCLUDED_SW_INC_BPARR_HXX
|
2012-03-21 10:21:03 +01:00
|
|
|
|
|
|
|
#include <assert.h>
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
#include <tools/solar.h>
|
2009-01-05 14:06:42 +00:00
|
|
|
#include <swdllapi.h>
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
struct BlockInfo;
|
|
|
|
class BigPtrArray;
|
|
|
|
|
|
|
|
class BigPtrEntry
|
|
|
|
{
|
|
|
|
friend class BigPtrArray;
|
2016-12-05 09:14:32 +01:00
|
|
|
BlockInfo* m_pBlock;
|
|
|
|
sal_uInt16 m_nOffset;
|
2006-08-14 14:17:05 +00:00
|
|
|
public:
|
2016-12-05 09:14:32 +01:00
|
|
|
BigPtrEntry() : m_pBlock(nullptr), m_nOffset(0) {}
|
2014-08-07 10:09:07 +02:00
|
|
|
virtual ~BigPtrEntry() {}
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_uLong GetPos() const;
|
2000-09-18 16:15:01 +00:00
|
|
|
inline BigPtrArray& GetArray() const;
|
|
|
|
};
|
|
|
|
typedef BigPtrEntry* ElementPtr;
|
|
|
|
|
2010-11-15 11:59:57 +00:00
|
|
|
// 1000 entries per Block = a bit less then 4K
|
2000-09-18 16:15:01 +00:00
|
|
|
#define MAXENTRY 1000
|
|
|
|
|
2010-11-15 23:37:49 +01:00
|
|
|
// number of entries that may remain free during compression
|
|
|
|
// this value is for the worst case; because we defined MAXBLOCK with ca 25%
|
|
|
|
// overhead, 80% = 800 entries are enough
|
|
|
|
// if complete compression is desired, 100 has to be specified
|
2000-09-18 16:15:01 +00:00
|
|
|
#define COMPRESSLVL 80
|
|
|
|
|
2010-11-15 23:37:49 +01:00
|
|
|
struct BlockInfo { // block info:
|
2012-07-22 11:29:48 +03:00
|
|
|
BigPtrArray* pBigArr; ///< in this array the block is located
|
|
|
|
ElementPtr* pData; ///< data block
|
|
|
|
sal_uLong nStart, nEnd; ///< start- and end index
|
|
|
|
sal_uInt16 nElem; ///< number of elements
|
2000-09-18 16:15:01 +00:00
|
|
|
};
|
|
|
|
|
2009-01-05 14:06:42 +00:00
|
|
|
class SW_DLLPUBLIC BigPtrArray
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2014-08-05 16:30:14 +02:00
|
|
|
protected:
|
2016-11-28 11:07:02 +01:00
|
|
|
BlockInfo** m_ppInf; // block info
|
|
|
|
sal_uLong m_nSize; ///< number of elements
|
|
|
|
sal_uInt16 m_nMaxBlock; ///< current max. number of blocks
|
|
|
|
sal_uInt16 m_nBlock; ///< number of blocks
|
2012-11-02 10:20:36 +01:00
|
|
|
mutable
|
2016-11-28 11:07:02 +01:00
|
|
|
sal_uInt16 m_nCur; ///< last used block
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2012-11-02 10:20:36 +01:00
|
|
|
sal_uInt16 Index2Block( sal_uLong ) const; ///< block search
|
2012-07-22 11:29:48 +03:00
|
|
|
BlockInfo* InsBlock( sal_uInt16 ); ///< insert block
|
|
|
|
void BlockDel( sal_uInt16 ); ///< some blocks were deleted
|
|
|
|
void UpdIndex( sal_uInt16 ); ///< recalculate indices
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2010-11-15 23:37:49 +01:00
|
|
|
// fill all blocks
|
2016-02-29 10:59:14 +02:00
|
|
|
sal_uInt16 Compress();
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
BigPtrArray();
|
|
|
|
~BigPtrArray();
|
|
|
|
|
2016-11-28 11:07:02 +01:00
|
|
|
sal_uLong Count() const { return m_nSize; }
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
void Insert( const ElementPtr& r, sal_uLong pos );
|
|
|
|
void Remove( sal_uLong pos, sal_uLong n = 1 );
|
|
|
|
void Move( sal_uLong from, sal_uLong to );
|
|
|
|
void Replace( sal_uLong pos, const ElementPtr& r);
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
ElementPtr operator[]( sal_uLong ) const;
|
2000-09-18 16:15:01 +00:00
|
|
|
};
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
inline sal_uLong BigPtrEntry::GetPos() const
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2016-12-05 09:14:32 +01:00
|
|
|
assert(this == m_pBlock->pData[ m_nOffset ]); // element not in the block
|
|
|
|
return m_pBlock->nStart + m_nOffset;
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline BigPtrArray& BigPtrEntry::GetArray() const
|
|
|
|
{
|
2016-12-05 09:14:32 +01:00
|
|
|
return *m_pBlock->pBigArr;
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2010-10-14 08:30:41 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|