18#ifndef __R_DIR_TREE_H__
19#define __R_DIR_TREE_H__
21#if !defined(__RLIB_H_INCLUDE_GUARD__) && !defined(RLIB_COMPILATION)
22#error "#include <rlib.h> only please."
50#define R_DIR_TREE_SEPARATOR '/'
62#define r_dir_tree_ref r_ref_ref
64#define r_dir_tree_unref r_ref_unref
70#define r_dir_tree_get_root(tree) r_dir_tree_get (tree, NULL, 0)
93#define r_dir_tree_set(tree, path, size, data, notify) \
94 r_dir_tree_set_full (tree, path, size, data, notify, NULL)
112#define r_dir_tree_clear_node(tree, path) r_dir_tree_set (tree, path, -1, NULL, NULL)
121#define r_dir_tree_remove_sub_tree(tree, path, size) \
122 r_dir_tree_remove_node_full (tree, r_dir_tree_get (tree, path, size))
124#define r_dir_tree_remove_all(tree) \
125 r_dir_tree_remove_node_full (tree, r_dir_tree_get_root (tree))
130#define r_dir_tree_node_set(node, data, notify) r_dir_tree_node_set_full (node, data, notify, NULL)
138#define r_dir_tree_node_clear(node) r_dir_tree_node_set (node, NULL, NULL)
RDirTreeNode * r_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.
rpointer r_dir_tree_node_get(RDirTreeNode *node)
Read the data pointer attached to node.
RDirTree * r_dir_tree_new(void)
Allocate an empty tree.
struct RDirTree RDirTree
Opaque, refcounted directory tree.
Definition rdirtree.h:55
RFunc r_dir_tree_node_func(const RDirTreeNode *node)
Return node's visit function, or NULL.
rchar * r_dir_tree_node_path(const RDirTreeNode *node)
Reconstruct node's full slash-separated path; caller frees with r_free.
RDirTreeNode * r_dir_tree_node_parent(const RDirTreeNode *node)
Parent of node, or NULL at the root.
const rchar * r_dir_tree_node_name(const RDirTreeNode *node)
Last path component of node (no slashes).
rsize r_dir_tree_node_count(const RDirTree *tree)
Total number of nodes in tree, including the root.
RDirTreeNode * r_dir_tree_create(RDirTree *tree, const rchar *path, rssize size)
Materialise the node at path, creating ancestors as needed; returns the leaf.
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 poin...
void r_dir_tree_remove_node_full(RDirTree *tree, RDirTreeNode *node)
Remove node and every descendant; destroy notifiers run.
RDirTreeNode * r_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 v...
RDirTreeNode * r_dir_tree_get(RDirTree *tree, const rchar *path, rssize size)
Look up the node at path; NULL if the path doesn't exist yet.
struct RDirTreeNode RDirTreeNode
Opaque node inside an RDirTree.
Definition rdirtree.h:57
#define R_ATTR_WARN_UNUSED_RESULT
Warn if a function's return value is ignored.
Definition rmacros.h:278
#define R_API
Public-API decoration: resolves to R_API_EXPORT while building rlib and R_API_IMPORT for consumers.
Definition rmacros.h:115
#define R_BEGIN_DECLS
Open an extern "C" block under C++ (no-op in C).
Definition rmacros.h:196
char rchar
Default character type (char).
Definition rtypes.h:137
void(* RFunc)(rpointer data, rpointer user)
Generic iteration callback over (data, user) pairs.
Definition rtypes.h:403
void(* RDestroyNotify)(rpointer ptr)
Destructor callback: free / release the value at ptr.
Definition rtypes.h:401
void * rpointer
Generic pointer (alias for void *).
Definition rtypes.h:327
unsigned long rsize
Unsigned pointer-sized size type (like size_t).
Definition rtypes.h:290
signed long rssize
Signed pointer-sized size type (like ssize_t).
Definition rtypes.h:291
Refcount base struct shared by every refcounted type in rlib.
Foundational type aliases used by every rlib header.