LCOV - code coverage report
Current view: top level - sd/source/ui/unoidl - unowcntr.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 40 42 95.2 %
Date: 2014-11-03 Functions: 5 5 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 <com/sun/star/lang/XComponent.hpp>
      21             : 
      22             : #include <unowcntr.hxx>
      23             : 
      24             : using namespace ::com::sun::star;
      25             : 
      26          62 : SvUnoWeakContainer::SvUnoWeakContainer() throw()
      27             : {
      28          62 : }
      29             : 
      30         124 : SvUnoWeakContainer::~SvUnoWeakContainer() throw()
      31             : {
      32         130 :     for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); ++it )
      33          68 :             delete *it;
      34          62 :     maList.clear();
      35          62 : }
      36             : 
      37             : /** inserts the given ref into this container */
      38         300 : void SvUnoWeakContainer::insert( uno::WeakReference< uno::XInterface > xRef ) throw()
      39             : {
      40         612 :     for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); )
      41             :     {
      42          12 :         uno::WeakReference< uno::XInterface >* pRef = *it;
      43          12 :         uno::Reference< uno::XInterface > xTestRef( *pRef );
      44          12 :         if ( !xTestRef.is() )
      45             :         {
      46           0 :             delete pRef;
      47           0 :             it = maList.erase( it );
      48             :         }
      49             :         else
      50             :         {
      51          12 :             if ( *pRef == xRef )
      52         300 :                 return;
      53          12 :             ++it;
      54             :         }
      55          12 :     }
      56         300 :     maList.push_back( new uno::WeakReference< uno::XInterface >( xRef ) );
      57             : }
      58             : 
      59             : /** searches the container for a ref that returns true on the given
      60             :     search function
      61             : */
      62         304 : bool SvUnoWeakContainer::findRef(
      63             :     uno::WeakReference< uno::XInterface >& rRef,
      64             :     void* pSearchData,
      65             :     weakref_searchfunc pSearchFunc
      66             : )
      67             : {
      68         858 :     for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); )
      69             :     {
      70         254 :         uno::WeakReference< uno::XInterface >* pRef = *it;
      71         254 :         uno::Reference< uno::XInterface > xTestRef( *pRef );
      72         254 :         if ( !xTestRef.is() )
      73             :         {
      74         232 :             delete pRef;
      75         232 :             it = maList.erase( it );
      76             :         }
      77             :         else
      78             :         {
      79          22 :             if( (*pSearchFunc)( *pRef, pSearchData ) )
      80             :             {
      81           4 :                 rRef = *pRef;
      82           4 :                 return true;
      83             :             }
      84          18 :             ++it;
      85             :         }
      86         250 :     }
      87         300 :     return false;
      88             : }
      89             : 
      90          62 : void SvUnoWeakContainer::dispose()
      91             : {
      92         130 :     for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); ++it )
      93             :     {
      94          68 :         uno::WeakReference< uno::XInterface >* pRef = *it;
      95          68 :         uno::Reference< uno::XInterface > xTestRef( *pRef );
      96          68 :         if ( xTestRef.is() )
      97             :         {
      98          10 :             uno::Reference< lang::XComponent > xComp( xTestRef, uno::UNO_QUERY );
      99          10 :             if( xComp.is() )
     100          10 :                 xComp->dispose();
     101             :         }
     102          68 :     }
     103          62 : }
     104             : 
     105             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10