24 #ifndef STATICLIB_IO_UNBUFFERED_STREAMBUF_HPP
25 #define STATICLIB_IO_UNBUFFERED_STREAMBUF_HPP
32 #include "staticlib/config.hpp"
53 throw std::ios_base::failure(
"'underflow' operation is not supported by unbuffered streambuf");
60 throw std::ios_base::failure(
"'uflow' operation is not supported by unbuffered streambuf");
67 throw std::ios_base::failure(
"'overflow' operation is not supported by unbuffered streambuf");
79 virtual std::streamsize
xsgetn(
char*, std::streamsize)
override {
80 throw std::ios_base::failure(
"'xsgetn' operation is not supported by unbuffered streambuf");
90 virtual std::streamsize
xsputn(
const char*, std::streamsize)
override {
91 throw std::ios_base::failure(
"'xsputn' operation is not supported by unbuffered streambuf");
98 throw std::ios_base::failure(
"'setbuf' operation is not supported by unbuffered streambuf");
104 virtual std::streampos
seekoff(std::streamoff, std::ios_base::seekdir, std::ios_base::openmode)
override {
105 throw std::ios_base::failure(
"'seekoff' operation is not supported by unbuffered streambuf");
111 virtual std::streampos
seekpos(std::streampos, std::ios_base::openmode)
override {
112 throw std::ios_base::failure(
"'seekpos' operation is not supported by unbuffered streambuf");
124 template <
typename Source, std::streamsize source_eof = -1>
127 bool exhausted =
false;
137 source(std::move(source)) { }
153 source(std::move(other.source)),
154 exhausted(other.exhausted) {
155 other.exhausted =
true;
162 source = std::move(other.source);
163 exhausted = other.exhausted;
164 other.exhausted =
true;
175 return std::char_traits<char>::eof();
177 throw std::ios_base::failure(
"'uflow' operation is not supported by unbuffered streambuf");
198 virtual std::streamsize
xsgetn(
char* s, std::streamsize count)
override {
200 auto res = source.read({s, count});
201 if (source_eof != res) {
220 template <
typename Source,
221 class =
typename std::enable_if<!std::is_lvalue_reference<Source>::value>::type>
233 template <
typename Source,
234 class =
typename std::enable_if<!std::is_lvalue_reference<Source>::value>::type>
236 return std::unique_ptr<unbuffered_istreambuf<Source>>(
247 template <
typename Source>
259 template <
typename Source>
261 return std::unique_ptr<unbuffered_istreambuf<reference_source<Source>>>(
269 template <
typename Sink>
281 sink(std::move(sink)) { }
297 sink(std::move(other.sink)) { }
303 sink = std::move(other.sink);
324 virtual std::streamsize
xsputn(
const char* s, std::streamsize count)
override {
325 return sink.write({s, count});
336 template <
typename Sink,
337 class =
typename std::enable_if<!std::is_lvalue_reference<Sink>::value>::type>
349 template <
typename Sink,
350 class =
typename std::enable_if<!std::is_lvalue_reference<Sink>::value>::type>
352 return std::unique_ptr<unbuffered_ostreambuf<Sink>>(
363 template <
typename Sink>
375 template <
typename Sink>
377 return std::unique_ptr<unbuffered_ostreambuf<reference_sink<Sink>>>(