libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
resource.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
13#include <promeki/namespace.h>
14#include <promeki/string.h>
15#include <promeki/buffer.h>
16#include <promeki/error.h>
17#include <promeki/list.h>
18#include <promeki/filepath.h>
19#include <promeki/util.h>
20
21// Forward declarations so this header does not pull in <cirf/types.h>
22// — which keeps cirf an internal implementation detail of promeki
23// and lets the cirf_runtime link stay PRIVATE. Consumers that want
24// to dereference the pointers returned by findFile()/findFolder()
25// can include <cirf/types.h> themselves; the header is installed
26// alongside the libpromeki thirdparty headers.
27struct cirf_file;
28struct cirf_folder;
29typedef struct cirf_file cirf_file_t;
30typedef struct cirf_folder cirf_folder_t;
31
32PROMEKI_NAMESPACE_BEGIN
33
82class Resource {
83 public:
85 static constexpr const char *Prefix = ":/";
86
91 static bool isResourcePath(const String &path);
92
101 static String stripPrefix(const String &path);
102
112 static const cirf_file_t *findFile(const String &path);
113
120 static const cirf_folder_t *findFolder(const String &path);
121
125 static bool exists(const String &path);
126
140 static Buffer data(const String &path, Error *err = nullptr);
141
149 static String mime(const String &path);
150
156 static size_t size(const String &path);
157
170 static List<FilePath> listFiles(const String &path, Error *err = nullptr);
171
175 static List<FilePath> listFolders(const String &path, Error *err = nullptr);
176
180 static List<FilePath> listEntries(const String &path, Error *err = nullptr);
181
202 static Error registerRoot(const cirf_folder_t *root, const String &prefix = String());
203
210 static void unregisterRoot(const String &prefix);
211};
212
232#define PROMEKI_REGISTER_RESOURCES(NAME, PREFIX) \
233 namespace { \
234 struct PROMEKI_CONCAT(_promeki_resreg_, NAME) { \
235 PROMEKI_CONCAT(_promeki_resreg_, NAME)() { \
236 ::promeki::Resource::registerRoot(&NAME##_root, PREFIX); \
237 } \
238 }; \
239 static PROMEKI_CONCAT(_promeki_resreg_, NAME) PROMEKI_CONCAT(_promeki_resreg_inst_, NAME); \
240 }
241
242PROMEKI_NAMESPACE_END
243
244#endif // PROMEKI_ENABLE_CORE