Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/comphelper/source/property/ChainablePropertySet.cxx
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
#include <comphelper/ChainablePropertySet.hxx>
21
#include <comphelper/ChainablePropertySetInfo.hxx>
22
#include <comphelper/solarmutex.hxx>
23
24
25
#include <optional>
26
27
using namespace ::comphelper;
28
using namespace ::com::sun::star;
29
using namespace ::com::sun::star::uno;
30
using namespace ::com::sun::star::lang;
31
using namespace ::com::sun::star::beans;
32
33
ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo* pInfo, comphelper::SolarMutex* pMutex )
34
    noexcept
35
29.0k
: mpMutex ( pMutex )
36
29.0k
, mxInfo ( pInfo )
37
29.0k
{
38
29.0k
}
39
40
ChainablePropertySet::~ChainablePropertySet()
41
    noexcept
42
29.0k
{
43
29.0k
}
44
45
// XPropertySet
46
Reference< XPropertySetInfo > SAL_CALL ChainablePropertySet::getPropertySetInfo(  )
47
0
{
48
0
    return mxInfo;
49
0
}
50
51
void SAL_CALL ChainablePropertySet::setPropertyValue( const OUString& rPropertyName, const Any& rValue )
52
112
{
53
    // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
54
112
    std::optional< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
55
112
    if (mpMutex)
56
112
        xMutexGuard.emplace( mpMutex );
57
58
112
    PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
59
60
112
    if( aIter == mxInfo->maMap.end())
61
0
        throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
62
63
112
    _preSetValues();
64
112
    _setSingleValue( *((*aIter).second), rValue );
65
112
    _postSetValues();
66
112
}
67
68
Any SAL_CALL ChainablePropertySet::getPropertyValue( const OUString& rPropertyName )
69
7.87k
{
70
    // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
71
7.87k
    std::optional< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
72
7.87k
    if (mpMutex)
73
7.87k
        xMutexGuard.emplace( mpMutex );
74
75
7.87k
    PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
76
77
7.87k
    if( aIter == mxInfo->maMap.end())
78
0
        throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
79
80
7.87k
    Any aAny;
81
7.87k
    _preGetValues ();
82
7.87k
    _getSingleValue( *((*aIter).second), aAny );
83
7.87k
    _postGetValues ();
84
85
7.87k
    return aAny;
86
7.87k
}
87
88
void SAL_CALL ChainablePropertySet::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
89
0
{
90
    // todo
91
0
}
92
93
void SAL_CALL ChainablePropertySet::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
94
0
{
95
    // todo
96
0
}
97
98
void SAL_CALL ChainablePropertySet::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
99
0
{
100
    // todo
101
0
}
102
103
void SAL_CALL ChainablePropertySet::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
104
0
{
105
    // todo
106
0
}
107
108
// XMultiPropertySet
109
void SAL_CALL ChainablePropertySet::setPropertyValues(const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rValues)
110
0
{
111
    // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
112
0
    std::optional< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
113
0
    if (mpMutex)
114
0
        xMutexGuard.emplace( mpMutex );
115
116
0
    const sal_Int32 nCount = rPropertyNames.getLength();
117
118
0
    if( nCount != rValues.getLength() )
119
0
        throw IllegalArgumentException(u"lengths do not match"_ustr, static_cast<cppu::OWeakObject*>(this), -1);
120
121
0
    if( !nCount )
122
0
        return;
123
124
0
    _preSetValues();
125
126
0
    for (sal_Int32 i = 0; i < nCount; ++i)
127
0
    {
128
0
        auto aIter = mxInfo->maMap.find(rPropertyNames[i]);
129
0
        if (aIter == mxInfo->maMap.end())
130
0
            throw RuntimeException(rPropertyNames[i], static_cast<XPropertySet*>(this));
131
132
0
        _setSingleValue(*((*aIter).second), rValues[i]);
133
0
    }
134
135
0
    _postSetValues();
136
0
}
137
138
Sequence< Any > SAL_CALL ChainablePropertySet::getPropertyValues(const Sequence< OUString >& rPropertyNames)
139
0
{
140
    // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
141
0
    std::optional< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
142
0
    if (mpMutex)
143
0
        xMutexGuard.emplace( mpMutex );
144
145
0
    const sal_Int32 nCount = rPropertyNames.getLength();
146
147
0
    Sequence < Any > aValues ( nCount );
148
149
0
    if( nCount )
150
0
    {
151
0
        _preGetValues();
152
153
0
        Any * pAny = aValues.getArray();
154
0
        for (sal_Int32 i = 0; i < nCount; ++i)
155
0
        {
156
0
            auto aIter = mxInfo->maMap.find(rPropertyNames[i]);
157
0
            if (aIter == mxInfo->maMap.end())
158
0
                throw RuntimeException(rPropertyNames[i], static_cast<XPropertySet*>(this));
159
160
0
            _getSingleValue(*((*aIter).second), pAny[i]);
161
0
        }
162
163
0
        _postGetValues();
164
0
    }
165
0
    return aValues;
166
0
}
167
168
void SAL_CALL ChainablePropertySet::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
169
0
{
170
    // todo
171
0
}
172
173
void SAL_CALL ChainablePropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
174
0
{
175
    // todo
176
0
}
177
178
void SAL_CALL ChainablePropertySet::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
179
0
{
180
    // todo
181
0
}
182
183
// XPropertyState
184
PropertyState SAL_CALL ChainablePropertySet::getPropertyState( const OUString& PropertyName )
185
0
{
186
0
    PropertyInfoHash::const_iterator aIter =  mxInfo->maMap.find( PropertyName );
187
0
    if( aIter == mxInfo->maMap.end())
188
0
        throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
189
190
0
    return PropertyState_AMBIGUOUS_VALUE;
191
0
}
192
193
Sequence< PropertyState > SAL_CALL ChainablePropertySet::getPropertyStates( const Sequence< OUString >& rPropertyNames )
194
0
{
195
0
    const sal_Int32 nCount = rPropertyNames.getLength();
196
197
0
    Sequence< PropertyState > aStates( nCount );
198
0
    if( nCount )
199
0
    {
200
0
        PropertyState * pState = aStates.getArray();
201
0
        PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
202
203
0
        for (sal_Int32 i = 0; i < nCount; ++i)
204
0
        {
205
0
            aIter = mxInfo->maMap.find(rPropertyNames[i]);
206
0
            if ( aIter == aEnd )
207
0
                throw UnknownPropertyException(rPropertyNames[i], static_cast<XPropertySet*>(this));
208
209
0
            pState[i] = PropertyState_AMBIGUOUS_VALUE;
210
0
        }
211
0
    }
212
0
    return aStates;
213
0
}
214
215
void SAL_CALL ChainablePropertySet::setPropertyToDefault( const OUString& rPropertyName )
216
0
{
217
0
    PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
218
219
0
    if( aIter == mxInfo->maMap.end())
220
0
        throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
221
0
}
222
223
Any SAL_CALL ChainablePropertySet::getPropertyDefault( const OUString& rPropertyName )
224
0
{
225
0
    PropertyInfoHash::const_iterator aIter = mxInfo->maMap.find ( rPropertyName );
226
227
0
    if( aIter == mxInfo->maMap.end())
228
0
        throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
229
0
    return Any();
230
0
}
231
232
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */