bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / unotools / configvaluecontainer.hxx
blob5d51b1e7dcaac8dd43805b003d3fce12eb68acd9
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 <unotools/unotoolsdllapi.h>
23 #include <com/sun/star/uno/Type.hxx>
24 #include <memory>
27 namespace com { namespace sun { namespace star { namespace uno { template <typename > class Reference; } } } }
28 namespace com { namespace sun { namespace star { namespace uno { class XComponentContext; } } } }
29 namespace osl { class Mutex; }
31 namespace utl
34 struct OConfigurationValueContainerImpl;
35 struct NodeValueAccessor;
37 //= OConfigurationValueContainer
39 /** allows simple access to static configuration structures.
41 <p>The basic idea of this class is that it's clients (usually derived classes) simply register an
42 address in memory and a node path, and upon explicit request, the configuration value and the memory
43 are synchronized.<br/>
44 This means that when calling <method>read</method>, the current configuration values are copied into
45 the memory registered for them, and upon calling <method>write</method> the current values in memory
46 are set in the configuration nodes.</p>
48 <p>This way, the usage of this class is pretty straight forward: derive your own class, spend some members
49 to it, and bind these members to configuration node (usually done in the ctor of the derived class).<br/>
50 In the dtor, simply call <method>write</method> and <method>commit</method>.</p>
52 <p>There is no auto-commit mechanism in the dtor: In the usual scenario, when you derive from this class
53 and bind some members of your derived class to config nodes, this means that your members will be destroyed
54 before your base class' dtor is called, so accessing the memory during such a theoretical auto-commit would
55 yield undefined behaviour.</p>
57 class UNOTOOLS_DLLPUBLIC OConfigurationValueContainer
59 private:
60 std::unique_ptr<OConfigurationValueContainerImpl> m_pImpl;
62 protected:
64 // construction/destruction
66 /** constructs the object
68 @param _rxORB
69 specifies the service factory which should be used to access the configuration
70 @param _rAccessSafety
71 As this class is intended to manipulate objects it does not hold itself (see the various
72 registerXXX methods), it needs to guard these access for multi threading safety.<br/>
73 The mutex given here is locked whenever such an access occurs.
74 @param _pConfigLocation
75 is an ASCII string describing the configurations node path
76 @param _nAccessFlags
77 specifies different aspects of the configuration aspect to be created, e.g. it's update mode etc.<br/>
78 See the CVC_xxx constants for what you can use here.
79 @param _nLevels
80 specifies the number of levels to access under the node given by <arg>_pConfigLocation</arg>
82 OConfigurationValueContainer(
83 const css::uno::Reference< css::uno::XComponentContext >& _rxORB,
84 ::osl::Mutex& _rAccessSafety,
85 const sal_Char* _pConfigLocation,
86 const sal_Int32 _nLevels
89 /// dtor
90 ~OConfigurationValueContainer();
92 // registering data containers
94 /** registers a data accessor of an arbitrary type.
96 <p>Usually, in your derived class you simply add a member of the correct type of the configuration
97 value, and then call this method with the address of this member.</p>
99 @param _pRelativePathAscii
100 is a relative (ASCII) path of the node which should be "mirrored" into the accessor.
101 @param _pContainer
102 points to the accessors location in memory. Usually, this is simply an address of your derived class
103 @param _rValueType
104 is the type of your accessor. This type must be supported by the configuration.
106 void registerExchangeLocation(
107 const sal_Char* _pRelativePathAscii,
108 void* _pContainer,
109 const css::uno::Type& _rValueType
112 public:
113 /** reads the configuration data
115 <p>The current values of the nodes bound (using the registerXXX methods) is copied into their
116 respective exchange locations.</p>
118 <p>Please note that any changes done to your exchange locations are overridden with the current config
119 values.</p>
121 @see write
123 void read( );
125 /** commits any changes done
127 <p>Note that calling <method>write</method>(<sal_True/) is the same as calling <method>commit</method>(<TRUE/>).</p>
129 The current values in the exchange locations are written to the configuration nodes
130 before the changes are committed.<br/>
132 @precond
133 The access must have been created for update access
135 void commit();
137 private:
138 /// implements the ctors
139 void implConstruct(
140 const OUString& _rConfigLocation,
141 const sal_Int32 _nLevels
144 /// registers a value container
145 void implRegisterExchangeLocation( const NodeValueAccessor& _rAccessor );
148 } // namespace utl
150 #endif // INCLUDED_UNOTOOLS_CONFIGVALUECONTAINER_HXX
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */