File indexing completed on 2025-01-18 09:39:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_JSON_IMPL_PARSE_INTO_HPP
0012 #define BOOST_JSON_IMPL_PARSE_INTO_HPP
0013
0014 #include <boost/json/basic_parser_impl.hpp>
0015 #include <boost/json/error.hpp>
0016 #include <istream>
0017
0018 namespace boost {
0019 namespace json {
0020
0021 template<class V>
0022 void
0023 parse_into(
0024 V& v,
0025 string_view sv,
0026 error_code& ec,
0027 parse_options const& opt )
0028 {
0029 parser_for<V> p( opt, &v );
0030
0031 std::size_t n = p.write_some( false, sv.data(), sv.size(), ec );
0032
0033 if( !ec && n < sv.size() )
0034 {
0035 BOOST_JSON_FAIL( ec, error::extra_data );
0036 }
0037 }
0038
0039 template<class V>
0040 void
0041 parse_into(
0042 V& v,
0043 string_view sv,
0044 std::error_code& ec,
0045 parse_options const& opt )
0046 {
0047 error_code jec;
0048 parse_into(v, sv, jec, opt);
0049 ec = jec;
0050 }
0051
0052 template<class V>
0053 void
0054 parse_into(
0055 V& v,
0056 string_view sv,
0057 parse_options const& opt )
0058 {
0059 error_code ec;
0060 parse_into(v, sv, ec, opt);
0061 if( ec.failed() )
0062 detail::throw_system_error( ec );
0063 }
0064
0065 template<class V>
0066 void
0067 parse_into(
0068 V& v,
0069 std::istream& is,
0070 error_code& ec,
0071 parse_options const& opt )
0072 {
0073 parser_for<V> p( opt, &v );
0074
0075 char read_buffer[BOOST_JSON_STACK_BUFFER_SIZE];
0076 do
0077 {
0078 if( is.eof() )
0079 {
0080 p.write_some(false, nullptr, 0, ec);
0081 break;
0082 }
0083
0084 if( !is )
0085 {
0086 BOOST_JSON_FAIL( ec, error::input_error );
0087 break;
0088 }
0089
0090 is.read(read_buffer, sizeof(read_buffer));
0091 std::size_t const consumed = static_cast<std::size_t>( is.gcount() );
0092
0093 std::size_t const n = p.write_some( true, read_buffer, consumed, ec );
0094 if( !ec.failed() && n < consumed )
0095 {
0096 BOOST_JSON_FAIL( ec, error::extra_data );
0097 }
0098 }
0099 while( !ec.failed() );
0100 }
0101
0102 template<class V>
0103 void
0104 parse_into(
0105 V& v,
0106 std::istream& is,
0107 std::error_code& ec,
0108 parse_options const& opt )
0109 {
0110 error_code jec;
0111 parse_into(v, is, jec, opt);
0112 ec = jec;
0113 }
0114
0115 template<class V>
0116 void
0117 parse_into(
0118 V& v,
0119 std::istream& is,
0120 parse_options const& opt )
0121 {
0122 error_code ec;
0123 parse_into(v, is, ec, opt);
0124 if( ec.failed() )
0125 detail::throw_system_error( ec );
0126 }
0127
0128 }
0129 }
0130
0131 #endif