diff --git a/ChangeLog b/ChangeLog index d926e85..31ca7ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2018-04-23 Kasper Peeters + + * Release 3.8. + + * Make fixed-depth iterators start at the first node in a range of + siblings. + 2018-01-30 Kasper Peeters * Release 3.6. diff --git a/examples/iterate_head.cc b/examples/iterate_head.cc new file mode 100644 index 0000000..eb7e953 --- /dev/null +++ b/examples/iterate_head.cc @@ -0,0 +1,22 @@ +#include "tree.hh" +#include + +// This example shows how to iterate over the head nodes +// of a tree only. + +int main(int, char **) + { + tree t; + + t.set_head("one"); + auto i2 = t.insert(t.end(), "two"); + auto i3 = t.insert(t.end(), "three"); + t.append_child(i2, "apple"); + t.append_child(i2, "pear"); + t.append_child(i3, "banana"); + t.append_child(i3, "kiwi"); + + tree::sibling_iterator it=t.begin(); + while(it!=t.end()) + std::cerr << (*it++) << std::endl; + } diff --git a/examples/move_subtree.cc b/examples/move_subtree.cc new file mode 100644 index 0000000..e77c08b --- /dev/null +++ b/examples/move_subtree.cc @@ -0,0 +1,33 @@ +#include +#include "tree.hh" +#include "tree_util.hh" + +void print_tree(const tree& tr) +{ + tree::pre_order_iterator it = tr.begin(); + tree::pre_order_iterator end = tr.end(); + if(!tr.is_valid(it)) return; + int rootdepth=tr.depth(it); + std::cout << "-----" << std::endl; + while(it!=end) { + for(int i=0; i my_tree; + + tree::iterator iA = my_tree.insert(my_tree.end(), "A"); + tree::iterator iB = my_tree.insert(my_tree.end(), "B"); + tree::iterator iB1 = my_tree.append_child(iB, "B1"); + tree::iterator iC = my_tree.insert(my_tree.end(), "C"); + print_tree(my_tree); + + my_tree.move_after(iB1, iC); + print_tree(my_tree); +} diff --git a/src/test_tree.cc b/src/test_tree.cc index 1386c14..a5d5e3a 100644 --- a/src/test_tree.cc +++ b/src/test_tree.cc @@ -365,6 +365,22 @@ int main(int argc, char **argv) ++li; } + // Fixed-depth. + tree fdt; + fdt.set_head("beings"); + auto mammals = fdt.append_child(fdt.begin(), "mammals"); + fdt.append_child(fdt.begin(), "birds"); + fdt.append_child(mammals, "human"); + auto felins = fdt.append_child(mammals, "felins"); + fdt.append_child(mammals, "canids"); + fdt.append_child(felins, "cats"); + + auto fi = tr.begin_fixed(felins, 0); + while(fdt.is_valid(fi)) { + std::cout << *fi << std::endl; + ++fi; + } + // test_move_constructor(); } diff --git a/src/tree.hh b/src/tree.hh index a07a1b0..6177bc9 100644 --- a/src/tree.hh +++ b/src/tree.hh @@ -9,8 +9,8 @@ /** \mainpage tree.hh \author Kasper Peeters - \version 3.7 - \date 30-Jan-2018 + \version 3.8 + \date 23-Apr-2018 \see http://tree.phi-sci.com/ \see http://tree.phi-sci.com/ChangeLog @@ -792,6 +792,10 @@ typename tree::fixed_depth_iterator treeprev_sibling!=0) + tmp=tmp->prev_sibling; + ret.node=tmp; return ret; }