Loading [MathJax]/extensions/tex2jax.js
Plugins
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
json_basics.hh
Go to the documentation of this file.
1// JSON lib.
2
3#pragma once
4
5#ifdef UG_JSON
6#include <nlohmann/json.hpp>
7#endif
8
9namespace ug {
10
11// #define UG4_WITH_JSON
12#ifdef UG_JSON
13typedef nlohmann::json JSONType;
14using JSONPointer = nlohmann::json::json_pointer;
15#endif
16
17#ifdef UG_JSON
18
19template <class T>
20struct is_json_constructible
21{
22 const static bool value = std::is_default_constructible<T>::value;
23};
24
25template <class T>
26inline constexpr bool is_json_constructible_v = is_json_constructible<T>::value;
27
28
29template <typename P>
30SmartPtr<P> JSONSerializer(const char *jstring)
31{
32 UG_COND_THROW(! is_json_constructible_v<P>, "ERROR: Type is not constructible!")
33 SmartPtr<P> data = make_sp(new P());
34 nlohmann::json j = nlohmann::json::parse(jstring);
35 j.get_to<P>(*data);
36 return data;
37
38};
39#endif
40
41
42} // namespace ug
#define UG_COND_THROW(cond, msg)
function ProblemDisc new(problemDesc, dom)