1 // ----------------------------------------------------------------------------
2 // Copyright (C) 2015 Sebastian Redl
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // For more information, see www.boost.org
9 // ----------------------------------------------------------------------------
10 #ifndef BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_READ_HPP
11 #define BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_READ_HPP
12 
13 #include <boost/property_tree/detail/json_parser/parser.hpp>
14 #include <boost/property_tree/detail/json_parser/narrow_encoding.hpp>
15 #include <boost/property_tree/detail/json_parser/wide_encoding.hpp>
16 #include <boost/property_tree/detail/json_parser/standard_callbacks.hpp>
17 
18 #include <boost/range/iterator_range_core.hpp>
19 
20 #include <istream>
21 #include <iterator>
22 #include <string>
23 
24 namespace boost { namespace property_tree {
25     namespace json_parser { namespace detail
26 {
27 
28     template <typename Ch> struct encoding;
29     template <> struct encoding<char> : utf8_utf8_encoding {};
30     template <> struct encoding<wchar_t> : wide_wide_encoding {};
31 
32     template <typename Ptree>
read_json_internal(std::basic_istream<typename Ptree::key_type::value_type> & stream,Ptree & pt,const std::string & filename)33     void read_json_internal(
34         std::basic_istream<typename Ptree::key_type::value_type> &stream,
35         Ptree &pt, const std::string &filename)
36     {
37         typedef typename Ptree::key_type::value_type char_type;
38         typedef standard_callbacks<Ptree> callbacks_type;
39         typedef detail::encoding<char_type> encoding_type;
40         typedef std::istreambuf_iterator<char_type> iterator;
41         callbacks_type callbacks;
42         encoding_type encoding;
43         detail::parser<callbacks_type, encoding_type, iterator, iterator>
44             parser(callbacks, encoding);
45         parser.set_input(filename,
46             boost::make_iterator_range(iterator(stream), iterator()));
47         parser.parse_value();
48         parser.finish();
49 
50         pt.swap(callbacks.output());
51     }
52 
53 }}}}
54 
55 #endif
56