LCOV - code coverage report
Current view: top level - sd/source/ui/unoidl - unowcntr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 40 42 95.2 %
Date: 2012-08-25 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 38 66 57.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <com/sun/star/lang/XComponent.hpp>
      30                 :            : 
      31                 :            : #include <unowcntr.hxx>
      32                 :            : 
      33                 :            : using namespace ::rtl;
      34                 :            : using namespace ::com::sun::star;
      35                 :            : 
      36                 :         27 : SvUnoWeakContainer::SvUnoWeakContainer() throw()
      37                 :            : {
      38                 :         27 : }
      39                 :            : 
      40                 :         27 : SvUnoWeakContainer::~SvUnoWeakContainer() throw()
      41                 :            : {
      42         [ +  + ]:         60 :     for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); ++it )
      43 [ +  - ][ +  - ]:         33 :             delete *it;
      44                 :         27 :     maList.clear();
      45                 :         27 : }
      46                 :            : 
      47                 :            : /** inserts the given ref into this container */
      48                 :        125 : void SvUnoWeakContainer::insert( uno::WeakReference< uno::XInterface > xRef ) throw()
      49                 :            : {
      50         [ +  + ]:        137 :     for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); )
      51                 :            :     {
      52                 :         12 :         uno::WeakReference< uno::XInterface >* pRef = *it;
      53         [ +  - ]:         12 :         uno::Reference< uno::XInterface > xTestRef( *pRef );
      54         [ -  + ]:         12 :         if ( !xTestRef.is() )
      55                 :            :         {
      56 [ #  # ][ #  # ]:          0 :             delete pRef;
      57         [ #  # ]:          0 :             it = maList.erase( it );
      58                 :            :         }
      59                 :            :         else
      60                 :            :         {
      61 [ +  - ][ -  + ]:         12 :             if ( *pRef == xRef )
      62                 :        125 :                 return;
      63                 :         12 :             ++it;
      64                 :            :         }
      65         [ +  - ]:         12 :     }
      66 [ +  - ][ +  - ]:        125 :     maList.push_back( new uno::WeakReference< uno::XInterface >( xRef ) );
      67                 :            : }
      68                 :            : 
      69                 :            : /** searches the container for a ref that returns true on the given
      70                 :            :     search function
      71                 :            : */
      72                 :        129 : sal_Bool SvUnoWeakContainer::findRef(
      73                 :            :     uno::WeakReference< uno::XInterface >& rRef,
      74                 :            :     void* pSearchData,
      75                 :            :     weakref_searchfunc pSearchFunc
      76                 :            : )
      77                 :            : {
      78         [ +  + ]:        239 :     for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); )
      79                 :            :     {
      80                 :        114 :         uno::WeakReference< uno::XInterface >* pRef = *it;
      81         [ +  - ]:        114 :         uno::Reference< uno::XInterface > xTestRef( *pRef );
      82         [ +  + ]:        114 :         if ( !xTestRef.is() )
      83                 :            :         {
      84 [ +  - ][ +  - ]:         92 :             delete pRef;
      85         [ +  - ]:         92 :             it = maList.erase( it );
      86                 :            :         }
      87                 :            :         else
      88                 :            :         {
      89 [ +  - ][ +  - ]:         22 :             if( (*pSearchFunc)( *pRef, pSearchData ) )
         [ +  - ][ +  + ]
      90                 :            :             {
      91         [ +  - ]:          4 :                 rRef = *pRef;
      92                 :          4 :                 return sal_True;
      93                 :            :             }
      94                 :        110 :             ++it;
      95                 :            :         }
      96         [ +  + ]:        114 :     }
      97                 :        129 :     return sal_False;
      98                 :            : }
      99                 :            : 
     100                 :         27 : void SvUnoWeakContainer::dispose()
     101                 :            : {
     102         [ +  + ]:         60 :     for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); ++it )
     103                 :            :     {
     104                 :         33 :         uno::WeakReference< uno::XInterface >* pRef = *it;
     105         [ +  - ]:         33 :         uno::Reference< uno::XInterface > xTestRef( *pRef );
     106         [ +  + ]:         33 :         if ( xTestRef.is() )
     107                 :            :         {
     108         [ +  - ]:         10 :             uno::Reference< lang::XComponent > xComp( xTestRef, uno::UNO_QUERY );
     109         [ +  - ]:         10 :             if( xComp.is() )
     110 [ +  - ][ +  - ]:         10 :                 xComp->dispose();
     111                 :            :         }
     112                 :         33 :     }
     113                 :         27 : }
     114                 :            : 
     115                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10