summaryrefslogtreecommitdiff
path: root/include/unotools/configvaluecontainer.hxx
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@canonical.com>2013-04-18 18:26:28 +0200
committerBjoern Michaelsen <bjoern.michaelsen@canonical.com>2013-04-23 22:20:31 +0200
commitb9337e22ce1dbf2eba0e8c8db294ae99f4111f91 (patch)
tree53ee1bd3dfd213815a21579151983cb997922b05 /include/unotools/configvaluecontainer.hxx
parentf4e1642a1761d5eab6ccdd89928869c2b2f1528a (diff)
execute move of global headers
see https://gerrit.libreoffice.org/#/c/3367/ and Change-Id: I00c96fa77d04b33a6f8c8cd3490dfcd9bdc9e84a for details Change-Id: I199a75bc4042af20817265d5ef85b1134a96ff5a
Diffstat (limited to 'include/unotools/configvaluecontainer.hxx')
-rw-r--r--include/unotools/configvaluecontainer.hxx183
1 files changed, 183 insertions, 0 deletions
diff --git a/include/unotools/configvaluecontainer.hxx b/include/unotools/configvaluecontainer.hxx
new file mode 100644
index 000000000000..2fa95c337bd0
--- /dev/null
+++ b/include/unotools/configvaluecontainer.hxx
@@ -0,0 +1,183 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#include "unotools/unotoolsdllapi.h"
+
+#ifndef UNOTOOLS_CONFIGVALUECONTAINER_HXX
+#define UNOTOOLS_CONFIGVALUECONTAINER_HXX
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <osl/mutex.hxx>
+
+//.........................................................................
+namespace utl
+{
+//.........................................................................
+
+#define CVC_READONLY_ACCESS 0x0000
+#define CVC_UPDATE_ACCESS 0x0001
+
+#define CVC_LAZY_UPDATE 0x0000
+#define CVC_IMMEDIATE_UPDATE 0x0002
+
+ struct OConfigurationValueContainerImpl;
+ struct NodeValueAccessor;
+ //=====================================================================
+ //= OConfigurationValueContainer
+ //=====================================================================
+ /** allows simple access to static configuration structures.
+
+ <p>The basic idea of this class is that it's clients (usually derived classes) simply register an
+ address in memory and a node path, and upon explicit request, the configuration value and the memory
+ are syncronized.<br/>
+ This means that when calling <method>read</method>, the current configuration values are copied into
+ the memory registered for them, and upon calling <method>write</method> the current values in memory
+ are set in the configuration nodes.</p>
+
+ <p>This way, the usage of this class is pretty straight forward: derive your own class, spend some members
+ to it, and bind these members to configuration node (usually done in the ctor of the derived class).<br/>
+ In the dtor, simply call <method>write</method> and <method>commit</method>.</p>
+
+ <p>There is no auto-commit mechanism in the dtor: In the usual scenario, when you derive from this class
+ and bind some members of your derived class to config nodes, this means that your members will be destroyed
+ before your base class' dtor is called, so accessing the memory during such a theoretical auto-commit would
+ yield undefined behaviour.</p>
+ */
+ class UNOTOOLS_DLLPUBLIC OConfigurationValueContainer
+ {
+ private:
+ OConfigurationValueContainerImpl*
+ m_pImpl;
+
+ protected:
+ //-----------------------------------------------------------------
+ // construction/destruction
+
+ /** constructs the object
+
+ @param _rxORB
+ specifies the service factory which should be used to access the configuration
+ @param _rAccessSafety
+ As this class is intented to manipulate objects it does not hold itself (see the various
+ registerXXX methods), it needs to guard these access for muti threading safety.<br/>
+ The mutex given here is locked whenever such an access occurs.
+ @param _pConfigLocation
+ is an ASCII string describing the configurations node path
+ @param _nAccessFlags
+ specifies different aspects of the configuration aspect to be created, e.g. it's update mode etc.<br/>
+ See the CVC_xxx constants for what you can use here.
+ @param _nLevels
+ specifies the number of levels to access under the node given by <arg>_pConfigLocation</arg>
+ */
+ OConfigurationValueContainer(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxORB,
+ ::osl::Mutex& _rAccessSafety,
+ const sal_Char* _pConfigLocation,
+ const sal_uInt16 _nAccessFlags = CVC_UPDATE_ACCESS | CVC_LAZY_UPDATE,
+ const sal_Int32 _nLevels = -1
+ );
+
+ /// dtor
+ ~OConfigurationValueContainer();
+
+ //-----------------------------------------------------------------
+ // registering data containers
+
+ /** registers a data accessor of an arbitrary type.
+
+ <p>Usually, in your derived class you simply add a member of the correct type of the configuration
+ value, and then call this method with the address of this member.</p>
+
+ @param _pRelativePathAscii
+ is a relative (ASCII) path of the node which should be "mirrored" into the accessor.
+ @param _pContainer
+ points to the accessors location in memory. Usually, this is simply an address of your derived class
+ @param _rValueType
+ is the type of your accessort. This type must be supported by the configuration.
+ */
+ void registerExchangeLocation(
+ const sal_Char* _pRelativePathAscii,
+ void* _pContainer,
+ const ::com::sun::star::uno::Type& _rValueType
+ );
+
+ public:
+ /** reads the configuration data
+
+ <p>The current values of the nodes bound (using the registerXXX methods) is copied into their
+ respective exchange locations.</p>
+
+ <p>Please note that any changes done to your exchange locations are overridden with the current config
+ values.</p>
+
+ @see write
+ */
+ void read( );
+
+ /** updates the configuration data
+
+ <p>The current values in memory (your exchange locations registered using the registerXXX methods) is
+ forwarded to their respective configuration nodes.</p>
+
+ <p>Note that calling <method>write</method>(<sal_True/) is the same as calling <method>commit</method>(<TRUE/>).</p>
+
+ @precond
+ The access must have been created for update access
+
+ @param _bCommit
+ If set to <TRUE/>, an automatic commit is done after the values have been synchronized.<br/>
+ If set to <FALSE/>, you must explicitly call <method>commit</method> to make your changes persistent.
+
+ @see read
+ @see commit
+ */
+ void write( sal_Bool _bCommit = sal_True );
+
+ /** commits any changes done
+
+ <p>Note that calling <method>write</method>(<sal_True/) is the same as calling <method>commit</method>(<TRUE/>).</p>
+
+ @precond
+ The access must have been created for update access
+
+ @param _bWrite
+ If <TRUE/>, the current values in the exchange locations are written to the configuration nodes
+ before the changes are committed.<br/>
+ If <FALSE/>, only the current values in the config nodes (as present since the last call to
+ <method>write</method>) are committed.
+ */
+ void commit( sal_Bool _bWrite = sal_True );
+
+ private:
+ /// implements the ctors
+ void implConstruct(
+ const OUString& _rConfigLocation,
+ const sal_uInt16 _nAccessFlags,
+ const sal_Int32 _nLevels
+ );
+
+ /// registers a value container
+ void implRegisterExchangeLocation( const NodeValueAccessor& _rAccessor );
+ };
+
+//.........................................................................
+} // namespace utl
+//.........................................................................
+
+#endif // UNOTOOLS_CONFIGVALUECONTAINER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */