LCOV - code coverage report
Current view: top level - sd/source/core - shapelist.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 54 64 84.4 %
Date: 2012-08-25 Functions: 12 13 92.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 51 110 46.4 %

           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                 :            : 
      29                 :            : #include <svx/svdobj.hxx>
      30                 :            : #include "shapelist.hxx"
      31                 :            : 
      32                 :            : #include <algorithm>
      33                 :            : 
      34                 :            : using namespace sd;
      35                 :            : 
      36 [ +  - ][ +  - ]:       1444 : ShapeList::ShapeList()
      37                 :            : {
      38                 :       1444 :     maIter = maShapeList.end();
      39                 :       1444 : }
      40                 :            : 
      41                 :       1426 : ShapeList::~ShapeList()
      42                 :            : {
      43         [ +  - ]:       1426 :     clear();
      44         [ -  + ]:       1842 : }
      45                 :            : 
      46                 :            : /** adds the given shape to this list */
      47                 :       3441 : void ShapeList::addShape( SdrObject& rObject )
      48                 :            : {
      49         [ +  - ]:       3441 :     ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
      50 [ +  - ][ +  - ]:       3441 :     if( aIter == maShapeList.end() )
      51                 :            :     {
      52         [ +  - ]:       3441 :         maShapeList.push_back(&rObject);
      53         [ +  - ]:       3441 :         rObject.AddObjectUser( *this );
      54                 :            :     }
      55                 :            :     else
      56                 :            :     {
      57                 :            :         OSL_FAIL("sd::ShapeList::addShape(), given shape already part of list!");
      58                 :            :     }
      59                 :       3441 : }
      60                 :            : 
      61                 :            : /** removes the given shape from this list */
      62                 :        390 : SdrObject* ShapeList::removeShape( SdrObject& rObject )
      63                 :            : {
      64         [ +  - ]:        390 :     ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
      65 [ +  - ][ +  - ]:        390 :     if( aIter != maShapeList.end() )
      66                 :            :     {
      67         [ +  - ]:        390 :         bool bIterErased = aIter == maIter;
      68                 :            : 
      69 [ +  - ][ +  - ]:        390 :         (*aIter)->RemoveObjectUser(*this);
      70         [ +  - ]:        390 :         aIter = maShapeList.erase( aIter );
      71                 :            : 
      72         [ -  + ]:        390 :         if( bIterErased )
      73                 :          0 :             maIter = aIter;
      74                 :            : 
      75 [ +  - ][ +  + ]:        390 :         if( aIter != maShapeList.end() )
      76         [ +  - ]:        290 :             return (*aIter);
      77                 :            :     }
      78                 :            :     else
      79                 :            :     {
      80                 :            :         OSL_FAIL("sd::ShapeList::removeShape(), given shape not part of list!");
      81                 :            :     }
      82                 :        390 :     return 0;
      83                 :            : }
      84                 :            : 
      85                 :            : /** removes all shapes from this list
      86                 :            :     NOTE: iterators will become invalid */
      87                 :       1426 : void ShapeList::clear()
      88                 :            : {
      89         [ +  - ]:       1426 :     ListImpl aShapeList;
      90         [ +  - ]:       1426 :     aShapeList.swap( maShapeList );
      91                 :            : 
      92                 :       1426 :     ListImpl::iterator aIter( aShapeList.begin() );
      93 [ +  - ][ +  + ]:       4405 :     while( aIter != aShapeList.end() )
      94 [ +  - ][ +  - ]:       2979 :         (*aIter++)->RemoveObjectUser(*this);
                 [ +  - ]
      95                 :            : 
      96                 :       1426 :     maIter = aShapeList.end();
      97                 :       1426 : }
      98                 :            : 
      99                 :            : /** returns true if this list is empty */
     100                 :        148 : bool ShapeList::isEmpty() const
     101                 :            : {
     102                 :        148 :     return maShapeList.empty();
     103                 :            : }
     104                 :            : 
     105                 :            : /** returns true if given shape is part of this list */
     106                 :       9850 : bool ShapeList::hasShape( SdrObject& rObject ) const
     107                 :            : {
     108 [ +  - ][ +  - ]:       9850 :     return std::find( maShapeList.begin(), maShapeList.end(), &rObject )  != maShapeList.end();
     109                 :            : }
     110                 :            : 
     111                 :      11287 : SdrObject* ShapeList::getNextShape(SdrObject* pObj) const
     112                 :            : {
     113         [ +  + ]:      11287 :     if( pObj )
     114                 :            :     {
     115         [ +  - ]:       7860 :         ListImpl::const_iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), pObj ) );
     116 [ +  - ][ +  - ]:       7860 :         if( aIter != maShapeList.end() )
     117                 :            :         {
     118         [ +  - ]:       7860 :             ++aIter;
     119 [ +  - ][ +  + ]:       7860 :             if( aIter != maShapeList.end() )
     120                 :            :             {
     121         [ +  - ]:       7860 :                 return (*aIter);
     122                 :            :             }
     123                 :            :         }
     124                 :            :     }
     125         [ +  + ]:       3427 :     else if( !maShapeList.empty() )
     126                 :            :     {
     127         [ +  - ]:       1915 :         return (*maShapeList.begin());
     128                 :            :     }
     129                 :            : 
     130                 :      11287 :     return 0;
     131                 :            : }
     132                 :            : 
     133                 :          0 : void ShapeList::ObjectInDestruction(const SdrObject& rObject)
     134                 :            : {
     135         [ #  # ]:          0 :     ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
     136 [ #  # ][ #  # ]:          0 :     if( aIter != maShapeList.end() )
     137                 :            :     {
     138         [ #  # ]:          0 :         bool bIterErased = aIter == maIter;
     139                 :            : 
     140         [ #  # ]:          0 :         aIter = maShapeList.erase( aIter );
     141                 :            : 
     142         [ #  # ]:          0 :         if( bIterErased )
     143                 :          0 :             maIter = aIter;
     144                 :            :     }
     145                 :            :     else
     146                 :            :     {
     147                 :            :         OSL_FAIL("sd::ShapeList::ObjectInDestruction(), got a call from an unknown friend!");
     148                 :            :     }
     149                 :          0 : }
     150                 :            : 
     151                 :        209 : SdrObject* ShapeList::getNextShape()
     152                 :            : {
     153 [ +  - ][ +  - ]:        209 :     if( maIter != maShapeList.end() )
     154                 :            :     {
     155         [ +  - ]:        209 :         return (*maIter++);
     156                 :            :     }
     157                 :            :     else
     158                 :            :     {
     159                 :        209 :         return 0;
     160                 :            :     }
     161                 :            : }
     162                 :            : 
     163                 :        416 : void ShapeList::seekShape( sal_uInt32 nIndex )
     164                 :            : {
     165                 :        416 :     maIter = maShapeList.begin();
     166 [ -  + ][ #  # ]:        416 :     while( nIndex-- && (maIter != maShapeList.end()) )
         [ #  # ][ -  + ]
           [ -  +  #  # ]
     167                 :          0 :         maIter++;
     168                 :        416 : }
     169                 :            : 
     170                 :        306 : bool ShapeList::hasMore() const
     171                 :            : {
     172         [ +  - ]:        306 :     return maIter != maShapeList.end();
     173                 :            : }
     174                 :            : 
     175                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10