summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSzilárd Pfeiffer <szilard.pfeiffer@gmail.com>2008-07-29 09:03:09 +0000
committerMurray Cumming <murrayc@src.gnome.org>2008-07-29 09:03:09 +0000
commite74b63cfa3ad05e586d95c6ed8a6fc86c36f885b (patch)
tree039153c461fb5d11e435ffb8ebd45bbd741b2a44 /tests
parent10914083179b01e8ab0086d01005f2afd7296e56 (diff)
downloadglibmm-e74b63cfa3ad05e586d95c6ed8a6fc86c36f885b.tar.gz
Make the callbacks take a Tree<> instead of just the data, so they can use
2008-07-29 Szilárd Pfeiffer <szilard.pfeiffer@gmail.com> * glib/src/tree.hg: Make the callbacks take a Tree<> instead of just the data, so they can use methods on the tree (which can be a node in the tree). gobject_: Make this protected. Provide the this pointer as data to g_node_new() so we can retrieve it later. Removed children_ and parent_ because we don't need a separate store now that we can get the C++ instance from the gobject instance. owns_gobject_: Removed because it is was always true, so the gobject was always destroyed (and still is). * tests/glibmm_tree/main.cc: Updated for the changed API. Bug #520778. svn path=/trunk/; revision=697
Diffstat (limited to 'tests')
-rw-r--r--tests/glibmm_tree/main.cc34
1 files changed, 23 insertions, 11 deletions
diff --git a/tests/glibmm_tree/main.cc b/tests/glibmm_tree/main.cc
index fb2edd6b..879458fc 100644
--- a/tests/glibmm_tree/main.cc
+++ b/tests/glibmm_tree/main.cc
@@ -2,15 +2,16 @@
#include <glibmm.h>
-bool echo(std::string& i)
+bool echo(Glib::Tree<std::string>& i)
{
- std::cout << i << ' ';
+ std::cout << i.data() << ' ';
return false;
}
-void echof(std::string& i)
+void echol(Glib::Tree<std::string>& i, bool is_leaf)
{
- std::cout << i << ' ';
+ if(i.is_leaf() == is_leaf)
+ std::cout << i.data() << ' ';
}
@@ -28,8 +29,7 @@ int main()
tc(c),
te(e);
- sigc::slot<bool, std::string&> echoslot = sigc::ptr_fun(echo);
- sigc::slot<void, std::string&>echofslot = sigc::ptr_fun(echof);
+ sigc::slot<bool, Glib::Tree<std::string>&> echoslot = sigc::ptr_fun(echo);
ta.insert(0, tc);
@@ -39,19 +39,27 @@ int main()
te.prepend_data(f);
std::cout << "Breadth-first:" << std::endl;
- ta.traverse(Glib::LEVEL_ORDER, Glib::TRAVERSE_LEAVES | Glib::TRAVERSE_NON_LEAVES, INT_MAX, &echoslot);
+ ta.traverse(Glib::LEVEL_ORDER, Glib::TRAVERSE_LEAVES | Glib::TRAVERSE_NON_LEAVES, INT_MAX, echoslot);
std::cout << std::endl;
std::cout << "Depth-first (pre):" << std::endl;
- ta.traverse(Glib::PRE_ORDER, Glib::TRAVERSE_LEAVES | Glib::TRAVERSE_NON_LEAVES, INT_MAX, &echoslot);
+ ta.traverse(Glib::PRE_ORDER, Glib::TRAVERSE_LEAVES | Glib::TRAVERSE_NON_LEAVES, INT_MAX, echoslot);
std::cout << std::endl;
std::cout << "Depth-first (in):" << std::endl;
- ta.traverse(Glib::IN_ORDER, Glib::TRAVERSE_LEAVES | Glib::TRAVERSE_NON_LEAVES, INT_MAX, &echoslot);
+ ta.traverse(Glib::IN_ORDER, Glib::TRAVERSE_LEAVES | Glib::TRAVERSE_NON_LEAVES, INT_MAX, echoslot);
std::cout << std::endl;
std::cout << "Depth-first (post):" << std::endl;
- ta.traverse(Glib::POST_ORDER, Glib::TRAVERSE_LEAVES | Glib::TRAVERSE_NON_LEAVES, INT_MAX, &echoslot);
+ ta.traverse(Glib::POST_ORDER, Glib::TRAVERSE_LEAVES | Glib::TRAVERSE_NON_LEAVES, INT_MAX, echoslot);
+ std::cout << std::endl;
+
+ std::cout << "Leaf children of 'a':" << std::endl;
+ ta.foreach(Glib::TRAVERSE_ALL, sigc::bind<bool>(sigc::ptr_fun(echol), true));
+ std::cout << std::endl;
+
+ std::cout << "Non-leaf children of 'a':" << std::endl;
+ ta.foreach(Glib::TRAVERSE_ALL, sigc::bind<bool>(sigc::ptr_fun(echol), false));
std::cout << std::endl;
Glib::Tree<std::string> *tmp = ta.find(Glib::IN_ORDER, Glib::TRAVERSE_LEAVES | Glib::TRAVERSE_NON_LEAVES, e);
@@ -62,13 +70,17 @@ int main()
if(NULL == tmp){ std::cout << a << " not found" << std::endl; }
else{ std::cout << "Found " << (tmp->data()) << std::endl; }
+ tmp = ta.find(Glib::IN_ORDER, Glib::TRAVERSE_LEAVES | Glib::TRAVERSE_NON_LEAVES, "f");
+ if(NULL == tmp){ std::cout << a << " not found" << std::endl; }
+ else{ std::cout << "Found " << (tmp->data()) << std::endl; }
+
tmp = ta.find_child(Glib::TRAVERSE_LEAVES | Glib::TRAVERSE_NON_LEAVES, e);
if(NULL == tmp){ std::cout << e << " is not a child of " << (ta.data()) << std::endl; }
else{ std::cout << "Mistakenly found " << e << " in " << (ta.data()) << "'s children" << std::endl; }
tmp = ta.find_child(Glib::TRAVERSE_LEAVES | Glib::TRAVERSE_NON_LEAVES, c);
if(NULL == tmp) {
- std::cout << c << " is the number " << ta.index_of(c) << " child of " << (ta.data()) << std::endl;
+ std::cout << c << " is the number " << ta.child_index(c) << " child of " << (ta.data()) << std::endl;
}
else{ std::cout << "Mistakenly didn't find " << c << " in " << (ta.data()) << "'s children" << std::endl; }