byteme
C++ wrappers for buffered inputs
Loading...
Searching...
No Matches
byteme::BufferedWriter< Type_, WriterPointer_ > Class Template Referenceabstract

Buffered wrapper around a Writer. More...

#include <BufferedWriter.hpp>

Inheritance diagram for byteme::BufferedWriter< Type_, WriterPointer_ >:

Public Member Functions

unsigned long long number ()
 
void write (Type_ input)
 
void write (const Type_ *input, std::size_t number)
 
void flush ()
 
virtual void finish ()=0
 

Detailed Description

template<typename Type_, class WriterPointer_ = std::unique_ptr<Writer>>
class byteme::BufferedWriter< Type_, WriterPointer_ >

Buffered wrapper around a Writer.

Template Parameters
Type_Type of the input bytes, usually char for text or unsigned char for binary.

In some applications, we may need to write many small chunks of bytes or even individual bytes. Naively calling Writer::write() for each request may be inefficient if the underlying implementation attempts to write to some storage device for each call. Instead, we can wrap our Writer in a BufferedWriter instance, which stores user-supplied data into a large intermediate buffer. It then calls Writer::write() every now and then to flush the buffer to the underlying representation.

Check out SerialBufferedWriter and ParallelBufferedWriter for subclasses.

Member Function Documentation

◆ finish()

template<typename Type_ , class WriterPointer_ = std::unique_ptr<Writer>>
virtual void byteme::BufferedWriter< Type_, WriterPointer_ >::finish ( )
pure virtual

Flush all currently-buffered bytes to the underlying Writer instance and call Writer::finish(). This terminates the write stream so no further calls to write(), flush() or finish() may be performed. It is not called automatically upon BufferedWriter destruction, as the user may want to write further bytes to the same Writer instance after exiting the BufferedWriter wrapper.

◆ flush()

template<typename Type_ , class WriterPointer_ = std::unique_ptr<Writer>>
void byteme::BufferedWriter< Type_, WriterPointer_ >::flush ( )
inline

Flush all currently-buffered bytes to the underlying Writer instance. This can be called at any time, before or after other calls to write() or flush(). It is also automatically called upon BufferedWriter destruction.

◆ number()

template<typename Type_ , class WriterPointer_ = std::unique_ptr<Writer>>
unsigned long long byteme::BufferedWriter< Type_, WriterPointer_ >::number ( )
inline
Returns
Number of bytes that have currently been written via calls to write().

◆ write() [1/2]

template<typename Type_ , class WriterPointer_ = std::unique_ptr<Writer>>
void byteme::BufferedWriter< Type_, WriterPointer_ >::write ( const Type_ * input,
std::size_t number )
inline

Write an array of bytes to the buffer. This may trigger a multiple calls to flush().

Parameters
[in]inputPointer to an array of bytes to be written.
numberLength of the array in input.

◆ write() [2/2]

template<typename Type_ , class WriterPointer_ = std::unique_ptr<Writer>>
void byteme::BufferedWriter< Type_, WriterPointer_ >::write ( Type_ input)
inline

Write a single byte to the buffer. This may trigger a call to flush().

Parameters
inputByte to be written.

The documentation for this class was generated from the following file: