Avoid potential negative array index access to cached text.
[LibreOffice.git] / configmgr / source / access.hxx
blobbd93b42221775d18a7db7d4c74a042b10d9e242e
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 .
20 #pragma once
22 #include <sal/config.h>
24 #include <set>
25 #include <vector>
26 #include "config_map.hxx"
28 #include <com/sun/star/beans/XExactName.hpp>
29 #include <com/sun/star/beans/XHierarchicalPropertySet.hpp>
30 #include <com/sun/star/beans/XHierarchicalPropertySetInfo.hpp>
31 #include <com/sun/star/beans/XMultiHierarchicalPropertySet.hpp>
32 #include <com/sun/star/beans/XMultiPropertySet.hpp>
33 #include <com/sun/star/beans/XProperty.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/beans/XPropertySetInfo.hpp>
36 #include <com/sun/star/container/XContainer.hpp>
37 #include <com/sun/star/container/XHierarchicalName.hpp>
38 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
39 #include <com/sun/star/configuration/XDocumentation.hpp>
40 #include <com/sun/star/container/XHierarchicalNameReplace.hpp>
41 #include <com/sun/star/container/XNameContainer.hpp>
42 #include <com/sun/star/container/XNamed.hpp>
43 #include <com/sun/star/lang/XComponent.hpp>
44 #include <com/sun/star/lang/XServiceInfo.hpp>
45 #include <com/sun/star/lang/XTypeProvider.hpp>
46 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
47 #include <com/sun/star/uno/Reference.hxx>
48 #include <com/sun/star/uno/Sequence.hxx>
49 #include <cppuhelper/weak.hxx>
50 #include <osl/interlck.h>
51 #include <rtl/ref.hxx>
52 #include <sal/types.h>
54 #include "modifications.hxx"
55 #include "type.hxx"
57 namespace com::sun::star {
58 namespace beans {
59 class XHierarchicalPropertySetInfo;
60 class XPropertiesChangeListener;
61 class XPropertyChangeListener;
62 class XVetoableChangeListener;
63 struct Property;
65 namespace container { class XContainerListener; }
66 namespace lang { class XEventListener; }
67 namespace uno {
68 class Any;
69 class Type;
70 class XInterface;
72 namespace util { struct ElementChange; }
75 namespace configmgr {
77 class Broadcaster;
78 class ChildAccess;
79 class Components;
80 class Node;
81 class RootAccess;
83 class Access:
84 public cppu::OWeakObject, public css::lang::XTypeProvider,
85 public css::lang::XServiceInfo,
86 public css::lang::XComponent,
87 public css::configuration::XDocumentation,
88 public css::container::XHierarchicalNameReplace,
89 public css::container::XContainer,
90 public css::beans::XExactName,
91 public css::beans::XPropertySetInfo,
92 public css::container::XHierarchicalName,
93 public css::container::XNamed,
94 public css::beans::XProperty,
95 public css::beans::XPropertySet,
96 public css::beans::XMultiPropertySet,
97 public css::beans::XHierarchicalPropertySet,
98 public css::beans::XMultiHierarchicalPropertySet,
99 public css::beans::XHierarchicalPropertySetInfo,
100 public css::container::XNameContainer,
101 public css::lang::XSingleServiceFactory
103 public:
104 oslInterlockedCount acquireCounting();
106 void releaseNondeleting();
108 bool isValue();
110 void markChildAsModified(rtl::Reference< ChildAccess > const & child);
111 void releaseChild(OUString const & name);
113 virtual std::vector<OUString> getAbsolutePath() = 0;
114 virtual std::vector<OUString> getRelativePath() = 0;
116 virtual OUString getRelativePathRepresentation() = 0;
117 virtual const rtl::Reference< Node > & getNode() = 0;
119 virtual bool isFinalized() = 0;
121 virtual void initBroadcaster(
122 Modifications::Node const & modifications, Broadcaster * broadcaster);
124 using OWeakObject::acquire;
125 using OWeakObject::release;
127 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
128 getTypes() override;
130 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
131 getImplementationId() override;
133 virtual OUString SAL_CALL getImplementationName() override;
135 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
137 virtual css::uno::Sequence< OUString > SAL_CALL
138 getSupportedServiceNames() override;
140 virtual void SAL_CALL dispose() override;
142 virtual void SAL_CALL addEventListener(
143 css::uno::Reference< css::lang::XEventListener >
144 const & xListener) override;
146 virtual void SAL_CALL removeEventListener(
147 css::uno::Reference< css::lang::XEventListener >
148 const & aListener) override;
150 virtual css::uno::Type SAL_CALL getElementType() override;
152 virtual sal_Bool SAL_CALL hasElements() override;
154 virtual css::uno::Any SAL_CALL getByName(
155 OUString const & aName) override;
157 virtual css::uno::Sequence< OUString > SAL_CALL
158 getElementNames() override;
160 virtual sal_Bool SAL_CALL hasByName(OUString const & aName) override;
162 virtual css::uno::Any SAL_CALL getByHierarchicalName(
163 OUString const & aName) override;
165 virtual OUString SAL_CALL getDescriptionByHierarchicalName(
166 OUString const & aName) override;
168 virtual css::uno::Type SAL_CALL getTypeByHierarchicalName(
169 OUString const & aName) override;
171 virtual sal_Bool SAL_CALL getModifiedByHierarchicalName(
172 OUString const & aName) override;
174 virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName) override;
176 virtual void SAL_CALL replaceByHierarchicalName(
177 OUString const & aName, css::uno::Any const & aElement) override;
179 virtual void SAL_CALL addContainerListener(
180 css::uno::Reference<
181 css::container::XContainerListener > const & xListener) override;
183 virtual void SAL_CALL removeContainerListener(
184 css::uno::Reference<
185 css::container::XContainerListener > const & xListener) override;
187 virtual OUString SAL_CALL getExactName(
188 OUString const & aApproximateName) override;
190 virtual css::uno::Sequence< css::beans::Property >
191 SAL_CALL getProperties() override;
193 virtual css::beans::Property SAL_CALL getPropertyByName(
194 OUString const & aName) override;
196 virtual sal_Bool SAL_CALL hasPropertyByName(OUString const & Name) override;
198 virtual OUString SAL_CALL getHierarchicalName() override;
200 virtual OUString SAL_CALL composeHierarchicalName(
201 OUString const & aRelativeName) override;
203 virtual OUString SAL_CALL getName() override;
205 virtual void SAL_CALL setName(OUString const & aName) override;
207 virtual css::beans::Property SAL_CALL getAsProperty() override;
209 virtual
210 css::uno::Reference< css::beans::XPropertySetInfo >
211 SAL_CALL getPropertySetInfo() override;
213 virtual void SAL_CALL setPropertyValue(
214 OUString const & aPropertyName,
215 css::uno::Any const & aValue) override;
217 virtual css::uno::Any SAL_CALL getPropertyValue(
218 OUString const & PropertyName) override;
220 virtual void SAL_CALL addPropertyChangeListener(
221 OUString const & aPropertyName,
222 css::uno::Reference<
223 css::beans::XPropertyChangeListener > const & xListener) override;
225 virtual void SAL_CALL removePropertyChangeListener(
226 OUString const & aPropertyName,
227 css::uno::Reference<
228 css::beans::XPropertyChangeListener > const & aListener) override;
230 virtual void SAL_CALL addVetoableChangeListener(
231 OUString const & PropertyName,
232 css::uno::Reference<
233 css::beans::XVetoableChangeListener > const & aListener) override;
235 virtual void SAL_CALL removeVetoableChangeListener(
236 OUString const & PropertyName,
237 css::uno::Reference<
238 css::beans::XVetoableChangeListener > const & aListener) override;
240 virtual void SAL_CALL setPropertyValues(
241 css::uno::Sequence< OUString > const & aPropertyNames,
242 css::uno::Sequence< css::uno::Any > const &
243 aValues) override;
245 virtual css::uno::Sequence< css::uno::Any > SAL_CALL
246 getPropertyValues(
247 css::uno::Sequence< OUString > const & aPropertyNames) override;
249 virtual void SAL_CALL addPropertiesChangeListener(
250 css::uno::Sequence< OUString > const & aPropertyNames,
251 css::uno::Reference<
252 css::beans::XPropertiesChangeListener > const &
253 xListener) override;
255 virtual void SAL_CALL removePropertiesChangeListener(
256 css::uno::Reference<
257 css::beans::XPropertiesChangeListener > const &
258 xListener) override;
260 virtual void SAL_CALL firePropertiesChangeEvent(
261 css::uno::Sequence< OUString > const & aPropertyNames,
262 css::uno::Reference<
263 css::beans::XPropertiesChangeListener > const &
264 xListener) override;
266 virtual
267 css::uno::Reference<
268 css::beans::XHierarchicalPropertySetInfo > SAL_CALL
269 getHierarchicalPropertySetInfo() override;
271 virtual void SAL_CALL setHierarchicalPropertyValue(
272 OUString const & aHierarchicalPropertyName,
273 css::uno::Any const & aValue) override;
275 virtual css::uno::Any SAL_CALL getHierarchicalPropertyValue(
276 OUString const & aHierarchicalPropertyName) override;
278 virtual void SAL_CALL setHierarchicalPropertyValues(
279 css::uno::Sequence< OUString > const &
280 aHierarchicalPropertyNames,
281 css::uno::Sequence< css::uno::Any > const &
282 Values) override;
284 virtual css::uno::Sequence< css::uno::Any > SAL_CALL
285 getHierarchicalPropertyValues(
286 css::uno::Sequence< OUString > const &
287 aHierarchicalPropertyNames) override;
289 virtual css::beans::Property SAL_CALL
290 getPropertyByHierarchicalName(OUString const & aHierarchicalName) override;
292 virtual sal_Bool SAL_CALL hasPropertyByHierarchicalName(
293 OUString const & aHierarchicalName) override;
295 virtual void SAL_CALL replaceByName(
296 OUString const & aName, css::uno::Any const & aElement) override;
298 virtual void SAL_CALL insertByName(
299 OUString const & aName, css::uno::Any const & aElement) override;
301 virtual void SAL_CALL removeByName(OUString const & aName) override;
303 virtual css::uno::Reference< css::uno::XInterface >
304 SAL_CALL createInstance() override;
306 virtual css::uno::Reference< css::uno::XInterface >
307 SAL_CALL createInstanceWithArguments(
308 css::uno::Sequence< css::uno::Any > const &
309 aArguments) override;
311 protected:
312 explicit Access(Components & components);
314 virtual ~Access() override;
316 virtual const OUString & getNameInternal() = 0;
317 virtual rtl::Reference< RootAccess > getRootAccess() = 0;
318 virtual rtl::Reference< Access > getParentAccess() = 0;
320 virtual void addTypes(std::vector< css::uno::Type > * types)
321 const = 0;
323 virtual void addSupportedServiceNames(
324 std::vector<OUString> * services) = 0;
326 virtual void initDisposeBroadcaster(Broadcaster * broadcaster);
327 virtual void clearListeners() noexcept;
329 virtual css::uno::Any SAL_CALL queryInterface(
330 css::uno::Type const & aType) override;
332 Components & getComponents() const { return components_;}
334 void checkLocalizedPropertyAccess();
336 rtl::Reference< Node > getParentNode();
337 rtl::Reference< ChildAccess > getChild(OUString const & name);
338 void forAllChildren(const std::function<bool(ChildAccess&)> & f);
339 bool isAllChildrenEmpty();
341 void checkValue(
342 css::uno::Any const & value, Type type, bool nillable);
344 void insertLocalizedValueChild(
345 OUString const & name, css::uno::Any const & value,
346 Modifications * localModifications);
348 void reportChildChanges(
349 std::vector< css::util::ElementChange > * changes);
351 void commitChildChanges(bool valid, Modifications * globalModifications);
353 void initBroadcasterAndChanges(
354 Modifications::Node const & modifications, Broadcaster * broadcaster,
355 std::vector< css::util::ElementChange > * changes);
357 bool isDisposed() const { return disposed_;}
359 private:
360 Access(const Access&) = delete;
361 Access& operator=(const Access&) = delete;
363 struct ModifiedChild {
364 rtl::Reference< ChildAccess > child;
365 bool directlyModified;
367 ModifiedChild();
369 ModifiedChild(
370 rtl::Reference< ChildAccess > theChild,
371 bool theDirectlyModified);
374 typedef config_map< ModifiedChild > ModifiedChildren;
376 rtl::Reference< ChildAccess > getModifiedChild(
377 ModifiedChildren::iterator const & childIterator);
379 rtl::Reference< ChildAccess > getUnmodifiedChild(
380 OUString const & name);
382 rtl::Reference< ChildAccess > getSubChild(OUString const & path);
384 bool setChildProperty(
385 OUString const & name, css::uno::Any const & value,
386 Modifications * localModifications);
388 css::beans::Property asProperty();
390 bool getByNameFast(const OUString & name, css::uno::Any & value);
391 rtl::Reference< ChildAccess > createUnmodifiedChild(const OUString &name,
392 const rtl::Reference< Node > &node);
394 void checkFinalized();
396 void checkKnownProperty(OUString const & descriptor);
398 rtl::Reference< ChildAccess > getFreeSetMember( css::uno::Any const & value);
400 rtl::Reference< Access > getNotificationRoot();
402 typedef config_map< ChildAccess * > WeakChildMap;
404 typedef
405 std::multiset<
406 css::uno::Reference<
407 css::lang::XEventListener > >
408 DisposeListeners;
410 typedef
411 std::multiset<
412 css::uno::Reference<
413 css::container::XContainerListener > >
414 ContainerListeners;
416 typedef
417 std::multiset<
418 css::uno::Reference<
419 css::beans::XPropertyChangeListener > >
420 PropertyChangeListenersElement;
422 typedef config_map< PropertyChangeListenersElement >
423 PropertyChangeListeners;
425 typedef
426 std::multiset<
427 css::uno::Reference<
428 css::beans::XVetoableChangeListener > >
429 VetoableChangeListenersElement;
431 typedef config_map< VetoableChangeListenersElement >
432 VetoableChangeListeners;
434 typedef
435 std::multiset<
436 css::uno::Reference<
437 css::beans::XPropertiesChangeListener > >
438 PropertiesChangeListeners;
440 Components & components_;
441 ModifiedChildren modifiedChildren_;
442 WeakChildMap cachedChildren_;
443 DisposeListeners disposeListeners_;
444 ContainerListeners containerListeners_;
445 PropertyChangeListeners propertyChangeListeners_;
446 VetoableChangeListeners vetoableChangeListeners_;
447 PropertiesChangeListeners propertiesChangeListeners_;
448 bool disposed_;
450 std::shared_ptr<osl::Mutex> lock_;
452 #if !defined NDEBUG
453 protected:
454 enum {
455 IS_ANY = 0, IS_GROUP = 0x01, IS_SET = 0x02, IS_EXTENSIBLE = 0x04,
456 IS_GROUP_MEMBER = 0x08, IS_SET_MEMBER = 0x10, IS_UPDATE = 0x20 };
457 bool thisIs(int what);
458 #endif
463 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */