GPAK  1.0.0
A general-purpose archive library
filesystem_tree.h
Go to the documentation of this file.
1 /**
2  * @file filesystem_tree.h
3  * @author AdamFull
4  * @date 23.04.2023
5  * @brief The filesystem_tree.h header file contains methods and data structures
6  * for working with a filesystem tree used in the Gpak library for
7  * managing game archives.
8  *
9  * This header file defines the data structures and functions for representing
10  * and manipulating a filesystem tree used to store files and directories
11  * within a Gpak game archive. It provides an interface for iterating over the
12  * directories and files stored in the archive, allowing for efficient and
13  * organized access to game assets.
14  *
15  * The filesystem tree consists of nodes representing directories and files
16  * within the game archive. Each node can have zero or more child nodes,
17  * representing the contents of a directory. File nodes store the file metadata
18  * and can be used to access the file data stored within the archive.
19  *
20  * To use the filesystem tree functions provided by this header, include it
21  * alongside the main gpak.h header file and link against the Gpak library in
22  * your project.
23  */
24 
25 #ifndef FILESYSTEM_TREE_H
26 #define FILESYSTEM_TREE_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32  #include "gpak_export.h"
33  #include "gpak_data.h"
34 
35  /**
36  * @brief Creates a new filesystem tree node.
37  *
38  * This function initializes and returns a new filesystem tree node,
39  * which is the root of the filesystem tree.
40  *
41  * @return A pointer to the created filesystem_tree_node_t.
42  */
44 
45  /**
46  * @brief Adds a directory to the filesystem tree.
47  *
48  * This function creates a new directory node under the given _root node.
49  *
50  * @param _root A pointer to the root filesystem_tree_node_t.
51  * @param _path The path of the directory to add.
52  */
53  GPAK_API void filesystem_tree_add_directory(filesystem_tree_node_t* _root, const char* _path);
54 
55  /**
56  * @brief Adds a file to the filesystem tree.
57  *
58  * This function creates a new file node under the given _root node.
59  *
60  * @param _root A pointer to the root filesystem_tree_node_t.
61  * @param _path The path of the directory where the file will be added.
62  * @param _file_path The file path of the file to add.
63  * @param _entry The pak_entry_t associated with the file.
64  */
65  GPAK_API void filesystem_tree_add_file(filesystem_tree_node_t* _root, const char* _path, const char* _file_path, pak_entry_t _entry);
66 
67  /**
68  * @brief Finds a directory in the filesystem tree.
69  *
70  * This function searches for a directory node with the specified path
71  * in the filesystem tree.
72  *
73  * @param _root A pointer to the root filesystem_tree_node_t.
74  * @param _path The path of the directory to find.
75  * @return A pointer to the found directory node or NULL if not found.
76  */
78 
79  /**
80  * @brief Finds a file in the filesystem tree.
81  *
82  * This function searches for a file node with the specified path
83  * in the filesystem tree.
84  *
85  * @param _root A pointer to the root filesystem_tree_node_t.
86  * @param _path The path of the file to find.
87  * @return A pointer to the found file node or NULL if not found.
88  */
89  GPAK_API filesystem_tree_file_t* filesystem_tree_find_file(filesystem_tree_node_t* _root, const char* _path);
90 
91  /**
92  * @brief Gets the path of a directory node.
93  *
94  * This function retrieves the path of the specified directory node.
95  *
96  * @param _node A pointer to the filesystem_tree_node_t.
97  * @return A string containing the path of the directory.
98  */
100 
101  /**
102  * @brief Gets the path of a file node.
103  *
104  * This function retrieves the path of the specified file node.
105  *
106  * @param _node A pointer to the filesystem_tree_node_t.
107  * @param _file A pointer to the filesystem_tree_file_t.
108  * @return A string containing the path of the file.
109  */
111 
112  /**
113  * @brief Deletes the filesystem tree.
114  *
115  * This function recursively deletes
116  * the filesystem tree and frees all associated memory.
117  * @param _root A pointer to the root filesystem_tree_node_t.
118  */
119  GPAK_API void filesystem_tree_delete(filesystem_tree_node_t* _root);
120 
121 
122  /**
123  * @brief Creates a new filesystem tree iterator.
124  *
125  * This function initializes and returns a new filesystem tree iterator
126  * for traversing the filesystem tree starting from the given _root node.
127  *
128  * @param _root A pointer to the root filesystem_tree_node_t.
129  * @return A pointer to the created filesystem_tree_iterator_t.
130  */
132 
133  /**
134  * @brief Retrieves the next directory in the filesystem tree.
135  *
136  * This function returns the next directory node in the filesystem tree
137  * using a depth-first search algorithm.
138  *
139  * @param _iterator A pointer to the filesystem_tree_iterator_t.
140  * @return A pointer to the next directory node or NULL if there are no more directories.
141  */
143 
144  /**
145  * @brief Retrieves the next sibling directory in the filesystem tree.
146  *
147  * This function returns the next sibling directory node in the filesystem tree
148  * without traversing its children.
149  *
150  * @param _iterator A pointer to the filesystem_tree_iterator_t.
151  * @return A pointer to the next sibling directory node or NULL if there are no more sibling directories.
152  */
154 
155  /**
156  * @brief Retrieves the next file in the filesystem tree.
157  *
158  * This function returns the next file node in the filesystem tree
159  * using a depth-first search algorithm.
160  *
161  * @param _iterator A pointer to the filesystem_tree_iterator_t.
162  * @return A pointer to the next file node or NULL if there are no more files.
163  */
165 
166  /**
167  * @brief Frees the memory associated with the filesystem tree iterator.
168  *
169  * This function deallocates the memory used by the filesystem tree iterator.
170  *
171  * @param _iterator A pointer to the filesystem_tree_iterator_t.
172  */
173  GPAK_API void filesystem_iterator_free(filesystem_tree_iterator_t* _iterator);
174 
175 #ifdef __cplusplus
176 }
177 #endif
178 
179 #endif // FILESYSTEM_TREE_H
GPAK_API filesystem_tree_node_t * filesystem_tree_find_directory(filesystem_tree_node_t *_root, const char *_path)
GPAK_API filesystem_tree_node_t * filesystem_iterator_next_subling_directory(filesystem_tree_iterator_t *_iterator)
GPAK_API char * filesystem_tree_file_path(filesystem_tree_node_t *_node, filesystem_tree_file_t *_file)
GPAK_API filesystem_tree_node_t * filesystem_tree_create()
GPAK_API filesystem_tree_node_t * filesystem_iterator_next_directory(filesystem_tree_iterator_t *_iterator)
GPAK_API void filesystem_iterator_free(filesystem_tree_iterator_t *_iterator)
GPAK_API void filesystem_tree_delete(filesystem_tree_node_t *_root)
GPAK_API char * filesystem_tree_directory_path(filesystem_tree_node_t *_node)
GPAK_API void filesystem_tree_add_file(filesystem_tree_node_t *_root, const char *_path, const char *_file_path, pak_entry_t _entry)
GPAK_API void filesystem_tree_add_directory(filesystem_tree_node_t *_root, const char *_path)
GPAK_API filesystem_tree_iterator_t * filesystem_iterator_create(filesystem_tree_node_t *_root)
GPAK_API filesystem_tree_file_t * filesystem_iterator_next_file(filesystem_tree_iterator_t *_iterator)
GPAK_API filesystem_tree_file_t * filesystem_tree_find_file(filesystem_tree_node_t *_root, const char *_path)
Definition: gpak_data.h:133