rlib
Convenience library for useful things
Loading...
Searching...
No Matches
rdirtree.h File Reference

Path-component-keyed tree with per-node data slots. More...

#include <rlib/rtypes.h>
#include <rlib/rref.h>

Go to the source code of this file.

Macros

#define R_DIR_TREE_SEPARATOR   '/'
 Path component separator ('/').
 
#define r_dir_tree_ref   r_ref_ref
 Increment the tree's refcount.
 
#define r_dir_tree_unref   r_ref_unref
 Decrement the tree's refcount; frees when it reaches zero.
 
#define r_dir_tree_get_root(tree)   r_dir_tree_get (tree, NULL, 0)
 Convenience: return the tree's root node.
 
#define r_dir_tree_set(tree, path, size, data, notify)    r_dir_tree_set_full (tree, path, size, data, notify, NULL)
 Convenience: r_dir_tree_set_full with no visit function.
 
#define r_dir_tree_clear_node(tree, path)   r_dir_tree_set (tree, path, -1, NULL, NULL)
 Convenience: drop the data at path (destroy notifier runs).
 
#define r_dir_tree_remove_sub_tree(tree, path, size)    r_dir_tree_remove_node_full (tree, r_dir_tree_get (tree, path, size))
 Convenience: remove the sub-tree rooted at path.
 
#define r_dir_tree_remove_all(tree)    r_dir_tree_remove_node_full (tree, r_dir_tree_get_root (tree))
 Convenience: remove every node (the tree itself remains valid).
 
#define r_dir_tree_node_set(node, data, notify)   r_dir_tree_node_set_full (node, data, notify, NULL)
 Convenience: r_dir_tree_node_set_full with no visit function.
 
#define r_dir_tree_node_clear(node)   r_dir_tree_node_set (node, NULL, NULL)
 Convenience: clear node's data (destroy notifier runs).
 

Typedefs

typedef struct RDirTree RDirTree
 Opaque, refcounted directory tree.
 
typedef struct RDirTreeNode RDirTreeNode
 Opaque node inside an RDirTree.
 

Functions

RDirTreer_dir_tree_new (void)
 Allocate an empty tree.
 
rsize r_dir_tree_node_count (const RDirTree *tree)
 Total number of nodes in tree, including the root.
 
RDirTreeNoder_dir_tree_get (RDirTree *tree, const rchar *path, rssize size)
 Look up the node at path; NULL if the path doesn't exist yet.
 
RDirTreeNoder_dir_tree_get_or_any_parent (RDirTree *tree, const rchar *path, rssize size)
 Look up path; if it doesn't exist, return the deepest existing ancestor.
 
RDirTreeNoder_dir_tree_create (RDirTree *tree, const rchar *path, rssize size)
 Materialise the node at path, creating ancestors as needed; returns the leaf.
 
RDirTreeNoder_dir_tree_set_full (RDirTree *tree, const rchar *path, rssize size, rpointer data, RDestroyNotify notify, RFunc func) R_ATTR_WARN_UNUSED_RESULT
 Create the node at path (if needed) and attach data with the supplied destroy notifier and optional visit function.
 
void r_dir_tree_remove_node_full (RDirTree *tree, RDirTreeNode *node)
 Remove node and every descendant; destroy notifiers run.
 
rpointer r_dir_tree_node_get (RDirTreeNode *node)
 Read the data pointer attached to node.
 
rpointer r_dir_tree_node_set_full (RDirTreeNode *node, rpointer data, RDestroyNotify notify, RFunc func)
 Attach data to node with optional destroy notifier and visit function; returns the previous data pointer.
 
RFunc r_dir_tree_node_func (const RDirTreeNode *node)
 Return node's visit function, or NULL.
 
RDirTreeNoder_dir_tree_node_parent (const RDirTreeNode *node)
 Parent of node, or NULL at the root.
 
const rcharr_dir_tree_node_name (const RDirTreeNode *node)
 Last path component of node (no slashes).
 
rcharr_dir_tree_node_path (const RDirTreeNode *node)
 Reconstruct node's full slash-separated path; caller frees with r_free.
 

Detailed Description

Path-component-keyed tree with per-node data slots.