1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #ifndef INCLUDED_SD_SOURCE_UI_INC_TOOLS_CONFIGURATIONACCESS_HXX
21 #define INCLUDED_SD_SOURCE_UI_INC_TOOLS_CONFIGURATIONACCESS_HXX
23 #include <rtl/ustring.hxx>
24 #include <com/sun/star/container/XNameAccess.hpp>
25 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <boost/function.hpp>
31 namespace sd
{ namespace tools
{
33 /** This class gives access to the configuration. Create an object of this
34 class for one node of the configuration. This will be the root node.
35 Its children are then accessible through the new ConfigurationAccess
38 class ConfigurationAccess
41 enum WriteMode
{ READ_WRITE
, READ_ONLY
};
43 /** Create a new object to access the configuration entries below the
48 This flag specifies whether to give read-write or read-only
52 const OUString
& rsRootName
,
53 const WriteMode eMode
);
56 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
,
57 const OUString
& rsRootName
,
58 const WriteMode eMode
);
60 /** Return a configuration node below the root of the called object.
62 The relative path from the root (as given the constructor) to
65 The type of the returned node varies with the requested node.
66 It is empty when the node was not found.
68 css::uno::Any
GetConfigurationNode (
69 const OUString
& rsPathToNode
);
71 /** Return a configuration node below the given node.
73 The node that acts as root to the given relative path.
75 The relative path from the given node to the requested node.
77 The type of the returned node varies with the requested node.
78 It is empty when the node was not found.
80 static css::uno::Any
GetConfigurationNode (
81 const css::uno::Reference
<css::container::XHierarchicalNameAccess
>& rxNode
,
82 const OUString
& rsPathToNode
);
84 /** Write any changes that have been made back to the configuration.
85 This call is ignored when the called ConfigurationAccess object was
86 not create with read-write mode.
90 /** This functor is typically called for every item in a set. Its two
91 parameters are the name of key item (often of no further interest)
92 and the value of the item.
94 typedef ::boost::function
<void(
96 const std::vector
<css::uno::Any
>&) > Functor
;
98 /** Execute a functor for all elements of the given container.
100 The container is a XNameAccess to a list of the configuration.
101 This can be a node returned by GetConfigurationNode().
103 The functor is called with arguments that are children of each
104 element of the container. The set of children is specified this
107 The functor to be executed for some or all of the elements in
111 const css::uno::Reference
<css::container::XNameAccess
>& rxContainer
,
112 const ::std::vector
<OUString
>& rArguments
,
113 const Functor
& rFunctor
);
115 /** Fill a list with the string contents of all sub-elements in the given container.
117 The container is a XNameAccess to a list of the configuration.
118 This can be a node returned by GetConfigurationNode().
120 This specifies which string children of the elements in the
121 container are to be inserted into the list. The specified child
122 has to be of type string.
124 The list to be filled.
126 static void FillList(
127 const css::uno::Reference
<css::container::XNameAccess
>& rxContainer
,
128 const OUString
& rsArgument
,
129 ::std::vector
<OUString
>& rList
);
132 css::uno::Reference
<css::uno::XInterface
> mxRoot
;
135 const css::uno::Reference
<css::lang::XMultiServiceFactory
>& rxProvider
,
136 const OUString
& rsRootName
,
137 const WriteMode eMode
);
140 } } // end of namespace sd::tools
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */