summaryrefslogtreecommitdiff
path: root/configmgr
diff options
context:
space:
mode:
authorJörg Barfurth <jb@openoffice.org>2001-02-13 15:13:27 +0000
committerJörg Barfurth <jb@openoffice.org>2001-02-13 15:13:27 +0000
commit80dc89898912d5d3859c76a6d52bf2d169139858 (patch)
tree54beb8a41c2d146d9e1b28a0f8f638fefe78b24b /configmgr
parent3fe0b6d4a1f8009209529c767bbe5d5b0233f410 (diff)
Support for deferring access to trees; Extended NodeID functionality
Diffstat (limited to 'configmgr')
-rw-r--r--configmgr/source/inc/noderef.hxx55
-rw-r--r--configmgr/source/treemgr/noderef.cxx86
2 files changed, 134 insertions, 7 deletions
diff --git a/configmgr/source/inc/noderef.hxx b/configmgr/source/inc/noderef.hxx
index f7fb61d6abd7..a64cd4f820d9 100644
--- a/configmgr/source/inc/noderef.hxx
+++ b/configmgr/source/inc/noderef.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: noderef.hxx,v $
*
- * $Revision: 1.7 $
+ * $Revision: 1.8 $
*
- * last change: $Author: mh $ $Date: 2001-02-02 18:09:11 $
+ * last change: $Author: jb $ $Date: 2001-02-13 16:13:26 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -160,6 +160,16 @@ namespace configmgr
*/
NodeRef getChild(Name const& aName, Tree& aTree) const;
+ /** gets the owned child node named <var>aName</var> of this node, if it is available.
+ <p>Also sets <var>aTree<var/> to point to the tree containing that node.</p>
+ <p>If there is no such node, returns an empty node.</p>
+ <p>Caution: May miss existing children unless hasChild/getChild has been called before.</p>
+
+ @throws InvalidName
+ if <var>aName</var> is not a valid child name for this node
+ */
+ NodeRef getAvailableChild(Name const& aName, Tree& aTree) const;
+
/// return a <type>NodeInfo</type> showing the attributes of this
NodeInfo getInfo() const;
@@ -326,6 +336,10 @@ namespace configmgr
{ return lhs.m_pTree == rhs.m_pTree && lhs.m_nNode == rhs.m_nNode; }
// ordering
friend bool operator < (NodeID const& lhs, NodeID const& rhs);
+ // checking
+ bool isEmpty() const;
+ // checking
+ bool isValidNode() const;
// hashing
size_t hashCode() const;
// use as index - returns a value in the range 0..rTree.getContainedNodes() for the tree used to construct this
@@ -390,11 +404,27 @@ namespace configmgr
@return
<TRUE/> if the child node exists
- (so <var>aNode</var> and <var>aTree</var> refer to the desired node and <var>aPath</var> is empty),
+ (so <var>aNode</var> and <var>aTree</var> refer to the desired node),
<FALSE/> otherwise
*/
bool findChildNode(Tree& aTree, NodeRef& aNode, Name const& aName);
+ /** tries to find the immediate child of <var>aNode</var> (which is in <var>aTree</var>)
+ specified by <var>aName</var>
+ <p> On return <var>aNode</var> is modified to refer to the node found and
+ <var>aTree</var> will then refer to the tree that node is in.
+ <p/>
+ <p>Caution: May miss an existing child unless the child has been accessed before.</p>
+
+ @return
+ <TRUE/> if the child node exists and is available
+ (so <var>aNode</var> and <var>aTree</var> refer to the desired node),
+ <FALSE/> otherwise
+
+ @see NodeRef::getAvailableChild
+ */
+ bool findAvailableChildNode(Tree& aTree, NodeRef& aNode, Name const& aName);
+
/** tries to find the descendant of <var>aNode</var> (which is in <var>aTree</var>) specified by <var>aPath</var>
<p> This function follows the given path stepwise, until a requested node is missing in the tree.</p>
<p> On return <var>aNode</var> is modified to refer to the last node found and
@@ -411,6 +441,25 @@ namespace configmgr
*/
bool findDescendantNode(Tree& aTree, NodeRef& aNode, RelativePath& aPath);
+ /** tries to find the descendant of <var>aNode</var> (which is in <var>aTree</var>) specified by <var>aPath</var>
+ <p> This function follows the given path stepwise, until a requested node is miss in the tree,
+ or is not availbale in a set node.
+ </p>
+ <p> On return <var>aNode</var> is modified to refer to the last node found and
+ <var>aTree</var> will then refer to the tree that node is in.
+ <p/>
+ <p> Also, <var>aPath</var> is modified to contain the unresolved part of the original path.
+ </p>
+ <p>Caution: May miss existing descendants unless the node has been accessed before.</p>
+
+ @return
+ <TRUE/> if the path could be resolved completely
+ (so <var>aNode</var> and <var>aTree</var> refer to the desired node,
+ <var>aPath</var> is empty)<BR/>
+ <FALSE/> otherwise
+ */
+ bool findDescendantAvailable(Tree& aTree, NodeRef& aNode, RelativePath& aPath);
+
/// test whether the given node is a plain value
bool isSimpleValue(Tree const& aTree, NodeRef const& aNode);
diff --git a/configmgr/source/treemgr/noderef.cxx b/configmgr/source/treemgr/noderef.cxx
index 2250d3185045..f56de3030ece 100644
--- a/configmgr/source/treemgr/noderef.cxx
+++ b/configmgr/source/treemgr/noderef.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: noderef.cxx,v $
*
- * $Revision: 1.14 $
+ * $Revision: 1.15 $
*
- * last change: $Author: jb $ $Date: 2000-12-06 12:15:45 $
+ * last change: $Author: jb $ $Date: 2001-02-13 16:13:27 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -102,6 +102,17 @@ NodeRef TreeImplHelper::makeNode(TreeImpl& rTree, NodeOffset nOffset)
}
//-----------------------------------------------------------------------------
+NodeRef TreeImplHelper::makeNode(NodeID const& aNodeID)
+{
+ if (TreeImpl* pTree = aNodeID.m_pTree)
+ {
+ return makeNode(*pTree,aNodeID.m_nNode);
+ }
+ else
+ return NodeRef();
+}
+//-----------------------------------------------------------------------------
+
bool TreeImplHelper::isSet(NodeRef const& aNode)
{
OSL_ASSERT(aNode.m_pImpl); return aNode.m_pImpl && aNode.m_pImpl->isSetNode();
@@ -287,8 +298,30 @@ NodeRef NodeRef::getChild(Name const& aName, Tree& rTree) const
}
return NodeRef(); // nothing found
}
+//-----------------------------------------------------------------------------
+
+// a version of NodeRef::getChild that retrieves only loaded nodes
+NodeRef NodeRef::getAvailableChild(Name const& aName, Tree& rTree) const
+{
+ OSL_PRECOND( isValid(), "ERROR: Configuration: NodeRef operation requires valid node" );
+
+ if (m_pImpl && m_pImpl->isSetNode())
+ {
+ SetEntry aChildEntry = m_pImpl->setImpl().findAvailableElement(aName);
+ if (TreeImpl* pTree = aChildEntry.tree())
+ {
+ NodeOffset nFoundOffset = pTree->root();
+ TreeDepth nChildDepth = pTree->getAvailableDepth();
+ Node* pNode = pTree->node(nFoundOffset);
+ // all fine ? now adjust the tree
+ rTree = Tree(pTree);
+ return NodeRef(pNode,nFoundOffset,nChildDepth);
+ }
+ }
+ return NodeRef(); // nothing found
+}
//-----------------------------------------------------------------------------
NodeInfo NodeRef::getInfo() const
@@ -727,6 +760,19 @@ size_t hash64(sal_uInt64 n)
}
//-----------------------------------------------------------------------------
+bool NodeID::isEmpty() const
+{
+ OSL_ENSURE( m_pTree == NULL || m_pTree->isValidNode(m_nNode), "Node does not match tree in NodeID");
+ return m_pTree == NULL;
+}
+//-----------------------------------------------------------------------------
+
+bool NodeID::isValidNode() const
+{
+ return m_pTree != NULL && m_pTree->isValidNode(m_nNode);
+}
+//-----------------------------------------------------------------------------
+
static // for now
// should move this to a more public place sometime
inline
@@ -869,6 +915,17 @@ bool findChildNode(Tree& aTree, NodeRef& aNode, Name const& aName)
}
//-----------------------------------------------------------------------------
+bool findAvailableChildNode(Tree& aTree, NodeRef& aNode, Name const& aName)
+{
+ NodeRef aChild = TreeImplHelper::isSet(aNode) ? aNode.getAvailableChild(aName,aTree) : aTree.getChild(aNode,aName);
+
+ if ( aChild.isValid() )
+ aNode = aChild;
+
+ return aChild.isValid();
+}
+//-----------------------------------------------------------------------------
+
bool findDescendantNode(Tree& aTree, NodeRef& aNode, RelativePath& aPath)
{
// requires: findChildNode leaves node and tree unchanged when returning false
@@ -879,9 +936,30 @@ bool findDescendantNode(Tree& aTree, NodeRef& aNode, RelativePath& aPath)
for ( ; itPath != itPathEnd; ++itPath)
if (!findChildNode(aTree,aNode,*itPath))
- return false;
+ break;
- return true;
+ aPath = RelativePath(Path::Components(itPath, itPathEnd));
+ return itPath == itPathEnd;
+}
+//-----------------------------------------------------------------------------
+
+// NOT exported through noderef.hxx, but through treeimpl.hxx
+bool findDescendantAvailable(Tree& aTree, NodeRef& aNode, RelativePath& aPath)
+{
+ // requires: findChildNode leaves node and tree unchanged when returning false
+ typedef Path::Iterator Iter;
+
+ Iter itPath = aPath.begin();
+ Iter const itPathEnd = aPath.end();
+
+ for ( ; itPath != itPathEnd; ++itPath)
+ {
+ if (!findAvailableChildNode(aTree,aNode,*itPath))
+ break;
+ }
+
+ aPath = RelativePath(Path::Components(itPath, itPathEnd));
+ return itPath == itPathEnd;
}
//-----------------------------------------------------------------------------