rlib
Convenience library for useful things
Loading...
Searching...
No Matches
rdirtree.h
Go to the documentation of this file.
1/* RLIB - Convenience library for useful things
2 * Copyright (C) 2017 Haakon Sporsheim <haakon.sporsheim@gmail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3.0 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library.
16 * See the COPYING file at the root of the source repository.
17 */
18#ifndef __R_DIR_TREE_H__
19#define __R_DIR_TREE_H__
20
21#if !defined(__RLIB_H_INCLUDE_GUARD__) && !defined(RLIB_COMPILATION)
22#error "#include <rlib.h> only please."
23#endif
24
45#include <rlib/rtypes.h>
46
47#include <rlib/rref.h>
48
50#define R_DIR_TREE_SEPARATOR '/'
51
53
55typedef struct RDirTree RDirTree;
58
60R_API RDirTree * r_dir_tree_new (void) R_ATTR_MALLOC;
62#define r_dir_tree_ref r_ref_ref
64#define r_dir_tree_unref r_ref_unref
65
68
70#define r_dir_tree_get_root(tree) r_dir_tree_get (tree, NULL, 0)
79R_API RDirTreeNode * r_dir_tree_get (RDirTree * tree, const rchar * path, rssize size);
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)
113
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))
126
130#define r_dir_tree_node_set(node, data, notify) r_dir_tree_node_set_full (node, data, notify, NULL)
136 rpointer data, RDestroyNotify notify, RFunc func);
138#define r_dir_tree_node_clear(node) r_dir_tree_node_set (node, NULL, NULL)
150
151R_END_DECLS
152
155#endif /* __R_DIR_TREE_H__ */
156
157
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.