Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/svl/itemprop.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
#ifndef INCLUDED_SVL_ITEMPROP_HXX
20
#define INCLUDED_SVL_ITEMPROP_HXX
21
22
#include <comphelper/propertysetinfo.hxx>
23
#include <cppuhelper/implbase.hxx>
24
#include <rtl/ref.hxx>
25
#include <svl/svldllapi.h>
26
#include <o3tl/sorted_vector.hxx>
27
#include <span>
28
#include <string_view>
29
#include <utility>
30
31
class SfxItemSet;
32
33
namespace com::sun::star::beans { class XPropertySetInfo; }
34
namespace com::sun::star::beans { enum class PropertyState; }
35
36
// values from com/sun/star/beans/PropertyAttribute
37
2.46M
#define PROPERTY_NONE 0
38
39
/// map a property between beans::XPropertySet and SfxPoolItem
40
struct SfxItemPropertyMapEntry
41
{
42
    OUString                            aName; ///< name of property
43
    css::uno::Type                      aType; ///< UNO type of property
44
    sal_uInt16                          nWID;  ///< WhichId of SfxPoolItem
45
    /// flag bitmap, @see css::beans::PropertyAttribute
46
    sal_Int16                           nFlags;
47
    /// "member ID" to tell QueryValue/PutValue which property it is
48
    /// (when multiple properties map to the same nWID)
49
    sal_uInt8                           nMemberId;
50
    PropertyMoreFlags                   nMoreFlags;
51
52
    SfxItemPropertyMapEntry(OUString _aName, sal_uInt16 _nWID, css::uno::Type const & _rType,
53
                               sal_Int16 _nFlags, sal_uInt8 const _nMemberId, PropertyMoreFlags _nMoreFlags = PropertyMoreFlags::NONE)
54
2.57M
        : aName(std::move( _aName ))
55
2.57M
        , aType(     _rType )
56
2.57M
        , nWID(      _nWID )
57
2.57M
        , nFlags(    _nFlags )
58
2.57M
        , nMemberId( _nMemberId )
59
2.57M
        , nMoreFlags( _nMoreFlags )
60
2.57M
        {
61
2.57M
            assert(_nFlags <= 0x1ff );
62
2.57M
            assert( (_nMemberId & 0x40) == 0 );
63
            // Verify that if METRIC_ITEM is set, we are one of the types supported by
64
            // SvxUnoConvertToMM.
65
2.57M
            assert(!(_nMoreFlags & PropertyMoreFlags::METRIC_ITEM) ||
66
2.57M
                ( (aType.getTypeClass() == css::uno::TypeClass_BYTE)
67
2.57M
                  || (aType.getTypeClass() == css::uno::TypeClass_SHORT)
68
2.57M
                  || (aType.getTypeClass() == css::uno::TypeClass_UNSIGNED_SHORT)
69
2.57M
                  || (aType.getTypeClass() == css::uno::TypeClass_LONG)
70
2.57M
                  || (aType.getTypeClass() == css::uno::TypeClass_UNSIGNED_LONG)
71
2.57M
                ) );
72
2.57M
        }
73
};
74
75
struct SfxItemPropertyMapCompare
76
{
77
    bool operator() ( const SfxItemPropertyMapEntry * lhs, const SfxItemPropertyMapEntry * rhs ) const
78
7.74M
    {
79
7.74M
        return lhs->aName < rhs->aName;
80
7.74M
    }
81
};
82
class SVL_DLLPUBLIC SfxItemPropertyMap
83
{
84
    o3tl::sorted_vector< const SfxItemPropertyMapEntry*, SfxItemPropertyMapCompare > m_aMap;
85
    mutable css::uno::Sequence< css::beans::Property > m_aPropSeq;
86
public:
87
    SfxItemPropertyMap( std::span<const SfxItemPropertyMapEntry> pEntries );
88
    SfxItemPropertyMap( const SfxItemPropertyMap& rSource );
89
    ~SfxItemPropertyMap();
90
91
    const SfxItemPropertyMapEntry* getByName( std::u16string_view rName ) const;
92
    css::uno::Sequence< css::beans::Property > const & getProperties() const;
93
    /// @throws css::beans::UnknownPropertyException
94
    css::beans::Property getPropertyByName( const OUString & rName ) const;
95
    bool hasPropertyByName( std::u16string_view rName ) const;
96
97
10.9k
    const o3tl::sorted_vector< const SfxItemPropertyMapEntry*, SfxItemPropertyMapCompare >& getPropertyEntries() const { return m_aMap; }
98
};
99
100
class SfxItemPropertySetInfo;
101
class SVL_DLLPUBLIC SfxItemPropertySet final
102
{
103
    SfxItemPropertyMap                                        m_aMap;
104
    mutable rtl::Reference<SfxItemPropertySetInfo> m_xInfo;
105
106
public:
107
                            SfxItemPropertySet( std::span<const SfxItemPropertyMapEntry> pMap ) :
108
39.1k
                                m_aMap(pMap) {}
109
                            ~SfxItemPropertySet();
110
111
    /// @throws css::uno::RuntimeException
112
    static void getPropertyValue( const SfxItemPropertyMapEntry& rEntry,
113
                                          const SfxItemSet& rSet,
114
                                          css::uno::Any& rAny);
115
    /// @throws css::uno::RuntimeException
116
    /// @throws css::beans::UnknownPropertyException
117
    void getPropertyValue( const OUString &rName,
118
                                            const SfxItemSet& rSet,
119
                                            css::uno::Any& rAny) const;
120
    /// @throws css::uno::RuntimeException
121
    /// @throws css::beans::UnknownPropertyException
122
    css::uno::Any
123
        getPropertyValue( const OUString &rName,
124
                                            const SfxItemSet& rSet ) const;
125
    /// @param bIgnoreUnknownProperty if true, don't throw an exception when the property is not one we know about
126
    /// @throws css::uno::RuntimeException
127
    /// @throws css::lang::IllegalArgumentException
128
    static void setPropertyValue( const SfxItemPropertyMapEntry& rEntry,
129
                                          const css::uno::Any& aVal,
130
                                          SfxItemSet& rSet,
131
                                  bool bIgnoreUnknownProperty = false);
132
    /// @param bIgnoreUnknownProperty if true, don't throw an exception when the property is not one we know about
133
    /// @throws css::uno::RuntimeException
134
    /// @throws css::lang::IllegalArgumentException
135
    /// @throws css::beans::UnknownPropertyException
136
    void                  setPropertyValue( const OUString& rPropertyName,
137
                                            const css::uno::Any& aVal,
138
                                            SfxItemSet& rSet,
139
                                            bool bIgnoreUnknownProperty = false) const;
140
141
    /// @throws css::beans::UnknownPropertyException
142
    css::beans::PropertyState
143
        getPropertyState(const OUString& rName, const SfxItemSet& rSet)const;
144
    static css::beans::PropertyState
145
        getPropertyState(const SfxItemPropertyMapEntry& rEntry, const SfxItemSet& rSet)
146
                                    noexcept;
147
148
    rtl::Reference<SfxItemPropertySetInfo> const & getPropertySetInfo() const;
149
8.09M
    const SfxItemPropertyMap& getPropertyMap() const {return m_aMap;}
150
};
151
152
// workaround for incremental linking bugs in MSVC2015
153
class SAL_DLLPUBLIC_TEMPLATE SfxItemPropertySetInfo_Base : public cppu::WeakImplHelper< css::beans::XPropertySetInfo > {};
154
155
class SVL_DLLPUBLIC SfxItemPropertySetInfo final : public SfxItemPropertySetInfo_Base
156
{
157
    SfxItemPropertyMap m_aOwnMap;
158
159
public:
160
    SfxItemPropertySetInfo(const SfxItemPropertyMap &rMap );
161
    SfxItemPropertySetInfo(std::span<const SfxItemPropertyMapEntry> pEntries );
162
    virtual ~SfxItemPropertySetInfo() override;
163
164
    virtual css::uno::Sequence< css::beans::Property > SAL_CALL
165
        getProperties(  ) override;
166
167
    virtual css::beans::Property SAL_CALL
168
        getPropertyByName( const OUString& aName ) override;
169
170
    virtual sal_Bool SAL_CALL
171
        hasPropertyByName( const OUString& Name ) override;
172
173
};
174
175
struct SfxItemPropertyMapCompare2
176
{
177
    bool operator() ( const SfxItemPropertyMapEntry & lhs, const SfxItemPropertyMapEntry & rhs ) const
178
22.3M
    {
179
22.3M
        return lhs.aName < rhs.aName;
180
22.3M
    }
181
};
182
183
// workaround for incremental linking bugs in MSVC2015
184
class SAL_DLLPUBLIC_TEMPLATE SfxExtItemPropertySetInfo_Base : public cppu::WeakImplHelper< css::beans::XPropertySetInfo > {};
185
186
class SVL_DLLPUBLIC SfxExtItemPropertySetInfo final : public SfxExtItemPropertySetInfo_Base
187
{
188
public:
189
                            SfxExtItemPropertySetInfo(
190
                                std::span<const SfxItemPropertyMapEntry> pMap,
191
                                const css::uno::Sequence<css::beans::Property>& rPropSeq );
192
                            virtual ~SfxExtItemPropertySetInfo() override;
193
194
    virtual css::uno::Sequence< css::beans::Property > SAL_CALL
195
        getProperties(  ) override;
196
197
    virtual css::beans::Property SAL_CALL
198
        getPropertyByName( const OUString& aName ) override;
199
200
    virtual sal_Bool SAL_CALL
201
        hasPropertyByName( const OUString& Name ) override;
202
203
private:
204
    const SfxItemPropertyMapEntry* getByName( std::u16string_view rName ) const;
205
    o3tl::sorted_vector< SfxItemPropertyMapEntry, SfxItemPropertyMapCompare2 > maMap;
206
    mutable css::uno::Sequence< css::beans::Property > m_aPropSeq;
207
};
208
209
#endif
210
211
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */