Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/comphelper/source/property/opropertybag.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
#pragma once
21
22
#include <com/sun/star/lang/XInitialization.hpp>
23
#include <com/sun/star/lang/XServiceInfo.hpp>
24
#include <com/sun/star/util/XModifiable.hpp>
25
#include <com/sun/star/beans/XPropertyBag.hpp>
26
#include <com/sun/star/container/XSet.hpp>
27
28
#include <cppuhelper/implbase.hxx>
29
#include <comphelper/interfacecontainer3.hxx>
30
#include <comphelper/propstate.hxx>
31
#include <comphelper/broadcasthelper.hxx>
32
#include <comphelper/propertybag.hxx>
33
#include <comphelper/uno3.hxx>
34
35
#include <map>
36
#include <set>
37
#include <memory>
38
39
40
namespace comphelper
41
{
42
43
44
    struct UnoTypeLess
45
    {
46
        bool operator()( const css::uno::Type& _rLHS, const css::uno::Type& _rRHS ) const
47
1.10M
        {
48
1.10M
            return rtl_ustr_compare(
49
1.10M
                _rLHS.getTypeLibType()->pTypeName->buffer,
50
1.10M
                _rRHS.getTypeLibType()->pTypeName->buffer
51
1.10M
            ) < 0;
52
1.10M
        }
53
    };
54
55
    typedef std::map< sal_Int32, css::uno::Any >     MapInt2Any;
56
    typedef std::set< css::uno::Type, UnoTypeLess >  TypeBag;
57
58
    typedef ::cppu::WeakImplHelper  <   css::beans::XPropertyBag
59
                                    ,   css::util::XModifiable
60
                                    ,   css::lang::XServiceInfo
61
                                    ,   css::lang::XInitialization
62
                                    ,   css::container::XSet
63
                                    >   OPropertyBag_Base;
64
    typedef ::comphelper::OPropertyStateHelper  OPropertyBag_PBase;
65
66
    class OPropertyBag final : public ::comphelper::OMutexAndBroadcastHelper  // must be before OPropertyBag_PBase
67
                        ,public OPropertyBag_PBase
68
                        ,public OPropertyBag_Base
69
                        ,public ::cppu::IEventNotificationHook
70
    {
71
    private:
72
        /// our IPropertyArrayHelper implementation
73
        std::unique_ptr< ::cppu::OPropertyArrayHelper >
74
                        m_pArrayHelper;
75
        ::comphelper::PropertyBag
76
                        m_aDynamicProperties;
77
        /// set of allowed property types
78
        TypeBag         m_aAllowedTypes;
79
        /// should we automatically add properties which are tried to set, if they don't exist previously?
80
        bool            m_bAutoAddProperties;
81
82
        /// for notification
83
        ::comphelper::OInterfaceContainerHelper3<css::util::XModifyListener> m_NotifyListeners;
84
        /// modify flag
85
        bool            m_isModified;
86
87
    public:
88
        //noncopyable
89
        OPropertyBag(const OPropertyBag&) = delete;
90
        const OPropertyBag& operator=(const OPropertyBag&) = delete;
91
        OPropertyBag();
92
        virtual ~OPropertyBag() override;
93
94
    private:
95
        DECLARE_XINTERFACE()
96
        DECLARE_XTYPEPROVIDER()
97
98
        /** === begin UNO interface implementations == **/
99
        // XInitialization
100
        virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
101
102
        // XServiceInfo
103
        virtual OUString SAL_CALL getImplementationName(  ) override;
104
        virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
105
        virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) override;
106
107
        // XModifiable:
108
        virtual sal_Bool SAL_CALL isModified(  ) override;
109
        virtual void SAL_CALL setModified( sal_Bool bModified ) override;
110
111
        // XModifyBroadcaster
112
        virtual void SAL_CALL addModifyListener(
113
            const css::uno::Reference<
114
                    css::util::XModifyListener > & xListener) override;
115
        virtual void SAL_CALL removeModifyListener(
116
            const css::uno::Reference<
117
                    css::util::XModifyListener > & xListener) override;
118
119
        // XPropertyContainer
120
        virtual void SAL_CALL addProperty( const OUString& Name, ::sal_Int16 Attributes, const css::uno::Any& DefaultValue ) override;
121
        virtual void SAL_CALL removeProperty( const OUString& Name ) override;
122
123
        // XPropertyAccess
124
        virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getPropertyValues(  ) override;
125
        virtual void SAL_CALL setPropertyValues( const css::uno::Sequence< css::beans::PropertyValue >& aProps ) override;
126
127
        // XPropertySet
128
        virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) override;
