Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/style/MultiPropertySetHelper.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
21
#include <MultiPropertySetHelper.hxx>
22
#include <com/sun/star/beans/XPropertySetInfo.hpp>
23
#include <com/sun/star/beans/XPropertySet.hpp>
24
#include <com/sun/star/beans/XMultiPropertySet.hpp>
25
26
#include <sal/log.hxx>
27
28
using ::com::sun::star::beans::XMultiPropertySet;
29
using ::com::sun::star::beans::XPropertySet;
30
using ::com::sun::star::beans::XPropertySetInfo;
31
using ::com::sun::star::uno::Any;
32
using ::com::sun::star::uno::Reference;
33
using ::com::sun::star::uno::UNO_QUERY;
34
35
36
MultiPropertySetHelper::MultiPropertySetHelper(
37
    std::span<const OUString> pNames ) :
38
4.43k
        pPropertyNames( pNames ),
39
4.43k
        pValues( nullptr )
40
4.43k
{
41
4.43k
}
42
43
44
MultiPropertySetHelper::~MultiPropertySetHelper()
45
4.43k
{
46
4.43k
    pValues = nullptr; // memory 'owned' by aValues
47
4.43k
}
48
49
50
void MultiPropertySetHelper::hasProperties(
51
    const Reference<XPropertySetInfo> & rInfo )
52
4.43k
{
53
4.43k
    SAL_WARN_IF( !rInfo.is(), "xmloff", "I'd really like an XPropertySetInfo here." );
54
55
    // allocate sequence index
56
4.43k
    if ( !pSequenceIndex )
57
4.43k
        pSequenceIndex.reset( new sal_Int16[pPropertyNames.size()] );
58
59
    // construct pSequenceIndex
60
4.43k
    sal_Int16 nNumberOfProperties = 0;
61
62
26.4k
    for( size_t i = 0; i < pPropertyNames.size(); i++ )
63
22.0k
    {
64
        // ask for property
65
22.0k
        bool bHasProperty =
66
22.0k
            rInfo->hasPropertyByName( pPropertyNames[i] );
67
68
        // set index and increment (if appropriate)
69
22.0k
        pSequenceIndex[i]= bHasProperty ? nNumberOfProperties : -1;
70
22.0k
        if ( bHasProperty )
71
4.43k
            nNumberOfProperties++;
72
22.0k
    }
73
74
    // construct property sequence from index array
75
4.43k
    if ( aPropertySequence.getLength() != nNumberOfProperties )
76
4.43k
        aPropertySequence.realloc( nNumberOfProperties );
77
4.43k
    OUString* pPropertySequence = aPropertySequence.getArray();
78
26.4k
    for( size_t i = 0; i < pPropertyNames.size(); i ++ )
79
22.0k
    {
80
22.0k
        sal_Int16 nIndex = pSequenceIndex[i];
81
22.0k
        if ( nIndex != -1 )
82
4.43k
            pPropertySequence[nIndex] = pPropertyNames[i];
83
22.0k
    }
84
4.43k
}
85
86
bool MultiPropertySetHelper::checkedProperties()
87
6.98k
{
88
6.98k
    return (nullptr != pSequenceIndex);
89
6.98k
}
90
91
92
void MultiPropertySetHelper::getValues(
93
    const Reference<XMultiPropertySet> & rMultiPropertySet )
94
2.36k
{
95
2.36k
    SAL_WARN_IF( !rMultiPropertySet.is(), "xmloff", "We need an XMultiPropertySet." );
96
97
2.36k
    aValues = rMultiPropertySet->getPropertyValues( aPropertySequence );
98
2.36k
    pValues = aValues.getConstArray();
99
2.36k
}
100
101
void MultiPropertySetHelper::getValues(
102
    const Reference<XPropertySet> & rPropertySet )
103
0
{
104
0
    SAL_WARN_IF( !rPropertySet.is(), "xmloff", "We need an XPropertySet." );
105
106
    // re-alloc aValues (if necessary) and fill with values from XPropertySet
107
0
    sal_Int16 nSupportedPropertiesCount =
108
0
        static_cast<sal_Int16>(aPropertySequence.getLength());
109
0
    if ( aValues.getLength() != nSupportedPropertiesCount )
110
0
        aValues.realloc( nSupportedPropertiesCount );
111
0
    Any* pMutableArray = aValues.getArray();
112
0
    for( sal_Int16 i = 0; i < nSupportedPropertiesCount; i++ )
113
0
    {
114
0
        pMutableArray[i] = rPropertySet->getPropertyValue(
115
0
            pPropertyNames[ pSequenceIndex[ i ] ] );
116
0
    }
117
118
    // re-establish pValues pointer
119
0
    pValues = aValues.getConstArray();
120
0
}
121
122
123
const Any& MultiPropertySetHelper::getValue( sal_Int16 nIndex,
124
                     const Reference< XPropertySet> & rPropSet,
125
                     bool bTryMulti )
126
2.36k
{
127
2.36k
    if( !pValues )
128
2.36k
    {
129
2.36k
        if( bTryMulti )
130
2.36k
        {
131
2.36k
            Reference < XMultiPropertySet > xMultiPropSet( rPropSet,
132
2.36k
                                                           UNO_QUERY );
133
2.36k
            if( xMultiPropSet.is() )
134
2.36k
                getValues( xMultiPropSet );
135
0
            else
136
0
                getValues( rPropSet );
137
2.36k
        }
138
0
        else
139
0
        {
140
0
            getValues( rPropSet );
141
0
        }
142
2.36k
    }
143
144
2.36k
    return getValue( nIndex );
145
2.36k
}
146
147
const Any& MultiPropertySetHelper::getValue( sal_Int16 nIndex,
148
                     const Reference< XMultiPropertySet> & rMultiPropSet )
149
0
{
150
0
    if( !pValues )
151
0
        getValues( rMultiPropSet );
152
153
0
    return getValue( nIndex );
154
0
}
155
156
// inline methods defined in header:
157
// inline Any& MultiPropertySetHelper::getValue( sal_Int16 nIndex )
158
// inline sal_Bool MultiPropertySetHelper::hasProperty( sal_Int16 nValueNo )
159
160
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */