LCOV - code coverage report
Current view: top level - sw/inc - index.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 37 42 88.1 %
Date: 2012-08-25 Functions: 20 23 87.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 10 80.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : #ifndef SW_INDEX_HXX
      29                 :            : #define SW_INDEX_HXX
      30                 :            : 
      31                 :            : #include <limits.h>
      32                 :            : 
      33                 :            : #include "rtl/instance.hxx"
      34                 :            : #include <tools/solar.h>
      35                 :            : #include <tools/rtti.hxx>               // for RTTI of SwIndexReg
      36                 :            : #include <swdllapi.h>
      37                 :            : 
      38                 :            : // Maximum index in IndexArray (for testing on overflows).
      39                 :            : #define INVALID_INDEX STRING_NOTFOUND
      40                 :            : 
      41                 :            : class SwIndex;
      42                 :            : class SwIndexReg;
      43                 :            : struct SwPosition;
      44                 :            : 
      45                 :            : #ifdef DBG_UTIL
      46                 :            : #define INLINE
      47                 :            : #else
      48                 :            : #define INLINE inline
      49                 :            : #endif
      50                 :            : 
      51                 :            : /// Marks a character position inside a document model node.
      52                 :            : class SW_DLLPUBLIC SwIndex
      53                 :            : {
      54                 :            : private:
      55                 :            :     friend class SwIndexReg;
      56                 :            : 
      57                 :            :     xub_StrLen m_nIndex;
      58                 :            :     SwIndexReg * m_pIndexReg;
      59                 :            :     // doubly linked list of Indexes registered at m_pIndexReg
      60                 :            :     SwIndex * m_pNext;
      61                 :            :     SwIndex * m_pPrev;
      62                 :            : 
      63                 :            :     SwIndex& ChgValue( const SwIndex& rIdx, xub_StrLen nNewValue );
      64                 :            :     void Init(xub_StrLen const nIdx);
      65                 :            :     void Remove();
      66                 :            : 
      67                 :            : public:
      68                 :            :     explicit SwIndex(SwIndexReg *const pReg, xub_StrLen const nIdx = 0);
      69                 :            :     SwIndex( const SwIndex & );
      70                 :            :     SwIndex( const SwIndex &, short nDiff );
      71                 :    1712266 :     ~SwIndex() { Remove(); }
      72                 :            : 
      73                 :            :     INLINE SwIndex& operator=( xub_StrLen const );
      74                 :            :     SwIndex& operator=( const SwIndex & );
      75                 :            : 
      76                 :            :     INLINE xub_StrLen operator++();
      77                 :            :     INLINE xub_StrLen operator--();
      78                 :            :     INLINE xub_StrLen operator++(int);
      79                 :            :     INLINE xub_StrLen operator--(int);
      80                 :            : 
      81                 :            :     INLINE xub_StrLen operator+=( xub_StrLen const );
      82                 :            :     INLINE xub_StrLen operator-=( xub_StrLen const );
      83                 :            :     INLINE xub_StrLen operator+=( const SwIndex& );
      84                 :            :     INLINE xub_StrLen operator-=( const SwIndex& );
      85                 :            : 
      86                 :            :     INLINE bool operator< ( const SwIndex& ) const;
      87                 :            :     INLINE bool operator<=( const SwIndex& ) const;
      88                 :            :     INLINE bool operator> ( const SwIndex& ) const;
      89                 :            :     INLINE bool operator>=( const SwIndex& ) const;
      90                 :            : 
      91                 :        105 :     bool operator< ( xub_StrLen const nVal ) const { return m_nIndex <  nVal; }
      92                 :          0 :     bool operator<=( xub_StrLen const nVal ) const { return m_nIndex <= nVal; }
      93                 :       3138 :     bool operator> ( xub_StrLen const nVal ) const { return m_nIndex >  nVal; }
      94                 :     341782 :     bool operator>=( xub_StrLen const nVal ) const { return m_nIndex >= nVal; }
      95                 :       6348 :     bool operator==( xub_StrLen const nVal ) const { return m_nIndex == nVal; }
      96                 :       5418 :     bool operator!=( xub_StrLen const nVal ) const { return m_nIndex != nVal; }
      97                 :            : 
      98                 :      14578 :     bool operator==( const SwIndex& rSwIndex ) const
      99                 :            :     {
     100                 :            :         return (m_nIndex    == rSwIndex.m_nIndex)
     101 [ +  + ][ +  - ]:      14578 :             && (m_pIndexReg == rSwIndex.m_pIndexReg);
     102                 :            :     }
     103                 :            : 
     104                 :     191750 :     bool operator!=( const SwIndex& rSwIndex ) const
     105                 :            :     {
     106                 :            :         return (m_nIndex    != rSwIndex.m_nIndex)
     107 [ +  + ][ -  + ]:     191750 :             || (m_pIndexReg != rSwIndex.m_pIndexReg);
     108                 :            :     }
     109                 :            : 
     110                 :    3050464 :     xub_StrLen GetIndex() const { return m_nIndex; }
     111                 :            : 
     112                 :            :     // Assignments without creating a temporary object.
     113                 :            :     SwIndex &Assign(SwIndexReg *,xub_StrLen);
     114                 :            : 
     115                 :            :     // Returns pointer to IndexArray (for RTTI at SwIndexReg).
     116                 :   14166961 :     const SwIndexReg* GetIdxReg() const { return m_pIndexReg; }
     117                 :            : };
     118                 :            : 
     119                 :            : #undef INLINE
     120                 :            : 
     121                 :            : class SwIndexReg
     122                 :            : {
     123                 :            :     friend class SwIndex;
     124                 :            :     friend bool lcl_PosOk(const SwPosition & aPos);
     125                 :            : 
     126                 :            :     const SwIndex * m_pFirst;
     127                 :            :     const SwIndex * m_pLast;
     128                 :            : 
     129                 :            : protected:
     130                 :            :     virtual void Update( SwIndex const & rPos, const xub_StrLen nChangeLen,
     131                 :            :                  const bool bNegative = false, const bool bDelete = false );
     132                 :            : 
     133                 :            :     void ChkArr();
     134                 :            : 
     135                 :        730 :     bool HasAnyIndex() const { return 0 != m_pFirst; }
     136                 :            : 
     137                 :            : public:
     138                 :            :     explicit SwIndexReg();
     139                 :            :     virtual ~SwIndexReg();
     140                 :            : 
     141                 :            :     // rtti, abgeleitete moegens gleichtun oder nicht. Wenn sie es gleichtun
     142                 :            :     // kann ueber das SwIndexReg typsicher gecastet werden.
     143                 :            :     TYPEINFO();
     144                 :            : 
     145                 :            :     void MoveTo( SwIndexReg& rArr );
     146                 :            : };
     147                 :            : 
     148                 :            : 
     149                 :            : #ifndef DBG_UTIL
     150                 :            : 
     151                 :          0 : inline xub_StrLen SwIndex::operator++()
     152                 :            : {
     153                 :          0 :     return ChgValue( *this, m_nIndex+1 ).m_nIndex;
     154                 :            : }
     155                 :            : inline xub_StrLen SwIndex::operator--()
     156                 :            : {
     157                 :            :     return ChgValue( *this, m_nIndex-1 ).m_nIndex;
     158                 :            : }
     159                 :        130 : inline xub_StrLen SwIndex::operator++(int)
     160                 :            : {
     161                 :        130 :     xub_StrLen const nOldIndex = m_nIndex;
     162                 :        130 :     ChgValue( *this, m_nIndex+1 );
     163                 :        130 :     return nOldIndex;
     164                 :            : }
     165                 :        991 : inline xub_StrLen SwIndex::operator--(int)
     166                 :            : {
     167                 :        991 :     xub_StrLen const nOldIndex = m_nIndex;
     168                 :        991 :     ChgValue( *this, m_nIndex-1 );
     169                 :        991 :     return nOldIndex;
     170                 :            : }
     171                 :            : 
     172                 :       3036 : inline xub_StrLen SwIndex::operator+=( xub_StrLen const nVal )
     173                 :            : {
     174                 :       3036 :     return ChgValue( *this, m_nIndex + nVal ).m_nIndex;
     175                 :            : }
     176                 :         15 : inline xub_StrLen SwIndex::operator-=( xub_StrLen const nVal )
     177                 :            : {
     178                 :         15 :     return ChgValue( *this, m_nIndex - nVal ).m_nIndex;
     179                 :            : }
     180                 :            : inline xub_StrLen SwIndex::operator+=( const SwIndex& rIndex )
     181                 :            : {
     182                 :            :     return ChgValue( *this, m_nIndex + rIndex.m_nIndex ).m_nIndex;
     183                 :            : }
     184                 :          0 : inline xub_StrLen SwIndex::operator-=( const SwIndex& rIndex )
     185                 :            : {
     186                 :          0 :     return ChgValue( *this, m_nIndex - rIndex.m_nIndex ).m_nIndex;
     187                 :            : }
     188                 :            : 
     189                 :     838366 : inline bool SwIndex::operator< ( const SwIndex& rIndex ) const
     190                 :            : {
     191                 :     838366 :     return m_nIndex <  rIndex.m_nIndex;
     192                 :            : }
     193                 :     561760 : inline bool SwIndex::operator<=( const SwIndex& rIndex ) const
     194                 :            : {
     195                 :     561760 :     return m_nIndex <= rIndex.m_nIndex;
     196                 :            : }
     197                 :     170165 : inline bool SwIndex::operator> ( const SwIndex& rIndex ) const
     198                 :            : {
     199                 :     170165 :     return m_nIndex >  rIndex.m_nIndex;
     200                 :            : }
     201                 :    5270257 : inline bool SwIndex::operator>=( const SwIndex& rIndex ) const
     202                 :            : {
     203                 :    5270257 :     return m_nIndex >= rIndex.m_nIndex;
     204                 :            : }
     205                 :     174972 : inline SwIndex& SwIndex::operator= ( xub_StrLen const nVal )
     206                 :            : {
     207         [ +  + ]:     174972 :     if (m_nIndex != nVal)
     208                 :            :     {
     209                 :     171426 :         ChgValue( *this, nVal );
     210                 :            :     }
     211                 :     174972 :     return *this;
     212                 :            : }
     213                 :            : 
     214                 :            : #endif // ifndef DBG_UTIL
     215                 :            : 
     216                 :            : #endif
     217                 :            : 
     218                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10