LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/inc - index.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 41 44 93.2 %
Date: 2013-07-09 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 SW_INDEX_HXX
      20             : #define SW_INDEX_HXX
      21             : 
      22             : #include <limits.h>
      23             : 
      24             : #include "rtl/instance.hxx"
      25             : #include <tools/solar.h>
      26             : #include <tools/rtti.hxx>               // for RTTI of SwIndexReg
      27             : #include <swdllapi.h>
      28             : 
      29             : // Maximum index in IndexArray (for testing on overflows).
      30             : #define INVALID_INDEX STRING_NOTFOUND
      31             : 
      32             : class SwIndex;
      33             : class SwIndexReg;
      34             : struct SwPosition;
      35             : 
      36             : #ifdef DBG_UTIL
      37             : #define INLINE
      38             : #else
      39             : #define INLINE inline
      40             : #endif
      41             : 
      42             : /// Marks a character position inside a document model node.
      43             : class SW_DLLPUBLIC SwIndex
      44             : {
      45             : private:
      46             :     friend class SwIndexReg;
      47             : 
      48             :     xub_StrLen m_nIndex;
      49             :     SwIndexReg * m_pIndexReg;
      50             :     // doubly linked list of Indexes registered at m_pIndexReg
      51             :     SwIndex * m_pNext;
      52             :     SwIndex * m_pPrev;
      53             : 
      54             :     SwIndex& ChgValue( const SwIndex& rIdx, xub_StrLen nNewValue );
      55             :     void Init(xub_StrLen const nIdx);
      56             :     void Remove();
      57             : 
      58             : public:
      59             :     explicit SwIndex(SwIndexReg *const pReg, xub_StrLen const nIdx = 0);
      60             :     SwIndex( const SwIndex & );
      61             :     SwIndex( const SwIndex &, short nDiff );
      62      994741 :     ~SwIndex() { Remove(); }
      63             : 
      64             :     INLINE SwIndex& operator=( xub_StrLen const );
      65             :     SwIndex& operator=( const SwIndex & );
      66             : 
      67             :     INLINE xub_StrLen operator++();
      68             :     INLINE xub_StrLen operator--();
      69             :     INLINE xub_StrLen operator++(int);
      70             :     INLINE xub_StrLen operator--(int);
      71             : 
      72             :     INLINE xub_StrLen operator+=( xub_StrLen const );
      73             :     INLINE xub_StrLen operator-=( xub_StrLen const );
      74             :     INLINE xub_StrLen operator+=( const SwIndex& );
      75             :     INLINE xub_StrLen operator-=( const SwIndex& );
      76             : 
      77             :     INLINE bool operator< ( const SwIndex& ) const;
      78             :     INLINE bool operator<=( const SwIndex& ) const;
      79             :     INLINE bool operator> ( const SwIndex& ) const;
      80             :     INLINE bool operator>=( const SwIndex& ) const;
      81             : 
      82         121 :     bool operator< ( xub_StrLen const nVal ) const { return m_nIndex <  nVal; }
      83           0 :     bool operator<=( xub_StrLen const nVal ) const { return m_nIndex <= nVal; }
      84        1146 :     bool operator> ( xub_StrLen const nVal ) const { return m_nIndex >  nVal; }
      85      114754 :     bool operator>=( xub_StrLen const nVal ) const { return m_nIndex >= nVal; }
      86        3940 :     bool operator==( xub_StrLen const nVal ) const { return m_nIndex == nVal; }
      87        7668 :     bool operator!=( xub_StrLen const nVal ) const { return m_nIndex != nVal; }
      88             : 
      89        6021 :     bool operator==( const SwIndex& rSwIndex ) const
      90             :     {
      91        6021 :         return (m_nIndex    == rSwIndex.m_nIndex)
      92        6021 :             && (m_pIndexReg == rSwIndex.m_pIndexReg);
      93             :     }
      94             : 
      95       92691 :     bool operator!=( const SwIndex& rSwIndex ) const
      96             :     {
      97       92691 :         return (m_nIndex    != rSwIndex.m_nIndex)
      98       92691 :             || (m_pIndexReg != rSwIndex.m_pIndexReg);
      99             :     }
     100             : 
     101     1571158 :     xub_StrLen GetIndex() const { return m_nIndex; }
     102             : 
     103             :     // Assignments without creating a temporary object.
     104             :     SwIndex &Assign(SwIndexReg *,xub_StrLen);
     105             : 
     106             :     // Returns pointer to IndexArray (for RTTI at SwIndexReg).
     107     6783591 :     const SwIndexReg* GetIdxReg() const { return m_pIndexReg; }
     108             : };
     109             : 
     110             : #undef INLINE
     111             : 
     112             : class SwIndexReg
     113             : {
     114             :     friend class SwIndex;
     115             :     friend bool sw_PosOk(const SwPosition & aPos);
     116             : 
     117             :     const SwIndex * m_pFirst;
     118             :     const SwIndex * m_pLast;
     119             : 
     120             : protected:
     121             :     virtual void Update( SwIndex const & rPos, const xub_StrLen nChangeLen,
     122             :                  const bool bNegative = false, const bool bDelete = false );
     123             : 
     124             :     void ChkArr();
     125             : 
     126         553 :     bool HasAnyIndex() const { return 0 != m_pFirst; }
     127             : 
     128             : public:
     129             :     explicit SwIndexReg();
     130             :     virtual ~SwIndexReg();
     131             : 
     132             :     /// rtti, derived classes might do the same. If so, one can cast typesavely
     133             :     /// via SwIndexReg.
     134             :     TYPEINFO();
     135             : 
     136             :     void MoveTo( SwIndexReg& rArr );
     137             : };
     138             : 
     139             : 
     140             : #ifndef DBG_UTIL
     141             : 
     142         118 : inline xub_StrLen SwIndex::operator++()
     143             : {
     144         118 :     return ChgValue( *this, m_nIndex+1 ).m_nIndex;
     145             : }
     146             : inline xub_StrLen SwIndex::operator--()
     147             : {
     148             :     return ChgValue( *this, m_nIndex-1 ).m_nIndex;
     149             : }
     150          29 : inline xub_StrLen SwIndex::operator++(int)
     151             : {
     152          29 :     xub_StrLen const nOldIndex = m_nIndex;
     153          29 :     ChgValue( *this, m_nIndex+1 );
     154          29 :     return nOldIndex;
     155             : }
     156        9039 : inline xub_StrLen SwIndex::operator--(int)
     157             : {
     158        9039 :     xub_StrLen const nOldIndex = m_nIndex;
     159        9039 :     ChgValue( *this, m_nIndex-1 );
     160        9039 :     return nOldIndex;
     161             : }
     162             : 
     163        1859 : inline xub_StrLen SwIndex::operator+=( xub_StrLen const nVal )
     164             : {
     165        1859 :     return ChgValue( *this, m_nIndex + nVal ).m_nIndex;
     166             : }
     167           7 : inline xub_StrLen SwIndex::operator-=( xub_StrLen const nVal )
     168             : {
     169           7 :     return ChgValue( *this, m_nIndex - nVal ).m_nIndex;
     170             : }
     171             : inline xub_StrLen SwIndex::operator+=( const SwIndex& rIndex )
     172             : {
     173             :     return ChgValue( *this, m_nIndex + rIndex.m_nIndex ).m_nIndex;
     174             : }
     175           0 : inline xub_StrLen SwIndex::operator-=( const SwIndex& rIndex )
     176             : {
     177           0 :     return ChgValue( *this, m_nIndex - rIndex.m_nIndex ).m_nIndex;
     178             : }
     179             : 
     180      420185 : inline bool SwIndex::operator< ( const SwIndex& rIndex ) const
     181             : {
     182      420185 :     return m_nIndex <  rIndex.m_nIndex;
     183             : }
     184      307464 : inline bool SwIndex::operator<=( const SwIndex& rIndex ) const
     185             : {
     186      307464 :     return m_nIndex <= rIndex.m_nIndex;
     187             : }
     188       91657 : inline bool SwIndex::operator> ( const SwIndex& rIndex ) const
     189             : {
     190       91657 :     return m_nIndex >  rIndex.m_nIndex;
     191             : }
     192     2457476 : inline bool SwIndex::operator>=( const SwIndex& rIndex ) const
     193             : {
     194     2457476 :     return m_nIndex >= rIndex.m_nIndex;
     195             : }
     196       90046 : inline SwIndex& SwIndex::operator= ( xub_StrLen const nVal )
     197             : {
     198       90046 :     if (m_nIndex != nVal)
     199             :     {
     200       86517 :         ChgValue( *this, nVal );
     201             :     }
     202       90046 :     return *this;
     203             : }
     204             : 
     205             : #endif // ifndef DBG_UTIL
     206             : 
     207             : #endif
     208             : 
     209             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10