LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/cppuhelper - interfacecontainer.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 51 68 75.0 %
Date: 2012-08-25 Functions: 32 77 41.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 58 130 44.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                 :            : #ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_
      29                 :            : #define _CPPUHELPER_INTERFACECONTAINER_HXX_
      30                 :            : 
      31                 :            : #include <cppuhelper/interfacecontainer.h>
      32                 :            : 
      33                 :            : 
      34                 :            : namespace cppu
      35                 :            : {
      36                 :            : 
      37                 :            : template< class key , class hashImpl , class equalImpl >
      38                 :     276930 : inline OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::OMultiTypeInterfaceContainerHelperVar( ::osl::Mutex & rMutex_ )
      39                 :            :     SAL_THROW(())
      40                 :     276930 :     : rMutex( rMutex_ )
      41                 :            : {
      42         [ +  - ]:     276930 :     m_pMap = new InterfaceMap;
      43                 :     276930 : }
      44                 :            : 
      45                 :            : //===================================================================
      46                 :            : template< class key , class hashImpl , class equalImpl >
      47                 :     275471 : inline OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::~OMultiTypeInterfaceContainerHelperVar()
      48                 :            :     SAL_THROW(())
      49                 :            : {
      50                 :     275471 :     typename InterfaceMap::iterator iter = m_pMap->begin();
      51                 :     275471 :     typename InterfaceMap::iterator end = m_pMap->end();
      52                 :            : 
      53 [ +  - ][ +  + ]:     375689 :     while( iter != end )
      54                 :            :     {
      55      [ +  +  - ]:     100218 :         delete (OInterfaceContainerHelper*)(*iter).second;
         [ +  - ][ +  - ]
      56         [ +  - ]:     100218 :         (*iter).second = 0;
      57         [ +  - ]:     100218 :         ++iter;
      58                 :            :     }
      59         [ +  - ]:     275471 :     delete m_pMap;
      60                 :     275471 : }
      61                 :            : 
      62                 :            : //===================================================================
      63                 :            : template< class key , class hashImpl , class equalImpl >
      64                 :          0 : inline ::com::sun::star::uno::Sequence< key > OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::getContainedTypes() const
      65                 :            :     SAL_THROW(())
      66                 :            : {
      67         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( rMutex );
      68                 :          0 :     typename InterfaceMap::size_type nSize = m_pMap->size();
      69         [ #  # ]:          0 :     if( nSize != 0 )
      70                 :            :     {
      71         [ #  # ]:          0 :         ::com::sun::star::uno::Sequence< key > aInterfaceTypes( nSize );
      72         [ #  # ]:          0 :         key * pArray = aInterfaceTypes.getArray();
      73                 :            : 
      74                 :          0 :         typename InterfaceMap::iterator iter = m_pMap->begin();
      75                 :          0 :         typename InterfaceMap::iterator end = m_pMap->end();
      76                 :            : 
      77                 :          0 :         sal_uInt32 i = 0;
      78 [ #  # ][ #  # ]:          0 :         while( iter != end )
      79                 :            :         {
      80                 :            :             // are interfaces added to this container?
      81 [ #  # ][ #  # ]:          0 :             if( ((OInterfaceContainerHelper*)(*iter).second)->getLength() )
      82                 :            :                 // yes, put the type in the array
      83                 :          0 :                 pArray[i++] = (*iter).first;
      84         [ #  # ]:          0 :             iter++;
      85                 :            :         }
      86         [ #  # ]:          0 :         if( i != nSize ) {
      87                 :            :             // may be empty container, reduce the sequence to the right size
      88 [ #  # ][ #  # ]:          0 :             aInterfaceTypes = ::com::sun::star::uno::Sequence<key>( pArray, i );
                 [ #  # ]
      89                 :            :         }
      90 [ #  # ][ #  # ]:          0 :         return aInterfaceTypes;
      91                 :            :     }
      92 [ #  # ][ #  # ]:          0 :     return ::com::sun::star::uno::Sequence<key>();
      93                 :            : }
      94                 :            : 
      95                 :            : //===================================================================
      96                 :            : template< class key , class hashImpl , class equalImpl >
      97                 :    1024065 : OInterfaceContainerHelper * OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::getContainer(
      98                 :            :     const key & rKey ) const SAL_THROW(())
      99                 :            : {
     100         [ +  - ]:    1024065 :     ::osl::MutexGuard aGuard( rMutex );
     101                 :            : 
     102         [ +  - ]:    1024065 :      typename InterfaceMap::iterator iter = find( rKey );
     103 [ +  - ][ +  + ]:    1024065 :     if( iter != m_pMap->end() )
     104         [ +  - ]:      53171 :             return (OInterfaceContainerHelper*) (*iter).second;
     105         [ +  - ]:    1024065 :     return 0;
     106                 :            : }
     107                 :            : 
     108                 :            : //===================================================================
     109                 :            : template< class key , class hashImpl , class equalImpl >
     110                 :     115438 : sal_Int32 OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::addInterface(
     111                 :            :     const key & rKey,
     112                 :            :     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rListener )
     113                 :            :     SAL_THROW(())
     114                 :            : {
     115         [ +  - ]:     115438 :     ::osl::MutexGuard aGuard( rMutex );
     116         [ +  - ]:     115438 :     typename InterfaceMap::iterator iter = find( rKey );
     117 [ +  - ][ +  + ]:     115438 :     if( iter == m_pMap->end() )
     118                 :            :     {
     119         [ +  - ]:     100228 :         OInterfaceContainerHelper * pLC = new OInterfaceContainerHelper( rMutex );
     120 [ +  - ][ +  - ]:     100228 :         m_pMap->push_back(std::pair<key, void*>(rKey, pLC));
     121 [ +  - ][ +  - ]:     100228 :         return pLC->addInterface( rListener );
     122                 :            :     }
     123                 :            :     else
     124      [ +  +  - ]:     115438 :         return ((OInterfaceContainerHelper*)(*iter).second)->addInterface( rListener );
         [ +  - ][ +  - ]
                 [ +  - ]
     125                 :            : }
     126                 :            : 
     127                 :            : //===================================================================
     128                 :            : template< class key , class hashImpl , class equalImpl >
     129                 :     118774 : inline sal_Int32 OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::removeInterface(
     130                 :            :     const key & rKey,
     131                 :            :     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rListener )
     132                 :            :     SAL_THROW(())
     133                 :            : {
     134         [ +  - ]:     118774 :     ::osl::MutexGuard aGuard( rMutex );
     135                 :            : 
     136                 :            :     // search container with id nUik
     137         [ +  - ]:     118774 :     typename InterfaceMap::iterator iter = find( rKey );
     138                 :            :     // container found?
     139 [ +  - ][ +  + ]:     118774 :     if( iter != m_pMap->end() )
     140      [ +  +  - ]:     115326 :         return ((OInterfaceContainerHelper*)(*iter).second)->removeInterface( rListener );
                 [ +  - ]
     141                 :            : 
     142                 :            :     // no container with this id. Always return 0
     143         [ +  - ]:     118774 :     return 0;
     144                 :            : }
     145                 :            : 
     146                 :            : //===================================================================
     147                 :            : template< class key , class hashImpl , class equalImpl >
     148                 :      25842 : void OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::disposeAndClear(
     149                 :            :     const ::com::sun::star::lang::EventObject & rEvt )
     150                 :            :     SAL_THROW(())
     151                 :            : {
     152                 :      25842 :     typename InterfaceMap::size_type nSize = 0;
     153                 :      25842 :     OInterfaceContainerHelper ** ppListenerContainers = NULL;
     154                 :            :     {
     155         [ +  - ]:      25842 :         ::osl::MutexGuard aGuard( rMutex );
     156                 :      25842 :         nSize = m_pMap->size();
     157         [ +  + ]:      25842 :         if( nSize )
     158                 :            :         {
     159                 :            :             typedef OInterfaceContainerHelper* ppp;
     160         [ +  - ]:         40 :             ppListenerContainers = new ppp[nSize];
     161                 :            : 
     162                 :         40 :             typename InterfaceMap::iterator iter = m_pMap->begin();
     163                 :         40 :             typename InterfaceMap::iterator end = m_pMap->end();
     164                 :            : 
     165                 :         40 :             typename InterfaceMap::size_type i = 0;
     166 [ +  - ][ +  + ]:        267 :             while( iter != end )
     167                 :            :             {
     168         [ +  - ]:        227 :                 ppListenerContainers[i++] = (OInterfaceContainerHelper*)(*iter).second;
     169      [ +  +  - ]:      26069 :                 ++iter;
                 [ +  - ]
     170                 :            :             }
     171                 :            :         }
     172                 :            :     }
     173                 :            : 
     174                 :            :     // create a copy, because do not fire event in a guarded section
     175         [ +  + ]:      26069 :     for( typename InterfaceMap::size_type i = 0; i < nSize; i++ )
     176                 :            :     {
     177         [ +  - ]:        227 :         if( ppListenerContainers[i] )
     178                 :        227 :             ppListenerContainers[i]->disposeAndClear( rEvt );
     179                 :            :     }
     180                 :            : 
     181         [ +  + ]:      25842 :     delete [] ppListenerContainers;
     182                 :      25842 : }
     183                 :            : 
     184                 :            : //===================================================================
     185                 :            : template< class key , class hashImpl , class equalImpl >
     186                 :            : void OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::clear() SAL_THROW(())
     187                 :            : {
     188                 :            :     ::osl::MutexGuard aGuard( rMutex );
     189                 :            :     typename InterfaceMap::iterator iter = m_pMap->begin();
     190                 :            :     typename InterfaceMap::iterator end = m_pMap->end();
     191                 :            : 
     192                 :            :     while( iter != end )
     193                 :            :     {
     194                 :            :         ((OInterfaceContainerHelper*)(*iter).second)->clear();
     195                 :            :         ++iter;
     196                 :            :     }
     197                 :            : }
     198                 :            : 
     199                 :            : 
     200                 :            : }
     201                 :            : 
     202                 :            : #endif
     203                 :            : 
     204                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10