dbertoni 2003/01/24 17:02:43
Modified: c/src/XercesParserLiaison XercesDocumentWrapper.cpp
XercesDocumentWrapper.hpp
XercesDOMFormatterWalker.cpp
XercesDOMFormatterWalker.hpp XercesDOMWalker.cpp
XercesDOMWalker.hpp
Log:
Implemented code to stop and restart a traversal.
Revision Changes Path
1.11 +6 -2
xml-xalan/c/src/XercesParserLiaison/XercesDocumentWrapper.cpp
Index: XercesDocumentWrapper.cpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/XercesParserLiaison/XercesDocumentWrapper.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- XercesDocumentWrapper.cpp 22 Jan 2003 19:41:14 -0000 1.10
+++ XercesDocumentWrapper.cpp 25 Jan 2003 01:02:42 -0000 1.11
@@ -1469,7 +1469,7 @@
-void
+bool
XercesDocumentWrapper::BuildWrapperTreeWalker::startNode(const DOMNodeType*
node)
{
XalanNode* const theWrapperNode =
@@ -1603,11 +1603,13 @@
++m_currentIndex;
}
}
+
+ return false;
}
-void
+bool
XercesDocumentWrapper::BuildWrapperTreeWalker::endNode(const DOMNodeType*
/* node */)
{
assert(m_parentNavigatorStack.empty() == false);
@@ -1630,6 +1632,8 @@
// Pop the context marker...
m_siblingNavigatorStack.pop_back();
+
+ return false;
}
1.7 +2 -2
xml-xalan/c/src/XercesParserLiaison/XercesDocumentWrapper.hpp
Index: XercesDocumentWrapper.hpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/XercesParserLiaison/XercesDocumentWrapper.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XercesDocumentWrapper.hpp 22 Jan 2003 19:41:15 -0000 1.6
+++ XercesDocumentWrapper.hpp 25 Jan 2003 01:02:42 -0000 1.7
@@ -443,10 +443,10 @@
protected:
- virtual void
+ virtual bool
startNode(const DOMNodeType* node);
- virtual void
+ virtual bool
endNode(const DOMNodeType* node);
private:
1.3 +7 -3
xml-xalan/c/src/XercesParserLiaison/XercesDOMFormatterWalker.cpp
Index: XercesDOMFormatterWalker.cpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/XercesParserLiaison/XercesDOMFormatterWalker.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XercesDOMFormatterWalker.cpp 24 Jan 2003 16:50:18 -0000 1.2
+++ XercesDOMFormatterWalker.cpp 25 Jan 2003 01:02:42 -0000 1.3
@@ -92,7 +92,7 @@
-void
+bool
XercesDOMFormatterWalker::startNode(const DOMNodeType* node)
{
assert(node != 0);
@@ -158,7 +158,7 @@
assert(length(data) ==
FormatterListener::size_type(length(data)));
m_formatterListener.characters(data,
FormatterListener::size_type(length(data)));
- }
+ }
break;
case DOMNodeType::ENTITY_REFERENCE_NODE:
@@ -169,11 +169,13 @@
// Do nothing...
break;
}
+
+ return false;
}
-void
+bool
XercesDOMFormatterWalker::endNode(const DOMNodeType* node)
{
assert(node != 0);
@@ -192,6 +194,8 @@
// Do nothing
break;
}
+
+ return false;
}
1.2 +2 -2
xml-xalan/c/src/XercesParserLiaison/XercesDOMFormatterWalker.hpp
Index: XercesDOMFormatterWalker.hpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/XercesParserLiaison/XercesDOMFormatterWalker.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XercesDOMFormatterWalker.hpp 24 Jan 2003 02:31:42 -0000 1.1
+++ XercesDOMFormatterWalker.hpp 25 Jan 2003 01:02:42 -0000 1.2
@@ -86,10 +86,10 @@
protected:
- virtual void
+ virtual bool
startNode(const DOMNodeType* node);
- virtual void
+ virtual bool
endNode(const DOMNodeType* node);
private:
1.5 +82 -24 xml-xalan/c/src/XercesParserLiaison/XercesDOMWalker.cpp
Index: XercesDOMWalker.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XercesParserLiaison/XercesDOMWalker.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XercesDOMWalker.cpp 24 Jan 2003 18:43:42 -0000 1.4
+++ XercesDOMWalker.cpp 25 Jan 2003 01:02:42 -0000 1.5
@@ -59,6 +59,10 @@
+#include <cassert>
+
+
+
// Xerces header files...
#include <xercesc/dom/DOMNode.hpp>
@@ -80,20 +84,31 @@
-void
+const DOMNodeType*
XercesDOMWalker::traverse(const DOMNodeType* pos)
{
+ assert(pos != 0);
+
const DOMNodeType* thePos = pos;
- while(thePos != 0)
+ bool fStop = false;
+
+ while(thePos != 0 && fStop == false)
{
- startNode(thePos);
+ fStop = startNode(thePos);
const DOMNodeType* nextNode = thePos->getFirstChild();
while(nextNode == 0)
{
- endNode(thePos);
+ if (fStop == false)
+ {
+ fStop = endNode(thePos);
+ }
+ else
+ {
+ endNode(thePos);
+ }
nextNode = thePos->getNextSibling();
@@ -112,24 +127,37 @@
thePos = nextNode;
}
+
+ return thePos;
}
-void
+DOMNodeType*
XercesDOMWalker::traverse(DOMNodeType* pos)
{
+ assert(pos != 0);
+
DOMNodeType* thePos = pos;
- while(thePos != 0)
+ bool fStop = false;
+
+ while(thePos != 0 && fStop == false)
{
- startNode(thePos);
+ fStop = startNode(thePos);
DOMNodeType* nextNode = thePos->getFirstChild();
while(nextNode == 0)
{
- endNode(thePos);
+ if (fStop == false)
+ {
+ fStop = endNode(thePos);
+ }
+ else
+ {
+ endNode(thePos);
+ }
nextNode = thePos->getNextSibling();
@@ -148,26 +176,40 @@
thePos = nextNode;
}
+
+ return thePos;
}
-void
+const DOMNodeType*
XercesDOMWalker::traverse(
const DOMNodeType* pos,
const DOMNodeType* parent)
{
+ assert(pos != 0);
+ assert(parent != 0);
+
const DOMNodeType* thePos = pos;
- while(parent != thePos)
- {
- startNode(thePos);
+ bool fStop = false;
+
+ while(parent != thePos && fStop == false)
+ {
+ fStop = startNode(thePos);
const DOMNodeType* nextNode = thePos->getFirstChild();
while(nextNode == 0)
{
- endNode(thePos);
+ if (fStop == false)
+ {
+ fStop = endNode(thePos);
+ }
+ else
+ {
+ endNode(thePos);
+ }
nextNode = thePos->getNextSibling();
@@ -186,26 +228,40 @@
thePos = nextNode;
}
+
+ return thePos;
}
-void
+DOMNodeType*
XercesDOMWalker::traverse(
DOMNodeType* pos,
DOMNodeType* parent)
{
+ assert(pos != 0);
+ assert(parent != 0);
+
DOMNodeType* thePos = pos;
- while(parent != thePos)
- {
- startNode(thePos);
+ bool fStop = false;
+
+ while(parent != thePos && fStop == false)
+ {
+ fStop = startNode(thePos);
DOMNodeType* nextNode = thePos->getFirstChild();
while(nextNode == 0)
{
- endNode(thePos);
+ if (fStop == false)
+ {
+ fStop = endNode(thePos);
+ }
+ else
+ {
+ endNode(thePos);
+ }
nextNode = thePos->getNextSibling();
@@ -224,6 +280,8 @@
thePos = nextNode;
}
+
+ return thePos;
}
@@ -268,25 +326,25 @@
-void
+bool
XercesDOMWalker::startNode(DOMNodeType* node)
{
#if defined(XALAN_OLD_STYLE_CASTS)
- startNode((const DOMNodeType*)node);
+ return startNode((const DOMNodeType*)node);
#else
- startNode(const_cast<const DOMNodeType*>(node));
+ return startNode(const_cast<const DOMNodeType*>(node));
#endif
}
-void
+bool
XercesDOMWalker::endNode(DOMNodeType* node)
{
#if defined(XALAN_OLD_STYLE_CASTS)
- endNode((const DOMNodeType*)node);
+ return endNode((const DOMNodeType*)node);
#else
- endNode(const_cast<const DOMNodeType*>(node));
+ return endNode(const_cast<const DOMNodeType*>(node));
#endif
}
1.5 +93 -13 xml-xalan/c/src/XercesParserLiaison/XercesDOMWalker.hpp
Index: XercesDOMWalker.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XercesParserLiaison/XercesDOMWalker.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XercesDOMWalker.hpp 24 Jan 2003 18:43:42 -0000 1.4
+++ XercesDOMWalker.hpp 25 Jan 2003 01:02:42 -0000 1.5
@@ -81,29 +81,81 @@
~XercesDOMWalker();
/**
- * Perform a pre-order traversal non-recursive style.
+ * Perform a document-order traversal.
+ *
+ * Derived classes and stop the traversal by returning
+ * true from startNode() or endNode(). If that happens,
+ * the function will return the next node in document
+ * order. If desired, the caller can start traversing
+ * the tree again from that point. Note that terminal
+ * nodes will always have startNode() and endNode()
+ * called before the traversal terminates.
+ *
+ * @param pos The node in the tree with which to start the walk
+ *
+ * @return 0 if the traversal completes, or the next node if the
traversal doesn't complete.
*/
- virtual void
+ virtual const DOMNodeType*
traverse(const DOMNodeType* pos);
/**
- * Perform a pre-order traversal non-recursive style.
+ * Perform a document-order traversal.
+ *
+ * Derived classes and stop the traversal by returning
+ * true from startNode() or endNode(). If that happens,
+ * the function will return the next node in document
+ * order. If desired, the caller can start traversing
+ * the tree again from that point. Note that terminal
+ * nodes will always have startNode() and endNode()
+ * called before the traversal terminates.
+ *
+ * @param pos The node in the tree with which to start the walk
+ *
+ * @return 0 if the traversal completes, or the next node if the
traversal doesn't complete.
*/
- virtual void
+ virtual DOMNodeType*
traverse(DOMNodeType* pos);
/**
- * Perform a pre-order traversal non-recursive style.
+ * Perform a document-order traversal stopping at the
+ * provided parent node.
+ *
+ * Derived classes and stop the traversal by returning
+ * true from startNode() or endNode(). If that happens,
+ * the function will return the next node in document
+ * order. If desired, the caller can start traversing
+ * the tree again from that point. Note that terminal
+ * nodes will always have startNode() and endNode()
+ * called before the traversal terminates.
+ *
+ * @param pos The node in the tree with which to start the walk
+ * @param parent The parent of pos. Note that for multiple calls that
continue the traversal, this node must remain the same.
+ *
+ * @return parent if the traversal completes, or the next node if the
traversal doesn't complete.
*/
- virtual void
+ virtual const DOMNodeType*
traverse(
const DOMNodeType* pos,
const DOMNodeType* parent);
/**
- * Perform a pre-order traversal non-recursive style.
+ * Perform a document-order traversal stopping at the
+ * provided parent node.
+ *
+ * Derived classes and stop the traversal by returning
+ * true from startNode() or endNode(). If that happens,
+ * the function will return the next node in document
+ * order. If desired, the caller can start traversing
+ * the tree again from that point. Note that terminal
+ * nodes will always have startNode() and endNode()
+ * called before the traversal terminates.
+ *
+ * @param pos The node in the tree with which to start the walk
+ * @param parent The parent of pos. Note that for multiple calls that
continue the traversal, this node must remain the same.
+ *
+ * @return parent if the traversal completes, or the next node if the
traversal doesn't complete.
*/
- virtual void
+ virtual DOMNodeType*
traverse(
DOMNodeType* pos,
DOMNodeType* parent);
@@ -117,7 +169,7 @@
traverseSubtree(const DOMNodeType* pos);
/**
- * Perform a pre-order traversal non-recursive style.
+ * Perform a document-order traversal non-recursive style.
*
* @param pos starting node
*/
@@ -126,16 +178,44 @@
protected:
- virtual void
+ /**
+ * Called when first walking a node
+ *
+ * @param node The node
+ *
+ * @return return false if the walk should continue, or true if it
should not.
+ */
+ virtual bool
startNode(const DOMNodeType* node) = 0;
- virtual void
+ /**
+ * Called when first walking a node
+ *
+ * @param node The node
+ *
+ * @return return false if the walk should continue, or true if it
should not.
+ */
+ virtual bool
startNode(DOMNodeType* node);
- virtual void
+ /**
+ * Called when leaving a node
+ *
+ * @param node The node
+ *
+ * @return return false if the walk should continue, or true if it
should not.
+ */
+ virtual bool
endNode(const DOMNodeType* node) = 0;
- virtual void
+ /**
+ * Called when leaving a node
+ *
+ * @param node The node
+ *
+ * @return return false if the walk should continue, or true if it
should not.
+ */
+ virtual bool
endNode(DOMNodeType* node);
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]