Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/resource/PrefixLoader.h

raw
1 /*
2 * Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2023 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 8 июн. 2021 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_RESOURCE_PREFIXLOADER_H_
23 #define LSP_PLUG_IN_RESOURCE_PREFIXLOADER_H_
24
25 #include <lsp-plug.in/resource/ILoader.h>
26 #include <lsp-plug.in/lltl/parray.h>
27
28 namespace lsp
29 {
30 namespace resource
31 {
32 /**
33 * This loader resolves resources according to the specified prefix
34 * Multiple prefixes are possible
35 */
36 class PrefixLoader: public ILoader
37 {
38 private:
39 ILoader & operator = (const ILoader &);
40 PrefixLoader(const PrefixLoader &);
41
42 protected:
43 typedef struct prefix_t
44 {
45 LSPString sPrefix;
46 ILoader *pLoader;
47 bool bFree;
48 } prefix_t;
49
50 protected:
51 lltl::parray<prefix_t> vLoaders;
52 ILoader *pDefault;
53
54 protected:
55 static bool match_prefix(const LSPString *str, const LSPString *prefix);
56
57 protected:
58 ILoader *lookup_prefix(LSPString *dst, const LSPString *path);
59 ILoader *lookup_prefix(LSPString *dst, const char *path);
60 ILoader *lookup_prefix(LSPString *dst, const io::Path *path);
61
62 public:
63 explicit PrefixLoader(ILoader *dfl = NULL);
64 virtual ~PrefixLoader();
65
66 public:
67 /**
68 * Associate some loader with prefix, loader will be automatically destroyed on destruction
69 * @param prefix prefix to use
70 * @param loader loader to associate
71 * @param free free after use
72 * @return status of operation
73 */
74 status_t add_prefix(const char *prefix, ILoader *loader, bool free);
75 status_t add_prefix(const LSPString *prefix, ILoader *loader, bool free);
76 status_t add_prefix(const io::Path *prefix, ILoader *loader, bool free);
77
78 public:
79 virtual io::IInStream *read_stream(const char *name);
80 virtual io::IInStream *read_stream(const LSPString *name);
81 virtual io::IInStream *read_stream(const io::Path *name);
82
83 virtual io::IInSequence *read_sequence(const char *name, const char *charset = NULL);
84 virtual io::IInSequence *read_sequence(const LSPString *name, const char *charset = NULL);
85 virtual io::IInSequence *read_sequence(const io::Path *name, const char *charset = NULL);
86
87 virtual ssize_t enumerate(const char *path, resource_t **list);
88 virtual ssize_t enumerate(const LSPString *path, resource_t **list);
89 virtual ssize_t enumerate(const io::Path *path, resource_t **list);
90 };
91 } /* namespace resource */
92 } /* namespace lsp */
93
94
95
96 #endif /* LSP_PLUG_IN_RESOURCE_PREFIXLOADER_H_ */