diff options
author | Murray Cumming <murrayc@murrayc.com> | 2008-07-29 11:12:23 +0000 |
---|---|---|
committer | Murray Cumming <murrayc@src.gnome.org> | 2008-07-29 11:12:23 +0000 |
commit | eebaa2ee37d734c9ab3ee69dd99a785c43d0ed53 (patch) | |
tree | 42af08474bbed2906951496919b07d36fdb57f3a | |
parent | 6c9256a16561e6bbb87607af7351e79ab3860bda (diff) | |
download | glibmm-eebaa2ee37d734c9ab3ee69dd99a785c43d0ed53.tar.gz |
Hand-code the TraverseType enum, to add a prefix to the values. Adapted.
2008-07-29 Murray Cumming <murrayc@murrayc.com>
* glib/src/nodetree.hg: Hand-code the TraverseType enum, to add
a prefix to the values.
* tests/glibmm_nodetree/main.cc: Adapted.
svn path=/trunk/; revision=703
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | glib/src/nodetree.hg | 41 | ||||
-rw-r--r-- | tests/glibmm_nodetree/main.cc | 14 |
3 files changed, 39 insertions, 22 deletions
@@ -1,5 +1,11 @@ 2008-07-29 Murray Cumming <murrayc@murrayc.com> + * glib/src/nodetree.hg: Hand-code the TraverseType enum, to add + a prefix to the values. + * tests/glibmm_nodetree/main.cc: Adapted. + +2008-07-29 Murray Cumming <murrayc@murrayc.com> + * glib/src/nodetree.hg: find(), find_child(), traverse(), foreach(): Rearrange the parameters so we can have default values. * tests/glibmm_nodetree/main.cc: Adapted. diff --git a/glib/src/nodetree.hg b/glib/src/nodetree.hg index 70c32f24..1a233d42 100644 --- a/glib/src/nodetree.hg +++ b/glib/src/nodetree.hg @@ -31,9 +31,20 @@ _DEFS(glibmm,glib) namespace Glib { -//TODO: NO_GTYPE shouldn't be necessary. -//TODO: Add a prefix? Otherwise, it's just Glib::IN_ORDER, etc. -_WRAP_ENUM(TraverseType, GTraverseType, NO_GTYPE) +//Hand-written, instead of using _WRAP_ENUM, +//because the C enum values don't have a prefix. + +/** Specifies the type of traveral performed by methods such as NodeTree::_traverse() and NodeTree::find(). + * + * @ingroup glibmmEnums + */ +enum TraverseType +{ + TRAVERSE_IN_ORDER = G_IN_ORDER, /*!< Visits a node's left child first, then the node itself, then its right child. This is the one to use if you want the output sorted according to the compare function. */ + TRAVERSE_PRE_ORDER = G_PRE_ORDER, /*!< Visits a node, then its children. */ + TRAVERSE_POST_ORDER = G_POST_ORDER, /*!< Visits the node's children, then the node itself. */ + TRAVERSE_LEVEL_ORDER = G_LEVEL_ORDER /*!< For NodeTree, it vists the root node first, then its children, then its grandchildren, and so on. Note that this is less efficient than the other orders. This is not implemented for Glib::Tree. */ +}; /** N-ary Trees — trees of data with any number of branches * The NodeTree class and its associated functions provide an N-ary tree data structure, in which nodes in the tree can contain arbitrary data. @@ -241,18 +252,18 @@ public: */ enum TraverseFlags { - TRAVERSE_LEAVES = G_TRAVERSE_LEAVES, - TRAVERSE_NON_LEAVES = G_TRAVERSE_NON_LEAVES, - TRAVERSE_ALL = G_TRAVERSE_ALL, - TRAVERSE_MASK = G_TRAVERSE_MASK + TRAVERSE_LEAVES = G_TRAVERSE_LEAVES, /*!< Only leaf nodes should be visited. */ + TRAVERSE_NON_LEAVES = G_TRAVERSE_NON_LEAVES, /*!< Only non-leaf nodes should be visited. */ + TRAVERSE_ALL = G_TRAVERSE_ALL, /*!< All nodes should be visited. */ + TRAVERSE_MASK = G_TRAVERSE_MASK /*!< A mask of all traverse flags. */ }; /** 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. * - * @param order The order in which nodes are visited: IN_ORDER, TRAVERSE_PRE_ORDER, TRAVERSE_POST_ORDER, or TRAVERSE_LEVEL_ORDER. - * @param flags Which types of children are to be visited: One of TRAVERSE_ALL, TRAVERSE_LEAVES and TRAVERSE_NON_LEAVES. + * @param order The order in which nodes are visited. + * @param flags Which types of children are to be visited. * @param max_depth The maximum depth of the traversal. * Nodes below this depth will not be visited. * If max_depth is -1 all nodes in the tree are visited. @@ -260,7 +271,7 @@ public: * If max_depth is 2, the root and its children are visited. And so on. * @param func the slot to invoke for each visited child */ - void traverse(const TraverseFunc& func, TraverseType order = IN_ORDER, TraverseFlags flags = TRAVERSE_ALL, int max_depth = -1) + void traverse(const TraverseFunc& func, TraverseType order = TRAVERSE_IN_ORDER, TraverseFlags flags = TRAVERSE_ALL, int max_depth = -1) { TraverseFunc func_copy = func; g_node_traverse(gobj(), (GTraverseType)order, (GTraverseFlags)flags, max_depth, c_callback_traverse, reinterpret_cast<gpointer>(&func_copy)); @@ -270,7 +281,7 @@ public: /** Calls a function for each of the children of a NodeTree. * Note that it doesn't descend beneath the child nodes. * - * @param flags Wwhich types of children are to be visited: One of TRAVERSE_ALL, TRAVERSE_LEAVES and TRAVERSE_NON_LEAVES. + * @param flags Wwhich types of children are to be visited. * @param func The slot to invoke for each visited node. */ void foreach(const ForeachFunc& func, TraverseFlags flags = TRAVERSE_ALL) @@ -318,7 +329,7 @@ public: * @param data The data for which to search. * @return The found node, or 0 if the data is not found. */ - NodeTree<T>* find(const T& data, TraverseType order = IN_ORDER, TraverseFlags flags = TRAVERSE_ALL) + NodeTree<T>* find(const T& data, TraverseType order = TRAVERSE_IN_ORDER, TraverseFlags flags = TRAVERSE_ALL) { //We use a sigc::slot for the C callback, so we can bind some extra data. sigc::slot<gboolean, GNode*, const T&, GNode**> real_slot = sigc::ptr_fun(on_compare_node); @@ -332,12 +343,12 @@ public: /** Finds a node in a tree. * - * @param order The order in which nodes are visited: IN_ORDER, TRAVERSE_PRE_ORDER, TRAVERSE_POST_ORDER, or TRAVERSE_LEVEL_ORDER - * @param flags Which types of children are to be visited: one of TRAVERSE_ALL, TRAVERSE_LEAVES and TRAVERSE_NON_LEAVES. + * @param order The order in which nodes are visited. + * @param flags Which types of children are to be visited. * @param data The data for which to search. * @return The found node, or 0 if the data is not found. */ - const NodeTree<T>* find(const T& data, TraverseType order = IN_ORDER, TraverseFlags flags = TRAVERSE_ALL) const + const NodeTree<T>* find(const T& data, TraverseType order = TRAVERSE_IN_ORDER, TraverseFlags flags = TRAVERSE_ALL) const { return const_cast<NodeTree<T>*>(this)->find(order, flags, data); } diff --git a/tests/glibmm_nodetree/main.cc b/tests/glibmm_nodetree/main.cc index 28fabfbd..20733c25 100644 --- a/tests/glibmm_nodetree/main.cc +++ b/tests/glibmm_nodetree/main.cc @@ -38,19 +38,19 @@ int main() std::cout << "Breadth-first:" << std::endl; - ta.traverse(echoslot, Glib::LEVEL_ORDER); + ta.traverse(echoslot, Glib::TRAVERSE_LEVEL_ORDER); std::cout << std::endl; std::cout << "Depth-first (pre):" << std::endl; - ta.traverse(echoslot, Glib::PRE_ORDER); + ta.traverse(echoslot, Glib::TRAVERSE_PRE_ORDER); std::cout << std::endl; std::cout << "Depth-first (in):" << std::endl; - ta.traverse(echoslot, Glib::IN_ORDER); + ta.traverse(echoslot, Glib::TRAVERSE_IN_ORDER); std::cout << std::endl; std::cout << "Depth-first (post):" << std::endl; - ta.traverse(echoslot, Glib::POST_ORDER); + ta.traverse(echoslot, Glib::TRAVERSE_POST_ORDER); std::cout << std::endl; std::cout << "Leaf children of 'a':" << std::endl; @@ -61,19 +61,19 @@ int main() ta.foreach(sigc::bind<bool>(sigc::ptr_fun(echol), false)); std::cout << std::endl; - type_nodetree_string* tmp = ta.find(e, Glib::IN_ORDER); + type_nodetree_string* tmp = ta.find(e); if(!tmp) std::cout << e << " not found" << std::endl; else std::cout << "Found " << (tmp->data()) << std::endl; - tmp = ta.find(a, Glib::IN_ORDER); + tmp = ta.find(a); if(!tmp) std::cout << a << " not found" << std::endl; else std::cout << "Found " << (tmp->data()) << std::endl; - tmp = ta.find("f", Glib::IN_ORDER); + tmp = ta.find("f"); if(!tmp) std::cout << a << " not found" << std::endl; else |