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

Generated by: LCOV version 1.11