My Project
UDK 3.2.7 C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
interfacecontainer.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 #ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_
29 #define _CPPUHELPER_INTERFACECONTAINER_HXX_
30 
32 
33 
34 namespace cppu
35 {
36 
37 template< class key , class hashImpl , class equalImpl >
39  SAL_THROW(())
40  : rMutex( rMutex_ )
41 {
42  m_pMap = new InterfaceMap;
43 }
44 
45 //===================================================================
46 template< class key , class hashImpl , class equalImpl >
48  SAL_THROW(())
49 {
50  typename InterfaceMap::iterator iter = m_pMap->begin();
51  typename InterfaceMap::iterator end = m_pMap->end();
52 
53  while( iter != end )
54  {
55  delete (OInterfaceContainerHelper*)(*iter).second;
56  (*iter).second = 0;
57  ++iter;
58  }
59  delete m_pMap;
60 }
61 
62 //===================================================================
63 template< class key , class hashImpl , class equalImpl >
65  SAL_THROW(())
66 {
67  ::osl::MutexGuard aGuard( rMutex );
68  typename InterfaceMap::size_type nSize = m_pMap->size();
69  if( nSize != 0 )
70  {
71  ::com::sun::star::uno::Sequence< key > aInterfaceTypes( nSize );
72  key * pArray = aInterfaceTypes.getArray();
73 
74  typename InterfaceMap::iterator iter = m_pMap->begin();
75  typename InterfaceMap::iterator end = m_pMap->end();
76 
77  sal_uInt32 i = 0;
78  while( iter != end )
79  {
80  // are interfaces added to this container?
81  if( ((OInterfaceContainerHelper*)(*iter).second)->getLength() )
82  // yes, put the type in the array
83  pArray[i++] = (*iter).first;
84  iter++;
85  }
86  if( i != nSize ) {
87  // may be empty container, reduce the sequence to the right size
88  aInterfaceTypes = ::com::sun::star::uno::Sequence<key>( pArray, i );
89  }
90  return aInterfaceTypes;
91  }
92  return ::com::sun::star::uno::Sequence<key>();
93 }
94 
95 //===================================================================
96 template< class key , class hashImpl , class equalImpl >
98  const key & rKey ) const SAL_THROW(())
99 {
100  ::osl::MutexGuard aGuard( rMutex );
101 
102  typename InterfaceMap::iterator iter = find( rKey );
103  if( iter != m_pMap->end() )
104  return (OInterfaceContainerHelper*) (*iter).second;
105  return 0;
106 }
107 
108 //===================================================================
109 template< class key , class hashImpl , class equalImpl >
111  const key & rKey,
112  const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rListener )
113  SAL_THROW(())
114 {
115  ::osl::MutexGuard aGuard( rMutex );
116  typename InterfaceMap::iterator iter = find( rKey );
117  if( iter == m_pMap->end() )
118  {
120  m_pMap->push_back(std::pair<key, void*>(rKey, pLC));
121  return pLC->addInterface( rListener );
122  }
123  else
124  return ((OInterfaceContainerHelper*)(*iter).second)->addInterface( rListener );
125 }
126 
127 //===================================================================
128 template< class key , class hashImpl , class equalImpl >
130  const key & rKey,
131  const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rListener )
132  SAL_THROW(())
133 {
134  ::osl::MutexGuard aGuard( rMutex );
135 
136  // search container with id nUik
137  typename InterfaceMap::iterator iter = find( rKey );
138  // container found?
139  if( iter != m_pMap->end() )
140  return ((OInterfaceContainerHelper*)(*iter).second)->removeInterface( rListener );
141 
142  // no container with this id. Always return 0
143  return 0;
144 }
145 
146 //===================================================================
147 template< class key , class hashImpl , class equalImpl >
149  const ::com::sun::star::lang::EventObject & rEvt )
150  SAL_THROW(())
151 {
152  typename InterfaceMap::size_type nSize = 0;
153  OInterfaceContainerHelper ** ppListenerContainers = NULL;
154  {
155  ::osl::MutexGuard aGuard( rMutex );
156  nSize = m_pMap->size();
157  if( nSize )
158  {
159  typedef OInterfaceContainerHelper* ppp;
160  ppListenerContainers = new ppp[nSize];
161 
162  typename InterfaceMap::iterator iter = m_pMap->begin();
163  typename InterfaceMap::iterator end = m_pMap->end();
164 
165  typename InterfaceMap::size_type i = 0;
166  while( iter != end )
167  {
168  ppListenerContainers[i++] = (OInterfaceContainerHelper*)(*iter).second;
169  ++iter;
170  }
171  }
172  }
173 
174  // create a copy, because do not fire event in a guarded section
175  for( typename InterfaceMap::size_type i = 0; i < nSize; i++ )
176  {
177  if( ppListenerContainers[i] )
178  ppListenerContainers[i]->disposeAndClear( rEvt );
179  }
180 
181  delete [] ppListenerContainers;
182 }
183 
184 //===================================================================
185 template< class key , class hashImpl , class equalImpl >
187 {
188  ::osl::MutexGuard aGuard( rMutex );
189  typename InterfaceMap::iterator iter = m_pMap->begin();
190  typename InterfaceMap::iterator end = m_pMap->end();
191 
192  while( iter != end )
193  {
194  ((OInterfaceContainerHelper*)(*iter).second)->clear();
195  ++iter;
196  }
197 }
198 
199 
200 }
201 
202 #endif
203 
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */