LCOV - code coverage report
Current view: top level - sd/source/core - shapelist.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 53 55 96.4 %
Date: 2014-11-03 Functions: 14 14 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 <svx/svdobj.hxx>
      21             : #include "shapelist.hxx"
      22             : 
      23             : #include <algorithm>
      24             : 
      25             : using namespace sd;
      26             : 
      27        3568 : ShapeList::ShapeList()
      28             : {
      29        3568 :     maIter = maShapeList.end();
      30        3568 : }
      31             : 
      32        7686 : ShapeList::~ShapeList()
      33             : {
      34        3568 :     clear();
      35        4118 : }
      36             : 
      37             : /** adds the given shape to this list */
      38       10656 : void ShapeList::addShape( SdrObject& rObject )
      39             : {
      40       10656 :     ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
      41       10656 :     if( aIter == maShapeList.end() )
      42             :     {
      43       10656 :         maShapeList.push_back(&rObject);
      44       10656 :         rObject.AddObjectUser( *this );
      45             :     }
      46             :     else
      47             :     {
      48             :         OSL_FAIL("sd::ShapeList::addShape(), given shape already part of list!");
      49             :     }
      50       10656 : }
      51             : 
      52             : /** removes the given shape from this list */
      53        2212 : SdrObject* ShapeList::removeShape( SdrObject& rObject )
      54             : {
      55        2212 :     ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
      56        2212 :     if( aIter != maShapeList.end() )
      57             :     {
      58        2210 :         bool bIterErased = aIter == maIter;
      59             : 
      60        2210 :         (*aIter)->RemoveObjectUser(*this);
      61        2210 :         aIter = maShapeList.erase( aIter );
      62             : 
      63        2210 :         if( bIterErased )
      64          35 :             maIter = aIter;
      65             : 
      66        2210 :         if( aIter != maShapeList.end() )
      67        1634 :             return (*aIter);
      68             :     }
      69             :     else
      70             :     {
      71             :         OSL_FAIL("sd::ShapeList::removeShape(), given shape not part of list!");
      72             :     }
      73         578 :     return 0;
      74             : }
      75             : 
      76             : /** removes all shapes from this list
      77             :     NOTE: iterators will become invalid */
      78        3568 : void ShapeList::clear()
      79             : {
      80        3568 :     ListImpl aShapeList;
      81        3568 :     aShapeList.swap( maShapeList );
      82             : 
      83        3568 :     ListImpl::iterator aIter( aShapeList.begin() );
      84        9332 :     while( aIter != aShapeList.end() )
      85        2196 :         (*aIter++)->RemoveObjectUser(*this);
      86             : 
      87        3568 :     maIter = aShapeList.end();
      88        3568 : }
      89             : 
      90             : /** returns true if this list is empty */
      91         560 : bool ShapeList::isEmpty() const
      92             : {
      93         560 :     return maShapeList.empty();
      94             : }
      95             : 
      96             : /** returns true if given shape is part of this list */
      97       29774 : bool ShapeList::hasShape( SdrObject& rObject ) const
      98             : {
      99       29774 :     return std::find( maShapeList.begin(), maShapeList.end(), &rObject )  != maShapeList.end();
     100             : }
     101             : 
     102        6250 : void ShapeList::ObjectInDestruction(const SdrObject& rObject)
     103             : {
     104        6250 :     ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
     105        6250 :     if( aIter != maShapeList.end() )
     106             :     {
     107        6250 :         bool bIterErased = aIter == maIter;
     108             : 
     109        6250 :         aIter = maShapeList.erase( aIter );
     110             : 
     111        6250 :         if( bIterErased )
     112           0 :             maIter = aIter;
     113             :     }
     114             :     else
     115             :     {
     116             :         OSL_FAIL("sd::ShapeList::ObjectInDestruction(), got a call from an unknown friend!");
     117             :     }
     118        6250 : }
     119             : 
     120       87464 : SdrObject* ShapeList::getNextShape()
     121             : {
     122       87464 :     if( maIter != maShapeList.end() )
     123             :     {
     124       67521 :         return (*maIter++);
     125             :     }
     126             :     else
     127             :     {
     128       19943 :         return 0;
     129             :     }
     130             : }
     131             : 
     132       20493 : void ShapeList::seekShape( sal_uInt32 nIndex )
     133             : {
     134       20493 :     maIter = maShapeList.begin();
     135       40986 :     while( nIndex-- && (maIter != maShapeList.end()) )
     136           0 :         maIter++;
     137       20493 : }
     138             : 
     139         109 : bool ShapeList::hasMore() const
     140             : {
     141         109 :     return maIter != maShapeList.end();
     142         114 : }
     143             : 
     144             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10