AnCH Framework 0.1
Another C++ Hack Framework
Loading...
Searching...
No Matches
json.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 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 <http://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include <ostream>
23#include <istream>
24#include <string>
25#include <vector>
26#include <list>
27#include <set>
28#include <map>
29
30#include "json/mapper.hpp"
31#include "json/mappingOptions.hpp"
32
33#include "flux.hpp"
34
35
36namespace anch::json {
37
46 template<typename T>
48
49 // Serialization functions +
50 // Functions which write result in output stream +
60 template<typename T>
61 void serialize(const T& value,
62 std::ostream& out,
64
75 template<template<typename> typename C, typename T>
76 void serialize(const C<T>& value,
77 std::ostream& out,
79
94 template<typename T>
96 std::ostream& out,
98
108 template<typename T>
109 void serialize(const std::map<std::string,T>& value,
110 std::ostream& out,
112 // Functions which write result in output stream -
113
114 // Functions which returns std::string +
125 template<typename T>
126 std::string serialize(const T& value,
128
140 template<template<typename> typename C, typename T>
141 std::string serialize(const C<T>& value,
143
154 template<typename T>
155 std::string serialize(const std::map<std::string,T>& value,
157 // Functions which returns std::string -
158 // Serialization functions -
159
160 // Deserialization functions +
170 template<typename T>
171 void deserialize(T& value,
172 std::istream& input,
174
185 template<typename T>
186 T deserialize(std::istream& input,
188
199 template<template<typename> typename C, typename T>
200 void deserialize(C<T>& values,
201 std::istream& input,
203
213 template<typename T>
214 void deserialize(std::map<std::string,T>& values,
215 std::istream& input,
217 // Deserialization functions -
218
219 // JSON mapper +
230
231 // Attributes +
232 private:
235 // Attributes -
236
237 // Constructors +
238 public:
242 JSONMapper() = delete;
243
250 // Constructors -
251
252 // Destructor +
253 public:
257 virtual ~JSONMapper();
258 // Destructor +
259
260 // Methods +
261 public:
262 // Serialization methods +
271 template<typename T>
272 void serialize(const T& value, std::ostream& out);
273
283 template<template<typename> typename C, typename T>
284 void serialize(const C<T>& value, std::ostream& out);
285
297 template<typename T>
298 void serialize(anch::Flux<T>& value, std::ostream& out);
299
308 template<typename T>
309 void serialize(const std::map<std::string,T>& value, std::ostream& out);
310
320 template<typename T>
321 std::string serialize(const T& value);
322
333 template<template<typename> typename C, typename T>
334 std::string serialize(const C<T>& value);
335
345 template<typename T>
346 std::string serialize(const std::map<std::string,T>& value);
347 // Serialization methods -
348
349 // Deserialization methods +
360 template<typename T>
361 void deserialize(T& value, std::istream& input);
362
372 template<typename T>
373 T deserialize(std::istream& input);
374
386 template<template<typename> typename C, typename T>
387 void deserialize(C<T>& values, std::istream& input);
388
397 template<typename T>
398 void deserialize(std::map<std::string,T>& values, std::istream& input);
399 // Deserialization methods -
400 // Methods -
401
402 };
403 // JSON mapper -
404
405} // anch::json
406
407#include "json/impl/jsonSerialize.hpp" // Serialization functions implementation
408#include "json/impl/jsonDeserialize.hpp" // Deserialization functions implementation
409#include "json/impl/jsonMapper.hpp" // JSONMapper methods implementation
Manage collection as stream.
Definition flux.hpp:50
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 complex object mapper.
Definition mapper.hpp:76
JSON namespace.
Definition constants.hpp:25
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
void registerObject(anch::json::ObjectMapper< T > &mapper)
JSON mapping options.
Definition mappingOptions.hpp:36