summaryrefslogtreecommitdiff
path: root/glib/src/nodetree.hg
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2017-04-18 20:18:52 +0200
committerMurray Cumming <murrayc@murrayc.com>2017-04-18 21:53:16 +0200
commitbfd34aa5a37c5ac4f28a9941a56352f873c2e745 (patch)
treeb33c9fba87a778a1b76d5bc78b05d6fd53197838 /glib/src/nodetree.hg
parent0e5df130392be8238f5bbbea3c9144e9dd683a17 (diff)
downloadglibmm-bfd34aa5a37c5ac4f28a9941a56352f873c2e745.tar.gz
NodeTree: Move enums into class, and use C++11 enum classes.
Diffstat (limited to 'glib/src/nodetree.hg')
-rw-r--r--glib/src/nodetree.hg64
1 files changed, 32 insertions, 32 deletions
diff --git a/glib/src/nodetree.hg b/glib/src/nodetree.hg
index 323a0e04..cf41b48f 100644
--- a/glib/src/nodetree.hg
+++ b/glib/src/nodetree.hg
@@ -31,21 +31,6 @@ _DEFS(glibmm,glib)
namespace Glib
{
-//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.
*
@@ -70,6 +55,21 @@ class NodeTree
{
_CLASS_GENERIC(NodeTree, GNode)
public:
+ //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 class TraverseType
+ {
+ 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. */
+ PRE_ORDER = G_PRE_ORDER, /*!< Visits a node, then its children. */
+ POST_ORDER = G_POST_ORDER, /*!< Visits the node's children, then the node itself. */
+ 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. */
+ };
+
using TraverseFunc = sigc::slot<bool(NodeTree<T>&)>;
using ForeachFunc = sigc::slot<void(NodeTree<T>&)>;
@@ -289,12 +289,12 @@ public:
*
* @ingroup glibmmEnums
*/
- enum TraverseFlags
+ enum class TraverseFlags
{
- 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. */
+ LEAVES = G_TRAVERSE_LEAVES, /*!< Only leaf nodes should be visited. */
+ NON_LEAVES = G_TRAVERSE_NON_LEAVES, /*!< Only non-leaf nodes should be visited. */
+ ALL = G_TRAVERSE_ALL, /*!< All nodes should be visited. */
+ MASK = G_TRAVERSE_MASK /*!< A mask of all traverse flags. */
};
/** Traverses a tree starting at the current node.
@@ -310,7 +310,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 = TRAVERSE_IN_ORDER, TraverseFlags flags = TRAVERSE_ALL, int max_depth = -1)
+ void traverse(const TraverseFunc& func, TraverseType order = TraverseType::IN_ORDER, TraverseFlags flags = TraverseFlags::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));
@@ -323,7 +323,7 @@ public:
* @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)
+ void foreach(const ForeachFunc& func, TraverseFlags flags = TraverseFlags::ALL)
{
ForeachFunc func_copy = func;
g_node_children_foreach(gobj(), (GTraverseFlags)flags, c_callback_foreach, reinterpret_cast<gpointer>(&func_copy));
@@ -332,11 +332,11 @@ public:
/** Finds the first child of a NodeTree with the given data.
*
- * @param flags Which types of children are to be visited, one of TRAVERSE_ALL, TRAVERSE_LEAVES and TRAVERSE_NON_LEAVES.
+ * @param flags Which types of children are to be visited, one of TraverseFlags::ALL, TraverseFlags::LEAVES or TraverseFlags::NON_LEAVES.
* @param the_data The data for which to search.
* @return the found child, or <tt>nullptr</tt> if the data is not found
*/
- NodeTree<T>* find_child(const T& the_data, TraverseFlags flags = TRAVERSE_ALL)
+ NodeTree<T>* find_child(const T& the_data, TraverseFlags flags = TraverseFlags::ALL)
{
sigc::slot<void(GNode*, const T&, GNode**)> real_slot = sigc::ptr_fun(on_compare_child);
@@ -351,11 +351,11 @@ public:
/** Finds the first child of a NodeTree with the given data.
*
- * @param flags Which types of children are to be visited, one of TRAVERSE_ALL, TRAVERSE_LEAVES and TRAVERSE_NON_LEAVES.
+ * @param flags Which types of children are to be visited, one of TraverseFlags::ALL, TraverseFlags::LEAVES or TraverseFlags::NON_LEAVES.
* @param the_data The data for which to search.
* @return the found child, or <tt>nullptr</tt> if the data is not found
*/
- const NodeTree<T>* find_child(const T& the_data, TraverseFlags flags = TRAVERSE_ALL) const
+ const NodeTree<T>* find_child(const T& the_data, TraverseFlags flags = TraverseFlags::ALL) const
{
return const_cast<NodeTree<T>*>(this)->find_child(flags, the_data);
}
@@ -364,12 +364,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: IN_ORDER, TraverseType::PRE_ORDER, TraverseType::POST_ORDER, or TraverseType::LEVEL_ORDER
+ * @param flags Which types of children are to be visited: one of TraverseFlags::ALL, TraverseFlags::LEAVES or TraverseFlags::NON_LEAVES.
* @param the_data The data for which to search.
* @return The found node, or <tt>nullptr</tt> if the data is not found.
*/
- NodeTree<T>* find(const T& the_data, TraverseType order = TRAVERSE_IN_ORDER, TraverseFlags flags = TRAVERSE_ALL)
+ NodeTree<T>* find(const T& the_data, TraverseType order = TraverseType::IN_ORDER, TraverseFlags flags = TraverseFlags::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);
@@ -390,7 +390,7 @@ public:
* @param the_data The data for which to search.
* @return The found node, or <tt>nullptr</tt> if the data is not found.
*/
- const NodeTree<T>* find(const T& the_data, TraverseType order = TRAVERSE_IN_ORDER, TraverseFlags flags = TRAVERSE_ALL) const
+ const NodeTree<T>* find(const T& the_data, TraverseType order = TraverseType::IN_ORDER, TraverseFlags flags = TraverseFlags::ALL) const
{
return const_cast<NodeTree<T>*>(this)->find(order, flags, the_data);
}
@@ -593,10 +593,10 @@ public:
/** Gets the number of nodes in a tree.
*
- * @param flags Which types of children are to be counted: one of TRAVERSE_ALL, TRAVERSE_LEAVES and TRAVERSE_NON_LEAVES
+ * @param flags Which types of children are to be counted: one of TraverseFlags::ALL, TraverseFlags::LEAVES or TraverseFlags::NON_LEAVES
* @return The number of nodes in the tree.
*/
- guint node_count(TraverseFlags flags = TRAVERSE_ALL) const
+ guint node_count(TraverseFlags flags = TraverseFlags::ALL) const
{
return g_node_n_nodes(const_cast<GNode*>(gobj()), (GTraverseFlags)flags);
}