LCOV - code coverage report
Current view: top level - include/cppuhelper - interfacecontainer.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 52 69 75.4 %
Date: 2014-11-03 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      306449 : inline OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::OMultiTypeInterfaceContainerHelperVar( ::osl::Mutex & rMutex_ )
      30      306449 :     : rMutex( rMutex_ )
      31             : {
      32      306449 :     m_pMap = new InterfaceMap;
      33      306449 : }
      34             : 
      35             : 
      36             : template< class key , class hashImpl , class equalImpl >
      37      305751 : inline OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::~OMultiTypeInterfaceContainerHelperVar()
      38             : {
      39      305751 :     typename InterfaceMap::iterator iter = m_pMap->begin();
      40      305751 :     typename InterfaceMap::iterator end = m_pMap->end();
      41             : 
      42      749505 :     while( iter != end )
      43             :     {
      44      138003 :         delete static_cast<OInterfaceContainerHelper*>((*iter).second);
      45      138003 :         (*iter).second = 0;
      46      138003 :         ++iter;
      47             :     }
      48      305751 :     delete m_pMap;
      49      305751 : }
      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      818009 : OInterfaceContainerHelper * OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::getContainer(
      86             :     const key & rKey ) const
      87             : {
      88      818009 :     ::osl::MutexGuard aGuard( rMutex );
      89             : 
      90      818009 :      typename InterfaceMap::iterator iter = find( rKey );
      91      818009 :     if( iter != m_pMap->end() )
      92       21986 :             return static_cast<OInterfaceContainerHelper*>( (*iter).second );
      93      796023 :     return 0;
      94             : }
      95             : 
      96             : 
      97             : template< class key , class hashImpl , class equalImpl >
      98      172654 : 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      172654 :     ::osl::MutexGuard aGuard( rMutex );
     103      172654 :     typename InterfaceMap::iterator iter = find( rKey );
     104      172654 :     if( iter == m_pMap->end() )
     105             :     {
     106      138018 :         OInterfaceContainerHelper * pLC = new OInterfaceContainerHelper( rMutex );
     107      138018 :         m_pMap->push_back(std::pair<key, void*>(rKey, pLC));
     108      138018 :         return pLC->addInterface( rListener );
     109             :     }
     110             :     else
     111       34636 :         return static_cast<OInterfaceContainerHelper*>((*iter).second)->addInterface( rListener );
     112             : }
     113             : 
     114             : 
     115             : template< class key , class hashImpl , class equalImpl >
     116      176757 : 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      176757 :     ::osl::MutexGuard aGuard( rMutex );
     121             : 
     122             :     // search container with id nUik
     123      176757 :     typename InterfaceMap::iterator iter = find( rKey );
     124             :     // container found?
     125      176757 :     if( iter != m_pMap->end() )
     126      172619 :         return static_cast<OInterfaceContainerHelper*>((*iter).second)->removeInterface( rListener );
     127             : 
     128             :     // no container with this id. Always return 0
     129        4138 :     return 0;
     130             : }
     131             : 
     132             : 
     133             : template< class key , class hashImpl , class equalImpl >
     134       15768 : void OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::disposeAndClear(
     135             :     const ::com::sun::star::lang::EventObject & rEvt )
     136             : {
     137       15768 :     typename InterfaceMap::size_type nSize = 0;
     138       15768 :     OInterfaceContainerHelper ** ppListenerContainers = NULL;
     139             :     {
     140       15768 :         ::osl::MutexGuard aGuard( rMutex );
     141       15768 :         nSize = m_pMap->size();
     142       15768 :         if( nSize )
     143             :         {
     144             :             typedef OInterfaceContainerHelper* ppp;
     145          34 :             ppListenerContainers = new ppp[nSize];
     146             : 
     147          34 :             typename InterfaceMap::iterator iter = m_pMap->begin();
     148          34 :             typename InterfaceMap::iterator end = m_pMap->end();
     149             : 
     150          34 :             typename InterfaceMap::size_type i = 0;
     151         262 :             while( iter != end )
     152             :             {
     153         194 :                 ppListenerContainers[i++] = static_cast<OInterfaceContainerHelper*>((*iter).second);
     154         194 :                 ++iter;
     155             :             }
     156       15768 :         }
     157             :     }
     158             : 
     159             :     // create a copy, because do not fire event in a guarded section
     160       15962 :     for( typename InterfaceMap::size_type i = 0; i < nSize; i++ )
     161             :     {
     162         194 :         if( ppListenerContainers[i] )
     163         194 :             ppListenerContainers[i]->disposeAndClear( rEvt );
     164             :     }
     165             : 
     166       15768 :     delete [] ppListenerContainers;
     167       15768 : }
     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.10