Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/fmt/obj/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: 21 апр. 2017 г.
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_OBJ_PULLPARSER_H_
23 #define LSP_PLUG_IN_FMT_OBJ_PULLPARSER_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/common/types.h>
27 #include <lsp-plug.in/common/status.h>
28
29 #include <lsp-plug.in/io/IInSequence.h>
30 #include <lsp-plug.in/io/IInStream.h>
31 #include <lsp-plug.in/io/Path.h>
32
33 #include <lsp-plug.in/fmt/obj/const.h>
34
35 namespace lsp
36 {
37 namespace obj
38 {
39 class PullParser
40 {
41 public:
42 static const size_t IO_BUF_SIZE = 8192;
43
44 protected:
45 io::IInSequence *pIn;
46 size_t nWFlags;
47
48 LSPString sLine; // Last read line
49 lsp_wchar_t *pBuffer; // Buffer for character data
50 size_t nBufOff; // Buffer offset
51 size_t nBufLen; // Buffer length
52 size_t nLines; // Number of lines read
53
54 event_t sEvent;
55 ssize_t nVx; // Number of vertexes
56 ssize_t nParVx; // Number of parameter vertexes
57 ssize_t nTexVx; // Number of texture vertexes
58 ssize_t nNormVx; // Number of normal vertexes
59
60 protected:
61 status_t read_event();
62 status_t read_line();
63 status_t copy_event(event_t *ev) const;
64 status_t eliminate_comments();
65 status_t parse_line(const char *s);
66
67 static inline bool is_space(char ch);
68 static bool prefix_match(const char *s, const char *prefix);
69 static const char *skip_spaces(const char *s);
70 static bool parse_float(float *dst, const char **s);
71 static bool parse_int(ssize_t *dst, const char **s);
72 static bool end_of_line(const char *s);
73
74 public:
75 explicit PullParser();
76 PullParser(const PullParser &) = delete;
77 PullParser(PullParser &&) = delete;
78 ~PullParser();
79
80 PullParser & operator = (const PullParser &) = delete;
81 PullParser & operator = (PullParser &&) = delete;
82
83 public:
84 /**
85 * Open parser
86 * @param path UTF-8 path to the file
87 * @param charset character set
88 * @return status of operation
89 */
90 status_t open(const char *path, const char *charset = NULL);
91
92 /**
93 * Open parser
94 * @param path string representation of path to the file
95 * @param charset character set
96 * @return status of operation
97 */
98 status_t open(const LSPString *path, const char *charset = NULL);
99
100 /**
101 * Open parser
102 * @param path path to the file
103 * @param charset character set
104 * @return status of operation
105 */
106 status_t open(const io::Path *path, const char *charset = NULL);
107
108 /**
109 * Wrap string with parser
110 * @param str string to wrap
111 * @param charset character set
112 * @return status of operation
113 */
114 status_t wrap(const char *str, const char *charset = NULL);
115
116 /**
117 * Wrap string with parser
118 * @param str string to wrap
119 * @return status of operation
120 */
121 status_t wrap(const LSPString *str);
122
123 /**
124 * Wrap input sequence with parser
125 * @param seq sequence to use for reads
126 * @return status of operation
127 */
128 status_t wrap(io::IInSequence *seq, size_t flags = WRAP_NONE);
129
130 /**
131 * Wrap input stream with parser
132 * @param is input stream
133 * @param flags wrap flags
134 * @param charset character set
135 * @return status of operation
136 */
137 status_t wrap(io::IInStream *is, size_t flags = WRAP_NONE, const char *charset = NULL);
138
139 /**
140 * Close parser
141 * @return status of operation
142 */
143 status_t close();
144
145 public:
146 /**
147 * Get next event
148 * @param ev pointer to structure to store the event
149 * @return status of operation
150 */
151 status_t next(event_t *ev = NULL);
152
153 /**
154 * Get current event
155 * @return NULL if there is no current event
156 */
157 const event_t *current() const;
158
159 /**
160 * Get current event
161 * @param ev pointer to structure to store the event
162 * @return NULL if there is no current event
163 */
164 status_t current(event_t *ev) const;
165
166 };
167 } /* namespace obj */
168 } /* namespace lsp */
169
170 #endif /* LSP_PLUG_IN_FMT_OBJ_PULLPARSER_H_ */