! Input adapter for a (caching) istream. Ignores a UFT Byte Order Mark at beginning of input. Does not support changing the underlying std::streambuf in mid-input. Maintains underlying std::istream and std::streambuf to support subsequent use of standard std::istream operations to process any input characters following those used in parsing the JSON input. Clears the std::istream flags; any input
| 6155 | subsequent call for input from the std::istream. |
| 6156 | */ |
| 6157 | class input_stream_adapter |
| 6158 | { |
| 6159 | public: |
| 6160 | using char_type = char; |
| 6161 | |
| 6162 | ~input_stream_adapter() |
| 6163 | { |
| 6164 | // clear stream flags; we use underlying streambuf I/O, do not |
| 6165 | // maintain ifstream flags, except eof |
| 6166 | if (is != nullptr) |
| 6167 | { |
| 6168 | is->clear(is->rdstate() & std::ios::eofbit); |
| 6169 | } |
| 6170 | } |
| 6171 | |
| 6172 | explicit input_stream_adapter(std::istream& i) |
| 6173 | : is(&i), sb(i.rdbuf()) |
| 6174 | {} |
| 6175 | |
| 6176 | // delete because of pointer members |
| 6177 | input_stream_adapter(const input_stream_adapter&) = delete; |
| 6178 | input_stream_adapter& operator=(input_stream_adapter&) = delete; |
| 6179 | input_stream_adapter& operator=(input_stream_adapter&&) = delete; |
| 6180 | |
| 6181 | input_stream_adapter(input_stream_adapter&& rhs) noexcept |
| 6182 | : is(rhs.is), sb(rhs.sb) |
| 6183 | { |
| 6184 | rhs.is = nullptr; |
| 6185 | rhs.sb = nullptr; |
| 6186 | } |
| 6187 | |
| 6188 | // std::istream/std::streambuf use std::char_traits<char>::to_int_type, to |
| 6189 | // ensure that std::char_traits<char>::eof() and the character 0xFF do not |
| 6190 | // end up as the same value, e.g. 0xFFFFFFFF. |
| 6191 | std::char_traits<char>::int_type get_character() |
| 6192 | { |
| 6193 | auto res = sb->sbumpc(); |
| 6194 | // set eof manually, as we don't use the istream interface. |
| 6195 | if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof())) |
| 6196 | { |
| 6197 | is->clear(is->rdstate() | std::ios::eofbit); |
| 6198 | } |
| 6199 | return res; |
| 6200 | } |
| 6201 | |
| 6202 | private: |
| 6203 | /// the associated input stream |
| 6204 | std::istream* is = nullptr; |
| 6205 | std::streambuf* sb = nullptr; |
| 6206 | }; |
| 6207 | #endif // JSON_NO_IO |
| 6208 | |
| 6209 | // General-purpose iterator-based adapter. It might not be as fast as |