nss: upgrade to release 3.73
[LibreOffice.git] / include / unotools / configvaluecontainer.hxx
blobc4447fca28f41b348cd448490b7b34dafb85b425
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 #ifndef INCLUDED_UNOTOOLS_CONFIGVALUECONTAINER_HXX
20 #define INCLUDED_UNOTOOLS_CONFIGVALUECONTAINER_HXX
22 #include <config_options.h>
23 #include <unotools/unotoolsdllapi.h>
24 #include <com/sun/star/uno/Type.hxx>
25 #include <memory>
28 namespace com::sun::star::uno { template <typename > class Reference; }
29 namespace com::sun::star::uno { class XComponentContext; }
30 namespace osl { class Mutex; }
32 namespace utl
35 struct OConfigurationValueContainerImpl;
36 struct NodeValueAccessor;
38 //= OConfigurationValueContainer
40 /** allows simple access to static configuration structures.
42 <p>The basic idea of this class is that it's clients (usually derived classes) simply register an
43 address in memory and a node path, and upon explicit request, the configuration value and the memory
44 are synchronized.<br/>
45 This means that when calling <method>read</method>, the current configuration values are copied into
46 the memory registered for them, and upon calling <method>write</method> the current values in memory
47 are set in the configuration nodes.</p>
49 <p>This way, the usage of this class is pretty straight forward: derive your own class, spend some members
50 to it, and bind these members to configuration node (usually done in the ctor of the derived class).<br/>
51 In the dtor, simply call <method>write</method> and <method>commit</method>.</p>
53 <p>There is no auto-commit mechanism in the dtor: In the usual scenario, when you derive from this class
54 and bind some members of your derived class to config nodes, this means that your members will be destroyed
55 before your base class' dtor is called, so accessing the memory during such a theoretical auto-commit would
56 yield undefined behaviour.</p>
58 class UNLESS_MERGELIBS(UNOTOOLS_DLLPUBLIC) OConfigurationValueContainer
60 private:
61 std::unique_ptr<OConfigurationValueContainerImpl> m_pImpl;
63 protected:
65 // construction/destruction
67 /** constructs the object
69 @param _rxORB
70 specifies the service factory which should be used to access the configuration
71 @param _rAccessSafety
72 As this class is intended to manipulate objects it does not hold itself (see the various
73 registerXXX methods), it needs to guard these access for multi threading safety.<br/>
74 The mutex given here is locked whenever such an access occurs.
75 @param _pConfigLocation
76 is an ASCII string describing the configurations node path
77 @param _nAccessFlags
78 specifies different aspects of the configuration aspect to be created, e.g. it's update mode etc.<br/>
79 See the CVC_xxx constants for what you can use here.
80 @param _nLevels
81 specifies the number of levels to access under the node given by <arg>_pConfigLocation</arg>
83 OConfigurationValueContainer(
84 const css::uno::Reference< css::uno::XComponentContext >& _rxORB,
85 ::osl::Mutex& _rAccessSafety,
86 const char* _pConfigLocation,
87 const sal_Int32 _nLevels
90 /// dtor
91 ~OConfigurationValueContainer();
93 // registering data containers
95 /** registers a data accessor of an arbitrary type.
97 <p>Usually, in your derived class you simply add a member of the correct type of the configuration
98 value, and then call this method with the address of this member.</p>
100 @param _pRelativePathAscii
101 is a relative (ASCII) path of the node which should be "mirrored" into the accessor.
102 @param _pContainer
103 points to the accessors location in memory. Usually, this is simply an address of your derived class
104 @param _rValueType
105 is the type of your accessor. This type must be supported by the configuration.
107 void registerExchangeLocation(
108 const char* _pRelativePathAscii,
109 void* _pContainer,
110 const css::uno::Type& _rValueType
113 public:
114 /** reads the configuration data
116 <p>The current values of the nodes bound (using the registerXXX methods) is copied into their
117 respective exchange locations.</p>
119 <p>Please note that any changes done to your exchange locations are overridden with the current config
120 values.</p>
122 @see write
124 void read( );
126 /** commits any changes done
128 <p>Note that calling <method>write</method>(<sal_True/) is the same as calling <method>commit</method>(<TRUE/>).</p>
130 The current values in the exchange locations are written to the configuration nodes
131 before the changes are committed.<br/>
133 @precond
134 The access must have been created for update access
136 void commit();
138 private:
139 /// implements the ctors
140 void implConstruct(
141 const OUString& _rConfigLocation,
142 const sal_Int32 _nLevels
145 /// registers a value container
146 void implRegisterExchangeLocation( const NodeValueAccessor& _rAccessor );
149 } // namespace utl
151 #endif // INCLUDED_UNOTOOLS_CONFIGVALUECONTAINER_HXX
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */