From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- include/unotools/configvaluecontainer.hxx | 153 ++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 include/unotools/configvaluecontainer.hxx (limited to 'include/unotools/configvaluecontainer.hxx') diff --git a/include/unotools/configvaluecontainer.hxx b/include/unotools/configvaluecontainer.hxx new file mode 100644 index 000000000..c4447fca2 --- /dev/null +++ b/include/unotools/configvaluecontainer.hxx @@ -0,0 +1,153 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_UNOTOOLS_CONFIGVALUECONTAINER_HXX +#define INCLUDED_UNOTOOLS_CONFIGVALUECONTAINER_HXX + +#include +#include +#include +#include + + +namespace com::sun::star::uno { template class Reference; } +namespace com::sun::star::uno { class XComponentContext; } +namespace osl { class Mutex; } + +namespace utl +{ + + struct OConfigurationValueContainerImpl; + struct NodeValueAccessor; + + //= OConfigurationValueContainer + + /** allows simple access to static configuration structures. + +

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 synchronized.
+ This means that when calling read, the current configuration values are copied into + the memory registered for them, and upon calling write the current values in memory + are set in the configuration nodes.

+ +

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).
+ In the dtor, simply call write and commit.

+ +

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.

+ */ + class UNLESS_MERGELIBS(UNOTOOLS_DLLPUBLIC) OConfigurationValueContainer + { + private: + std::unique_ptr 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 intended to manipulate objects it does not hold itself (see the various + registerXXX methods), it needs to guard these access for multi threading safety.
+ 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.
+ 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 _pConfigLocation + */ + OConfigurationValueContainer( + const css::uno::Reference< css::uno::XComponentContext >& _rxORB, + ::osl::Mutex& _rAccessSafety, + const char* _pConfigLocation, + const sal_Int32 _nLevels + ); + + /// dtor + ~OConfigurationValueContainer(); + + // registering data containers + + /** registers a data accessor of an arbitrary type. + +

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.

+ + @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 accessor. This type must be supported by the configuration. + */ + void registerExchangeLocation( + const char* _pRelativePathAscii, + void* _pContainer, + const css::uno::Type& _rValueType + ); + + public: + /** reads the configuration data + +

The current values of the nodes bound (using the registerXXX methods) is copied into their + respective exchange locations.

+ +

Please note that any changes done to your exchange locations are overridden with the current config + values.

+ + @see write + */ + void read( ); + + /** commits any changes done + +

Note that calling write(commit().

+ + The current values in the exchange locations are written to the configuration nodes + before the changes are committed.
+ + @precond + The access must have been created for update access + */ + void commit(); + + private: + /// implements the ctors + void implConstruct( + const OUString& _rConfigLocation, + const sal_Int32 _nLevels + ); + + /// registers a value container + void implRegisterExchangeLocation( const NodeValueAccessor& _rAccessor ); + }; + +} // namespace utl + +#endif // INCLUDED_UNOTOOLS_CONFIGVALUECONTAINER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3