LibreOffice: cppuhelper/interfacecontainer.hxx Source File

LibreOffice LibreOffice 5.2 SDK C/C++ API Reference

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

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 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19 #ifndef INCLUDED_CPPUHELPER_INTERFACECONTAINER_HXX
20 #define INCLUDED_CPPUHELPER_INTERFACECONTAINER_HXX
21
22 #include <sal/config.h>
23
24 #include <cstddef>
25
26 #include <cppuhelper/interfacecontainer.h>
27
28
29 namespace cppu
30 {
31
32 template< class key , class hashImpl , class equalImpl >
33 inline OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::OMultiTypeInterfaceContainerHelperVar( ::osl::Mutex & rMutex_ )
34 : rMutex( rMutex_ )
35 {
36 m_pMap = new InterfaceMap;
37 }
38
39
40 template< class key , class hashImpl , class equalImpl >
41 inline OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::~OMultiTypeInterfaceContainerHelperVar()
42 {
43 typename InterfaceMap::iterator iter = m_pMap->begin();
44 typename InterfaceMap::iterator end = m_pMap->end();
45
46 while( iter != end )
47 {
48 delete static_cast<OInterfaceContainerHelper*>((*iter).second);
49 (*iter).second = 0;
50 ++iter;
51 }
52 delete m_pMap;
53 }
54
55
56 template< class key , class hashImpl , class equalImpl >
57 inline css::uno::Sequence< key > OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::getContainedTypes() const
58 {
59 ::osl::MutexGuard aGuard( rMutex );
60 typename InterfaceMap::size_type nSize = m_pMap->size();
61 if( nSize != 0 )
62 {
63 css::uno::Sequence< key > aInterfaceTypes( nSize );
64 key * pArray = aInterfaceTypes.getArray();
65
66 typename InterfaceMap::iterator iter = m_pMap->begin();
67 typename InterfaceMap::iterator end = m_pMap->end();
68
69 sal_uInt32 i = 0;
70 while( iter != end )
71 {
72 // are interfaces added to this container?
73 if( static_cast<OInterfaceContainerHelper*>((*iter).second)->getLength() )
74 // yes, put the type in the array
75 pArray[i++] = (*iter).first;
76 ++iter;
77 }
78 if( i != nSize ) {
79 // may be empty container, reduce the sequence to the right size
80 aInterfaceTypes = css::uno::Sequence<key>( pArray, i );
81 }
82 return aInterfaceTypes;
83 }
84 return css::uno::Sequence<key>();
85 }
86
87
88 template< class key , class hashImpl , class equalImpl >
89 OInterfaceContainerHelper * OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::getContainer(
90 const key & rKey ) const
91 {
92 ::osl::MutexGuard aGuard( rMutex );
93
94 typename InterfaceMap::iterator iter = find( rKey );
95 if( iter != m_pMap->end() )
96 return static_cast<OInterfaceContainerHelper*>( (*iter).second );
97 return NULL;
98 }
99
100
101 template< class key , class hashImpl , class equalImpl >
102 sal_Int32 OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::addInterface(
103 const key & rKey,
104 const css::uno::Reference< css::uno::XInterface > & rListener )
105 {
106 ::osl::MutexGuard aGuard( rMutex );
107 typename InterfaceMap::iterator iter = find( rKey );
108 if( iter == m_pMap->end() )
109 {
110 OInterfaceContainerHelper * pLC = new OInterfaceContainerHelper( rMutex );
111 m_pMap->push_back(std::pair<key, void*>(rKey, pLC));
112 return pLC->addInterface( rListener );
113 }
114 else
115 return static_cast<OInterfaceContainerHelper*>((*iter).second)->addInterface( rListener );
116 }
117
118
119 template< class key , class hashImpl , class equalImpl >
120 inline sal_Int32 OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::removeInterface(
121 const key & rKey,
122 const css::uno::Reference< css::uno::XInterface > & rListener )
123 {
124 ::osl::MutexGuard aGuard( rMutex );
125
126 // search container with id nUik
127 typename InterfaceMap::iterator iter = find( rKey );
128 // container found?
129 if( iter != m_pMap->end() )
130 return static_cast<OInterfaceContainerHelper*>((*iter).second)->removeInterface( rListener );
131
132 // no container with this id. Always return 0
133 return 0;
134 }
135
136
137 template< class key , class hashImpl , class equalImpl >
138 void OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::disposeAndClear(
139 const css::lang::EventObject & rEvt )
140 {
141 typename InterfaceMap::size_type nSize = 0;
142 OInterfaceContainerHelper ** ppListenerContainers = NULL;
143 {
144 ::osl::MutexGuard aGuard( rMutex );
145 nSize = m_pMap->size();
146 if( nSize )
147 {
148 typedef OInterfaceContainerHelper* ppp;
149 ppListenerContainers = new ppp[nSize];
150
151 typename InterfaceMap::iterator iter = m_pMap->begin();
152 typename InterfaceMap::iterator end = m_pMap->end();
153
154 typename InterfaceMap::size_type i = 0;
155 while( iter != end )
156 {
157 ppListenerContainers[i++] = static_cast<OInterfaceContainerHelper*>((*iter).second);
158 ++iter;
159 }
160 }
161 }
162
163 // create a copy, because do not fire event in a guarded section
164 for( typename InterfaceMap::size_type i = 0; i < nSize; i++ )
165 {
166 if( ppListenerContainers[i] )
167 ppListenerContainers[i]->disposeAndClear( rEvt );
168 }
169
170 delete [] ppListenerContainers;
171 }
172
173
174 template< class key , class hashImpl , class equalImpl >
175 void OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::clear()
176 {
177 ::osl::MutexGuard aGuard( rMutex );
178 typename InterfaceMap::iterator iter = m_pMap->begin();
179 typename InterfaceMap::iterator end = m_pMap->end();
180
181 while( iter != end )
182 {
183 static_cast<OInterfaceContainerHelper*>((*iter).second)->clear();
184 ++iter;
185 }
186 }
187
188
189 }
190
191 #endif
192
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
cppu::OMultiTypeInterfaceContainerHelperVar::disposeAndClear
void disposeAndClear(const css::lang::EventObject &rEvt)
Call disposing on all references in the container, that support XEventListener.
Definition: interfacecontainer.hxx:138
interfacecontainer.h
cppu::OInterfaceContainerHelper::disposeAndClear
void disposeAndClear(const css::lang::EventObject &rEvt)
Call disposing on all object in the container that support XEventListener.
cppu
Definition: Enterable.hxx:26
cppu::OMultiTypeInterfaceContainerHelperVar::~OMultiTypeInterfaceContainerHelperVar
~OMultiTypeInterfaceContainerHelperVar()
Deletes all containers.
Definition: interfacecontainer.hxx:41
config.h
osl::Mutex
A mutual exclusion synchronization object.
Definition: mutex.hxx:30
cppu::OMultiTypeInterfaceContainerHelperVar::addInterface
sal_Int32 addInterface(const key &rKey, const css::uno::Reference< css::uno::XInterface > &r)
Inserts an element into the container with the specified key.
Definition: interfacecontainer.hxx:102
cppu::OMultiTypeInterfaceContainerHelperVar::OMultiTypeInterfaceContainerHelperVar
OMultiTypeInterfaceContainerHelperVar(::osl::Mutex &rMutex)
Create a container of interface containers.
Definition: interfacecontainer.hxx:33
cppu::OMultiTypeInterfaceContainerHelperVar::getContainer
OInterfaceContainerHelper * getContainer(const key &) const
Return the container created under this key.
Definition: interfacecontainer.hxx:89
cppu::OInterfaceContainerHelper::addInterface
sal_Int32 addInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
Inserts an element into the container.
cppu::OMultiTypeInterfaceContainerHelperVar::clear
void clear()
Remove all elements of all containers.
Definition: interfacecontainer.hxx:175
cppu::OInterfaceContainerHelper
A container of interfaces.
Definition: interfacecontainer.h:127
osl::Guard
A helper class for mutex objects and interfaces.
Definition: mutex.hxx:108
cppu::OMultiTypeInterfaceContainerHelperVar::removeInterface
sal_Int32 removeInterface(const key &rKey, const css::uno::Reference< css::uno::XInterface > &rxIFace)
Removes an element from the container with the specified key.
Definition: interfacecontainer.hxx:120
cppu::OMultiTypeInterfaceContainerHelperVar::getContainedTypes
css::uno::Sequence< key > getContainedTypes() const
Return all id&#39;s under which at least one interface is added.
Definition: interfacecontainer.hxx:57