1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: noderef.hxx,v $
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"
40 #ifndef INCLUDED_VECTOR
42 #define INCLUDED_VECTOR
49 namespace view
{ class ViewTreeAccess
; }
50 namespace configapi
{ class Factory
; }
51 namespace node
{ struct Attributes
; }
52 namespace configuration
54 //-------------------------------------------------------------------------
57 namespace Path
{ class Component
; }
67 const unsigned int C_TreeDepthAll
= ~0u;
68 //-------------------------------------------------------------------------
70 /// represents a inner node position in some tree
74 /// constructs an empty (invalid) node
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
);
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;
98 friend class AnyNodeRef
;
101 unsigned int m_nDepth
;
103 //-------------------------------------------------------------------------
108 NodeID(rtl::Reference
< Tree
> const& rTree
, NodeRef
const& rNode
);
109 NodeID(Tree
* pImpl
, unsigned int nNode
);
113 friend bool operator==(NodeID
const& lhs
, NodeID
const& rhs
)
114 { return lhs
.m_pTree
== rhs
.m_pTree
&& lhs
.m_nNode
== rhs
.m_nNode
; }
116 friend bool operator < (NodeID
const& lhs
, NodeID
const& rhs
);
118 bool isEmpty() const;
120 bool isValidNode() const;
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;
134 unsigned int m_nNode
;
136 //-------------------------------------------------------------------------
138 /** make a name out of <var>sName</var>.
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>.
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>.
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>.
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/>.
170 <var>aPath<var/> parsed as a relative path
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/>.
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/>
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>
192 <TRUE/> if the child node exists
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>
201 <TRUE/> if the child node exists
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.
211 <p>Caution: May miss an existing child unless the child has been accessed before.</p>
214 <TRUE/> if the child node exists and is available
215 (so <var>aNode</var> and <var>aTree</var> refer to the desired node),
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
243 //-------------------------------------------------------------------------
244 inline unsigned int NodeRef::getOffset() const
249 //-------------------------------------------------------------------------
250 inline unsigned int NodeRef::getDepth() const
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_