MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / input_stream_adapter

Class input_stream_adapter

Source/external/json.hpp:6153–6202  ·  view source on GitHub ↗

! 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

Source from the content-addressed store, hash-verified

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

Callers 1

input_adapterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected