Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/fmt/config/PullParser.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: 29 апр. 2020 г.
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_CONFIG_PULLPARSER_H_
23 #define LSP_PLUG_IN_FMT_CONFIG_PULLPARSER_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/runtime/LSPString.h>
27 #include <lsp-plug.in/common/status.h>
28 #include <lsp-plug.in/io/Path.h>
29 #include <lsp-plug.in/io/IInSequence.h>
30 #include <lsp-plug.in/io/IInStream.h>
31
32 #include <lsp-plug.in/fmt/config/types.h>
33
34 namespace lsp
35 {
36 namespace config
37 {
38
39 class PullParser
40 {
41 protected:
42 io::IInSequence *pIn;
43 size_t nWFlags;
44 param_t sParam;
45
46 LSPString sLine;
47 LSPString sKey;
48 LSPString sValue;
49
50 protected:
51 bool skip_spaces(size_t &off);
52 status_t read_key(size_t &off);
53 status_t read_type(size_t &off, size_t &flags);
54 status_t read_value(size_t &off, size_t &flags);
55 status_t parse_line(size_t &flags);
56 status_t do_close();
57
58 static status_t parse_int32(const LSPString *str, int32_t *dst);
59 static status_t parse_uint32(const LSPString *str, uint32_t *dst);
60 static status_t parse_float(const LSPString *str, float *dst, size_t *flags);
61 static status_t parse_int64(const LSPString *str, int64_t *dst);
62 static status_t parse_uint64(const LSPString *str, uint64_t *dst);
63 static status_t parse_double(const LSPString *str, double *dst, size_t *flags);
64 static status_t parse_bool(const LSPString *str, bool *dst);
65 static status_t parse_blob(const LSPString *str, blob_t *dst);
66
67 protected:
68 virtual status_t commit_param(const LSPString *key, const LSPString *value, size_t flags);
69
70 public:
71 explicit PullParser();
72 PullParser(const PullParser &) = delete;
73 PullParser(PullParser &&) = delete;
74 virtual ~PullParser();
75
76 PullParser & operator = (const PullParser &) = delete;
77 PullParser & operator = (PullParser &&) = delete;
78
79 public:
80 /**
81 * Open parser
82 * @param path UTF-8 path to the file
83 * @param charset character set
84 * @return status of operation
85 */
86 virtual status_t open(const char *path, const char *charset = NULL);
87
88 /**
89 * Open parser
90 * @param path string representation of path to the file
91 * @param charset character set
92 * @return status of operation
93 */
94 virtual status_t open(const LSPString *path, const char *charset = NULL);
95
96 /**
97 * Open parser
98 * @param path path to the file
99 * @param charset character set
100 * @return status of operation
101 */
102 virtual status_t open(const io::Path *path, const char *charset = NULL);
103
104 /**
105 * Wrap string with parser
106 * @param str string to wrap
107 * @param charset character set
108 * @return status of operation
109 */
110 virtual status_t wrap(const char *str, const char *charset = NULL);
111
112 /**
113 * Wrap string with parser
114 * @param str string to wrap
115 * @return status of operation
116 */
117 virtual status_t wrap(const LSPString *str);
118
119 /**
120 * Wrap input sequence with parser
121 * @param seq sequence to use for reads
122 * @return status of operation
123 */
124 virtual status_t wrap(io::IInSequence *seq, size_t flags = WRAP_NONE);
125
126 /**
127 * Wrap input stream with parser
128 * @param is input stream
129 * @param flags wrap flags
130 * @param charset character set
131 * @return status of operation
132 */
133 virtual status_t wrap(io::IInStream *is, size_t flags = WRAP_NONE, const char *charset = NULL);
134
135 /**
136 * Close parser
137 * @return status of operation
138 */
139 virtual status_t close();
140
141 public:
142 /**
143 * Get next event
144 * @param ev pointer to structure to store the event
145 * @return status of operation
146 */
147 virtual status_t next(param_t *ev = NULL);
148
149 /**
150 * Get current event
151 * @return NULL if there is no current event
152 */
153 virtual const param_t *current() const;
154
155 /**
156 * Get current event
157 * @param ev pointer to structure to store the event
158 * @return NULL if there is no current event
159 */
160 virtual status_t current(param_t *ev) const;
161 };
162
163 } /* namespace config */
164 } /* namespace lsp */
165
166 #endif /* LSP_PLUG_IN_FMT_CONFIG_PULLPARSER_H_ */