UDK 3.2.7 C/C++ API Reference
cppuhelper/interfacecontainer.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*************************************************************************
00003  *
00004  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00005  *
00006  * Copyright 2000, 2010 Oracle and/or its affiliates.
00007  *
00008  * OpenOffice.org - a multi-platform office productivity suite
00009  *
00010  * This file is part of OpenOffice.org.
00011  *
00012  * OpenOffice.org is free software: you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 3
00014  * only, as published by the Free Software Foundation.
00015  *
00016  * OpenOffice.org is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License version 3 for more details
00020  * (a copy is included in the LICENSE file that accompanied this code).
00021  *
00022  * You should have received a copy of the GNU Lesser General Public License
00023  * version 3 along with OpenOffice.org.  If not, see
00024  * <http://www.openoffice.org/license.html>
00025  * for a copy of the LGPLv3 License.
00026  *
00027  ************************************************************************/
00028 #ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_
00029 #define _CPPUHELPER_INTERFACECONTAINER_HXX_
00030 
00031 #include <cppuhelper/interfacecontainer.h>
00032 
00033 
00034 namespace cppu
00035 {
00036 
00037 template< class key , class hashImpl , class equalImpl >
00038 inline OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::OMultiTypeInterfaceContainerHelperVar( ::osl::Mutex & rMutex_ )
00039     SAL_THROW(())
00040     : rMutex( rMutex_ )
00041 {
00042     m_pMap = new InterfaceMap;
00043 }
00044 
00045 //===================================================================
00046 template< class key , class hashImpl , class equalImpl >
00047 inline OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::~OMultiTypeInterfaceContainerHelperVar()
00048     SAL_THROW(())
00049 {
00050     typename InterfaceMap::iterator iter = m_pMap->begin();
00051     typename InterfaceMap::iterator end = m_pMap->end();
00052 
00053     while( iter != end )
00054     {
00055         delete (OInterfaceContainerHelper*)(*iter).second;
00056         (*iter).second = 0;
00057         ++iter;
00058     }
00059     delete m_pMap;
00060 }
00061 
00062 //===================================================================
00063 template< class key , class hashImpl , class equalImpl >
00064 inline ::com::sun::star::uno::Sequence< key > OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::getContainedTypes() const
00065     SAL_THROW(())
00066 {
00067     ::osl::MutexGuard aGuard( rMutex );
00068     typename InterfaceMap::size_type nSize = m_pMap->size();
00069     if( nSize != 0 )
00070     {
00071         ::com::sun::star::uno::Sequence< key > aInterfaceTypes( nSize );
00072         key * pArray = aInterfaceTypes.getArray();
00073 
00074         typename InterfaceMap::iterator iter = m_pMap->begin();
00075         typename InterfaceMap::iterator end = m_pMap->end();
00076 
00077         sal_uInt32 i = 0;
00078         while( iter != end )
00079         {
00080             // are interfaces added to this container?
00081             if( ((OInterfaceContainerHelper*)(*iter).second)->getLength() )
00082                 // yes, put the type in the array
00083                 pArray[i++] = (*iter).first;
00084             iter++;
00085         }
00086         if( i != nSize ) {
00087             // may be empty container, reduce the sequence to the right size
00088             aInterfaceTypes = ::com::sun::star::uno::Sequence<key>( pArray, i );
00089         }
00090         return aInterfaceTypes;
00091     }
00092     return ::com::sun::star::uno::Sequence<key>();
00093 }
00094 
00095 //===================================================================
00096 template< class key , class hashImpl , class equalImpl >
00097 OInterfaceContainerHelper * OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::getContainer(
00098     const key & rKey ) const SAL_THROW(())
00099 {
00100     ::osl::MutexGuard aGuard( rMutex );
00101 
00102      typename InterfaceMap::iterator iter = find( rKey );
00103     if( iter != m_pMap->end() )
00104             return (OInterfaceContainerHelper*) (*iter).second;
00105     return 0;
00106 }
00107 
00108 //===================================================================
00109 template< class key , class hashImpl , class equalImpl >
00110 sal_Int32 OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::addInterface(
00111     const key & rKey,
00112     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rListener )
00113     SAL_THROW(())
00114 {
00115     ::osl::MutexGuard aGuard( rMutex );
00116     typename InterfaceMap::iterator iter = find( rKey );
00117     if( iter == m_pMap->end() )
00118     {
00119         OInterfaceContainerHelper * pLC = new OInterfaceContainerHelper( rMutex );
00120         m_pMap->push_back(std::pair<key, void*>(rKey, pLC));
00121         return pLC->addInterface( rListener );
00122     }
00123     else
00124         return ((OInterfaceContainerHelper*)(*iter).second)->addInterface( rListener );
00125 }
00126 
00127 //===================================================================
00128 template< class key , class hashImpl , class equalImpl >
00129 inline sal_Int32 OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::removeInterface(
00130     const key & rKey,
00131     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rListener )
00132     SAL_THROW(())
00133 {
00134     ::osl::MutexGuard aGuard( rMutex );
00135 
00136     // search container with id nUik
00137     typename InterfaceMap::iterator iter = find( rKey );
00138     // container found?
00139     if( iter != m_pMap->end() )
00140         return ((OInterfaceContainerHelper*)(*iter).second)->removeInterface( rListener );
00141 
00142     // no container with this id. Always return 0
00143     return 0;
00144 }
00145 
00146 //===================================================================
00147 template< class key , class hashImpl , class equalImpl >
00148 void OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::disposeAndClear(
00149     const ::com::sun::star::lang::EventObject & rEvt )
00150     SAL_THROW(())
00151 {
00152     typename InterfaceMap::size_type nSize = 0;
00153     OInterfaceContainerHelper ** ppListenerContainers = NULL;
00154     {
00155         ::osl::MutexGuard aGuard( rMutex );
00156         nSize = m_pMap->size();
00157         if( nSize )
00158         {
00159             typedef OInterfaceContainerHelper* ppp;
00160             ppListenerContainers = new ppp[nSize];
00161 
00162             typename InterfaceMap::iterator iter = m_pMap->begin();
00163             typename InterfaceMap::iterator end = m_pMap->end();
00164 
00165             typename InterfaceMap::size_type i = 0;
00166             while( iter != end )
00167             {
00168                 ppListenerContainers[i++] = (OInterfaceContainerHelper*)(*iter).second;
00169                 ++iter;
00170             }
00171         }
00172     }
00173 
00174     // create a copy, because do not fire event in a guarded section
00175     for( typename InterfaceMap::size_type i = 0; i < nSize; i++ )
00176     {
00177         if( ppListenerContainers[i] )
00178             ppListenerContainers[i]->disposeAndClear( rEvt );
00179     }
00180 
00181     delete [] ppListenerContainers;
00182 }
00183 
00184 //===================================================================
00185 template< class key , class hashImpl , class equalImpl >
00186 void OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::clear() SAL_THROW(())
00187 {
00188     ::osl::MutexGuard aGuard( rMutex );
00189     typename InterfaceMap::iterator iter = m_pMap->begin();
00190     typename InterfaceMap::iterator end = m_pMap->end();
00191 
00192     while( iter != end )
00193     {
00194         ((OInterfaceContainerHelper*)(*iter).second)->clear();
00195         ++iter;
00196     }
00197 }
00198 
00199 
00200 }
00201 
00202 #endif
00203 
00204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines