]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/json/impl/stream_parser.ipp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / json / impl / stream_parser.ipp
1 //
2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/json
8 //
9
10 #ifndef BOOST_JSON_IMPL_STREAM_PARSER_IPP
11 #define BOOST_JSON_IMPL_STREAM_PARSER_IPP
12
13 #include <boost/json/stream_parser.hpp>
14 #include <boost/json/basic_parser_impl.hpp>
15 #include <boost/json/error.hpp>
16 #include <cstring>
17 #include <stdexcept>
18 #include <utility>
19
20 BOOST_JSON_NS_BEGIN
21
22 stream_parser::
23 stream_parser(
24 storage_ptr sp,
25 parse_options const& opt,
26 unsigned char* buffer,
27 std::size_t size) noexcept
28 : p_(
29 opt,
30 std::move(sp),
31 buffer,
32 size)
33 {
34 reset();
35 }
36
37 stream_parser::
38 stream_parser(
39 storage_ptr sp,
40 parse_options const& opt) noexcept
41 : p_(
42 opt,
43 std::move(sp),
44 nullptr,
45 0)
46 {
47 reset();
48 }
49
50 void
51 stream_parser::
52 reset(storage_ptr sp) noexcept
53 {
54 p_.reset();
55 p_.handler().st.reset(sp);
56 }
57
58 std::size_t
59 stream_parser::
60 write_some(
61 char const* data,
62 std::size_t size,
63 error_code& ec)
64 {
65 return p_.write_some(
66 true, data, size, ec);
67 }
68
69 std::size_t
70 stream_parser::
71 write_some(
72 char const* data,
73 std::size_t size,
74 std::error_code& ec)
75 {
76 error_code jec;
77 std::size_t const result = write_some(data, size, jec);
78 ec = jec;
79 return result;
80 }
81
82 std::size_t
83 stream_parser::
84 write_some(
85 char const* data,
86 std::size_t size)
87 {
88 error_code ec;
89 auto const n = write_some(
90 data, size, ec);
91 if(ec)
92 detail::throw_system_error(ec,
93 BOOST_JSON_SOURCE_POS);
94 return n;
95 }
96
97 std::size_t
98 stream_parser::
99 write(
100 char const* data,
101 std::size_t size,
102 error_code& ec)
103 {
104 auto const n = write_some(
105 data, size, ec);
106 if(! ec && n < size)
107 {
108 BOOST_STATIC_CONSTEXPR source_location loc = BOOST_JSON_SOURCE_POS;
109 BOOST_JSON_ASSIGN_ERROR_CODE(ec, error::extra_data, &loc);
110 p_.fail(ec);
111 }
112 return n;
113 }
114
115 std::size_t
116 stream_parser::
117 write(
118 char const* data,
119 std::size_t size,
120 std::error_code& ec)
121 {
122 error_code jec;
123 std::size_t const result = write(data, size, jec);
124 ec = jec;
125 return result;
126 }
127
128 std::size_t
129 stream_parser::
130 write(
131 char const* data,
132 std::size_t size)
133 {
134 error_code ec;
135 auto const n = write(
136 data, size, ec);
137 if(ec)
138 detail::throw_system_error(ec,
139 BOOST_JSON_SOURCE_POS);
140 return n;
141 }
142
143 void
144 stream_parser::
145 finish(error_code& ec)
146 {
147 p_.write_some(false, nullptr, 0, ec);
148 }
149
150 void
151 stream_parser::
152 finish()
153 {
154 error_code ec;
155 finish(ec);
156 if(ec)
157 detail::throw_system_error(ec,
158 BOOST_JSON_SOURCE_POS);
159 }
160
161 void
162 stream_parser::
163 finish(std::error_code& ec)
164 {
165 error_code jec;
166 finish(jec);
167 ec = jec;
168 }
169
170 value
171 stream_parser::
172 release()
173 {
174 if(! p_.done())
175 {
176 // prevent undefined behavior
177 finish();
178 }
179 return p_.handler().st.release();
180 }
181
182 BOOST_JSON_NS_END
183
184 #endif