diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tree.c | 32 | ||||
-rw-r--r-- | src/tree.h | 4 |
2 files changed, 36 insertions, 0 deletions
@@ -201,3 +201,35 @@ mq_tree_foreach_child(MqTree *node, { foreach_child(node->root->first_child, cb, user_data); } + +static gboolean +foreach_from(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), + gpointer user_data) +{ + for (; node; node = node->next) { + if (cb(node, user_data) == MQ_TREE_STOP) { + return MQ_TREE_STOP; + } + if (node->first_child) { + if (foreach_from(node->first_child, cb, user_data) == + MQ_TREE_STOP) { + return MQ_TREE_STOP; + } + } + if (node->parent && node->parent->next) { + if (foreach_from(node->parent->next, cb, user_data) == + MQ_TREE_STOP) { + return MQ_TREE_STOP; + } + } + } + + return MQ_TREE_CONTINUE; +} + +void +mq_tree_foreach_from(MqTree *node, + gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data) +{ + foreach_from(node, cb, user_data); +} @@ -81,6 +81,10 @@ void mq_tree_foreach_child(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data); +void +mq_tree_foreach_from(MqTree *node, + gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data); + G_END_DECLS #endif /* MQ_TREE_H */ |