LCOV - code coverage report
Current view: top level - sw/inc - index.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 44 47 93.6 %
Date: 2014-11-03 Functions: 24 26 92.3 %
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             : #ifndef INCLUDED_SW_INC_INDEX_HXX
      20             : #define INCLUDED_SW_INC_INDEX_HXX
      21             : 
      22             : #include <sal/types.h>
      23             : #include <tools/rtti.hxx>
      24             : #include <swdllapi.h>
      25             : 
      26             : class SwIndexReg;
      27             : struct SwPosition;
      28             : 
      29             : namespace sw {
      30             : namespace mark {
      31             : class IMark;
      32             : }
      33             : }
      34             : 
      35             : /// Marks a character position inside a document model node.
      36             : class SW_DLLPUBLIC SwIndex
      37             : {
      38             : private:
      39             :     friend class SwIndexReg;
      40             : 
      41             :     sal_Int32 m_nIndex;
      42             :     SwIndexReg * m_pIndexReg;
      43             :     // doubly linked list of Indexes registered at m_pIndexReg
      44             :     SwIndex * m_pNext;
      45             :     SwIndex * m_pPrev;
      46             : 
      47             :     /// Pointer to a mark that owns this position to allow fast lookup of marks of an SwIndexReg.
      48             :     const sw::mark::IMark* m_pMark;
      49             : 
      50             :     SwIndex& ChgValue( const SwIndex& rIdx, sal_Int32 nNewValue );
      51             :     void Init(sal_Int32 const nIdx);
      52             :     void Remove();
      53             : 
      54             : public:
      55             :     explicit SwIndex(SwIndexReg *const pReg, sal_Int32 const nIdx = 0);
      56             :     SwIndex( const SwIndex & );
      57             :     SwIndex( const SwIndex &, short nDiff );
      58     6739478 :     ~SwIndex() { Remove(); }
      59             : 
      60             :     SwIndex& operator=( sal_Int32 const );
      61             :     SwIndex& operator=( const SwIndex & );
      62             : 
      63             :     sal_Int32 operator++();
      64             :     sal_Int32 operator--();
      65             :     sal_Int32 operator++(int);
      66             :     sal_Int32 operator--(int);
      67             : 
      68             :     sal_Int32 operator+=( sal_Int32 const );
      69             :     sal_Int32 operator-=( sal_Int32 const );
      70             :     sal_Int32 operator+=( const SwIndex& );
      71             :     sal_Int32 operator-=( const SwIndex& );
      72             : 
      73             :     bool operator< ( const SwIndex& ) const;
      74             :     bool operator<=( const SwIndex& ) const;
      75             :     bool operator> ( const SwIndex& ) const;
      76             :     bool operator>=( const SwIndex& ) const;
      77             : 
      78         888 :     bool operator< ( sal_Int32 const nVal ) const { return m_nIndex <  nVal; }
      79           0 :     bool operator<=( sal_Int32 const nVal ) const { return m_nIndex <= nVal; }
      80        8980 :     bool operator> ( sal_Int32 const nVal ) const { return m_nIndex >  nVal; }
      81      373680 :     bool operator>=( sal_Int32 const nVal ) const { return m_nIndex >= nVal; }
      82      279272 :     bool operator==( sal_Int32 const nVal ) const { return m_nIndex == nVal; }
      83      119094 :     bool operator!=( sal_Int32 const nVal ) const { return m_nIndex != nVal; }
      84             : 
      85      243487 :     bool operator==( const SwIndex& rSwIndex ) const
      86             :     {
      87      243487 :         return (m_nIndex    == rSwIndex.m_nIndex)
      88      243487 :             && (m_pIndexReg == rSwIndex.m_pIndexReg);
      89             :     }
      90             : 
      91      639158 :     bool operator!=( const SwIndex& rSwIndex ) const
      92             :     {
      93      639158 :         return (m_nIndex    != rSwIndex.m_nIndex)
      94      639158 :             || (m_pIndexReg != rSwIndex.m_pIndexReg);
      95             :     }
      96             : 
      97     8519490 :     sal_Int32 GetIndex() const { return m_nIndex; }
      98             : 
      99             :     // Assignments without creating a temporary object.
     100             :     SwIndex &Assign(SwIndexReg *, sal_Int32);
     101             : 
     102             :     // Returns pointer to IndexArray (for RTTI at SwIndexReg).
     103    45245664 :     const SwIndexReg* GetIdxReg() const { return m_pIndexReg; }
     104       22642 :     const SwIndex* GetNext() const { return m_pNext; }
     105             : 
     106       22642 :     const sw::mark::IMark* GetMark() const { return m_pMark; }
     107             :     void SetMark(const sw::mark::IMark* pMark);
     108             : };
     109             : 
     110             : class SwIndexReg
     111             : {
     112             :     friend class SwIndex;
     113             :     friend bool sw_PosOk(const SwPosition & aPos);
     114             : 
     115             :     const SwIndex * m_pFirst;
     116             :     const SwIndex * m_pLast;
     117             : 
     118             : protected:
     119             :     virtual void Update( SwIndex const & rPos, const sal_Int32 nChangeLen,
     120             :                  const bool bNegative = false, const bool bDelete = false );
     121             : 
     122             :     void ChkArr();
     123             : 
     124        5692 :     bool HasAnyIndex() const { return 0 != m_pFirst; }
     125             : 
     126             : public:
     127             :     SwIndexReg();
     128             :     virtual ~SwIndexReg();
     129             : 
     130             :     /// rtti, derived classes might do the same. If so, one can cast typesavely
     131             :     /// via SwIndexReg.
     132             :     TYPEINFO();
     133             : 
     134             :     void MoveTo( SwIndexReg& rArr );
     135         372 :     const SwIndex* GetFirstIndex() const { return m_pFirst; }
     136             : };
     137             : 
     138             : #ifndef DBG_UTIL
     139             : 
     140         120 : inline sal_Int32 SwIndex::operator++()
     141             : {
     142         120 :     return ChgValue( *this, m_nIndex+1 ).m_nIndex;
     143             : }
     144             : 
     145             : inline sal_Int32 SwIndex::operator--()
     146             : {
     147             :     return ChgValue( *this, m_nIndex-1 ).m_nIndex;
     148             : }
     149             : 
     150         344 : inline sal_Int32 SwIndex::operator++(int)
     151             : {
     152         344 :     sal_Int32 const nOldIndex = m_nIndex;
     153         344 :     ChgValue( *this, m_nIndex+1 );
     154         344 :     return nOldIndex;
     155             : }
     156             : 
     157       24564 : inline sal_Int32 SwIndex::operator--(int)
     158             : {
     159       24564 :     sal_Int32 const nOldIndex = m_nIndex;
     160       24564 :     ChgValue( *this, m_nIndex-1 );
     161       24564 :     return nOldIndex;
     162             : }
     163             : 
     164       18032 : inline sal_Int32 SwIndex::operator+=( sal_Int32 const nVal )
     165             : {
     166       18032 :     return ChgValue( *this, m_nIndex + nVal ).m_nIndex;
     167             : }
     168             : 
     169          34 : inline sal_Int32 SwIndex::operator-=( sal_Int32 const nVal )
     170             : {
     171          34 :     return ChgValue( *this, m_nIndex - nVal ).m_nIndex;
     172             : }
     173             : 
     174             : inline sal_Int32 SwIndex::operator+=( const SwIndex& rIndex )
     175             : {
     176             :     return ChgValue( *this, m_nIndex + rIndex.m_nIndex ).m_nIndex;
     177             : }
     178             : 
     179           0 : inline sal_Int32 SwIndex::operator-=( const SwIndex& rIndex )
     180             : {
     181           0 :     return ChgValue( *this, m_nIndex - rIndex.m_nIndex ).m_nIndex;
     182             : }
     183             : 
     184     9271525 : inline bool SwIndex::operator< ( const SwIndex& rIndex ) const
     185             : {
     186     9271525 :     return m_nIndex <  rIndex.m_nIndex;
     187             : }
     188             : 
     189     2742542 : inline bool SwIndex::operator<=( const SwIndex& rIndex ) const
     190             : {
     191     2742542 :     return m_nIndex <= rIndex.m_nIndex;
     192             : }
     193             : 
     194     1176414 : inline bool SwIndex::operator> ( const SwIndex& rIndex ) const
     195             : {
     196     1176414 :     return m_nIndex >  rIndex.m_nIndex;
     197             : }
     198             : 
     199     8490165 : inline bool SwIndex::operator>=( const SwIndex& rIndex ) const
     200             : {
     201     8490165 :     return m_nIndex >= rIndex.m_nIndex;
     202             : }
     203             : 
     204      359661 : inline SwIndex& SwIndex::operator= ( sal_Int32 const nVal )
     205             : {
     206      359661 :     if (m_nIndex != nVal)
     207             :     {
     208      262777 :         ChgValue( *this, nVal );
     209             :     }
     210      359661 :     return *this;
     211             : }
     212             : 
     213             : #endif // ifndef DBG_UTIL
     214             : 
     215             : #endif
     216             : 
     217             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10