1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_
20 #define _CPPUHELPER_INTERFACECONTAINER_HXX_
22 #include <cppuhelper/interfacecontainer.h>
28 template< class key
, class hashImpl
, class equalImpl
>
29 inline OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::OMultiTypeInterfaceContainerHelperVar( ::osl::Mutex
& rMutex_
)
33 m_pMap
= new InterfaceMap
;
36 //===================================================================
37 template< class key
, class hashImpl
, class equalImpl
>
38 inline OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::~OMultiTypeInterfaceContainerHelperVar()
41 typename
InterfaceMap::iterator iter
= m_pMap
->begin();
42 typename
InterfaceMap::iterator end
= m_pMap
->end();
46 delete (OInterfaceContainerHelper
*)(*iter
).second
;
53 //===================================================================
54 template< class key
, class hashImpl
, class equalImpl
>
55 inline ::com::sun::star::uno::Sequence
< key
> OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::getContainedTypes() const
58 ::osl::MutexGuard
aGuard( rMutex
);
59 typename
InterfaceMap::size_type nSize
= m_pMap
->size();
62 ::com::sun::star::uno::Sequence
< key
> aInterfaceTypes( nSize
);
63 key
* pArray
= aInterfaceTypes
.getArray();
65 typename
InterfaceMap::iterator iter
= m_pMap
->begin();
66 typename
InterfaceMap::iterator end
= m_pMap
->end();
71 // are interfaces added to this container?
72 if( ((OInterfaceContainerHelper
*)(*iter
).second
)->getLength() )
73 // yes, put the type in the array
74 pArray
[i
++] = (*iter
).first
;
78 // may be empty container, reduce the sequence to the right size
79 aInterfaceTypes
= ::com::sun::star::uno::Sequence
<key
>( pArray
, i
);
81 return aInterfaceTypes
;
83 return ::com::sun::star::uno::Sequence
<key
>();
86 //===================================================================
87 template< class key
, class hashImpl
, class equalImpl
>
88 OInterfaceContainerHelper
* OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::getContainer(
89 const key
& rKey
) const SAL_THROW(())
91 ::osl::MutexGuard
aGuard( rMutex
);
93 typename
InterfaceMap::iterator iter
= find( rKey
);
94 if( iter
!= m_pMap
->end() )
95 return (OInterfaceContainerHelper
*) (*iter
).second
;
99 //===================================================================
100 template< class key
, class hashImpl
, class equalImpl
>
101 sal_Int32 OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::addInterface(
103 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> & rListener
)
106 ::osl::MutexGuard
aGuard( rMutex
);
107 typename
InterfaceMap::iterator iter
= find( rKey
);
108 if( iter
== m_pMap
->end() )
110 OInterfaceContainerHelper
* pLC
= new OInterfaceContainerHelper( rMutex
);
111 m_pMap
->push_back(std::pair
<key
, void*>(rKey
, pLC
));
112 return pLC
->addInterface( rListener
);
115 return ((OInterfaceContainerHelper
*)(*iter
).second
)->addInterface( rListener
);
118 //===================================================================
119 template< class key
, class hashImpl
, class equalImpl
>
120 inline sal_Int32 OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::removeInterface(
122 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> & rListener
)
125 ::osl::MutexGuard
aGuard( rMutex
);
127 // search container with id nUik
128 typename
InterfaceMap::iterator iter
= find( rKey
);
130 if( iter
!= m_pMap
->end() )
131 return ((OInterfaceContainerHelper
*)(*iter
).second
)->removeInterface( rListener
);
133 // no container with this id. Always return 0
137 //===================================================================
138 template< class key
, class hashImpl
, class equalImpl
>
139 void OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::disposeAndClear(
140 const ::com::sun::star::lang::EventObject
& rEvt
)
143 typename
InterfaceMap::size_type nSize
= 0;
144 OInterfaceContainerHelper
** ppListenerContainers
= NULL
;
146 ::osl::MutexGuard
aGuard( rMutex
);
147 nSize
= m_pMap
->size();
150 typedef OInterfaceContainerHelper
* ppp
;
151 ppListenerContainers
= new ppp
[nSize
];
153 typename
InterfaceMap::iterator iter
= m_pMap
->begin();
154 typename
InterfaceMap::iterator end
= m_pMap
->end();
156 typename
InterfaceMap::size_type i
= 0;
159 ppListenerContainers
[i
++] = (OInterfaceContainerHelper
*)(*iter
).second
;
165 // create a copy, because do not fire event in a guarded section
166 for( typename
InterfaceMap::size_type i
= 0; i
< nSize
; i
++ )
168 if( ppListenerContainers
[i
] )
169 ppListenerContainers
[i
]->disposeAndClear( rEvt
);
172 delete [] ppListenerContainers
;
175 //===================================================================
176 template< class key
, class hashImpl
, class equalImpl
>
177 void OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::clear() SAL_THROW(())
179 ::osl::MutexGuard
aGuard( rMutex
);
180 typename
InterfaceMap::iterator iter
= m_pMap
->begin();
181 typename
InterfaceMap::iterator end
= m_pMap
->end();
185 ((OInterfaceContainerHelper
*)(*iter
).second
)->clear();
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */