//# This file is a part of toml++ and is subject to the the terms of the MIT license. //# Copyright (c) 2019-2020 Mark Gillard //# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text. // SPDX-License-Identifier: MIT #include "tt.hpp" using nlohmann::json; using namespace std::string_view_literals; [[nodiscard]] static bool is_tt_value(const json& j) noexcept { return j.is_object() // && j.size() == 2u // && j.contains("type") // && j["type"].is_string() // && j.contains("value") // && j["value"].is_string(); } TOML_NAMESPACE_START { static void from_json(const json& j, value& val) { assert(is_tt_value(j)); assert(j["type"] == "string"); *val = j["value"]; } template static void from_json_via_parse(const json& j, value& val) { assert(is_tt_value(j)); std::stringstream ss; ss.imbue(std::locale::classic()); ss << "value = " << j["value"].get_ref(); auto tbl = toml::parse(ss); tbl["value"sv].visit( [&](auto& v) { if constexpr (is_value) { using value_type = typename std::remove_cv_t>::value_type; if constexpr (std::is_same_v) val = std::move(v); else if constexpr (std::is_constructible_v) *val = T(*v); else if constexpr (std::is_convertible_v) *val = static_cast(*v); } }); } static void from_json(const json& j, value& val) { assert(is_tt_value(j)); assert(j["type"] == "integer"); from_json_via_parse(j, val); } static void from_json(const json& j, value& val) { assert(is_tt_value(j)); assert(j["type"] == "float"); from_json_via_parse(j, val); } static void from_json(const json& j, value& val) { assert(is_tt_value(j)); assert(j["type"] == "bool"); from_json_via_parse(j, val); } static void from_json(const json& j, value& val) { assert(is_tt_value(j)); assert(j["type"] == "date-local"); from_json_via_parse(j, val); } static void from_json(const json& j, value