// ---------------------------------------------------------------------------- // Copyright (C) 2015 Sebastian Redl // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // For more information, see www.boost.org // ---------------------------------------------------------------------------- #ifndef BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_READ_HPP #define BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_READ_HPP #include #include #include #include #include #include #include #include #include namespace boost { namespace property_tree { namespace json_parser { namespace detail { template class minirange { public: minirange(Iterator first, Sentinel last) : first(first), last(last) {} Iterator begin() const { return first; } Sentinel end() const { return last; } private: Iterator first; Sentinel last; }; template minirange make_minirange(Iterator first, Sentinel last) { return minirange(first, last); } template void read_json_internal(Iterator first, Sentinel last, Encoding& encoding, Callbacks& callbacks, const std::string& filename) { BOOST_STATIC_ASSERT_MSG((boost::is_same< typename std::iterator_traits::value_type, typename Encoding::external_char>::value), "Encoding is not capable of using the iterator's value type."); BOOST_STATIC_ASSERT_MSG((boost::is_same< typename Callbacks::char_type, typename Encoding::internal_char>::value), "Encoding is not capable of producing the needed character type."); detail::parser parser(callbacks, encoding); parser.set_input(filename, make_minirange(first, last)); parser.parse_value(); parser.finish(); } template struct encoding; template <> struct encoding : utf8_utf8_encoding {}; template <> struct encoding : wide_wide_encoding {}; template void read_json_internal( std::basic_istream &stream, Ptree &pt, const std::string &filename) { typedef typename Ptree::key_type::value_type char_type; typedef standard_callbacks callbacks_type; typedef detail::encoding encoding_type; typedef std::istreambuf_iterator iterator; callbacks_type callbacks; encoding_type encoding; read_json_internal(iterator(stream), iterator(), encoding, callbacks, filename); pt.swap(callbacks.output()); } }}}} #endif