// Copyright (c) 2021-2022 configor - Nomango // // 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. #pragma once #include "configor.hpp" #include // std::for_each #include // std::setprecision #include // std::noskipws, std::noshowbase, std::right namespace configor { namespace detail { template class json_parser; template class json_serializer; } // namespace detail template class _DefaultEncoding = encoding::auto_utf> class basic_json final : public detail::serializable<_Args, detail::json_serializer, _DefaultEncoding> , public detail::parsable<_Args, detail::json_parser, _DefaultEncoding> , public detail::value_maker> , public detail::iostream_wrapper_maker, basic_value<_Args>> { public: using value = basic_value<_Args>; using serializer = typename detail::serializable<_Args, detail::json_serializer, _DefaultEncoding>::template serializer_type; using parser = typename detail::parsable<_Args, detail::json_parser, _DefaultEncoding>::template parser_type; }; using json = basic_json; using wjson = basic_json; // type traits template struct is_json : std::false_type { }; template class _DefaultEncoding> struct is_json> : std::true_type { }; namespace detail { template struct json_hex { const _IntTy i; template friend inline std::basic_ostream<_CharTy>& operator<<(std::basic_ostream<_CharTy>& os, const json_hex& i) { os << std::setfill(_CharTy('0')) << std::hex << std::uppercase; os << '\\' << 'u' << std::setw(sizeof(i.i)) << i.i; os << std::dec << std::nouppercase; return os; } }; namespace { template inline json_hex<_IntTy> make_json_hex(const _IntTy i) { return json_hex<_IntTy>{ i }; } } // namespace // // json_parser // template class json_parser : public basic_parser<_ValTy, _SourceCharTy> { public: using value_type = _ValTy; using source_char_type = _SourceCharTy; using target_char_type = typename value_type::char_type; using option = std::function; static option with_error_handler(error_handler* eh) { return [=](json_parser& p) { p.set_error_handler(eh); }; } template