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

Generated by: LCOV version 1.11