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 .
21 * This file is part of LibreOffice published API.
23 #ifndef INCLUDED_CPPUHELPER_INTERFACECONTAINER_HXX
24 #define INCLUDED_CPPUHELPER_INTERFACECONTAINER_HXX
26 #include "sal/config.h"
30 #include "cppuhelper/interfacecontainer.h"
36 template< class key
, class hashImpl
, class equalImpl
>
37 inline OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::OMultiTypeInterfaceContainerHelperVar( ::osl::Mutex
& rMutex_
)
40 m_pMap
= new InterfaceMap
;
44 template< class key
, class hashImpl
, class equalImpl
>
45 inline OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::~OMultiTypeInterfaceContainerHelperVar()
47 typename
InterfaceMap::iterator iter
= m_pMap
->begin();
48 typename
InterfaceMap::iterator end
= m_pMap
->end();
52 delete static_cast<OInterfaceContainerHelper
*>((*iter
).second
);
53 (*iter
).second
= NULL
;
60 template< class key
, class hashImpl
, class equalImpl
>
61 inline css::uno::Sequence
< key
> OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::getContainedTypes() const
63 ::osl::MutexGuard
aGuard( rMutex
);
64 typename
InterfaceMap::size_type nSize
= m_pMap
->size();
67 css::uno::Sequence
< key
> aInterfaceTypes( nSize
);
68 key
* pArray
= aInterfaceTypes
.getArray();
70 typename
InterfaceMap::iterator iter
= m_pMap
->begin();
71 typename
InterfaceMap::iterator end
= m_pMap
->end();
76 // are interfaces added to this container?
77 if( static_cast<OInterfaceContainerHelper
*>((*iter
).second
)->getLength() )
78 // yes, put the type in the array
79 pArray
[i
++] = (*iter
).first
;
83 // may be empty container, reduce the sequence to the right size
84 aInterfaceTypes
= css::uno::Sequence
<key
>( pArray
, i
);
86 return aInterfaceTypes
;
88 return css::uno::Sequence
<key
>();
92 template< class key
, class hashImpl
, class equalImpl
>
93 OInterfaceContainerHelper
* OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::getContainer(
94 const key
& rKey
) const
96 ::osl::MutexGuard
aGuard( rMutex
);
98 typename
InterfaceMap::iterator iter
= find( rKey
);
99 if( iter
!= m_pMap
->end() )
100 return static_cast<OInterfaceContainerHelper
*>( (*iter
).second
);
105 template< class key
, class hashImpl
, class equalImpl
>
106 sal_Int32 OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::addInterface(
108 const css::uno::Reference
< css::uno::XInterface
> & rListener
)
110 ::osl::MutexGuard
aGuard( rMutex
);
111 typename
InterfaceMap::iterator iter
= find( rKey
);
112 if( iter
== m_pMap
->end() )
114 OInterfaceContainerHelper
* pLC
= new OInterfaceContainerHelper( rMutex
);
115 m_pMap
->push_back(std::pair
<key
, void*>(rKey
, pLC
));
116 return pLC
->addInterface( rListener
);
119 return static_cast<OInterfaceContainerHelper
*>((*iter
).second
)->addInterface( rListener
);
123 template< class key
, class hashImpl
, class equalImpl
>
124 inline sal_Int32 OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::removeInterface(
126 const css::uno::Reference
< css::uno::XInterface
> & rListener
)
128 ::osl::MutexGuard
aGuard( rMutex
);
130 // search container with id nUik
131 typename
InterfaceMap::iterator iter
= find( rKey
);
133 if( iter
!= m_pMap
->end() )
134 return static_cast<OInterfaceContainerHelper
*>((*iter
).second
)->removeInterface( rListener
);
136 // no container with this id. Always return 0
141 template< class key
, class hashImpl
, class equalImpl
>
142 void OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::disposeAndClear(
143 const css::lang::EventObject
& rEvt
)
145 typename
InterfaceMap::size_type nSize
= 0;
146 OInterfaceContainerHelper
** ppListenerContainers
= NULL
;
148 ::osl::MutexGuard
aGuard( rMutex
);
149 nSize
= m_pMap
->size();
152 typedef OInterfaceContainerHelper
* ppp
;
153 ppListenerContainers
= new ppp
[nSize
];
155 typename
InterfaceMap::iterator iter
= m_pMap
->begin();
156 typename
InterfaceMap::iterator end
= m_pMap
->end();
158 typename
InterfaceMap::size_type i
= 0;
161 ppListenerContainers
[i
++] = static_cast<OInterfaceContainerHelper
*>((*iter
).second
);
167 // create a copy, because do not fire event in a guarded section
168 for( typename
InterfaceMap::size_type i
= 0; i
< nSize
; i
++ )
170 if( ppListenerContainers
[i
] )
171 ppListenerContainers
[i
]->disposeAndClear( rEvt
);
174 delete [] ppListenerContainers
;
178 template< class key
, class hashImpl
, class equalImpl
>
179 void OMultiTypeInterfaceContainerHelperVar
< key
, hashImpl
, equalImpl
>::clear()
181 ::osl::MutexGuard
aGuard( rMutex
);
182 typename
InterfaceMap::iterator iter
= m_pMap
->begin();
183 typename
InterfaceMap::iterator end
= m_pMap
->end();
187 static_cast<OInterfaceContainerHelper
*>((*iter
).second
)->clear();
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */