LCOV - code coverage report
Current view: top level - libreoffice/sd/source/core - shapelist.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 44 64 68.8 %
Date: 2012-12-17 Functions: 8 13 61.5 %
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         272 : ShapeList::ShapeList()
      28             : {
      29         272 :     maIter = maShapeList.end();
      30         272 : }
      31             : 
      32         496 : ShapeList::~ShapeList()
      33             : {
      34         248 :     clear();
      35         248 : }
      36             : 
      37             : /** adds the given shape to this list */
      38         930 : void ShapeList::addShape( SdrObject& rObject )
      39             : {
      40         930 :     ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
      41         930 :     if( aIter == maShapeList.end() )
      42             :     {
      43         930 :         maShapeList.push_back(&rObject);
      44         930 :         rObject.AddObjectUser( *this );
      45             :     }
      46             :     else
      47             :     {
      48             :         OSL_FAIL("sd::ShapeList::addShape(), given shape already part of list!");
      49             :     }
      50         930 : }
      51             : 
      52             : /** removes the given shape from this list */
      53         204 : SdrObject* ShapeList::removeShape( SdrObject& rObject )
      54             : {
      55         204 :     ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
      56         204 :     if( aIter != maShapeList.end() )
      57             :     {
      58         204 :         bool bIterErased = aIter == maIter;
      59             : 
      60         204 :         (*aIter)->RemoveObjectUser(*this);
      61         204 :         aIter = maShapeList.erase( aIter );
      62             : 
      63         204 :         if( bIterErased )
      64           0 :             maIter = aIter;
      65             : 
      66         204 :         if( aIter != maShapeList.end() )
      67         144 :             return (*aIter);
      68             :     }
      69             :     else
      70             :     {
      71             :         OSL_FAIL("sd::ShapeList::removeShape(), given shape not part of list!");
      72             :     }
      73          60 :     return 0;
      74             : }
      75             : 
      76             : /** removes all shapes from this list
      77             :     NOTE: iterators will become invalid */
      78         248 : void ShapeList::clear()
      79             : {
      80         248 :     ListImpl aShapeList;
      81         248 :     aShapeList.swap( maShapeList );
      82             : 
      83         248 :     ListImpl::iterator aIter( aShapeList.begin() );
      84        1128 :     while( aIter != aShapeList.end() )
      85         632 :         (*aIter++)->RemoveObjectUser(*this);
      86             : 
      87         248 :     maIter = aShapeList.end();
      88         248 : }
      89             : 
      90             : /** returns true if this list is empty */
      91          16 : bool ShapeList::isEmpty() const
      92             : {
      93          16 :     return maShapeList.empty();
      94             : }
      95             : 
      96             : /** returns true if given shape is part of this list */
      97        2684 : bool ShapeList::hasShape( SdrObject& rObject ) const
      98             : {
      99        2684 :     return std::find( maShapeList.begin(), maShapeList.end(), &rObject )  != maShapeList.end();
     100             : }
     101             : 
     102        8200 : SdrObject* ShapeList::getNextShape(SdrObject* pObj) const
     103             : {
     104        8200 :     if( pObj )
     105             :     {
     106        6412 :         ListImpl::const_iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), pObj ) );
     107        6412 :         if( aIter != maShapeList.end() )
     108             :         {
     109        6412 :             ++aIter;
     110        6412 :             if( aIter != maShapeList.end() )
     111             :             {
     112        4874 :                 return (*aIter);
     113             :             }
     114             :         }
     115             :     }
     116        1788 :     else if( !maShapeList.empty() )
     117             :     {
     118        1538 :         return (*maShapeList.begin());
     119             :     }
     120             : 
     121        1788 :     return 0;
     122             : }
     123             : 
     124           0 : void ShapeList::ObjectInDestruction(const SdrObject& rObject)
     125             : {
     126           0 :     ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
     127           0 :     if( aIter != maShapeList.end() )
     128             :     {
     129           0 :         bool bIterErased = aIter == maIter;
     130             : 
     131           0 :         aIter = maShapeList.erase( aIter );
     132             : 
     133           0 :         if( bIterErased )
     134           0 :             maIter = aIter;
     135             :     }
     136             :     else
     137             :     {
     138             :         OSL_FAIL("sd::ShapeList::ObjectInDestruction(), got a call from an unknown friend!");
     139             :     }
     140           0 : }
     141             : 
     142           0 : SdrObject* ShapeList::getNextShape()
     143             : {
     144           0 :     if( maIter != maShapeList.end() )
     145             :     {
     146           0 :         return (*maIter++);
     147             :     }
     148             :     else
     149             :     {
     150           0 :         return 0;
     151             :     }
     152             : }
     153             : 
     154           0 : void ShapeList::seekShape( sal_uInt32 nIndex )
     155             : {
     156           0 :     maIter = maShapeList.begin();
     157           0 :     while( nIndex-- && (maIter != maShapeList.end()) )
     158           0 :         maIter++;
     159           0 : }
     160             : 
     161           0 : bool ShapeList::hasMore() const
     162             : {
     163           0 :     return maIter != maShapeList.end();
     164             : }
     165             : 
     166             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10