|
UDK 3.2.7 C/C++ API Reference
|
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 /* 00003 * This file is part of the LibreOffice project. 00004 * 00005 * This Source Code Form is subject to the terms of the Mozilla Public 00006 * License, v. 2.0. If a copy of the MPL was not distributed with this 00007 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 00008 * 00009 * This file incorporates work covered by the following license notice: 00010 * 00011 * Licensed to the Apache Software Foundation (ASF) under one or more 00012 * contributor license agreements. See the NOTICE file distributed 00013 * with this work for additional information regarding copyright 00014 * ownership. The ASF licenses this file to you under the Apache 00015 * License, Version 2.0 (the "License"); you may not use this file 00016 * except in compliance with the License. You may obtain a copy of 00017 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 00018 */ 00019 #ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ 00020 #define _CPPUHELPER_INTERFACECONTAINER_HXX_ 00021 00022 #include <cppuhelper/interfacecontainer.h> 00023 00024 00025 namespace cppu 00026 { 00027 00028 template< class key , class hashImpl , class equalImpl > 00029 inline OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::OMultiTypeInterfaceContainerHelperVar( ::osl::Mutex & rMutex_ ) 00030 SAL_THROW(()) 00031 : rMutex( rMutex_ ) 00032 { 00033 m_pMap = new InterfaceMap; 00034 } 00035 00036 //=================================================================== 00037 template< class key , class hashImpl , class equalImpl > 00038 inline OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::~OMultiTypeInterfaceContainerHelperVar() 00039 SAL_THROW(()) 00040 { 00041 typename InterfaceMap::iterator iter = m_pMap->begin(); 00042 typename InterfaceMap::iterator end = m_pMap->end(); 00043 00044 while( iter != end ) 00045 { 00046 delete (OInterfaceContainerHelper*)(*iter).second; 00047 (*iter).second = 0; 00048 ++iter; 00049 } 00050 delete m_pMap; 00051 } 00052 00053 //=================================================================== 00054 template< class key , class hashImpl , class equalImpl > 00055 inline ::com::sun::star::uno::Sequence< key > OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::getContainedTypes() const 00056 SAL_THROW(()) 00057 { 00058 ::osl::MutexGuard aGuard( rMutex ); 00059 typename InterfaceMap::size_type nSize = m_pMap->size(); 00060 if( nSize != 0 ) 00061 { 00062 ::com::sun::star::uno::Sequence< key > aInterfaceTypes( nSize ); 00063 key * pArray = aInterfaceTypes.getArray(); 00064 00065 typename InterfaceMap::iterator iter = m_pMap->begin(); 00066 typename InterfaceMap::iterator end = m_pMap->end(); 00067 00068 sal_uInt32 i = 0; 00069 while( iter != end ) 00070 { 00071 // are interfaces added to this container? 00072 if( ((OInterfaceContainerHelper*)(*iter).second)->getLength() ) 00073 // yes, put the type in the array 00074 pArray[i++] = (*iter).first; 00075 iter++; 00076 } 00077 if( i != nSize ) { 00078 // may be empty container, reduce the sequence to the right size 00079 aInterfaceTypes = ::com::sun::star::uno::Sequence<key>( pArray, i ); 00080 } 00081 return aInterfaceTypes; 00082 } 00083 return ::com::sun::star::uno::Sequence<key>(); 00084 } 00085 00086 //=================================================================== 00087 template< class key , class hashImpl , class equalImpl > 00088 OInterfaceContainerHelper * OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::getContainer( 00089 const key & rKey ) const SAL_THROW(()) 00090 { 00091 ::osl::MutexGuard aGuard( rMutex ); 00092 00093 typename InterfaceMap::iterator iter = find( rKey ); 00094 if( iter != m_pMap->end() ) 00095 return (OInterfaceContainerHelper*) (*iter).second; 00096 return 0; 00097 } 00098 00099 //=================================================================== 00100 template< class key , class hashImpl , class equalImpl > 00101 sal_Int32 OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::addInterface( 00102 const key & rKey, 00103 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rListener ) 00104 SAL_THROW(()) 00105 { 00106 ::osl::MutexGuard aGuard( rMutex ); 00107 typename InterfaceMap::iterator iter = find( rKey ); 00108 if( iter == m_pMap->end() ) 00109 { 00110 OInterfaceContainerHelper * pLC = new OInterfaceContainerHelper( rMutex ); 00111 m_pMap->push_back(std::pair<key, void*>(rKey, pLC)); 00112 return pLC->addInterface( rListener ); 00113 } 00114 else 00115 return ((OInterfaceContainerHelper*)(*iter).second)->addInterface( rListener ); 00116 } 00117 00118 //=================================================================== 00119 template< class key , class hashImpl , class equalImpl > 00120 inline sal_Int32 OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::removeInterface( 00121 const key & rKey, 00122 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rListener ) 00123 SAL_THROW(()) 00124 { 00125 ::osl::MutexGuard aGuard( rMutex ); 00126 00127 // search container with id nUik 00128 typename InterfaceMap::iterator iter = find( rKey ); 00129 // container found? 00130 if( iter != m_pMap->end() ) 00131 return ((OInterfaceContainerHelper*)(*iter).second)->removeInterface( rListener ); 00132 00133 // no container with this id. Always return 0 00134 return 0; 00135 } 00136 00137 //=================================================================== 00138 template< class key , class hashImpl , class equalImpl > 00139 void OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::disposeAndClear( 00140 const ::com::sun::star::lang::EventObject & rEvt ) 00141 SAL_THROW(()) 00142 { 00143 typename InterfaceMap::size_type nSize = 0; 00144 OInterfaceContainerHelper ** ppListenerContainers = NULL; 00145 { 00146 ::osl::MutexGuard aGuard( rMutex ); 00147 nSize = m_pMap->size(); 00148 if( nSize ) 00149 { 00150 typedef OInterfaceContainerHelper* ppp; 00151 ppListenerContainers = new ppp[nSize]; 00152 00153 typename InterfaceMap::iterator iter = m_pMap->begin(); 00154 typename InterfaceMap::iterator end = m_pMap->end(); 00155 00156 typename InterfaceMap::size_type i = 0; 00157 while( iter != end ) 00158 { 00159 ppListenerContainers[i++] = (OInterfaceContainerHelper*)(*iter).second; 00160 ++iter; 00161 } 00162 } 00163 } 00164 00165 // create a copy, because do not fire event in a guarded section 00166 for( typename InterfaceMap::size_type i = 0; i < nSize; i++ ) 00167 { 00168 if( ppListenerContainers[i] ) 00169 ppListenerContainers[i]->disposeAndClear( rEvt ); 00170 } 00171 00172 delete [] ppListenerContainers; 00173 } 00174 00175 //=================================================================== 00176 template< class key , class hashImpl , class equalImpl > 00177 void OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::clear() SAL_THROW(()) 00178 { 00179 ::osl::MutexGuard aGuard( rMutex ); 00180 typename InterfaceMap::iterator iter = m_pMap->begin(); 00181 typename InterfaceMap::iterator end = m_pMap->end(); 00182 00183 while( iter != end ) 00184 { 00185 ((OInterfaceContainerHelper*)(*iter).second)->clear(); 00186 ++iter; 00187 } 00188 } 00189 00190 00191 } 00192 00193 #endif 00194 00195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1.7.3