// Copyright 2024 Dolphin Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include #include #include #include #include "Common/Matrix.h" // Ideally this would use a concept like, 'template ' to constrain it, // but unfortunately we'd need to require clang 15 for that, since the ranges library isn't // fully implemented until then, but this should suffice. template picojson::array ToJsonArray(const Range& data) { using RangeUnderlyingType = typename Range::value_type; picojson::array result; result.reserve(std::size(data)); for (const auto& value : data) { if constexpr (std::is_integral_v || std::is_floating_point_v) { result.emplace_back(static_cast(value)); } else { result.emplace_back(value); } } return result; } template std::optional ReadNumericFromJson(const picojson::object& obj, const std::string& key) { const auto it = obj.find(key); if (it == obj.end()) return std::nullopt; if (!it->second.is()) return std::nullopt; return static_cast(it->second.get()); } std::optional ReadStringFromJson(const picojson::object& obj, const std::string& key); std::optional ReadBoolFromJson(const picojson::object& obj, const std::string& key); picojson::object ToJsonObject(const Common::Vec3& vec); void FromJson(const picojson::object& obj, Common::Vec3& vec); bool JsonToFile(const std::string& filename, const picojson::value& root, bool prettify = false); bool JsonFromFile(const std::string& filename, picojson::value* root, std::string* error);