merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / inc / anynoderef.hxx
blob29683dad19dee3dd3bed48f491af3fa387e1c677
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: anynoderef.hxx,v $
10 * $Revision: 1.8 $
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_CONFIGANYNODE_HXX_
32 #define CONFIGMGR_CONFIGANYNODE_HXX_
34 #include "noderef.hxx"
36 namespace configmgr
38 namespace configapi { class Factory; }
39 namespace node { struct Attributes; }
41 namespace configuration
43 //-------------------------------------------------------------------------
44 class NodeRef;
45 class ValueRef;
46 class AnyNodeRef;
47 class NodeID;
48 class Tree;
49 //-------------------------------------------------------------------------
51 /// represents any node in some tree
52 class AnyNodeRef
54 public:
55 /// constructs an empty (invalid) node
56 AnyNodeRef();
58 AnyNodeRef(unsigned int nParentPos, unsigned int m_nDepth);
59 AnyNodeRef(rtl::OUString const& aName, unsigned int nParentPos);
61 /// converts an inner node
62 explicit AnyNodeRef(NodeRef const& aInnerNode);
63 /// converts a value node
64 explicit AnyNodeRef(ValueRef const& aValueNode);
66 /// copy a node (with reference semantics)
67 AnyNodeRef(AnyNodeRef const& rOther);
68 /// copy a node (with reference semantics)
69 AnyNodeRef& operator=(AnyNodeRef const& rOther);
71 void swap(AnyNodeRef& rOther);
73 ~AnyNodeRef();
75 /// checks, if this represents an existing node
76 inline bool isValid() const;
78 /// checks if this a node (rather than a value only)
79 bool isNode() const;
81 /// converts this, if it is a value
82 ValueRef toValue() const;
84 /// converts this, if it is a inner node
85 NodeRef toNode() const;
87 #if OSL_DEBUG_LEVEL > 0
88 bool checkValidState() const;
89 #endif
91 rtl::OUString m_sNodeName;
92 unsigned int m_nUsedPos;
93 unsigned int m_nDepth;
95 //-------------------------------------------------------------------------
97 /** checks whether there is an immediate child of <var>aNode</var> (which is in <var>aTree</var>)
98 specified by <var>aName</var>
100 @return
101 <TRUE/> if the child node exists
102 <FALSE/> otherwise
104 inline
105 bool hasChildOrElement(rtl::Reference< Tree > const& aTree, AnyNodeRef const& aNode, rtl::OUString const& aName)
106 { return aNode.isNode() && hasChildOrElement(aTree,aNode.toNode(),aName); }
108 /** tries to find the immediate child of <var>aNode</var> (which is in <var>aTree</var>)
109 specified by <var>aName</var>
110 <p> On return <var>aNode</var> is modified to refer to the node found and
111 <var>aTree</var> will then refer to the tree that node is in.
112 <p/>
114 @return The requested child node, if it exists
115 (then <var>aTree</var> refers to the tree containing the desired node),
117 AnyNodeRef getChildOrElement(rtl::Reference< Tree > & aTree, NodeRef const& aParentNode, rtl::OUString const& aName);
119 /** tries to find the descendant of <var>aNode</var> specified by <var>aPath</var> within <var>aTree</var>
120 <p> This function follows the given path stepwise, until a requested node is missing in the tree.</p>
121 <p> On return <var>aNode</var> is modified to refer to the last inner node found
122 and <var>aTree</var> will be unchanged (except for deprecated usage).
123 <p/>
124 <p> Also, <var>aPath</var> is modified to contain the unresolved part of the original path.
125 </p>
127 @return the requested node, if the path could be resolved completely
128 (so <var>aNode</var> refers to the desired node or its parent,
129 and <var>aPath</var> is empty)<BR/>
130 an invalid node otherwise
132 AnyNodeRef getLocalDescendant(rtl::Reference< Tree > const& aTree, NodeRef const& aNode, RelativePath const& aPath);
134 /** tries to find the descendant of <var>aNode</var> (which is in <var>aTree</var>) specified by <var>aPath</var>
135 <p> This function follows the given path stepwise, until a requested node is missing in the tree.</p>
136 <p> On return <var>aNode</var> is modified to refer to the last inner node found and
137 <var>aTree</var> will then refer to the tree that node is in.
138 <p/>
139 <p> Also, <var>aPath</var> is modified to contain the unresolved part of the original path.
140 </p>
142 @return the requested node, if the path could be resolved completely
143 (so <var>aNode</var> and <var>aTree</var> refer to the desired node or its parent,
144 and <var>aPath</var> is empty)<BR/>
145 an invalid node otherwise
147 AnyNodeRef getDeepDescendant(rtl::Reference< Tree > & aTree, NodeRef& aNode, RelativePath& aPath);
149 //-------------------------------------------------------------------------
150 inline bool AnyNodeRef::isValid() const
152 OSL_ASSERT( m_nUsedPos == 0 || checkValidState() );
153 return m_nUsedPos != 0;
156 //-------------------------------------------------------------------------
160 #endif // CONFIGMGR_CONFIGANYNODE_HXX_