-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
filedirectory.h
169 lines (151 loc) · 7 KB
/
filedirectory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/**\file filedirectory.h
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2009-2012 Daniel Swanson <danij@dengine.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef LIBDENG_FILEDIRECTORY_H
#define LIBDENG_FILEDIRECTORY_H
#include "dd_string.h"
#include "uri.h"
#include "pathdirectory.h"
/**
* Callback function type for FileDirectory::Iterate
*
* @param node PathDirectoryNode being processed.
* @param paramaters User data passed to this.
* @return Non-zero if iteration should stop.
*/
typedef pathdirectory_iteratecallback_t filedirectory_iteratecallback_t;
/// Const variant.
typedef pathdirectory_iterateconstcallback_t filedirectory_iterateconstcallback_t;
/**
* FileDirectory. Core system component representing a hierarchical
* file path structure.
*
* A specialization of de::PathDirectory which implements automatic
* population of the directory itself from the virtual file system.
* Also, paths are resolved prior to pushing them into the directory.
*
* @todo Perhaps this should be derived from PathDirectory instead of
* encapsulating an instance of it?
*
* @ingroup fs
*/
struct filedirectory_s; // The filedirectory instance (opaque).
typedef struct filedirectory_s FileDirectory;
FileDirectory* FileDirectory_New(const char* basePath);
/**
* Construct a new FileDirectory instance, populating it with nodes
* for the given search paths.
*
* @param basePath Used with directories which represent the internal paths
* natively as relative paths. @c NULL means only absolute
* paths will be added to the directory (attempts to add
* relative paths will fail silently).
* @param searchPathList List of search paths. @c NULL terminated.
* @param flags @see searchPathFlags
*/
FileDirectory* FileDirectory_NewWithPathListStr(const char* basePath, const ddstring_t* searchPathList, int flags);
FileDirectory* FileDirectory_NewWithPathList(const char* basePath, const char* searchPathList, int flags);
void FileDirectory_Delete(FileDirectory* fd);
/**
* Clear the directory contents.
*/
void FileDirectory_Clear(FileDirectory* fd);
/**
* Resolve and collate all paths in the directory into a list.
*
* @param fd FileDirectory instance.
* @param type If a valid type, only paths of this type will be visited.
* @param count Number of visited paths is written back here.
*
* @return Ptr to the allocated list; it is the responsibility of the caller to
* Str_Free each string in the list and Z_Free the list itself.
*/
ddstring_t* FileDirectory_AllPaths(FileDirectory* fd, pathdirectorynode_type_t type, size_t* count);
/**
* Add a new set of paths. Duplicates are automatically pruned.
*
* @param fd FileDirectory instance.
* @param flags @see searchPathFlags
* @param paths One or more paths.
* @param pathsCount Number of elements in @a paths.
* @param callback Callback function ptr.
* @param paramaters Passed to the callback.
*/
void FileDirectory_AddPaths3(FileDirectory* fd, int flags, const Uri* const* paths, uint pathsCount,
int (*callback) (PathDirectoryNode* node, void* paramaters), void* paramaters);
void FileDirectory_AddPaths2(FileDirectory* fd, int flags, const Uri* const* paths, uint pathsCount,
int (*callback) (PathDirectoryNode* node, void* paramaters)); /*paramaters=NULL*/
void FileDirectory_AddPaths(FileDirectory* fd, int flags, const Uri* const* paths, uint pathsCount); /*callback=NULL*/
/**
* Add a new set of paths from a path list. Duplicates are automatically pruned.
*
* @param fd FileDirectory instance.
* @param flags @see searchPathFlags
* @param pathList One or more paths separated by semicolons.
* @param callback Callback function ptr.
* @param paramaters Passed to the callback.
*/
void FileDirectory_AddPathList3(FileDirectory* fd, int flags, const char* pathList,
int (*callback) (PathDirectoryNode* node, void* paramaters), void* paramaters);
void FileDirectory_AddPathList2(FileDirectory* fd, int flags, const char* pathList,
int (*callback) (PathDirectoryNode* node, void* paramaters)); /*paramaters=NULL*/
void FileDirectory_AddPathList(FileDirectory* fd, int flags, const char* pathList); /*callback=NULL*/
/**
* Find a path in the directory.
*
* @param fd FileDirectory instance.
* @param type If a valid path type only consider nodes of this type.
* @param searchPath Relative or absolute path.
* @param searchDelimiter Fragments of @a searchPath are delimited by this character.
* @param foundPath If not @c NULL, the full path of the node is written back here if found.
* @param foundDelimiter Delimiter to be used when composing @a foundPath.
*
* @return @c true, iff successful.
*/
boolean FileDirectory_Find(FileDirectory* fd, pathdirectorynode_type_t type,
const char* searchPath, char searchDelimiter, ddstring_t* foundPath, char foundDelimiter);
/**
* Iterate over nodes in the directory making a callback for each.
* Iteration ends when all nodes have been visited or a callback returns non-zero.
*
* @param fd FileDirectory instance.
* @param type If a valid path type only process nodes of this type.
* @param parent If not @c NULL, only process child nodes of this node.
* @param callback Callback function ptr.
* @param paramaters Passed to the callback.
*
* @return @c 0 iff iteration completed wholly.
*/
int FileDirectory_Iterate2(FileDirectory* fd, pathdirectorynode_type_t type, PathDirectoryNode* parent, ushort hash,
filedirectory_iteratecallback_t callback, void* paramaters);
int FileDirectory_Iterate(FileDirectory* fd, pathdirectorynode_type_t type, PathDirectoryNode* parent, ushort hash,
filedirectory_iteratecallback_t callback); /*paramaters=NULL*/
int FileDirectory_Iterate2_Const(const FileDirectory* fd, pathdirectorynode_type_t type, const PathDirectoryNode* parent, ushort hash,
filedirectory_iterateconstcallback_t callback, void* paramaters);
int FileDirectory_Iterate_Const(const FileDirectory* fd, pathdirectorynode_type_t type, const PathDirectoryNode* parent, ushort hash,
filedirectory_iterateconstcallback_t callback); /*paramaters=NULL*/
#if _DEBUG
void FileDirectory_Print(FileDirectory* fd);
void FileDirectory_PrintHashDistribution(FileDirectory* fd);
#endif
#endif /* LIBDENG_FILEDIRECTORY_H */