LCOV - code coverage report
Current view: top level - sw/inc - bparr.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 8 0.0 %
Date: 2014-04-14 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <tools/solar.h>
      26             : #include <swdllapi.h>
      27             : 
      28             : struct BlockInfo;
      29             : class BigPtrArray;
      30             : 
      31           0 : class BigPtrEntry
      32             : {
      33             :     friend class BigPtrArray;
      34             :     BlockInfo* pBlock;
      35             :     sal_uInt16 nOffset;
      36             : public:
      37           0 :     virtual ~BigPtrEntry() {}
      38             : protected:
      39           0 :     BigPtrEntry() : pBlock(0), nOffset(0) {}
      40             : 
      41             :     inline sal_uLong GetPos() const;
      42             :     inline BigPtrArray& GetArray() const;
      43             : };
      44             : typedef BigPtrEntry* ElementPtr;
      45             : 
      46             : typedef bool (*FnForEach)( const ElementPtr&, void* pArgs );
      47             : 
      48             : // 1000 entries per Block = a bit less then 4K
      49             : #define MAXENTRY 1000
      50             : 
      51             : // number of entries that may remain free during compression
      52             : // this value is for the worst case; because we defined MAXBLOCK with ca 25%
      53             : // overhead, 80% = 800 entries are enough
      54             : // if complete compression is desired, 100 has to be specified
      55             : #define COMPRESSLVL 80
      56             : 
      57             : struct BlockInfo {                  // block info:
      58             :     BigPtrArray* pBigArr;           ///< in this array the block is located
      59             :     ElementPtr* pData;              ///< data block
      60             :     sal_uLong nStart, nEnd;         ///< start- and end index
      61             :     sal_uInt16 nElem;               ///< number of elements
      62             : };
      63             : 
      64             : class SW_DLLPUBLIC BigPtrArray
      65             : {
      66             :     BlockInfo**     ppInf;              // block info
      67             :     sal_uLong       nSize;              ///< number of elements
      68             :     sal_uInt16      nMaxBlock;          ///< current max. number of blocks
      69             :     sal_uInt16      nBlock;             ///< number of blocks
      70             :     mutable
      71             :         sal_uInt16  nCur;               ///< last used block
      72             : 
      73             :     sal_uInt16  Index2Block( sal_uLong ) const; ///< block search
      74             :     BlockInfo*  InsBlock( sal_uInt16 );         ///< insert block
      75             :     void        BlockDel( sal_uInt16 );         ///< some blocks were deleted
      76             :     void        UpdIndex( sal_uInt16 );         ///< recalculate indices
      77             : 
      78             : protected:
      79             :     // fill all blocks
      80             :     // the short parameter specifies in percent, how full the blocks should be
      81             :     // made
      82             :     sal_uInt16 Compress( short = COMPRESSLVL );
      83             : 
      84             : public:
      85             :     BigPtrArray();
      86             :     ~BigPtrArray();
      87             : 
      88           0 :     sal_uLong Count() const { return nSize; }
      89             : 
      90             :     void Insert( const ElementPtr& r, sal_uLong pos );
      91             :     void Remove( sal_uLong pos, sal_uLong n = 1 );
      92             :     void Move( sal_uLong from, sal_uLong to );
      93             :     void Replace( sal_uLong pos, const ElementPtr& r);
      94             : 
      95             :     ElementPtr operator[]( sal_uLong ) const;
      96             :     void ForEach( FnForEach fn, void* pArgs = NULL )
      97             :     {
      98             :         ForEach( 0, nSize, fn, pArgs );
      99             :     }
     100             :     void ForEach( sal_uLong nStart, sal_uLong nEnd, FnForEach fn, void* pArgs = NULL );
     101             : };
     102             : 
     103           0 : inline sal_uLong BigPtrEntry::GetPos() const
     104             : {
     105             :     assert(this == pBlock->pData[ nOffset ]); // element not in the block
     106           0 :     return pBlock->nStart + nOffset;
     107             : }
     108             : 
     109           0 : inline BigPtrArray& BigPtrEntry::GetArray() const
     110             : {
     111           0 :     return *pBlock->pBigArr;
     112             : }
     113             : 
     114             : #endif
     115             : 
     116             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10