LCOV - code coverage report
Current view: top level - sw/source/core/text - txtcache.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 55 56 98.2 %
Date: 2014-04-11 Functions: 11 11 100.0 %
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             : 
      20             : #include "txtcache.hxx"
      21             : #include "txtfrm.hxx"
      22             : #include "porlay.hxx"
      23             : 
      24             : /*************************************************************************
      25             : |*
      26             : |*  SwTxtLine::SwTxtLine(), ~SwTxtLine()
      27             : |*
      28             : |*************************************************************************/
      29             : 
      30       16448 : SwTxtLine::SwTxtLine( SwTxtFrm *pFrm, SwParaPortion *pNew ) :
      31             :     SwCacheObj( (void*)pFrm ),
      32       16448 :     pLine( pNew )
      33             : {
      34       16448 : }
      35             : 
      36       49344 : SwTxtLine::~SwTxtLine()
      37             : {
      38       16448 :     delete pLine;
      39       32896 : }
      40             : 
      41             : /*************************************************************************
      42             : |*
      43             : |*  SwTxtLineAccess::NewObj()
      44             : |*
      45             : |*************************************************************************/
      46             : 
      47       15229 : SwCacheObj *SwTxtLineAccess::NewObj()
      48             : {
      49       15229 :     return new SwTxtLine( (SwTxtFrm*)pOwner );
      50             : }
      51             : 
      52             : /*************************************************************************
      53             : |*
      54             : |*  SwTxtLineAccess::GetPara()
      55             : |*
      56             : |*************************************************************************/
      57             : 
      58       67281 : SwParaPortion *SwTxtLineAccess::GetPara()
      59             : {
      60             :     SwTxtLine *pRet;
      61       67281 :     if ( pObj )
      62       52052 :         pRet = (SwTxtLine*)pObj;
      63             :     else
      64             :     {
      65       15229 :         pRet = (SwTxtLine*)Get();
      66       15229 :         ((SwTxtFrm*)pOwner)->SetCacheIdx( pRet->GetCachePos() );
      67             :     }
      68       67281 :     if ( !pRet->GetPara() )
      69       23306 :         pRet->SetPara( new SwParaPortion );
      70       67281 :     return pRet->GetPara();
      71             : }
      72             : 
      73             : /*************************************************************************
      74             : |*
      75             : |*  SwTxtLineAccess::SwTxtLineAccess()
      76             : |*
      77             : |*************************************************************************/
      78             : 
      79       65103 : SwTxtLineAccess::SwTxtLineAccess( const SwTxtFrm *pOwn ) :
      80       65103 :     SwCacheAccess( *SwTxtFrm::GetTxtCache(), pOwn, pOwn->GetCacheIdx() )
      81             : {
      82       65103 : }
      83             : 
      84             : /*************************************************************************
      85             : |*
      86             : |*  SwTxtLineAccess::IsAvailable
      87             : |*
      88             : |*************************************************************************/
      89             : 
      90       32435 : bool SwTxtLineAccess::IsAvailable() const
      91             : {
      92       32435 :     return pObj && ((SwTxtLine*)pObj)->GetPara();
      93             : }
      94             : 
      95             : /*************************************************************************
      96             : |*
      97             : |*  SwTxtFrm::HasPara()
      98             : |*
      99             : |*************************************************************************/
     100             : 
     101      231817 : bool SwTxtFrm::_HasPara() const
     102             : {
     103             :     SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
     104      231817 :                                             Get( this, GetCacheIdx(), false );
     105      231817 :     if ( pTxtLine )
     106             :     {
     107      231751 :         if ( pTxtLine->GetPara() )
     108      219108 :             return true;
     109             :     }
     110             :     else
     111          66 :         ((SwTxtFrm*)this)->nCacheIdx = MSHRT_MAX;
     112             : 
     113       12709 :     return false;
     114             : }
     115             : 
     116             : /*************************************************************************
     117             : |*
     118             : |*  SwTxtFrm::GetPara()
     119             : |*
     120             : |*************************************************************************/
     121             : 
     122      514436 : SwParaPortion *SwTxtFrm::GetPara()
     123             : {
     124      514436 :     if ( GetCacheIdx() != MSHRT_MAX )
     125             :     {   SwTxtLine *pLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
     126      432102 :                                         Get( this, GetCacheIdx(), false );
     127      432102 :         if ( pLine )
     128      432032 :             return pLine->GetPara();
     129             :         else
     130          70 :             nCacheIdx = MSHRT_MAX;
     131             :     }
     132       82404 :     return 0;
     133             : }
     134             : 
     135             : /*************************************************************************
     136             : |*
     137             : |*  SwTxtFrm::ClearPara()
     138             : |*
     139             : |*************************************************************************/
     140             : 
     141       33651 : void SwTxtFrm::ClearPara()
     142             : {
     143             :     OSL_ENSURE( !IsLocked(), "+SwTxtFrm::ClearPara: this is locked." );
     144       33651 :     if ( !IsLocked() && GetCacheIdx() != MSHRT_MAX )
     145             :     {
     146             :         SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
     147       23886 :                                         Get( this, GetCacheIdx(), false );
     148       23886 :         if ( pTxtLine )
     149             :         {
     150       19192 :             delete pTxtLine->GetPara();
     151       19192 :             pTxtLine->SetPara( 0 );
     152             :         }
     153             :         else
     154        4694 :             nCacheIdx = MSHRT_MAX;
     155             :     }
     156       33651 : }
     157             : 
     158             : /*************************************************************************
     159             : |*
     160             : |*  SwTxtFrm::SetPara()
     161             : |*
     162             : |*************************************************************************/
     163             : 
     164        4439 : void SwTxtFrm::SetPara( SwParaPortion *pNew, bool bDelete )
     165             : {
     166        4439 :     if ( GetCacheIdx() != MSHRT_MAX )
     167             :     {
     168             :         // Only change the information, the CacheObj stays there
     169             :         SwTxtLine *pTxtLine = (SwTxtLine*)SwTxtFrm::GetTxtCache()->
     170        3220 :                                         Get( this, GetCacheIdx(), false );
     171        3220 :         if ( pTxtLine )
     172             :         {
     173        3220 :             if( bDelete )
     174        2240 :                 delete pTxtLine->GetPara();
     175        3220 :             pTxtLine->SetPara( pNew );
     176             :         }
     177             :         else
     178             :         {
     179             :             OSL_ENSURE( !pNew, "+SetPara: Losing SwParaPortion" );
     180           0 :             nCacheIdx = MSHRT_MAX;
     181             :         }
     182             :     }
     183        1219 :     else if ( pNew )
     184             :     {   // Insert a new one
     185        1219 :         SwTxtLine *pTxtLine = new SwTxtLine( this, pNew );
     186        1219 :         if ( SwTxtFrm::GetTxtCache()->Insert( pTxtLine ) )
     187        1219 :             nCacheIdx = pTxtLine->GetCachePos();
     188             :         else
     189             :         {
     190             :             OSL_FAIL( "+SetPara: InsertCache failed." );
     191             :         }
     192             :     }
     193        4439 : }
     194             : 
     195             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10