Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/include/comphelper/propertysetinfo.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
#ifndef INCLUDED_COMPHELPER_PROPERTYSETINFO_HXX
21
#define INCLUDED_COMPHELPER_PROPERTYSETINFO_HXX
22
23
#include <sal/config.h>
24
25
#include <com/sun/star/beans/XPropertySetInfo.hpp>
26
#include <cppuhelper/implbase.hxx>
27
#include <comphelper/comphelperdllapi.h>
28
#include <o3tl/typed_flags_set.hxx>
29
#include <span>
30
#include <unordered_map>
31
#include <utility>
32
33
enum class PropertyMoreFlags : sal_uInt8 {
34
    NONE            = 0x00,
35
    METRIC_ITEM     = 0x01,
36
};
37
namespace o3tl {
38
    template<> struct typed_flags<PropertyMoreFlags> : is_typed_flags<PropertyMoreFlags, 0x1> {};
39
}
40
41
namespace comphelper
42
{
43
44
struct PropertyMapEntry
45
{
46
    OUString       maName;
47
    css::uno::Type maType;
48
    sal_Int32      mnHandle;
49
    /// flag bitmap, @see css::beans::PropertyAttribute
50
    sal_Int16      mnAttributes;
51
    sal_uInt8      mnMemberId;
52
    PropertyMoreFlags mnMoreFlags;
53
54
    PropertyMapEntry(OUString _aName, sal_Int32 _nHandle, css::uno::Type const & _rType,
55
                     sal_Int16 _nAttributes, sal_uInt8 _nMemberId, PropertyMoreFlags _nMoreFlags = PropertyMoreFlags::NONE)
56
1.38k
        : maName(std::move( _aName ))
57
1.38k
        , maType( _rType )
58
1.38k
        , mnHandle( _nHandle )
59
1.38k
        , mnAttributes( _nAttributes )
60
1.38k
        , mnMemberId( _nMemberId )
61
1.38k
        , mnMoreFlags( _nMoreFlags )
62
1.38k
    {
63
1.38k
        assert(mnAttributes <= 0x1ff );
64
1.38k
        assert( (_nMemberId & 0x40) == 0 );
65
        // Verify that if METRIC_ITEM is set, we are one of the types supported by
66
        // SvxUnoConvertToMM.
67
1.38k
        assert(!(_nMoreFlags & PropertyMoreFlags::METRIC_ITEM) ||
68
1.38k
            ( (maType.getTypeClass() == css::uno::TypeClass_BYTE)
69
1.38k
              || (maType.getTypeClass() == css::uno::TypeClass_SHORT)
70
1.38k
              || (maType.getTypeClass() == css::uno::TypeClass_UNSIGNED_SHORT)
71
1.38k
              || (maType.getTypeClass() == css::uno::TypeClass_LONG)
72
1.38k
              || (maType.getTypeClass() == css::uno::TypeClass_UNSIGNED_LONG)
73
1.38k
            ) );
74
1.38k
    }
75
    PropertyMapEntry() = default;
76
};
77
78
typedef std::unordered_map<OUString, PropertyMapEntry const *> PropertyMap;
79
80
// don't export to avoid duplicate WeakImplHelper definitions with MSVC
81
class SAL_DLLPUBLIC_TEMPLATE PropertySetInfo_BASE
82
    : public ::cppu::WeakImplHelper< css::beans::XPropertySetInfo >
83
{};
84
85
/** this class implements a XPropertySetInfo that is initialized with arrays of PropertyMapEntry.
86
    It is used by the class PropertySetHelper.
87
*/
88
class COMPHELPER_DLLPUBLIC PropertySetInfo final
89
    : public PropertySetInfo_BASE
90
{
91
public:
92
    PropertySetInfo() noexcept;
93
    PropertySetInfo( std::span<const PropertyMapEntry> pMap ) noexcept;
94
    virtual ~PropertySetInfo() noexcept override;
95
96
    /** returns a stl map with all PropertyMapEntry pointer.<p>
97
        The key is the property name.
98
    */
99
2.01M
    const PropertyMap& getPropertyMap() const noexcept { return maPropertyMap; }
100
101
    /** adds an array of PropertyMapEntry to this instance.<p>
102
        The end is marked with a PropertyMapEntry where mpName equals NULL</p>
103
    */
104
    void add( std::span<PropertyMapEntry const> pMap ) noexcept;
105
106
    /** removes an already added PropertyMapEntry which string in mpName equals to aName */
107
    void remove( const OUString& aName ) noexcept;
108
109
    virtual css::uno::Sequence< css::beans::Property > SAL_CALL getProperties() override;
110
    virtual css::beans::Property SAL_CALL getPropertyByName( const OUString& aName ) override;
111
    virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) override;
112
113
private:
114
    PropertyMap maPropertyMap;
115
    /// Cache the value we return in getProperties because it is expensive to construct
116
    css::uno::Sequence< css::beans::Property > maProperties;
117
};
118
119
}
120
121
#endif // _UTL_PROPERTSETINFO_HXX_
122
123
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */