AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
json.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2020 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-json-export.hpp"
23
24#include <ostream>
25#include <istream>
26#include <string>
27#include <vector>
28#include <list>
29#include <set>
30#include <map>
31
32#include "json/mapper.hpp"
33#include "json/mappingOptions.hpp"
34
35#include "flux.hpp"
36
37
38namespace anch::json {
39
40 // Serialization functions +
41 // Functions which write result in output stream +
51 template<typename T>
52 void serialize(const T& value,
53 std::ostream& out,
55
66 template<template<typename> typename C, typename T>
67 void serialize(const C<T>& value,
68 std::ostream& out,
70
85 template<typename T>
87 std::ostream& out,
89
99 template<typename T>
100 void serialize(const std::map<std::string,T>& value,
101 std::ostream& out,
103 // Functions which write result in output stream -
104
105 // Functions which returns std::string +
116 template<typename T>
117 std::string serialize(const T& value,
119
131 template<template<typename> typename C, typename T>
132 std::string serialize(const C<T>& value,
134
145 template<typename T>
146 std::string serialize(const std::map<std::string,T>& value,
148 // Functions which returns std::string -
149 // Serialization functions -
150
151 // Deserialization functions +
161 template<typename T>
162 void deserialize(T& value,
163 std::istream& input,
165
176 template<typename T>
177 T deserialize(std::istream& input,
179
190 template<template<typename> typename C, typename T>
191 void deserialize(C<T>& values,
192 std::istream& input,
194
207 template<typename T>
209 std::istream& input,
211
221 template<typename T>
222 void deserialize(std::map<std::string,T>& values,
223 std::istream& input,
225 // Deserialization functions -
226
227 // JSON mapper +
237 class ANCH_JSON_EXPORT JSONMapper {
238
239 // Attributes +
240 private:
243 // Attributes -
244
245 // Constructors +
246 public:
250 JSONMapper() = delete;
251
258 // Constructors -
259
260 // Destructor +
261 public:
265 virtual ~JSONMapper();
266 // Destructor +
267
268 // Methods +
269 public:
270 // Serialization methods +
279 template<typename T>
280 void serialize(const T& value, std::ostream& out);
281
291 template<template<typename> typename C, typename T>
292 void serialize(const C<T>& value, std::ostream& out);
293
305 template<typename T>
306 void serialize(anch::Flux<T>& value, std::ostream& out);
307
316 template<typename T>
317 void serialize(const std::map<std::string,T>& value, std::ostream& out);
318
328 template<typename T>
329 std::string serialize(const T& value);
330
341 template<template<typename> typename C, typename T>
342 std::string serialize(const C<T>& value);
343
353 template<typename T>
354 std::string serialize(const std::map<std::string,T>& value);
355 // Serialization methods -
356
357 // Deserialization methods +
366 template<typename T>
367 void deserialize(T& value, std::istream& input);
368
378 template<typename T>
379 T deserialize(std::istream& input);
380
390 template<template<typename> typename C, typename T>
391 void deserialize(C<T>& values, std::istream& input);
392
403 template<typename T>
404 void deserialize(anch::Flux<T>& values, std::istream& input);
405
414 template<typename T>
415 void deserialize(std::map<std::string,T>& values, std::istream& input);
416 // Deserialization methods -
417 // Methods -
418
419 };
420 // JSON mapper -
421
422} // anch::json
423
424#include "json/impl/jsonSerialize.hpp" // Serialization functions implementation
425#include "json/impl/jsonDeserialize.hpp" // Deserialization functions implementation
426#include "json/impl/jsonMapper.hpp" // JSONMapper methods implementation
Manage collection as stream.
Definition flux.hpp:51
void deserialize(anch::Flux< T > &values, std::istream &input)
void serialize(const T &value, std::ostream &out)
void deserialize(T &value, std::istream &input)
std::string serialize(const std::map< std::string, T > &value)
JSONMapper(const anch::json::MappingOptions &options)
void serialize(anch::Flux< T > &value, std::ostream &out)
void serialize(const std::map< std::string, T > &value, std::ostream &out)
std::string serialize(const T &value)
T deserialize(std::istream &input)
std::string serialize(const C< T > &value)
void deserialize(std::map< std::string, T > &values, std::istream &input)
void deserialize(C< T > &values, std::istream &input)
void serialize(const C< T > &value, std::ostream &out)
JSON namespace.
Definition constants.hpp:27
void deserialize(T &value, std::istream &input, const anch::json::MappingOptions &options=anch::json::DEFAULT_MAPPING_OPTIONS)
void serialize(const T &value, std::ostream &out, const anch::json::MappingOptions &options=anch::json::DEFAULT_MAPPING_OPTIONS)
MappingOptions DEFAULT_MAPPING_OPTIONS
JSON mapping options.
Definition mappingOptions.hpp:38