glibmm r701 - in trunk: . glib/src tests/glibmm_nodetree



Author: murrayc
Date: Tue Jul 29 10:45:39 2008
New Revision: 701
URL: http://svn.gnome.org/viewvc/glibmm?rev=701&view=rev

Log:
2008-07-29  Murray Cumming  <murrayc murrayc com>

* glib/src/nodetree.hg: Move the TraverseFlags enum into 
the class, and hand-code it to avoid problems with _WRAP_ENUM(). 
* tests/glibmm_nodetree/main.cc: Adapted.
Bug #545050 (SzilÃrd Pfeiffer).

Added:
   trunk/glib/src/nodetree.ccg
      - copied, changed from r700, /trunk/glib/src/tree.ccg
Removed:
   trunk/glib/src/tree.ccg
Modified:
   trunk/ChangeLog
   trunk/glib/src/nodetree.hg
   trunk/tests/glibmm_nodetree/main.cc

Copied: trunk/glib/src/nodetree.ccg (from r700, /trunk/glib/src/tree.ccg)
==============================================================================
--- /trunk/glib/src/tree.ccg	(original)
+++ trunk/glib/src/nodetree.ccg	Tue Jul 29 10:45:39 2008
@@ -1 +1 @@
-#include <glibmm/tree.h>
+#include <glibmm/nodetree.h>

Modified: trunk/glib/src/nodetree.hg
==============================================================================
--- trunk/glib/src/nodetree.hg	(original)
+++ trunk/glib/src/nodetree.hg	Tue Jul 29 10:45:39 2008
@@ -31,7 +31,7 @@
 namespace Glib
 {
 
-_WRAP_ENUM(TraverseFlags, GTraverseFlags, NO_GTYPE)
+//TODO: NO_GTYPE shouldn't be necessary.
 _WRAP_ENUM(TraverseType, GTraverseType, NO_GTYPE)
 
 /** N-ary Trees â trees of data with any number of branches
@@ -230,9 +230,22 @@
   {
     return wrap(g_node_get_root(gobj()));
   }
-
   _IGNORE(g_node_get_root)
 
+
+  /** Specifies which nodes are visited during several of the NodeTree methods,
+   *  including traverse() and find().
+   *
+   * @ingroup glibmmEnums
+   */
+  enum TraverseFlags
+  {
+    TRAVERSE_LEAVES = G_TRAVERSE_LEAVES,
+    TRAVERSE_NON_LEAVES = G_TRAVERSE_NON_LEAVES,
+    TRAVERSE_ALL = G_TRAVERSE_ALL,
+    TRAVERSE_MASK = G_TRAVERSE_MASK
+  };
+
   /** Traverses a tree starting at the current node.
    * It calls the given function for each node visited. 
    * The traversal can be halted at any point by returning true from @a func.

Modified: trunk/tests/glibmm_nodetree/main.cc
==============================================================================
--- trunk/tests/glibmm_nodetree/main.cc	(original)
+++ trunk/tests/glibmm_nodetree/main.cc	Tue Jul 29 10:45:39 2008
@@ -1,13 +1,15 @@
 #include <iostream>
 #include <glibmm.h>
 
-bool echo(Glib::NodeTree<std::string>& i)
+typedef Glib::NodeTree<std::string> type_nodetree_string;
+
+bool echo(type_nodetree_string& i)
 {
   std::cout << i.data() << ' ';
   return false;
 }
 
-void echol(Glib::NodeTree<std::string>& i, bool is_leaf)
+void echol(type_nodetree_string& i, bool is_leaf)
 {
   if(i.is_leaf() == is_leaf)
     std::cout << i.data() << ' ';
@@ -23,12 +25,9 @@
               e("e"),
               f("f");
 
-  Glib::NodeTree<std::string> ta(a),
-                          tb(b),
-                          tc(c),
-                          te(e);
+  type_nodetree_string ta(a), tb(b), tc(c), te(e);
 
-  sigc::slot<bool, Glib::NodeTree<std::string>&> echoslot = sigc::ptr_fun(echo);
+  sigc::slot<bool, type_nodetree_string&> echoslot = sigc::ptr_fun(echo);
 
 
   ta.insert(0, tc);
@@ -37,55 +36,58 @@
   tc.append(te);
   te.prepend_data(f);
 
+  const type_nodetree_string::TraverseFlags flags = 
+     type_nodetree_string::TraverseFlags(type_nodetree_string::TRAVERSE_LEAVES | type_nodetree_string::TRAVERSE_NON_LEAVES);
+
   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, flags, 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, flags, 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, flags, 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, flags, 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));
+  ta.foreach(type_nodetree_string::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));
+  ta.foreach(type_nodetree_string::TRAVERSE_ALL, sigc::bind<bool>(sigc::ptr_fun(echol), false));
   std::cout << std::endl;
 
-  Glib::NodeTree<std::string>* tmp = ta.find(Glib::IN_ORDER, Glib::TRAVERSE_LEAVES | Glib::TRAVERSE_NON_LEAVES, e);
+  type_nodetree_string* tmp = ta.find(Glib::IN_ORDER, flags, e);
   if(!tmp)
     std::cout << e << " 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, a);
+  tmp = ta.find(Glib::IN_ORDER, flags, a);
   if(!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");
+  tmp = ta.find(Glib::IN_ORDER, flags, "f");
   if(!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);
+  tmp = ta.find_child(flags, e);
   if(!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);
+  tmp = ta.find_child(flags, c);
   if(!tmp)
     std::cout << c << " is the number " << ta.child_index(c) << " child of " << (ta.data()) << std::endl;
   else



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]