LCOV - code coverage report
Current view: top level - sw/inc - index.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 41 44 93.2 %
Date: 2014-04-11 Functions: 21 23 91.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             : /// Marks a character position inside a document model node.
      30             : class SW_DLLPUBLIC SwIndex
      31             : {
      32             : private:
      33             :     friend class SwIndexReg;
      34             : 
      35             :     sal_Int32 m_nIndex;
      36             :     SwIndexReg * m_pIndexReg;
      37             :     // doubly linked list of Indexes registered at m_pIndexReg
      38             :     SwIndex * m_pNext;
      39             :     SwIndex * m_pPrev;
      40             : 
      41             :     SwIndex& ChgValue( const SwIndex& rIdx, sal_Int32 nNewValue );
      42             :     void Init(sal_Int32 const nIdx);
      43             :     void Remove();
      44             : 
      45             : public:
      46             :     explicit SwIndex(SwIndexReg *const pReg, sal_Int32 const nIdx = 0);
      47             :     SwIndex( const SwIndex & );
      48             :     SwIndex( const SwIndex &, short nDiff );
      49     2493699 :     ~SwIndex() { Remove(); }
      50             : 
      51             :     SwIndex& operator=( sal_Int32 const );
      52             :     SwIndex& operator=( const SwIndex & );
      53             : 
      54             :     sal_Int32 operator++();
      55             :     sal_Int32 operator--();
      56             :     sal_Int32 operator++(int);
      57             :     sal_Int32 operator--(int);
      58             : 
      59             :     sal_Int32 operator+=( sal_Int32 const );
      60             :     sal_Int32 operator-=( sal_Int32 const );
      61             :     sal_Int32 operator+=( const SwIndex& );
      62             :     sal_Int32 operator-=( const SwIndex& );
      63             : 
      64             :     bool operator< ( const SwIndex& ) const;
      65             :     bool operator<=( const SwIndex& ) const;
      66             :     bool operator> ( const SwIndex& ) const;
      67             :     bool operator>=( const SwIndex& ) const;
      68             : 
      69         250 :     bool operator< ( sal_Int32 const nVal ) const { return m_nIndex <  nVal; }
      70           0 :     bool operator<=( sal_Int32 const nVal ) const { return m_nIndex <= nVal; }
      71        2633 :     bool operator> ( sal_Int32 const nVal ) const { return m_nIndex >  nVal; }
      72      149707 :     bool operator>=( sal_Int32 const nVal ) const { return m_nIndex >= nVal; }
      73       68831 :     bool operator==( sal_Int32 const nVal ) const { return m_nIndex == nVal; }
      74       50243 :     bool operator!=( sal_Int32 const nVal ) const { return m_nIndex != nVal; }
      75             : 
      76      127120 :     bool operator==( const SwIndex& rSwIndex ) const
      77             :     {
      78      127120 :         return (m_nIndex    == rSwIndex.m_nIndex)
      79      127120 :             && (m_pIndexReg == rSwIndex.m_pIndexReg);
      80             :     }
      81             : 
      82      237321 :     bool operator!=( const SwIndex& rSwIndex ) const
      83             :     {
      84      237321 :         return (m_nIndex    != rSwIndex.m_nIndex)
      85      237321 :             || (m_pIndexReg != rSwIndex.m_pIndexReg);
      86             :     }
      87             : 
      88     3084528 :     sal_Int32 GetIndex() const { return m_nIndex; }
      89             : 
      90             :     // Assignments without creating a temporary object.
      91             :     SwIndex &Assign(SwIndexReg *, sal_Int32);
      92             : 
      93             :     // Returns pointer to IndexArray (for RTTI at SwIndexReg).
      94   147092831 :     const SwIndexReg* GetIdxReg() const { return m_pIndexReg; }
      95             : };
      96             : 
      97             : class SwIndexReg
      98             : {
      99             :     friend class SwIndex;
     100             :     friend bool sw_PosOk(const SwPosition & aPos);
     101             : 
     102             :     const SwIndex * m_pFirst;
     103             :     const SwIndex * m_pLast;
     104             : 
     105             : protected:
     106             :     virtual void Update( SwIndex const & rPos, const sal_Int32 nChangeLen,
     107             :                  const bool bNegative = false, const bool bDelete = false );
     108             : 
     109             :     void ChkArr();
     110             : 
     111        1955 :     bool HasAnyIndex() const { return 0 != m_pFirst; }
     112             : 
     113             : public:
     114             :     SwIndexReg();
     115             :     virtual ~SwIndexReg();
     116             : 
     117             :     /// rtti, derived classes might do the same. If so, one can cast typesavely
     118             :     /// via SwIndexReg.
     119             :     TYPEINFO();
     120             : 
     121             :     void MoveTo( SwIndexReg& rArr );
     122             : };
     123             : 
     124             : #ifndef DBG_UTIL
     125             : 
     126          83 : inline sal_Int32 SwIndex::operator++()
     127             : {
     128          83 :     return ChgValue( *this, m_nIndex+1 ).m_nIndex;
     129             : }
     130             : 
     131             : inline sal_Int32 SwIndex::operator--()
     132             : {
     133             :     return ChgValue( *this, m_nIndex-1 ).m_nIndex;
     134             : }
     135             : 
     136         137 : inline sal_Int32 SwIndex::operator++(int)
     137             : {
     138         137 :     sal_Int32 const nOldIndex = m_nIndex;
     139         137 :     ChgValue( *this, m_nIndex+1 );
     140         137 :     return nOldIndex;
     141             : }
     142             : 
     143       10668 : inline sal_Int32 SwIndex::operator--(int)
     144             : {
     145       10668 :     sal_Int32 const nOldIndex = m_nIndex;
     146       10668 :     ChgValue( *this, m_nIndex-1 );
     147       10668 :     return nOldIndex;
     148             : }
     149             : 
     150        6224 : inline sal_Int32 SwIndex::operator+=( sal_Int32 const nVal )
     151             : {
     152        6224 :     return ChgValue( *this, m_nIndex + nVal ).m_nIndex;
     153             : }
     154             : 
     155          12 : inline sal_Int32 SwIndex::operator-=( sal_Int32 const nVal )
     156             : {
     157          12 :     return ChgValue( *this, m_nIndex - nVal ).m_nIndex;
     158             : }
     159             : 
     160             : inline sal_Int32 SwIndex::operator+=( const SwIndex& rIndex )
     161             : {
     162             :     return ChgValue( *this, m_nIndex + rIndex.m_nIndex ).m_nIndex;
     163             : }
     164             : 
     165           0 : inline sal_Int32 SwIndex::operator-=( const SwIndex& rIndex )
     166             : {
     167           0 :     return ChgValue( *this, m_nIndex - rIndex.m_nIndex ).m_nIndex;
     168             : }
     169             : 
     170    67740364 : inline bool SwIndex::operator< ( const SwIndex& rIndex ) const
     171             : {
     172    67740364 :     return m_nIndex <  rIndex.m_nIndex;
     173             : }
     174             : 
     175     1006145 : inline bool SwIndex::operator<=( const SwIndex& rIndex ) const
     176             : {
     177     1006145 :     return m_nIndex <= rIndex.m_nIndex;
     178             : }
     179             : 
     180      484632 : inline bool SwIndex::operator> ( const SwIndex& rIndex ) const
     181             : {
     182      484632 :     return m_nIndex >  rIndex.m_nIndex;
     183             : }
     184             : 
     185     3925390 : inline bool SwIndex::operator>=( const SwIndex& rIndex ) const
     186             : {
     187     3925390 :     return m_nIndex >= rIndex.m_nIndex;
     188             : }
     189             : 
     190      154172 : inline SwIndex& SwIndex::operator= ( sal_Int32 const nVal )
     191             : {
     192      154172 :     if (m_nIndex != nVal)
     193             :     {
     194      120003 :         ChgValue( *this, nVal );
     195             :     }
     196      154172 :     return *this;
     197             : }
     198             : 
     199             : #endif // ifndef DBG_UTIL
     200             : 
     201             : #endif
     202             : 
     203             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10