LCOV - code coverage report
Current view: top level - sd/source/core - shapelist.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 45 54 83.3 %
Date: 2014-04-11 Functions: 11 12 91.7 %
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        1198 : ShapeList::ShapeList()
      28             : {
      29        1198 :     maIter = maShapeList.end();
      30        1198 : }
      31             : 
      32        2295 : ShapeList::~ShapeList()
      33             : {
      34        1046 :     clear();
      35        1249 : }
      36             : 
      37             : /** adds the given shape to this list */
      38        3354 : void ShapeList::addShape( SdrObject& rObject )
      39             : {
      40        3354 :     ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
      41        3354 :     if( aIter == maShapeList.end() )
      42             :     {
      43        3354 :         maShapeList.push_back(&rObject);
      44        3354 :         rObject.AddObjectUser( *this );
      45             :     }
      46             :     else
      47             :     {
      48             :         OSL_FAIL("sd::ShapeList::addShape(), given shape already part of list!");
      49             :     }
      50        3354 : }
      51             : 
      52             : /** removes the given shape from this list */
      53         692 : SdrObject* ShapeList::removeShape( SdrObject& rObject )
      54             : {
      55         692 :     ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
      56         692 :     if( aIter != maShapeList.end() )
      57             :     {
      58         692 :         bool bIterErased = aIter == maIter;
      59             : 
      60         692 :         (*aIter)->RemoveObjectUser(*this);
      61         692 :         aIter = maShapeList.erase( aIter );
      62             : 
      63         692 :         if( bIterErased )
      64          12 :             maIter = aIter;
      65             : 
      66         692 :         if( aIter != maShapeList.end() )
      67         546 :             return (*aIter);
      68             :     }
      69             :     else
      70             :     {
      71             :         OSL_FAIL("sd::ShapeList::removeShape(), given shape not part of list!");
      72             :     }
      73         146 :     return 0;
      74             : }
      75             : 
      76             : /** removes all shapes from this list
      77             :     NOTE: iterators will become invalid */
      78        1046 : void ShapeList::clear()
      79             : {
      80        1046 :     ListImpl aShapeList;
      81        1046 :     aShapeList.swap( maShapeList );
      82             : 
      83        1046 :     ListImpl::iterator aIter( aShapeList.begin() );
      84        4341 :     while( aIter != aShapeList.end() )
      85        2249 :         (*aIter++)->RemoveObjectUser(*this);
      86             : 
      87        1046 :     maIter = aShapeList.end();
      88        1046 : }
      89             : 
      90             : /** returns true if this list is empty */
      91         142 : bool ShapeList::isEmpty() const
      92             : {
      93         142 :     return maShapeList.empty();
      94             : }
      95             : 
      96             : /** returns true if given shape is part of this list */
      97       10769 : bool ShapeList::hasShape( SdrObject& rObject ) const
      98             : {
      99       10769 :     return std::find( maShapeList.begin(), maShapeList.end(), &rObject )  != maShapeList.end();
     100             : }
     101             : 
     102           0 : void ShapeList::ObjectInDestruction(const SdrObject& rObject)
     103             : {
     104           0 :     ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
     105           0 :     if( aIter != maShapeList.end() )
     106             :     {
     107           0 :         bool bIterErased = aIter == maIter;
     108             : 
     109           0 :         aIter = maShapeList.erase( aIter );
     110             : 
     111           0 :         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           0 : }
     119             : 
     120       26998 : SdrObject* ShapeList::getNextShape()
     121             : {
     122       26998 :     if( maIter != maShapeList.end() )
     123             :     {
     124       20907 :         return (*maIter++);
     125             :     }
     126             :     else
     127             :     {
     128        6091 :         return 0;
     129             :     }
     130             : }
     131             : 
     132        6300 : void ShapeList::seekShape( sal_uInt32 nIndex )
     133             : {
     134        6300 :     maIter = maShapeList.begin();
     135       12600 :     while( nIndex-- && (maIter != maShapeList.end()) )
     136           0 :         maIter++;
     137        6300 : }
     138             : 
     139         270 : bool ShapeList::hasMore() const
     140             : {
     141         270 :     return maIter != maShapeList.end();
     142             : }
     143             : 
     144             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10