LCOV - code coverage report
Current view: top level - libreoffice/sw/inc - bparr.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 10 10 100.0 %
Date: 2012-12-27 Functions: 6 7 85.7 %
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 SW_BPARR_HXX
      21             : #define SW_BPARR_HXX
      22             : 
      23             : #include <assert.h>
      24             : 
      25             : #include <tools/solar.h>
      26             : #include <osl/diagnose.h>
      27             : #include <swdllapi.h>
      28             : 
      29             : struct BlockInfo;
      30             : class BigPtrArray;
      31             : 
      32             : class BigPtrEntry
      33             : {
      34             :     friend class BigPtrArray;
      35             :     BlockInfo* pBlock;
      36             :     sal_uInt16 nOffset;
      37             : public:
      38        8831 :     virtual ~BigPtrEntry() {}
      39             : protected:
      40       14449 :     BigPtrEntry() : pBlock(0), nOffset(0) {}
      41             : 
      42             :     inline sal_uLong GetPos() const;
      43             :     inline BigPtrArray& GetArray() const;
      44             : };
      45             : typedef BigPtrEntry* ElementPtr;
      46             : 
      47             : 
      48             : typedef bool (*FnForEach)( const ElementPtr&, void* pArgs );
      49             : 
      50             : // 1000 entries per Block = a bit less then 4K
      51             : #define MAXENTRY 1000
      52             : 
      53             : 
      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
      59             : 
      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
      65             : };
      66             : 
      67             : class SW_DLLPUBLIC BigPtrArray
      68             : {
      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
      75             : 
      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
      80             : 
      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 );
      86             : 
      87             : public:
      88             :     BigPtrArray();
      89             :     ~BigPtrArray();
      90             : 
      91       23551 :     sal_uLong Count() const { return nSize; }
      92             : 
      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);
      97             : 
      98             :     ElementPtr operator[]( sal_uLong ) const;
      99           1 :     void ForEach( FnForEach fn, void* pArgs = NULL )
     100             :     {
     101           1 :         ForEach( 0, nSize, fn, pArgs );
     102           1 :     }
     103             :     void ForEach( sal_uLong nStart, sal_uLong nEnd, FnForEach fn, void* pArgs = NULL );
     104             : };
     105             : 
     106             : 
     107             : 
     108     2143010 : inline sal_uLong BigPtrEntry::GetPos() const
     109             : {
     110             :     assert(this == pBlock->pData[ nOffset ]); // element not in the block
     111     2143010 :     return pBlock->nStart + nOffset;
     112             : }
     113             : 
     114     1941956 : inline BigPtrArray& BigPtrEntry::GetArray() const
     115             : {
     116     1941956 :     return *pBlock->pBigArr;
     117             : }
     118             : 
     119             : 
     120             : #endif
     121             : 
     122             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10