LibreOffice Module comphelper (master) 1
configuration.hxx
Go to the documentation of this file.
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
10#ifndef INCLUDED_COMPHELPER_CONFIGURATION_HXX
11#define INCLUDED_COMPHELPER_CONFIGURATION_HXX
12
13#include <sal/config.h>
14
15#include <optional>
16#include <string_view>
17
18#include <com/sun/star/uno/Any.hxx>
19#include <com/sun/star/uno/Reference.h>
22#include <sal/types.h>
23#include <memory>
24
25namespace com::sun::star {
26 namespace configuration { class XReadWriteAccess; }
27 namespace container {
28 class XHierarchicalNameAccess;
29 class XHierarchicalNameReplace;
30 class XNameAccess;
31 class XNameContainer;
32 }
33 namespace uno { class XComponentContext; }
34}
35
36namespace comphelper {
37
38namespace detail { class ConfigurationWrapper; }
39
48public:
49 static std::shared_ptr<ConfigurationChanges> create();
50
52
53 void commit() const;
54
55private:
58
59 SAL_DLLPRIVATE ConfigurationChanges(
60 css::uno::Reference< css::uno::XComponentContext >
61 const & context);
62
63 SAL_DLLPRIVATE void setPropertyValue(
64 OUString const & path, css::uno::Any const & value)
65 const;
66
67 SAL_DLLPRIVATE css::uno::Reference<
68 css::container::XHierarchicalNameReplace >
69 getGroup(OUString const & path) const;
70
71 SAL_DLLPRIVATE
72 css::uno::Reference< css::container::XNameContainer >
73 getSet(OUString const & path) const;
74
75 css::uno::Reference<
76 css::configuration::XReadWriteAccess > access_;
77
79};
80
81namespace detail {
82
85public:
86 static ConfigurationWrapper const & get();
87
88 bool isReadOnly(OUString const & path) const;
89
90 css::uno::Any getPropertyValue(OUString const & path) const;
91
92 static void setPropertyValue(
93 std::shared_ptr< ConfigurationChanges > const & batch,
94 OUString const & path, css::uno::Any const & value);
95
96 css::uno::Any getLocalizedPropertyValue(
97 std::u16string_view path) const;
98
99 static void setLocalizedPropertyValue(
100 std::shared_ptr< ConfigurationChanges > const & batch,
101 OUString const & path, css::uno::Any const & value);
102
103 css::uno::Reference<
104 css::container::XHierarchicalNameAccess >
105 getGroupReadOnly(OUString const & path) const;
106
107 static css::uno::Reference<
108 css::container::XHierarchicalNameReplace >
109 getGroupReadWrite(
110 std::shared_ptr< ConfigurationChanges > const & batch,
111 OUString const & path);
112
113 css::uno::Reference< css::container::XNameAccess >
114 getSetReadOnly(OUString const & path) const;
115
116 static css::uno::Reference< css::container::XNameContainer >
117 getSetReadWrite(
118 std::shared_ptr< ConfigurationChanges > const & batch,
119 OUString const & path);
120
121 std::shared_ptr< ConfigurationChanges > createChanges() const;
122
123private:
124 SAL_DLLPRIVATE explicit ConfigurationWrapper();
125
126 SAL_DLLPRIVATE ~ConfigurationWrapper();
127
130
131 css::uno::Reference< css::uno::XComponentContext > context_;
132
133 css::uno::Reference< css::configuration::XReadWriteAccess > access_;
134 // should really be a css.configuration.ReadOnlyAccess (with added
135 // css.beans.XHierarchicalPropertySetInfo), but then
136 // configmgr::Access::asProperty() would report all properties as
137 // READONLY, so isReadOnly() would not work
138};
139
141template< typename T > struct Convert {
142 static css::uno::Any toAny(T const & value)
143 { return css::uno::Any(value); }
144
145 static T fromAny(css::uno::Any const & value)
146 { return value.get< T >(); }
147
148private:
149 Convert(const Convert&) = delete;
150 Convert& operator=(const Convert&) = delete;
151
152 Convert() = delete;
153 ~Convert() = delete;
154};
155
157template< typename T > struct Convert< std::optional< T > >
158{
159 static css::uno::Any toAny(std::optional< T > const & value) {
160 return value
161 ? css::uno::Any(*value)
162 : css::uno::Any();
163 }
164
165 static std::optional< T > fromAny(css::uno::Any const & value)
166 {
167 return value.hasValue()
168 ? std::optional< T >(value.get< T >()) : std::optional< T >();
169 }
170
171private:
172 Convert(const Convert&) = delete;
173 Convert& operator=(const Convert&) = delete;
174
175 Convert() = delete;
176 ~Convert() = delete;
177};
178
179}
180
186template< typename T, typename U > struct ConfigurationProperty
187{
190 static bool isReadOnly()
191 {
193 }
194
198 static U get()
199 {
200 // Folding this into one statement causes a bogus error at least with
201 // Red Hat GCC 4.6.2-1:
202 css::uno::Any a(
204 T::path()));
206 }
207
212 static void set(
213 U const & value,
214 std::shared_ptr< ConfigurationChanges > const & batch)
215 {
217 batch, T::path(), detail::Convert< U >::toAny(value));
218 }
219
220private:
223
226};
227
233template< typename T, typename U > struct ConfigurationLocalizedProperty
234{
240 static U get()
241 {
242 // Folding this into one statement causes a bogus error at least with
243 // Red Hat GCC 4.6.2-1:
244 css::uno::Any a(
246 getLocalizedPropertyValue(T::path()));
248 }
249
256 static void set(
257 U const & value,
258 std::shared_ptr< ConfigurationChanges > const & batch)
259 {
261 batch, T::path(), detail::Convert< U >::toAny(value));
262 }
263
264private:
267
270};
271
277template< typename T > struct ConfigurationGroup {
279 static css::uno::Reference<
280 css::container::XHierarchicalNameAccess >
282 {
284 T::path());
285 }
286
289 static css::uno::Reference<
290 css::container::XHierarchicalNameReplace >
291 get(std::shared_ptr< ConfigurationChanges > const & batch)
292 {
294 batch, T::path());
295 }
296
297private:
300
303};
304
310template< typename T > struct ConfigurationSet {
312 static
313 css::uno::Reference< css::container::XNameAccess >
315 {
317 T::path());
318 }
319
322 static
323 css::uno::Reference< css::container::XNameContainer >
324 get(std::shared_ptr< ConfigurationChanges > const & batch)
325 {
327 batch, T::path());
328 }
329
330private:
333
336};
337
338}
339
340#endif
341
342/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
A batch of configuration changes that is committed as a whole.
css::uno::Reference< css::configuration::XReadWriteAccess > access_
ConfigurationChanges(const ConfigurationChanges &)=delete
ConfigurationChanges & operator=(const ConfigurationChanges &)=delete
ConfigurationWrapper(const ConfigurationWrapper &)=delete
css::uno::Reference< css::container::XHierarchicalNameAccess > getGroupReadOnly(OUString const &path) const
bool isReadOnly(OUString const &path) const
ConfigurationWrapper & operator=(const ConfigurationWrapper &)=delete
css::uno::Reference< css::configuration::XReadWriteAccess > access_
static void setPropertyValue(std::shared_ptr< ConfigurationChanges > const &batch, OUString const &path, css::uno::Any const &value)
css::uno::Reference< css::uno::XComponentContext > context_
static void setLocalizedPropertyValue(std::shared_ptr< ConfigurationChanges > const &batch, OUString const &path, css::uno::Any const &value)
css::uno::Reference< css::container::XNameAccess > getSetReadOnly(OUString const &path) const
static css::uno::Reference< css::container::XNameContainer > getSetReadWrite(std::shared_ptr< ConfigurationChanges > const &batch, OUString const &path)
static ConfigurationWrapper const & get()
static css::uno::Reference< css::container::XHierarchicalNameReplace > getGroupReadWrite(std::shared_ptr< ConfigurationChanges > const &batch, OUString const &path)
#define COMPHELPER_DLLPUBLIC
Any value
uno_Any a
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
A type-safe wrapper around a configuration group.
static css::uno::Reference< css::container::XHierarchicalNameAccess > get()
Get read-only access to the given configuration group.
ConfigurationGroup & operator=(const ConfigurationGroup &)=delete
static css::uno::Reference< css::container::XHierarchicalNameReplace > get(std::shared_ptr< ConfigurationChanges > const &batch)
Get read/write access to the given configuration group, storing any modifications via the given chang...
ConfigurationGroup(const ConfigurationGroup &)=delete
A type-safe wrapper around a localized configuration property.
ConfigurationLocalizedProperty & operator=(const ConfigurationLocalizedProperty &)=delete
ConfigurationLocalizedProperty(const ConfigurationLocalizedProperty &)=delete
static U get()
Get the value of the given localized configuration property, for the locale currently set at the com....
static void set(U const &value, std::shared_ptr< ConfigurationChanges > const &batch)
Set the value of the given localized configuration property, for the locale currently set at the com....
A type-safe wrapper around a (non-localized) configuration property.
ConfigurationProperty & operator=(const ConfigurationProperty &)=delete
static U get()
Get the value of the given (non-localized) configuration property.
static bool isReadOnly()
Get the read-only status of the given (non-localized) configuration property.
static void set(U const &value, std::shared_ptr< ConfigurationChanges > const &batch)
Set the value of the given (non-localized) configuration property, via a given changes batch.
ConfigurationProperty(const ConfigurationProperty &)=delete
A type-safe wrapper around a configuration set.
ConfigurationSet & operator=(const ConfigurationSet &)=delete
ConfigurationSet(const ConfigurationSet &)=delete
static css::uno::Reference< css::container::XNameAccess > get()
Get read-only access to the given configuration set.
static css::uno::Reference< css::container::XNameContainer > get(std::shared_ptr< ConfigurationChanges > const &batch)
Get read/write access to the given configuration set, storing any modifications via the given changes...
Convert & operator=(const Convert &)=delete
static css::uno::Any toAny(std::optional< T > const &value)
static std::optional< T > fromAny(css::uno::Any const &value)
Convert(const Convert &)=delete
static css::uno::Any toAny(T const &value)
static T fromAny(css::uno::Any const &value)
Convert & operator=(const Convert &)=delete