X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=xml-tree-inc.hpp;h=cd8db71e49e699d1c2e95b0f5d4a74f43b3899ad;hb=429f734c9f9241dfb9c587e8b333777f3540625f;hp=6ce172432832a9f420b89b66cf9ce60fce99477d;hpb=cd438c6db9deacac203891fd76a49a768ba53e70;p=SXSI%2FXMLTree.git diff --git a/xml-tree-inc.hpp b/xml-tree-inc.hpp index 6ce1724..cd8db71 100644 --- a/xml-tree-inc.hpp +++ b/xml-tree-inc.hpp @@ -5,6 +5,19 @@ #ifndef XML_TREE_INC_HPP_ #define XML_TREE_INC_HPP_ +#include + +#if 0 +#define ASSERT_NODE(orig, res) do { \ + if (res < -1 || res >= par->n|| (res != -1 && res < orig)) \ + fprintf(stderr, \ + "Assertion failure: original node %i, result %i, line %i\n", \ + orig, res, __LINE__); \ + } while (0) +#else +#define ASSERT_NODE(orig, res) +#endif + inline uint32_t xml_tree::size() const { return tag_seq_len / 2; @@ -86,7 +99,9 @@ inline xml_tree::node_t xml_tree::parent(xml_tree::node_t x) const inline xml_tree::node_t xml_tree::first_child(node_t x) const { - return bp_first_child(this->par, x); + xml_tree::node_t result = bp_first_child(this->par, x); + ASSERT_NODE(x, result); + return result; } inline xml_tree::node_t xml_tree::last_child(xml_tree::node_t x) const @@ -99,7 +114,9 @@ inline xml_tree::node_t xml_tree::last_child(xml_tree::node_t x) const inline xml_tree::node_t xml_tree::next_sibling(xml_tree::node_t x) const { - return bp_next_sibling(this->par, x); + xml_tree::node_t result = bp_next_sibling(this->par, x); + ASSERT_NODE(x, result); + return result; } inline xml_tree::node_t xml_tree::prev_sibling(xml_tree::node_t x) const @@ -119,6 +136,8 @@ inline xml_tree::node_t xml_tree::first_element(xml_tree::node_t x) const case PCDATA_OPEN_TAG_ID: n = n + 2; return bp_inspect(this->par, n) ? n : xml_tree::NIL; + default: + return n; }; } @@ -161,17 +180,29 @@ inline xml_tree::node_t xml_tree::tagged_child(xml_tree::node_t x, xml_tree::tag_t t) const { xml_tree::node_t c = first_child(x); + xml_tree::node_t result; if (is_nil(c) || tag(c) == t) return c; else - tagged_sibling(c, t); + return tagged_sibling(c, t); + /* ASSERT_NODE(x, result); + return result;*/ } inline xml_tree::node_t xml_tree::tagged_sibling(xml_tree::node_t x, xml_tree::tag_t t) const { xml_tree::node_t sibling = next_sibling(x); - while(!is_nil(sibling) && tag(sibling) != t) sibling = next_sibling(sibling); + xml_tree::tag_t stag; + while (sibling != xml_tree::NIL) { + stag = tag(sibling); + if (stag == t) { + ASSERT_NODE(x, sibling); + return sibling; + } + sibling = next_sibling(sibling); + }; + ASSERT_NODE(x, sibling); return sibling; }