| 1 |
/* |
| 2 |
* Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2026 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 1 мая 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_SERIALIZER_H_ |
| 23 |
#define LSP_PLUG_IN_FMT_CONFIG_SERIALIZER_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 |
#include <lsp-plug.in/runtime/LSPString.h> |
| 29 |
#include <lsp-plug.in/io/IOutSequence.h> |
| 30 |
#include <lsp-plug.in/io/IOutStream.h> |
| 31 |
#include <lsp-plug.in/io/Path.h> |
| 32 |
#include <lsp-plug.in/fmt/config/types.h> |
| 33 |
|
| 34 |
namespace lsp |
| 35 |
{ |
| 36 |
namespace config |
| 37 |
{ |
| 38 |
/** |
| 39 |
* Configuration serializer |
| 40 |
*/ |
| 41 |
class Serializer |
| 42 |
{ |
| 43 |
protected: |
| 44 |
io::IOutSequence *pOut; |
| 45 |
size_t nWFlags; |
| 46 |
|
| 47 |
protected: |
| 48 |
status_t write_key(const LSPString *key); |
| 49 |
|
| 50 |
status_t write_escaped(const LSPString *key, size_t flags); |
| 51 |
status_t write_uint(uint64_t v, size_t flags); |
| 52 |
status_t write_int(int64_t v, size_t flags); |
| 53 |
status_t write_float(double v, size_t flags); |
| 54 |
status_t write_bool(bool v, size_t flags); |
| 55 |
status_t write_string_impl(const LSPString *key, const LSPString *v, size_t flags); |
| 56 |
|
| 57 |
status_t do_close(); |
| 58 |
|
| 59 |
public: |
| 60 |
explicit Serializer(); |
| 61 |
Serializer(const Serializer &) = delete; |
| 62 |
Serializer(Serializer &&) = delete; |
| 63 |
virtual ~Serializer(); |
| 64 |
|
| 65 |
Serializer & operator = (const Serializer &) = delete; |
| 66 |
Serializer & operator = (Serializer &&) = delete; |
| 67 |
|
| 68 |
public: |
| 69 |
/** |
| 70 |
* Open parser |
| 71 |
* @param path UTF-8 path to the file |
| 72 |
* @param charset character set |
| 73 |
* @return status of operation |
| 74 |
*/ |
| 75 |
virtual status_t open(const char *path, const char *charset = NULL); |
| 76 |
|
| 77 |
/** |
| 78 |
* Open parser |
| 79 |
* @param path string representation of path to the file |
| 80 |
* @param charset character set |
| 81 |
* @return status of operation |
| 82 |
*/ |
| 83 |
virtual status_t open(const LSPString *path, const char *charset = NULL); |
| 84 |
|
| 85 |
/** |
| 86 |
* Open parser |
| 87 |
* @param path path to the file |
| 88 |
* @param charset character set |
| 89 |
* @return status of operation |
| 90 |
*/ |
| 91 |
virtual status_t open(const io::Path *path, const char *charset = NULL); |
| 92 |
|
| 93 |
/** |
| 94 |
* Wrap string with parser |
| 95 |
* @param str string to wrap |
| 96 |
* @return status of operation |
| 97 |
*/ |
| 98 |
virtual status_t wrap(LSPString *str); |
| 99 |
|
| 100 |
/** |
| 101 |
* Wrap input sequence with parser |
| 102 |
* @param seq sequence to use for reads |
| 103 |
* @param flags wrapping flags |
| 104 |
* @return status of operation |
| 105 |
*/ |
| 106 |
virtual status_t wrap(io::IOutSequence *seq, size_t flags = WRAP_NONE); |
| 107 |
|
| 108 |
/** |
| 109 |
* Wrap input stream with parser |
| 110 |
* @param os output stream |
| 111 |
* @param flags wrapping flags |
| 112 |
* @param charset character set |
| 113 |
* @return status of operation |
| 114 |
*/ |
| 115 |
virtual status_t wrap(io::IOutStream *os, size_t flags = WRAP_NONE, const char *charset = NULL); |
| 116 |
|
| 117 |
/** |
| 118 |
* Close parser |
| 119 |
* @return status of operation |
| 120 |
*/ |
| 121 |
virtual status_t close(); |
| 122 |
|
| 123 |
public: |
| 124 |
/** |
| 125 |
* Write comment to the output stream |
| 126 |
* @param v comment |
| 127 |
* @return status of operation |
| 128 |
*/ |
| 129 |
virtual status_t write_comment(const LSPString *v); |
| 130 |
|
| 131 |
/** |
| 132 |
* Write comment to the output stream |
| 133 |
* @param v UTF-8 encoded comment |
| 134 |
* @return status of operation |
| 135 |
*/ |
| 136 |
virtual status_t write_comment(const char *v); |
| 137 |
|
| 138 |
/** |
| 139 |
* Write empty line to the output file |
| 140 |
* @return status of operation |
| 141 |
*/ |
| 142 |
virtual status_t writeln(); |
| 143 |
|
| 144 |
/** |
| 145 |
* Write value to the output stream |
| 146 |
* @param key key |
| 147 |
* @param v value |
| 148 |
* @param flags value flags |
| 149 |
* @return status of operation |
| 150 |
*/ |
| 151 |
virtual status_t write(const LSPString *key, const value_t *v, size_t flags); |
| 152 |
virtual status_t write(const char *key, const value_t *v, size_t flags); |
| 153 |
|
| 154 |
/** |
| 155 |
* Write 32-bit signed integer to the output stream |
| 156 |
* @param key key |
| 157 |
* @param value value |
| 158 |
* @param flags value flags |
| 159 |
* @return status of operation |
| 160 |
*/ |
| 161 |
virtual status_t write_i32(const LSPString *key, int32_t value, size_t flags); |
| 162 |
virtual status_t write_i32(const char *key, int32_t value, size_t flags); |
| 163 |
|
| 164 |
/** |
| 165 |
* Write 32-bit unsigned integer to the output stream |
| 166 |
* @param key key |
| 167 |
* @param value value |
| 168 |
* @param flags value flags |
| 169 |
* @return status of operation |
| 170 |
*/ |
| 171 |
virtual status_t write_u32(const LSPString *key, uint32_t value, size_t flags); |
| 172 |
virtual status_t write_u32(const char *key, uint32_t value, size_t flags); |
| 173 |
|
| 174 |
/** |
| 175 |
* Write 32-bit floating-point to the output stream |
| 176 |
* @param key key |
| 177 |
* @param value value |
| 178 |
* @param flags value flags |
| 179 |
* @return status of operation |
| 180 |
*/ |
| 181 |
virtual status_t write_f32(const LSPString *key, float value, size_t flags); |
| 182 |
virtual status_t write_f32(const char *key, float value, size_t flags); |
| 183 |
|
| 184 |
/** |
| 185 |
* Write 64-bit signed integer to the output stream |
| 186 |
* @param key key |
| 187 |
* @param value value |
| 188 |
* @param flags value flags |
| 189 |
* @return status of operation |
| 190 |
*/ |
| 191 |
virtual status_t write_i64(const LSPString *key, int64_t value, size_t flags); |
| 192 |
virtual status_t write_i64(const char *key, int64_t value, size_t flags); |
| 193 |
|
| 194 |
/** |
| 195 |
* Write 64-bit unsigned integer to the output stream |
| 196 |
* @param key key |
| 197 |
* @param value value |
| 198 |
* @param flags value flags |
| 199 |
* @return status of operation |
| 200 |
*/ |
| 201 |
virtual status_t write_u64(const LSPString *key, uint64_t value, size_t flags); |
| 202 |
virtual status_t write_u64(const char *key, uint64_t value, size_t flags); |
| 203 |
|
| 204 |
/** |
| 205 |
* Write 64-bit floating-point to the output stream |
| 206 |
* @param key key |
| 207 |
* @param value value |
| 208 |
* @param flags value flags |
| 209 |
* @return status of operation |
| 210 |
*/ |
| 211 |
virtual status_t write_f64(const LSPString *key, double value, size_t flags); |
| 212 |
virtual status_t write_f64(const char *key, double value, size_t flags); |
| 213 |
|
| 214 |
/** |
| 215 |
* Write boolean value to the output stream |
| 216 |
* @param key key |
| 217 |
* @param value value |
| 218 |
* @param flags value flags |
| 219 |
* @return status of operation |
| 220 |
*/ |
| 221 |
virtual status_t write_bool(const LSPString *key, bool value, size_t flags); |
| 222 |
virtual status_t write_bool(const char *key, bool value, size_t flags); |
| 223 |
|
| 224 |
/** |
| 225 |
* Write text string |
| 226 |
* @param key key |
| 227 |
* @param v string |
| 228 |
* @param flags value flags |
| 229 |
* @return status of operation |
| 230 |
*/ |
| 231 |
virtual status_t write_string(const LSPString *key, const LSPString *v, size_t flags); |
| 232 |
virtual status_t write_string(const LSPString *key, const char *v, size_t flags); |
| 233 |
virtual status_t write_string(const char *key, const LSPString *v, size_t flags); |
| 234 |
virtual status_t write_string(const char *key, const char *v, size_t flags); |
| 235 |
|
| 236 |
/** |
| 237 |
* Write blob data |
| 238 |
* @param key key |
| 239 |
* @param v blob data |
| 240 |
* @param flags value flags |
| 241 |
* @return status of operation |
| 242 |
*/ |
| 243 |
virtual status_t write_blob(const LSPString *key, const blob_t *v, size_t flags); |
| 244 |
virtual status_t write_blob(const char *key, const blob_t *v, size_t flags); |
| 245 |
|
| 246 |
/** |
| 247 |
* Write configuration parameter |
| 248 |
* @param param configuration parameter |
| 249 |
* @return status of operation |
| 250 |
*/ |
| 251 |
status_t write(const config::param_t * param); |
| 252 |
status_t write(const config::param_t & param); |
| 253 |
}; |
| 254 |
|
| 255 |
} /* namespace config */ |
| 256 |
} /* namespace lsp */ |
| 257 |
|
| 258 |
#endif /* LSP_PLUG_IN_FMT_CONFIG_SERIALIZER_H_ */ |