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

Generated by: LCOV version 1.10