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

Generated by: LCOV version 1.11