Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / inc / OPropertySet.hxx
blobaa5d2e7cd4ba0b5f51ee8e16610fd4d2ac8f5378
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #pragma once
21 // helper classes
22 #include <cppuhelper/basemutex.hxx>
23 #include <cppuhelper/propshlp.hxx>
25 // interfaces and types
26 #include <com/sun/star/lang/XTypeProvider.hpp>
27 #include <com/sun/star/beans/XPropertyState.hpp>
28 #include <com/sun/star/beans/XMultiPropertyStates.hpp>
29 #include <com/sun/star/style/XStyleSupplier.hpp>
30 #include "charttoolsdllapi.hxx"
32 #include <unordered_map>
34 namespace property
37 class OOO_DLLPUBLIC_CHARTTOOLS OPropertySet :
38 protected cppu::BaseMutex,
39 public ::cppu::OBroadcastHelper,
40 // includes beans::XPropertySet, XMultiPropertySet and XFastPropertySet
41 public ::cppu::OPropertySetHelper,
42 // includes uno::XWeak (and XInterface, esp. ref-counting)
44 public css::lang::XTypeProvider,
45 public css::beans::XPropertyState,
46 public css::beans::XMultiPropertyStates,
47 public css::style::XStyleSupplier
49 public:
50 OPropertySet();
51 virtual ~OPropertySet();
53 protected:
54 explicit OPropertySet( const OPropertySet & rOther );
56 void SetNewValuesExplicitlyEvenIfTheyEqualDefault();
58 /** implement this method to provide default values for all properties
59 supporting defaults. If a property does not have a default value, you
60 may throw an UnknownPropertyException.
61 We pass the any by reference because this code is very hot and doing
62 it this way is cheaper than the two step process of constructing a new
63 any and then assigning to via a return value.
65 @throws css::beans::UnknownPropertyException
66 @throws css::uno::RuntimeException
68 virtual void GetDefaultValue( sal_Int32 nHandle, css::uno::Any& rAny ) const = 0;
70 /** The InfoHelper table contains all property names and types of
71 this object.
73 @return the object that provides information for the
74 PropertySetInfo
76 @see ::cppu::OPropertySetHelper
78 virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override = 0;
80 /** Try to convert the value <code>rValue</code> to the type required by the
81 property associated with <code>nHandle</code>.
83 Override this method to take influence in modification of properties.
85 If the conversion changed , </sal_True> is returned and the converted value
86 is in <code>rConvertedValue</code>. The former value is contained in
87 <code>rOldValue</code>.
89 After this call returns successfully, the vetoable listeners are
90 notified.
92 @throws IllegalArgumentException, if the conversion was not successful,
93 or if there is no corresponding property to the given handle.
95 @param rConvertedValue the converted value. Only set if return is true.
96 @param rOldValue the old value. Only set if return is true.
97 @param nHandle the handle of the property.
99 @return true, if the conversion was successful and converted value
100 differs from the old value.
102 @see ::cppu::OPropertySetHelper
104 virtual sal_Bool SAL_CALL convertFastPropertyValue
105 ( css::uno::Any & rConvertedValue,
106 css::uno::Any & rOldValue,
107 sal_Int32 nHandle,
108 const css::uno::Any& rValue ) override final;
110 /** The same as setFastPropertyValue; nHandle is always valid.
111 The changes must not be broadcasted in this method.
113 @attention
114 Although you are permitted to throw any UNO exception, only the following
115 are valid for usage:
116 -- css::beans::UnknownPropertyException
117 -- css::beans::PropertyVetoException
118 -- css::lang::IllegalArgumentException
119 -- css::lang::WrappedTargetException
120 -- css::uno::RuntimeException
122 @param nHandle handle
123 @param rValue value
125 @see ::cppu::OPropertySetHelper
127 virtual void SAL_CALL setFastPropertyValue_NoBroadcast
128 ( sal_Int32 nHandle,
129 const css::uno::Any& rValue ) override;
132 The same as getFastPropertyValue, but return the value through rValue and
133 nHandle is always valid.
135 @see ::cppu::OPropertySetHelper
137 virtual void SAL_CALL getFastPropertyValue
138 ( css::uno::Any& rValue,
139 sal_Int32 nHandle ) const override;
141 /** implement this method in derived classes to get called when properties
142 change.
144 virtual void firePropertyChangeEvent();
146 public:
147 /// make original interface function visible again
148 using ::cppu::OPropertySetHelper::getFastPropertyValue;
150 // Interfaces
152 // ____ XInterface ____
153 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
155 // ____ XTypeProvider ____
156 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
157 getTypes() override;
158 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
159 getImplementationId() override;
161 // ____ XPropertyState ____
162 virtual css::beans::PropertyState SAL_CALL
163 getPropertyState( const OUString& PropertyName ) override final;
164 virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL
165 getPropertyStates( const css::uno::Sequence< OUString >& aPropertyName ) override final;
166 virtual void SAL_CALL
167 setPropertyToDefault( const OUString& PropertyName ) override final;
168 virtual css::uno::Any SAL_CALL
169 getPropertyDefault( const OUString& aPropertyName ) override final;
171 // ____ XMultiPropertyStates ____
172 // Note: getPropertyStates() is already implemented in XPropertyState with the
173 // same signature
174 virtual void SAL_CALL
175 setAllPropertiesToDefault() override final;
176 virtual void SAL_CALL
177 setPropertiesToDefault( const css::uno::Sequence< OUString >& aPropertyNames ) override final;
178 virtual css::uno::Sequence< css::uno::Any > SAL_CALL
179 getPropertyDefaults( const css::uno::Sequence< OUString >& aPropertyNames ) override final;
181 // ____ XStyleSupplier ____
182 virtual css::uno::Reference< css::style::XStyle > SAL_CALL getStyle() override final;
183 virtual void SAL_CALL setStyle( const css::uno::Reference< css::style::XStyle >& xStyle ) override final;
185 // ____ XMultiPropertySet ____
186 virtual void SAL_CALL setPropertyValues(
187 const css::uno::Sequence< OUString >& PropertyNames,
188 const css::uno::Sequence< css::uno::Any >& Values ) override final;
190 // ____ XFastPropertySet ____
191 virtual void SAL_CALL setFastPropertyValue( sal_Int32 nHandle, const css::uno::Any& rValue ) override final;
193 // Note: it is assumed that the base class implements setPropertyValue by
194 // using setFastPropertyValue
196 private:
197 /** supports states DIRECT_VALUE and DEFAULT_VALUE
199 css::beans::PropertyState
200 GetPropertyStateByHandle( sal_Int32 nHandle ) const;
202 css::uno::Sequence< css::beans::PropertyState >
203 GetPropertyStatesByHandle( const std::vector< sal_Int32 > & aHandles ) const;
205 void SetPropertyToDefault( sal_Int32 nHandle );
206 void SetPropertiesToDefault( const std::vector< sal_Int32 > & aHandles );
207 void SetAllPropertiesToDefault();
209 /** @param rValue is set to the value for the property given in nHandle. If
210 the property is not set, the style chain is searched for any
211 instance set there. If there was no value found either in the
212 property set itself or any of its styles, rValue remains
213 unchanged and false is returned.
215 @return false if the property is default, true otherwise.
217 bool GetPropertyValueByHandle(
218 css::uno::Any & rValue,
219 sal_Int32 nHandle ) const;
221 void SetPropertyValueByHandle( sal_Int32 nHandle,
222 const css::uno::Any & rValue );
224 bool SetStyle( const css::uno::Reference< css::style::XStyle > & xStyle );
226 bool m_bSetNewValuesExplicitlyEvenIfTheyEqualDefault;
227 std::unordered_map< sal_Int32, css::uno::Any > m_aProperties;
228 css::uno::Reference< css::style::XStyle > m_xStyle;
231 } // namespace property
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */