LCOV - code coverage report
Current view: top level - sw/inc - ndindex.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 109 111 98.2 %
Date: 2015-06-13 12:38:46 Functions: 39 40 97.5 %
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_NDINDEX_HXX
      20             : #define INCLUDED_SW_INC_NDINDEX_HXX
      21             : 
      22             : #include <limits.h>
      23             : #include <iostream>
      24             : 
      25             : #include <tools/solar.h>
      26             : 
      27             : #include <node.hxx>
      28             : #include <ring.hxx>
      29             : #include <ndarr.hxx>
      30             : 
      31             : class SwNode;
      32             : class SwNodes;
      33             : 
      34             : /// Marks a node in the document model.
      35             : class SW_DLLPUBLIC SwNodeIndex SAL_FINAL : public sw::Ring<SwNodeIndex>
      36             : {
      37             :     SwNode* pNd;
      38             : 
      39             :     // These are not allowed!
      40             :     SwNodeIndex( SwNodes& rNds, sal_uInt16 nIdx ) SAL_DELETED_FUNCTION;
      41             :     SwNodeIndex( SwNodes& rNds, int nIdx ) SAL_DELETED_FUNCTION;
      42    64171482 :     void RegisterIndex( SwNodes& rNodes )
      43             :     {
      44    64171482 :         if(!rNodes.vIndices)
      45       14885 :             rNodes.vIndices = this;
      46    64171482 :         MoveTo(rNodes.vIndices);
      47    64171482 :     }
      48    64171361 :     void DeRegisterIndex( SwNodes& rNodes )
      49             :     {
      50    64171361 :         if(rNodes.vIndices == this)
      51       34221 :             rNodes.vIndices = GetNextInRing();
      52    64171361 :         MoveTo(nullptr);
      53    64171361 :         if(rNodes.vIndices == this)
      54       14871 :             rNodes.vIndices = nullptr;
      55    64171361 :     }
      56             : 
      57             : public:
      58     1265040 :     SwNodeIndex( SwNodes& rNds, sal_uLong nIdx = 0 )
      59     1265040 :         : pNd( rNds[ nIdx ] )
      60             :     {
      61     1265040 :         RegisterIndex( rNds );
      62     1265040 :     };
      63    27394013 :     SwNodeIndex( const SwNodeIndex& rIdx, long nDiff = 0 )
      64    27394013 :         : sw::Ring<SwNodeIndex>()
      65             :     {
      66    27394013 :         if( nDiff )
      67      702336 :             pNd = rIdx.GetNodes()[ rIdx.GetIndex() + nDiff ];
      68             :         else
      69    26691677 :             pNd = rIdx.pNd;
      70    27394013 :         RegisterIndex( pNd->GetNodes() );
      71    27394013 :     }
      72             : 
      73    35512381 :     SwNodeIndex( const SwNode& rNd, long nDiff = 0 )
      74    35512381 :     {
      75    35512381 :         if( nDiff )
      76       97225 :             pNd = rNd.GetNodes()[ rNd.GetIndex() + nDiff ];
      77             :         else
      78    35415156 :             pNd = const_cast<SwNode*>(&rNd);
      79    35512381 :         RegisterIndex( pNd->GetNodes() );
      80    35512381 :     }
      81             : 
      82    64268493 :    virtual  ~SwNodeIndex()
      83    64268493 :         { DeRegisterIndex( pNd->GetNodes() ); };
      84             : 
      85             :     inline sal_uLong operator++();
      86             :     inline sal_uLong operator--();
      87             :     inline sal_uLong operator++(int);
      88             :     inline sal_uLong operator--(int);
      89             : 
      90             :     inline sal_uLong operator+=( sal_uLong );
      91             :     inline sal_uLong operator-=( sal_uLong );
      92             :     inline sal_uLong operator+=( const  SwNodeIndex& );
      93             :     inline sal_uLong operator-=( const SwNodeIndex& );
      94             : 
      95             :     inline bool operator< ( const SwNodeIndex& ) const;
      96             :     inline bool operator<=( const SwNodeIndex& ) const;
      97             :     inline bool operator> ( const SwNodeIndex& ) const;
      98             :     inline bool operator>=( const SwNodeIndex& ) const;
      99             :     inline bool operator==( const SwNodeIndex& ) const;
     100             :     inline bool operator!=( const SwNodeIndex& ) const;
     101             : 
     102             :     inline bool operator< ( sal_uLong nWert ) const;
     103             :     inline bool operator<=( sal_uLong nWert ) const;
     104             :     inline bool operator> ( sal_uLong nWert ) const;
     105             :     inline bool operator>=( sal_uLong nWert ) const;
     106             :     inline bool operator==( sal_uLong nWert ) const;
     107             :     inline bool operator!=( sal_uLong nWert ) const;
     108             : 
     109             :     inline SwNodeIndex& operator=( sal_uLong );
     110             :     inline SwNodeIndex& operator=( const SwNodeIndex& );
     111             :     inline SwNodeIndex& operator=( const SwNode& );
     112             : 
     113             :     // Return value of index as sal_uLong.
     114             :     inline sal_uLong GetIndex() const;
     115             : 
     116             :     // Enables assignments without creation of a temporary object.
     117             :     inline SwNodeIndex& Assign( SwNodes& rNds, sal_uLong );
     118             :     inline SwNodeIndex& Assign( const SwNode& rNd, long nOffset = 0 );
     119             : 
     120             :     // Gets pointer on NodesArray.
     121             :     inline const SwNodes& GetNodes() const;
     122             :     inline       SwNodes& GetNodes();
     123             : 
     124   105928812 :     SwNode& GetNode() const { return *pNd; }
     125             : };
     126             : 
     127             : inline std::ostream &operator <<(std::ostream& s, const SwNodeIndex& index)
     128             : {
     129             :     return s << "SwNodeIndex (node " << index.GetIndex() << ")";
     130             : };
     131             : 
     132             : // SwRange
     133             : 
     134       66016 : class SW_DLLPUBLIC SwNodeRange
     135             : {
     136             : public:
     137             :     SwNodeIndex aStart;
     138             :     SwNodeIndex aEnd;
     139             : 
     140       21096 :     SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE )
     141       21096 :         : aStart( rS ), aEnd( rE ) {};
     142       29625 :     SwNodeRange( const SwNodeRange &rRange )
     143       29625 :         : aStart( rRange.aStart ), aEnd( rRange.aEnd ) {};
     144             : 
     145           0 :     SwNodeRange( SwNodes& rNds, sal_uLong nSttIdx = 0, sal_uLong nEndIdx = 0 )
     146           0 :         : aStart( rNds, nSttIdx ), aEnd( rNds, nEndIdx ) {};
     147             : 
     148        8210 :     SwNodeRange( const SwNodeIndex& rS, long nSttDiff, const SwNodeIndex& rE, long nEndDiff = 0 )
     149        8210 :         : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff ) {};
     150        7085 :     SwNodeRange( const SwNode& rS, long nSttDiff, const SwNode& rE, long nEndDiff = 0 )
     151        7085 :         : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff ) {};
     152             : };
     153             : 
     154             : // For inlines node.hxx is needed which in turn needs this one.
     155             : // Therefore all inlines accessing pNd are implemented here.
     156             : 
     157    63722877 : inline sal_uLong SwNodeIndex::GetIndex() const
     158             : {
     159    63722877 :     return pNd->GetIndex();
     160             : }
     161      876577 : inline const SwNodes& SwNodeIndex::GetNodes() const
     162             : {
     163      876577 :     return pNd->GetNodes();
     164             : }
     165      901423 : inline SwNodes& SwNodeIndex::GetNodes()
     166             : {
     167      901423 :     return pNd->GetNodes();
     168             : }
     169      488906 : inline bool SwNodeIndex::operator< ( sal_uLong nWert ) const
     170             : {
     171      488906 :     return pNd->GetIndex() < nWert;
     172             : }
     173        3640 : inline bool SwNodeIndex::operator<=( sal_uLong nWert ) const
     174             : {
     175        3640 :     return pNd->GetIndex() <= nWert;
     176             : }
     177        6461 : inline bool SwNodeIndex::operator> ( sal_uLong nWert ) const
     178             : {
     179        6461 :     return pNd->GetIndex() > nWert;
     180             : }
     181        2140 : inline bool SwNodeIndex::operator>=( sal_uLong nWert ) const
     182             : {
     183        2140 :     return pNd->GetIndex() >= nWert;
     184             : }
     185     1103290 : inline bool SwNodeIndex::operator==( sal_uLong nWert ) const
     186             : {
     187     1103290 :     return pNd->GetIndex() == nWert;
     188             : }
     189        3980 : inline bool SwNodeIndex::operator!=( sal_uLong nWert ) const
     190             : {
     191        3980 :     return pNd->GetIndex() != nWert;
     192             : }
     193    42447791 : inline bool SwNodeIndex::operator<( const SwNodeIndex& rIndex ) const
     194             : {
     195    42447791 :     return pNd->GetIndex() < rIndex.GetIndex();
     196             : }
     197       74599 : inline bool SwNodeIndex::operator<=( const SwNodeIndex& rIndex ) const
     198             : {
     199       74599 :     return pNd->GetIndex() <= rIndex.GetIndex();
     200             : }
     201    12068516 : inline bool SwNodeIndex::operator>( const SwNodeIndex& rIndex ) const
     202             : {
     203    12068516 :     return pNd->GetIndex() > rIndex.GetIndex();
     204             : }
     205       85183 : inline bool SwNodeIndex::operator>=( const SwNodeIndex& rIndex ) const
     206             : {
     207       85183 :     return pNd->GetIndex() >= rIndex.GetIndex();
     208             : }
     209    33013700 : inline bool SwNodeIndex::operator==( const SwNodeIndex& rIdx ) const
     210             : {
     211    33013700 :     return pNd == rIdx.pNd;
     212             : }
     213      507079 : inline bool SwNodeIndex::operator!=( const SwNodeIndex& rIdx ) const
     214             : {
     215      507079 :     return pNd != rIdx.pNd;
     216             : }
     217             : 
     218      408442 : inline sal_uLong SwNodeIndex::operator++()
     219             : {
     220      408442 :     return ( pNd = GetNodes()[ pNd->GetIndex()+1 ] )->GetIndex();
     221             : }
     222       87417 : inline sal_uLong SwNodeIndex::operator--()
     223             : {
     224       87417 :     return ( pNd = GetNodes()[ pNd->GetIndex()-1 ] )->GetIndex();
     225             : }
     226       44709 : inline sal_uLong SwNodeIndex::operator++(int)
     227             : {
     228       44709 :     sal_uLong nOldIndex = pNd->GetIndex();
     229       44709 :     pNd = GetNodes()[ nOldIndex + 1 ];
     230       44709 :     return nOldIndex;
     231             : }
     232        1009 : inline sal_uLong SwNodeIndex::operator--(int)
     233             : {
     234        1009 :     sal_uLong nOldIndex = pNd->GetIndex();
     235        1009 :     pNd = GetNodes()[ nOldIndex - 1 ];
     236        1009 :     return nOldIndex;
     237             : }
     238             : 
     239        1318 : inline sal_uLong SwNodeIndex::operator+=( sal_uLong nWert )
     240             : {
     241        1318 :     return ( pNd = GetNodes()[ pNd->GetIndex() + nWert ] )->GetIndex();
     242             : }
     243         556 : inline sal_uLong SwNodeIndex::operator-=( sal_uLong nWert )
     244             : {
     245         556 :     return ( pNd = GetNodes()[ pNd->GetIndex() - nWert ] )->GetIndex();
     246             : }
     247             : inline sal_uLong SwNodeIndex::operator+=( const  SwNodeIndex& rIndex )
     248             : {
     249             :     return ( pNd = GetNodes()[ pNd->GetIndex() + rIndex.GetIndex() ] )->GetIndex();
     250             : }
     251             : inline sal_uLong SwNodeIndex::operator-=( const SwNodeIndex& rIndex )
     252             : {
     253             :     return ( pNd = GetNodes()[ pNd->GetIndex() - rIndex.GetIndex() ] )->GetIndex();
     254             : }
     255             : 
     256       62064 : inline SwNodeIndex& SwNodeIndex::operator=( sal_uLong nWert )
     257             : {
     258       62064 :     pNd = GetNodes()[ nWert ];
     259       62064 :     return *this;
     260             : }
     261             : 
     262     1424266 : SwNodeIndex& SwNodeIndex::operator=( const SwNodeIndex& rIdx )
     263             : {
     264     1424266 :     *this = *(rIdx.pNd);
     265     1424266 :     return *this;
     266             : }
     267             : 
     268     1789762 : SwNodeIndex& SwNodeIndex::operator=( const SwNode& rNd )
     269             : {
     270     1789762 :     if( &pNd->GetNodes() != &rNd.GetNodes() )
     271             :     {
     272          48 :         DeRegisterIndex( pNd->GetNodes() );
     273          48 :         pNd = const_cast<SwNode*>(&rNd);
     274          48 :         RegisterIndex( pNd->GetNodes() );
     275             :     }
     276             :     else
     277     1789714 :         pNd = const_cast<SwNode*>(&rNd);
     278     1789762 :     return *this;
     279             : }
     280             : 
     281           1 : SwNodeIndex& SwNodeIndex::Assign( SwNodes& rNds, sal_uLong nIdx )
     282             : {
     283           1 :     *this = *rNds[ nIdx ];
     284           1 :     return *this;
     285             : }
     286             : 
     287       57604 : SwNodeIndex& SwNodeIndex::Assign( const SwNode& rNd, long nOffset )
     288             : {
     289       57604 :     *this = rNd;
     290             : 
     291       57604 :     if( nOffset )
     292       57583 :         pNd = pNd->GetNodes()[ pNd->GetIndex() + nOffset ];
     293             : 
     294       57604 :     return *this;
     295             : }
     296             : 
     297             : #endif
     298             : 
     299             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11