Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/fmt/sfz/PullParser.h

raw
1 /*
2 * Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2025 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 29 янв. 2023 г.
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_FMT_SFZ_PULLPARSER_H_
23 #define LSP_PLUG_IN_FMT_SFZ_PULLPARSER_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26
27 #include <lsp-plug.in/io/IInSequence.h>
28 #include <lsp-plug.in/io/IInStream.h>
29 #include <lsp-plug.in/io/IOutStream.h>
30 #include <lsp-plug.in/io/Path.h>
31
32 #include <lsp-plug.in/fmt/sfz/types.h>
33
34 namespace lsp
35 {
36 namespace sfz
37 {
38 /**
39 * SFZ file format pull parser
40 */
41 class LSP_RUNTIME_LIB_PUBLIC PullParser
42 {
43 private:
44 io::IInStream *pIn;
45 size_t nWFlags;
46 event_t sCurrent;
47 event_t sSample; // Pending sample event
48 LSPString sUnget; // Buffer for 'unget' operations
49 size_t nUnget; // Read offset relative to the beginning of the 'unget' buffer
50
51 protected:
52 static bool is_identifier(lsp_wchar_t ch, bool first);
53 static bool is_space(lsp_wchar_t ch);
54 static void trim_right(LSPString *value);
55 static bool is_string_opcode(const LSPString *name);
56
57 protected:
58 lsp_swchar_t get_char();
59 status_t expect_string(const char *text);
60 status_t expect_char(lsp_swchar_t expected);
61 status_t read_opcode(lsp_wchar_t ch, event_t *ev);
62 status_t read_opcode_name(lsp_swchar_t ch, LSPString *name);
63 status_t read_opcode_value(LSPString *value);
64 status_t read_string_opcode(LSPString *value);
65 status_t read_variable_name(LSPString *value);
66 status_t read_variable_value(LSPString *value);
67 status_t read_sample_data(io::IOutStream *os);
68
69 status_t peek_pending_event(event_t *ev);
70 status_t read_next_event(event_t *ev);
71 status_t read_header(event_t *ev);
72 status_t read_comment(event_t *ev);
73 status_t read_define(event_t *ev);
74 status_t read_include(event_t *ev);
75 status_t read_preprocessor(event_t *ev);
76 status_t set_error(status_t code);
77
78 public:
79 explicit PullParser();
80 PullParser(const PullParser &) = delete;
81 PullParser(PullParser &&) = delete;
82 ~PullParser();
83
84 PullParser & operator = (const PullParser &) = delete;
85 PullParser & operator = (PullParser &&) = delete;
86
87 public:
88 /**
89 * Open parser
90 * @param path UTF-8 path to the file
91 * @return status of operation
92 */
93 status_t open(const char *path);
94
95 /**
96 * Open parser
97 * @param path string representation of path to the file
98 * @return status of operation
99 */
100 status_t open(const LSPString *path);
101
102 /**
103 * Open parser
104 * @param path path to the file
105 * @return status of operation
106 */
107 status_t open(const io::Path *path);
108
109 /**
110 * Wrap string with parser
111 * @param str string to wrap
112 * @return status of operation
113 */
114 status_t wrap(const char *str);
115
116 /**
117 * Wrap string with parser
118 * @param buf buffer to wrap
119 * @param len length of buffer to wrap
120 * @return status of operation
121 */
122 status_t wrap(const void *buf, size_t len);
123
124 /**
125 * Wrap string with parser
126 * @param str string to wrap
127 * @return status of operation
128 */
129 status_t wrap(const LSPString *str);
130
131 /**
132 * Wrap input stream with parser
133 * @param is input stream
134 * @param flags wrap flags
135 * @return status of operation
136 */
137 status_t wrap(io::IInStream *is, size_t flags = WRAP_NONE);
138
139 /**
140 * Close parser
141 * @return status of operation
142 */
143 status_t close();
144
145 public:
146 /**
147 * Get current event
148 * @return current event
149 */
150 const event_t *current() const;
151
152 /**
153 * Get next event
154 * @param event pointer to store the event data, can be NULL
155 * @return status of operation
156 */
157 status_t next(event_t *event = NULL);
158 };
159
160 } /* namespace sfz */
161 } /* namespace lsp */
162
163
164
165 #endif /* LSP_PLUG_IN_FMT_SFZ_PULLPARSER_H_ */