Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/cppuhelper/interfacecontainer.hxx
Line
Count
Source
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
20
/*
21
 * This file is part of LibreOffice published API.
22
 */
23
#ifndef INCLUDED_CPPUHELPER_INTERFACECONTAINER_HXX
24
#define INCLUDED_CPPUHELPER_INTERFACECONTAINER_HXX
25
26
#include "sal/config.h"
27
28
#include <cstddef>
29
30
#include "cppuhelper/interfacecontainer.h"
31
32
33
namespace cppu
34
{
35
36
template< class key , class hashImpl , class equalImpl >
37
inline OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::OMultiTypeInterfaceContainerHelperVar( ::osl::Mutex & rMutex_ )
38
0
    : rMutex( rMutex_ )
39
0
{
40
0
    m_pMap = new InterfaceMap;
41
0
}
42
43
44
template< class key , class hashImpl , class equalImpl >
45
inline OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::~OMultiTypeInterfaceContainerHelperVar()
46
0
{
47
0
    typename InterfaceMap::iterator iter = m_pMap->begin();
48
0
    typename InterfaceMap::iterator end = m_pMap->end();
49
50
0
    while( iter != end )
51
0
    {
52
0
        delete static_cast<OInterfaceContainerHelper*>((*iter).second);
53
0
        (*iter).second = NULL;
54
0
        ++iter;
55
0
    }
56
0
    delete m_pMap;
57
0
}
58
59
60
template< class key , class hashImpl , class equalImpl >
61
inline css::uno::Sequence< key > OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::getContainedTypes() const
62
{
63
    ::osl::MutexGuard aGuard( rMutex );
64
    typename InterfaceMap::size_type nSize = m_pMap->size();
65
    if( nSize != 0 )
66
    {
67
        css::uno::Sequence< key > aInterfaceTypes( nSize );
68
        key * pArray = aInterfaceTypes.getArray();
69
70
        typename InterfaceMap::iterator iter = m_pMap->begin();
71
        typename InterfaceMap::iterator end = m_pMap->end();
72
73
        sal_uInt32 i = 0;
74
        while( iter != end )
75
        {
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;
80
            ++iter;
81
        }
82
        if( i != nSize ) {
83
            // may be empty container, reduce the sequence to the right size
84
            aInterfaceTypes = css::uno::Sequence<key>( pArray, i );
85
        }
86
        return aInterfaceTypes;
87
    }
88
    return css::uno::Sequence<key>();
89
}
90
91
92
template< class key , class hashImpl , class equalImpl >
93
OInterfaceContainerHelper * OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::getContainer(
94
    const key & rKey ) const
95
0
{
96
0
    ::osl::MutexGuard aGuard( rMutex );
97
98
0
    typename InterfaceMap::iterator iter = find( rKey );
99
0
    if( iter != m_pMap->end() )
100
0
            return static_cast<OInterfaceContainerHelper*>( (*iter).second );
101
0
    return NULL;
102
0
}
103
104
105
template< class key , class hashImpl , class equalImpl >
106
sal_Int32 OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::addInterface(
107
    const key & rKey,
108
    const css::uno::Reference< css::uno::XInterface > & rListener )
109
0
{
110
0
    ::osl::MutexGuard aGuard( rMutex );
111
0
    typename InterfaceMap::iterator iter = find( rKey );
112
0
    if( iter == m_pMap->end() )
113
0
    {
114
0
        OInterfaceContainerHelper * pLC = new OInterfaceContainerHelper( rMutex );
115
0
        m_pMap->push_back(std::pair<key, void*>(rKey, pLC));
116
0
        return pLC->addInterface( rListener );
117
0
    }
118
0
    else
119
0
        return static_cast<OInterfaceContainerHelper*>((*iter).second)->addInterface( rListener );
120
0
}
121
122
123
template< class key , class hashImpl , class equalImpl >
124
inline sal_Int32 OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::removeInterface(
125
    const key & rKey,
126
    const css::uno::Reference< css::uno::XInterface > & rListener )
127
0
{
128
0
    ::osl::MutexGuard aGuard( rMutex );
129
130
    // search container with id nUik
131
0
    typename InterfaceMap::iterator iter = find( rKey );
132
    // container found?
133
0
    if( iter != m_pMap->end() )
134
0
        return static_cast<OInterfaceContainerHelper*>((*iter).second)->removeInterface( rListener );
135
136
    // no container with this id. Always return 0
137
0
    return 0;
138
0
}
139
140
141
template< class key , class hashImpl , class equalImpl >
142
void OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::disposeAndClear(
143
    const css::lang::EventObject & rEvt )
144
0
{
145
0
    typename InterfaceMap::size_type nSize = 0;
146
0
    OInterfaceContainerHelper ** ppListenerContainers = NULL;
147
0
    {
148
0
        ::osl::MutexGuard aGuard( rMutex );
149
0
        nSize = m_pMap->size();
150
0
        if( nSize )
151
0
        {
152
0
            typedef OInterfaceContainerHelper* ppp;
153
0
            ppListenerContainers = new ppp[nSize];
154
155
0
            typename InterfaceMap::iterator iter = m_pMap->begin();
156
0
            typename InterfaceMap::iterator end = m_pMap->end();
157
158
0
            typename InterfaceMap::size_type i = 0;
159
0
            while( iter != end )
160
0
            {
161
0
                ppListenerContainers[i++] = static_cast<OInterfaceContainerHelper*>((*iter).second);
162
0
                ++iter;
163
0
            }
164
0
        }
165
0
    }
166
167
    // create a copy, because do not fire event in a guarded section
168
0
    for( typename InterfaceMap::size_type i = 0; i < nSize; i++ )
169
0
    {
170
0
        if( ppListenerContainers[i] )
171
0
            ppListenerContainers[i]->disposeAndClear( rEvt );
172
0
    }
173
174
0
    delete [] ppListenerContainers;
175
0
}
176
177
178
template< class key , class hashImpl , class equalImpl >
179
void OMultiTypeInterfaceContainerHelperVar< key , hashImpl , equalImpl >::clear()
180
{
181
    ::osl::MutexGuard aGuard( rMutex );
182
    typename InterfaceMap::iterator iter = m_pMap->begin();
183
    typename InterfaceMap::iterator end = m_pMap->end();
184
185
    while( iter != end )
186
    {
187
        static_cast<OInterfaceContainerHelper*>((*iter).second)->clear();
188
        ++iter;
189
    }
190
}
191
192
193
}
194
195
#endif
196
197
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */