LOK: custom widgets: check size of API structures
[LibreOffice.git] / include / unotools / confignode.hxx
blobbc4937e181a7bede399430e992da0a7a73bbc494
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_CONFIGNODE_HXX
20 #define INCLUDED_UNOTOOLS_CONFIGNODE_HXX
22 #include <unotools/unotoolsdllapi.h>
23 #include <unotools/eventlisteneradapter.hxx>
25 namespace com { namespace sun { namespace star { namespace container { class XHierarchicalNameAccess; } } } }
26 namespace com { namespace sun { namespace star { namespace container { class XNameAccess; } } } }
27 namespace com { namespace sun { namespace star { namespace container { class XNameContainer; } } } }
28 namespace com { namespace sun { namespace star { namespace container { class XNameReplace; } } } }
29 namespace com { namespace sun { namespace star { namespace lang { class XMultiServiceFactory; } } } }
30 namespace com { namespace sun { namespace star { namespace uno { class XComponentContext; } } } }
31 namespace com { namespace sun { namespace star { namespace util { class XChangesBatch; } } } }
33 namespace utl
36 /** a small wrapper around a configuration node.<p/>
37 Nodes in the terminology used herein are <em>inner</em> nodes of a configuration
38 tree, which means <em>no leafs</em>.
40 class UNOTOOLS_DLLPUBLIC OConfigurationNode : public ::utl::OEventListenerAdapter
42 private:
43 css::uno::Reference< css::container::XHierarchicalNameAccess >
44 m_xHierarchyAccess; /// accessing children grandchildren (mandatory interface of our UNO object)
45 css::uno::Reference< css::container::XNameAccess >
46 m_xDirectAccess; /// accessing children (mandatory interface of our UNO object)
47 css::uno::Reference< css::container::XNameReplace >
48 m_xReplaceAccess; /// replacing child values
49 css::uno::Reference< css::container::XNameContainer >
50 m_xContainerAccess; /// modifying set nodes (optional interface of our UNO object)
51 bool m_bEscapeNames; /// escape names before accessing children ?
53 OConfigurationNode insertNode(const OUString& _rName,const css::uno::Reference< css::uno::XInterface >& _xNode) const throw();
55 protected:
56 /// constructs a node object with an interface representing a node
57 OConfigurationNode(
58 const css::uno::Reference< css::uno::XInterface >& _rxNode
61 const css::uno::Reference< css::container::XNameAccess >&
62 getUNONode() const { return m_xDirectAccess; }
64 public:
65 /// constructs an empty and invalid node object
66 OConfigurationNode() :m_bEscapeNames(false) { }
67 /// copy ctor
68 OConfigurationNode(const OConfigurationNode& _rSource);
69 /// move ctor
70 OConfigurationNode(OConfigurationNode&& _rSource);
72 /// assignment
73 OConfigurationNode& operator=(const OConfigurationNode& _rSource);
74 OConfigurationNode& operator=(OConfigurationNode&& _rSource);
76 /// returns the local name of the node
77 OUString getLocalName() const;
79 /** open a sub node
80 @param _rPath access path of the to-be-opened sub node. May be a hierarchical path.
82 OConfigurationNode openNode(const OUString& _rPath) const throw();
84 OConfigurationNode openNode( const sal_Char* _pAsciiPath ) const
86 return openNode( OUString::createFromAscii( _pAsciiPath ) );
89 /** create a new child node
91 If the object represents a set node, this method may be used to create a new child. For non-set-nodes, the
92 method will fail.<br/>
93 Unless the respective operations on the pure configuration API, the to-be-created node immediately
94 becomes a part of its hierarchy, no explicit insertion is necessary.
95 @param _rName name for the new child. Must be level-1-depth.
97 OConfigurationNode createNode(const OUString& _rName) const throw();
99 /** remove an existent child nod
101 If the object represents a set node, this method may be used to delete an existent child. For non-set-nodes,
102 the method will fail.
104 bool removeNode(const OUString& _rName) const throw();
106 /** retrieves the content of a descendant
108 the returned value may contain anything from an interface (if <arg>_rPath</arg> refers to inner node of
109 the configuration tree) to any explicit value (e.g. string, integer) or even void.<br/>
110 Unfortunately, this implies that if a void value is returned, you won't have a clue if this means
111 "the path does not exist" (besides the assertion made :), or if the value is really void.
113 css::uno::Any getNodeValue(const OUString& _rPath) const throw();
115 css::uno::Any getNodeValue( const sal_Char* _pAsciiPath ) const
117 return getNodeValue( OUString::createFromAscii( _pAsciiPath ) );
120 /** write a node value<p/>
121 The value given is written into the node specified by the given relative path.<br/>
122 In opposite to <method>getNodeValue</method>, _rName must refer to a leaf in the configuration tree, not an inner
123 node.
124 @return sal_True if and only if the write was successful.
126 bool setNodeValue(const OUString& _rPath, const css::uno::Any& _rValue) const throw();
128 bool setNodeValue( const sal_Char* _pAsciiPath, const css::uno::Any& _rValue ) const
130 return setNodeValue( OUString::createFromAscii( _pAsciiPath ), _rValue );
133 /// return the names of the existing children
134 css::uno::Sequence< OUString >
135 getNodeNames() const throw();
137 /** get the flag specifying the current escape behaviour
138 @see setEscape
140 bool getEscape() const { return m_bEscapeNames; }
142 /// invalidate the object
143 virtual void clear() throw();
145 // meta information about the node
147 /// checks whether or not the object represents a set node.
148 bool isSetNode() const;
150 /// checks whether or not a direct child with a given name exists
151 bool hasByName(const OUString& _rName) const throw();
152 bool hasByName( const sal_Char* _pAsciiName ) const { return hasByName( OUString::createFromAscii( _pAsciiName ) ); }
154 /// checks whether or not a descendent (no matter if direct or indirect) with the given name exists
155 bool hasByHierarchicalName( const OUString& _rName ) const throw();
157 /// check if the objects represents a valid configuration node
158 bool isValid() const { return m_xHierarchyAccess.is(); }
160 /// check whether the object is read-only of updatable
161 bool isReadonly() const { return !m_xReplaceAccess.is(); }
163 protected:
164 // OEventListenerAdapter
165 virtual void _disposing( const css::lang::EventObject& _rSource ) override;
167 protected:
168 enum NAMEORIGIN
170 NO_CONFIGURATION, /// the name came from a configuration node
171 NO_CALLER /// the name came from a client of this class
173 OUString normalizeName(const OUString& _rName, NAMEORIGIN _eOrigin) const;
176 //= OConfigurationTreeRoot
178 /** a specialized version of a OConfigurationNode, representing the root
179 of a configuration sub tree<p/>
180 Only this class is able to commit any changes made any any OConfigurationNode
181 objects.
183 class UNOTOOLS_DLLPUBLIC OConfigurationTreeRoot : public OConfigurationNode
185 css::uno::Reference< css::util::XChangesBatch >
186 m_xCommitter;
187 protected:
188 /** ctor for a readonly node
190 OConfigurationTreeRoot(
191 const css::uno::Reference< css::uno::XInterface >& _rxRootNode
194 public:
195 /// modes to use when creating a top-level node object
196 enum CREATION_MODE
198 /// open the node (i.e. sub tree) for read access only
199 CM_READONLY,
200 /// open the node (i.e. sub tree) for read and write access, fall back to read-only if write access is not possible
201 CM_UPDATABLE
204 public:
205 /** default ctor<p/>
206 The object constructed here is invalid (i.e. <method>isValid</method> will return sal_False).
208 OConfigurationTreeRoot() :OConfigurationNode() { }
210 /** creates a configuration tree for the given path in the given mode
212 OConfigurationTreeRoot(
213 const css::uno::Reference<css::uno::XComponentContext> & i_rContext,
214 const OUString& i_rNodePath,
215 const bool i_bUpdatable
218 /** open a new top-level configuration node
220 opens a new node which is the root if an own configuration sub tree. This is what "top level" means: The
221 node does not have a parent. It does not mean that the node represents a module tree (like org.openoffice.Office.Writer
222 or such).<br/>
223 In opposite to <method>createWithServiceFactory</method>, createWithProvider expects a configuration provider
224 to work with.
226 @param _rxConfProvider configuration provider to use when retrieving the node.
227 @param _rPath path to the node the object should represent
228 @param _nDepth depth for node retrieval
229 @param _eMode specifies which privileges should be applied when retrieving the node
231 @see createWithServiceFactory
233 static OConfigurationTreeRoot createWithProvider(
234 const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxConfProvider,
235 const OUString& _rPath,
236 sal_Int32 _nDepth,
237 CREATION_MODE _eMode
240 /** open a new top-level configuration node<p/>
241 opens a new node which is the root if an own configuration sub tree. This is what "top level" means: The
242 node does not have a parent. It does not mean that the node represents a module tree (like org.openoffice.Office.Writer
243 or such).<br/>
244 In opposite to <method>createWithProvider</method>, createWithProvider expects a service factory. This factory
245 is used to create a configuration provider, and this provider is used to retrieve the node
246 @see createWithProvider
247 @param _rxContext service factory to use to create the configuration provider.
248 @param _rPath path to the node the object should represent
249 @param _nDepth depth for node retrieval
250 @param _eMode specifies which privileges should be applied when retrieving the node
252 static OConfigurationTreeRoot createWithComponentContext(const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
253 const OUString& _rPath, sal_Int32 _nDepth = -1, CREATION_MODE _eMode = CM_UPDATABLE);
255 /** tolerant version of the <member>createWithServiceFactory</member>
257 <p>No assertions are thrown in case of an failure to initialize the configuration service, but once
258 the configuration could be initialized, errors in the creation of the specific node (e.g. because the
259 given node path does not exist) are still asserted.</p>
261 static OConfigurationTreeRoot tryCreateWithComponentContext( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
262 const OUString& _rPath, sal_Int32 _nDepth = -1, CREATION_MODE _eMode = CM_UPDATABLE );
264 /** commit all changes made on the subtree the object is the root for<p/>
265 All changes made on any OConfigurationNode object retrieved (maybe indirect) from this root
266 object are committed when calling this method.
267 @return sal_True if and only if the commit was successful
269 bool commit() const throw();
271 /// invalidate the object
272 virtual void clear() throw() override;
275 } // namespace utl
277 #endif // INCLUDED_UNOTOOLS_CONFIGNODE_HXX
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */