merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / inc / noderef.hxx
blob78cee2868e4d812e20dcb66576b7ed2cd4be01ac
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: noderef.hxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef CONFIGMGR_CONFIGNODE_HXX_
32 #define CONFIGMGR_CONFIGNODE_HXX_
34 #include "rtl/ref.hxx"
36 #include "configexcept.hxx"
37 #include "configpath.hxx"
38 #include "tree.hxx"
40 #ifndef INCLUDED_VECTOR
41 #include <vector>
42 #define INCLUDED_VECTOR
43 #endif
45 namespace configmgr
47 class INode;
49 namespace view { class ViewTreeAccess; }
50 namespace configapi { class Factory; }
51 namespace node { struct Attributes; }
52 namespace configuration
54 //-------------------------------------------------------------------------
55 class AbsolutePath;
56 class RelativePath;
57 namespace Path { class Component; }
59 class NodeChange;
60 class NodeChanges;
61 class NodeRef;
62 class ValueRef;
63 class AnyNodeRef;
65 class NodeID;
67 const unsigned int C_TreeDepthAll = ~0u;
68 //-------------------------------------------------------------------------
70 /// represents a inner node position in some tree
71 class NodeRef
73 public:
74 /// constructs an empty (invalid) node
75 NodeRef();
77 NodeRef(unsigned int nPos, unsigned int nDepth);
79 /// copy a node (with reference semantics)
80 NodeRef(NodeRef const& rOther);
81 /// copy a node (with reference semantics)
82 NodeRef& operator=(NodeRef const& rOther);
84 void swap(NodeRef& rOther);
86 ~NodeRef();
88 /// checks, if this represents an existing node
89 inline bool isValid() const;
91 /// returns the offset of this Node
92 inline unsigned int getOffset() const;
94 /// returns the offset of this Node
95 inline unsigned int getDepth() const;
97 private:
98 friend class AnyNodeRef;
99 private:
100 unsigned int m_nPos;
101 unsigned int m_nDepth;
103 //-------------------------------------------------------------------------
105 class NodeID
107 public:
108 NodeID(rtl::Reference< Tree > const& rTree, NodeRef const& rNode);
109 NodeID(Tree* pImpl, unsigned int nNode);
111 // comparison
112 // equality
113 friend bool operator==(NodeID const& lhs, NodeID const& rhs)
114 { return lhs.m_pTree == rhs.m_pTree && lhs.m_nNode == rhs.m_nNode; }
115 // ordering
116 friend bool operator < (NodeID const& lhs, NodeID const& rhs);
117 // checking
118 bool isEmpty() const;
119 // checking
120 bool isValidNode() const;
121 // hashing
122 size_t hashCode() const;
123 // use as index - returns a value in the range 0..rTree.getContainedNodes() for the tree used to construct this
124 unsigned int toIndex() const;
126 Tree * getTree() const { return m_pTree; }
128 unsigned int getOffset() const { return m_nNode; }
130 NodeRef getNode() const;
132 private:
133 Tree* m_pTree;
134 unsigned int m_nNode;
136 //-------------------------------------------------------------------------
138 /** make a name out of <var>sName</var>.
139 @throws InvalidName
140 if <var>sName</var> is not a valid name for a member of group <var>aNode</var> within <var>aTree</var>
143 rtl::OUString validateChildName(rtl::OUString const& sName, rtl::Reference< Tree > const& aTree, NodeRef const& aNode );
145 /** make a name out of <var>sName</var>.
146 @throws InvalidName
147 if <var>sName</var> is not a valid name for an element of set <var>aNode</var> within <var>aTree</var>
150 rtl::OUString validateElementName(rtl::OUString const& sName, rtl::Reference< Tree > const& aTree, NodeRef const& aNode );
152 /** make a name out of <var>sName</var>.
153 @throws InvalidName
154 if <var>sName</var> is not a valid name for a child of <var>aNode</var> within <var>aTree</var>
157 rtl::OUString validateChildOrElementName(rtl::OUString const& sName, rtl::Reference< Tree > const& aTree, NodeRef const& aNode );
159 /** make one path component out of <var>sName</var>.
160 @throws InvalidName
161 if <var>sName</var> is not a valid name for an element of set <var>aNode</var> within <var>aTree</var>
164 Path::Component validateElementPathComponent(rtl::OUString const& sName, rtl::Reference< Tree > const& aTree, NodeRef const& aNode );
166 /** parse <var>aPath</var> into a relative path,
167 valid in the context of node <var>aNode<var/> in <var>aTree<var/>.
169 @returns
170 <var>aPath<var/> parsed as a relative path
171 @throws InvalidName
172 if <var>aPath<var/> is not a relative path or not valid in the context of <var>aNode<var/>
174 RelativePath validateRelativePath(rtl::OUString const& aPath, rtl::Reference< Tree > const& aTree, NodeRef const& aNode);
176 /** parse <var>aPath</var> as a configuration path
177 and reduce it to be relative to node <var>aNode<var/> in <var>aTree<var/>.
179 @returns
180 the result of parsing <var>aPath<var/>, if that results in a relative path, or
181 the part of it relative to <var>aNode<var/>,
182 if it is an absolute path to a descendant of <var>aNode<var/>
183 @throws InvalidName
184 if <var>aPath<var/> is not awell-formed path or
185 if it is an absolute path that is not to a descendant of <var>aNode<var/>
187 RelativePath validateAndReducePath(rtl::OUString const& aPath, rtl::Reference< Tree > const& aTree, NodeRef const& aNode);
188 /** checks whether there is an immediate child of <var>aNode</var> (which is in <var>aTree</var>)
189 specified by <var>aName</var>
191 @return
192 <TRUE/> if the child node exists
193 <FALSE/> otherwise
195 bool hasChildOrElement(rtl::Reference< Tree > const& aTree, NodeRef const& aNode, rtl::OUString const& aName);
197 /** checks whether there is an immediate child of <var>aNode</var> (which is in <var>aTree</var>)
198 specified by <var>aName</var>
200 @return
201 <TRUE/> if the child node exists
202 <FALSE/> otherwise
204 bool hasChildOrElement(rtl::Reference< Tree > const& aTree, NodeRef const& aNode, Path::Component const& aName);
206 /** tries to find the immediate child of <var>aNode</var> (which is in <var>aTree</var>)
207 specified by <var>aName</var>
208 <p> On return <var>aNode</var> is modified to refer to the node found and
209 <var>aTree</var> will then refer to the tree that node is in.
210 <p/>
211 <p>Caution: May miss an existing child unless the child has been accessed before.</p>
213 @return
214 <TRUE/> if the child node exists and is available
215 (so <var>aNode</var> and <var>aTree</var> refer to the desired node),
216 <FALSE/> otherwise
218 @see NodeRef::getAvailableChild
220 bool findInnerChildOrAvailableElement(rtl::Reference< Tree >& aTree, NodeRef& aNode, rtl::OUString const& aName);
222 /// test whether the given node is a structural (inner) node
223 bool isStructuralNode(rtl::Reference< Tree > const& aTree, NodeRef const& aNode);
225 /// test whether the given inner node is a group node
226 bool isGroupNode(rtl::Reference< Tree > const& aTree, NodeRef const& aNode);
228 /// get the value for a node that is a simple value (as tree element)
229 com::sun::star::uno::Any getSimpleElementValue(rtl::Reference< Tree > const& aTree, NodeRef const& aNode);
231 /// test whether the given inner node is a set node
232 bool isSetNode(rtl::Reference< Tree > const& aTree, NodeRef const& aNode);
234 void getAllContainedNodes(rtl::Reference< Tree > const& aTree, std::vector<NodeID>& aList);
235 NodeID findNodeFromIndex(rtl::Reference< Tree > const& aTreeRef, unsigned int nIndex);
237 //-------------------------------------------------------------------------
238 inline bool NodeRef::isValid() const
240 return m_nPos != 0;
243 //-------------------------------------------------------------------------
244 inline unsigned int NodeRef::getOffset() const
246 return m_nPos;
249 //-------------------------------------------------------------------------
250 inline unsigned int NodeRef::getDepth() const
252 return m_nDepth;
255 //-------------------------------------------------------------------------
256 inline bool operator!=(NodeID const& lhs, NodeID const& rhs)
257 { return !(lhs == rhs); }
258 //---------------------------------------------------------------------
260 inline bool operator>=(NodeID const& lhs, NodeID const& rhs)
261 { return !(lhs < rhs); }
262 //---------------------------------------------------------------------
263 inline bool operator > (NodeID const& lhs, NodeID const& rhs)
264 { return (rhs < lhs); }
265 inline bool operator<=(NodeID const& lhs, NodeID const& rhs)
266 { return !(rhs < lhs); }
267 //-------------------------------------------------------------------------
271 #endif // CONFIGMGR_CONFIGNODE_HXX_