129
        virtual void SAL_CALL setPropertyValue(const OUString& p1, const css::uno::Any& p2) override
130
0
           { OPropertyBag_PBase::setPropertyValue(p1, p2); }
131
        virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& p1) override
132
18.5k
           { return OPropertyBag_PBase::getPropertyValue(p1); }
133
        virtual void SAL_CALL addPropertyChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XPropertyChangeListener>& p2) override
134
0
           { OPropertyBag_PBase::addPropertyChangeListener(p1, p2); }
135
        virtual void SAL_CALL removePropertyChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XPropertyChangeListener>& p2) override
136
0
           { OPropertyBag_PBase::removePropertyChangeListener(p1, p2); }
137
        virtual void SAL_CALL addVetoableChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XVetoableChangeListener>& p2) override
138
0
           { OPropertyBag_PBase::addVetoableChangeListener(p1, p2); }
139
        virtual void SAL_CALL removeVetoableChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XVetoableChangeListener>& p2) override
140
0
           { OPropertyBag_PBase::removeVetoableChangeListener(p1, p2); }
141
142
        // XSet
143
        virtual sal_Bool SAL_CALL has( const css::uno::Any& aElement ) override;
144
        virtual void SAL_CALL insert( const css::uno::Any& aElement ) override;
145
        virtual void SAL_CALL remove( const css::uno::Any& aElement ) override;
146
147
        // XEnumerationAccess (base of XSet)
148
        virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration(  ) override;
149
150
        // XElementAccess (base of XEnumerationAccess)
151
        virtual css::uno::Type SAL_CALL getElementType(  ) override;
152
        virtual sal_Bool SAL_CALL hasElements(  ) override;
153
        // UNO interface implementations
154
155
        // XPropertyState
156
        virtual css::uno::Any  getPropertyDefaultByHandle( sal_Int32 _nHandle ) const override;
157
158
        // OPropertyStateHelper
159
        virtual css::beans::PropertyState  getPropertyStateByHandle( sal_Int32 _nHandle ) override;
160
161
        // OPropertySetHelper
162
        virtual void SAL_CALL getFastPropertyValue( css::uno::Any& rValue, sal_Int32 nHandle ) const override;
163
        virtual sal_Bool SAL_CALL convertFastPropertyValue( css::uno::Any & rConvertedValue, css::uno::Any & rOldValue, sal_Int32 nHandle, const css::uno::Any& rValue ) override;
164
        virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue ) override;
165
        virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
166
167
        // IEventNotificationHook
168
        virtual void fireEvents(
169
            sal_Int32 * pnHandles,
170
            sal_Int32 nCount,
171
            sal_Bool bVetoable,
172
            bool bIgnoreRuntimeExceptionsWhileFiring) override;
173
174
        void setModifiedImpl( bool bModified,
175
            bool bIgnoreRuntimeExceptionsWhileFiring);
176
177
        /** finds a free property handle
178
            @precond
179
                our mutex is locked
180
        */
181
        sal_Int32   findFreeHandle() const;
182
183
        /** implements the setPropertyValues method
184
            @param _rProps
185
                the property values to set
186
187
            @throws PropertyVetoException
188
                if the XMultiPropertySet::setPropertyValues call does so
189
190
            @throws css::lang::IllegalArgumentException
191
                if the XMultiPropertySet::setPropertyValues call does so
192
193
            @throws css::lang::WrappedTargetException
194
                if the XMultiPropertySet::setPropertyValues call does so
195
196
            @throws css::uno::RuntimeException
197
                if the XMultiPropertySet::setPropertyValues call does so
198
199
            @throws css::beans::UnknownPropertyException
200
                if the XMultiPropertySet::setPropertyValues call does so, and <arg>_bTolerateUnknownProperties</arg>
201
                was set to <FALSE/>
202
203
            @throws css::lang::WrappedTargetException
204
                if the XMultiPropertySet::setPropertyValues call did throw an exception not listed
205
                above
206
        */
207
        void impl_setPropertyValues_throw( const css::uno::Sequence< css::beans::PropertyValue >& _rProps );
208
209
        using ::cppu::OPropertySetHelper::getPropertyValues;
210
        using ::cppu::OPropertySetHelper::setPropertyValues;
211
        using ::cppu::OPropertySetHelper::getFastPropertyValue;
212
    };
213
214
215
} // namespace comphelper
216
217
218
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */