26 : output_(
other.output_),
28 offset_(
other.offset_),
29 status_(
other.status_) {
30 other.output_ =
nullptr;
41 output_ =
other.output_;
42 buffer_ = std::move(
other.buffer_);
43 offset_ =
other.offset_;
44 status_ =
other.status_;
45 other.output_ =
nullptr;
76 if (status_ !=
kOk)
return;
79 buffer_[offset_++] =
v;
92 if (status_ !=
kOk)
return 0;
105 status_ = output_->
status();
115 if (status_ ==
kOk) {
116 if (offset_ > 0) writeBuffer();
118 status_ = output_->
status();
148 status_ =
output.status();
149 if (status_ ==
kOk) {
150 if (buffer_ ==
nullptr) {
161 inline void writeBuffer() {
162 if (output_->
writeFully(buffer_.get(), offset_) < offset_) {
163 status_ = output_->
status();
169 std::unique_ptr<byte[]> buffer_;
void reset(roo_io::OutputStream &output)
Rebinds iterator to output and clears buffered state.
~BufferedOutputStreamIterator()
Flushes pending output on destruction.
void flush()
Flushes buffered data and then flushes underlying stream.
void reset()
Detaches from stream and releases internal buffer.
Status status() const
Returns current iterator status.
void write(byte v)
Writes one byte.
BufferedOutputStreamIterator(roo_io::OutputStream &output)
Creates iterator over output.
BufferedOutputStreamIterator(BufferedOutputStreamIterator &&other)
Move-constructs iterator state.
BufferedOutputStreamIterator & operator=(BufferedOutputStreamIterator &&other)
Move-assigns iterator state.
bool ok() const
Returns whether status() == kOk.
size_t write(const byte *buf, size_t count)
Writes up to count bytes.
BufferedOutputStreamIterator()
Creates a detached iterator with kClosed status.
Virtualizes access to writable sinks (files, memory, devices).
virtual Status status() const =0
Returns underlying stream status.
virtual void flush()
Flushes buffered data to the underlying sink.
virtual size_t writeFully(const byte *buf, size_t count)
Attempts to write count bytes from buf.
virtual size_t write(const byte *buf, size_t count)=0
Attempts to write up to count bytes from buf.
static const size_t kOutputStreamIteratorBufferSize
roo::basic_string_view< CharT, Traits > basic_string_view