/***************************************************************************************** * * * OpenSpace * * * * Copyright (c) 2014-2023 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * * without restriction, including without limitation the rights to use, copy, modify, * * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * * permit persons to whom the Software is furnished to do so, subject to the following * * conditions: * * * * The above copyright notice and this permission notice shall be included in all copies * * or substantial portions of the Software. * * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ #include #include #include #include namespace openspace { namespace internal { template struct is_any : std::disjunction...> {}; template constexpr bool isGlmMatrix() { return is_any::value; } template constexpr bool isGlmVector() { return is_any::value; } } // namespace internal template std::string formatJson(T value) { if constexpr (std::is_same_v) { return value ? "true" : "false"; } else if constexpr (std::is_arithmetic_v) { return formatJsonNumber(static_cast(value)); } else if constexpr (std::is_same_v) { return escapedJson(value); } else if constexpr (std::is_same_v) { return ghoul::formatJson(value); } else if constexpr (internal::isGlmVector()) { std::string values; for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { values += std::to_string(value[i]) + ','; } values.pop_back(); return fmt::format("[{}]", values); } else if constexpr (internal::isGlmMatrix()) { std::string values; for (glm::length_t i = 0; i < T::type::row_type::length(); ++i) { for (glm::length_t j = 0; j < T::type::col_type::length(); ++j) { values += std::to_string(value[i][j]) + ','; } } values.pop_back(); return fmt::format("[{}]", values); } else { static_assert(sizeof(T) == 0, "JSON formatting of type T not implemented"); } } } // namespace openspace