|
@@ -7,8 +7,6 @@
|
|
|
|
|
|
|
|
#pragma once
|
|
#pragma once
|
|
|
|
|
|
|
|
-#include <fstream>
|
|
|
|
|
-#include <iostream>
|
|
|
|
|
#include <stdexcept>
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
#include <expect/expect.hpp>
|
|
#include <expect/expect.hpp>
|
|
@@ -17,6 +15,7 @@
|
|
|
#include <string_utils/cast.h>
|
|
#include <string_utils/cast.h>
|
|
|
|
|
|
|
|
#include <serializer/jsonizer.h>
|
|
#include <serializer/jsonizer.h>
|
|
|
|
|
+#include <serializer/jsonizer_ios.tpp>
|
|
|
#include <serializer/shared_cache.h>
|
|
#include <serializer/shared_cache.h>
|
|
|
#include <serializer/strconv.h>
|
|
#include <serializer/strconv.h>
|
|
|
#include <serializer/traits.h>
|
|
#include <serializer/traits.h>
|
|
@@ -41,6 +40,10 @@ Json::Value Jsonizer::to_json(T & value, std::index_sequence<Is...>) const {
|
|
|
return json;
|
|
return json;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+template <typename T> Json::Value Jsonizer::to_json(std::optional<T> const &opt) const {
|
|
|
|
|
+ return opt.has_value() ? to_json(*opt) : Json::Value();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
template <typename T> Json::Value Jsonizer::to_json(T const & value) const {
|
|
template <typename T> Json::Value Jsonizer::to_json(T const & value) const {
|
|
|
if constexpr (detail::has_serial_type_v<T>) {
|
|
if constexpr (detail::has_serial_type_v<T>) {
|
|
|
return to_json(static_cast<typename T::serial_type>(value));
|
|
return to_json(static_cast<typename T::serial_type>(value));
|
|
@@ -91,6 +94,11 @@ void Jsonizer::from_json(T & value, Json::Value const & json,
|
|
|
0)...};
|
|
0)...};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+template <typename T>
|
|
|
|
|
+void Jsonizer::from_json(std::optional<T> &opt, Json::Value const & json) const {
|
|
|
|
|
+ opt = json.isNull() ? std::nullopt : std::optional{from_json<T>(json)};
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
template <typename T>
|
|
template <typename T>
|
|
|
void Jsonizer::from_json(T & value, Json::Value const & json) const {
|
|
void Jsonizer::from_json(T & value, Json::Value const & json) const {
|
|
|
if (json.isNull()) return;
|
|
if (json.isNull()) return;
|
|
@@ -167,33 +175,4 @@ void Jsonizer::from_json(std::shared_ptr<T const> & ptr,
|
|
|
ptr = p_cache->store(local.name, local);
|
|
ptr = p_cache->store(local.name, local);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-template <typename T> T Jsonizer::from_json(Json::Value const & json) const {
|
|
|
|
|
- std::decay_t<T> tmp;
|
|
|
|
|
- from_json(tmp, json);
|
|
|
|
|
- return tmp;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-template <typename T> T Jsonizer::from_stream(std::istream & in) const {
|
|
|
|
|
- Json::Value root;
|
|
|
|
|
- in >> root;
|
|
|
|
|
- return from_json<T>(root);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-template <typename T> T Jsonizer::from_string(std::string const & in) const {
|
|
|
|
|
- std::stringstream ss;
|
|
|
|
|
- ss << in;
|
|
|
|
|
- return from_stream<T>(ss);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-template <typename T>
|
|
|
|
|
-void Jsonizer::to_stream(T const & value, std::ostream & out) const {
|
|
|
|
|
- Json::Value root = to_json(value);
|
|
|
|
|
- out << root;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-template <typename T> T Jsonizer::from_file(std::string const & file) const {
|
|
|
|
|
- std::ifstream in(file);
|
|
|
|
|
- return from_stream<T>(in);
|
|
|
|
|
-}
|
|
|
|
|
}
|
|
}
|