Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
sese::io::BufferedStream Class Referencefinal

Stream buffer class. More...

#include <BufferedStream.h>

Inheritance diagram for sese::io::BufferedStream:
sese::Noncopyable sese::io::Stream sese::io::InputStream sese::io::OutputStream

Public Types

using Ptr = std::shared_ptr<BufferedStream>
 
- Public Types inherited from sese::io::Stream
typedef std::shared_ptr< StreamPtr
 
- Public Types inherited from sese::io::InputStream
typedef std::shared_ptr< InputStreamPtr
 
- Public Types inherited from sese::io::OutputStream
typedef std::shared_ptr< OutputStreamPtr
 

Public Member Functions

 BufferedStream (const Stream::Ptr &source, size_t buffer_size=STREAM_BYTE_STREAM_SIZE_FACTOR)
 
 ~BufferedStream () noexcept override
 
int64_t read (void *buffer, size_t length) override
 
void clear () noexcept
 Clear the current read flag.
 
int64_t write (const void *buffer, size_t length) override
 
int64_t flush () noexcept
 Flush all current buffer contents to the stream and reset the current write flag.
 
void reset (const Stream::Ptr &source) noexcept
 
size_t getPosition () const
 
size_t getLength () const
 
size_t getCapacity () const
 
- Public Member Functions inherited from sese::Noncopyable
 Noncopyable ()=default
 
virtual ~Noncopyable ()=default
 
 Noncopyable (const Noncopyable &)=delete
 
Noncopyableoperator= (const Noncopyable &)=delete
 
- Public Member Functions inherited from sese::io::InputStream
virtual ~InputStream () noexcept=default
 
- Public Member Functions inherited from sese::io::OutputStream
virtual ~OutputStream () noexcept=default
 
int64_t write (const std::string_view &buffer)
 
int64_t write (const text::StringView &buffer)
 
template<typename T >
int64_t write (std::vector< T > &buffer)
 
template<typename T , size_t N>
int64_t write (std::array< T, N > &buffer)
 

Private Member Functions

int64_t preRead ()
 

Private Attributes

Stream::Ptr source
 Source stream pointer.
 
void * buffer = nullptr
 Cache pointer.
 
size_t pos
 Size of processed data.
 
size_t len
 Size of data available for operation.
 
size_t cap
 Cache capacity.
 

Detailed Description

Member Typedef Documentation

◆ Ptr

Constructor & Destructor Documentation

◆ BufferedStream()

BufferedStream::BufferedStream ( const Stream::Ptr & source,
size_t buffer_size = STREAM_BYTE_STREAM_SIZE_FACTOR )
explicit

Wrap the specified stream

Parameters
sourceStream to be wrapped
buffer_sizeBuffer size

References buffer, cap, len, pos, and source.

◆ ~BufferedStream()

BufferedStream::~BufferedStream ( )
overridenoexcept

References buffer, and free().

Member Function Documentation

◆ clear()

void BufferedStream::clear ( )
noexcept

Clear the current read flag.

Warning
Ensure that all content in BufferedStream has been read out before performing this operation, otherwise it may result in the loss of necessary information

References len, and pos.

◆ flush()

int64_t BufferedStream::flush ( )
noexcept

Flush all current buffer contents to the stream and reset the current write flag.

Returns
Number of bytes flushed to the stream

References buffer, len, pos, and source.

Referenced by write().

◆ getCapacity()

size_t sese::io::BufferedStream::getCapacity ( ) const
inlinenodiscard

References cap.

◆ getLength()

size_t sese::io::BufferedStream::getLength ( ) const
inlinenodiscard

References len.

◆ getPosition()

size_t sese::io::BufferedStream::getPosition ( ) const
inlinenodiscard

References pos.

◆ preRead()

int64_t BufferedStream::preRead ( )
inlineprivate

References buffer, cap, len, pos, read(), and source.

Referenced by read().

◆ read()

int64_t BufferedStream::read ( void * buffer,
size_t length )
overridevirtual
* Read a certain number of bytes
* If the read size does not exceed the BufferedStream buffer size, the read will be automatically cached
* Otherwise, direct raw stream reading is performed to reduce copy operations
* 
Parameters
bufferUser buffer pointer
lengthUser buffer size
Returns
Actual number of bytes read

Implements sese::io::InputStream.

References buffer, cap, len, pos, preRead(), read(), and source.

Referenced by preRead(), and read().

◆ reset()

void BufferedStream::reset ( const Stream::Ptr & source)
noexcept

Reset output source; this will cause existing data to be cleared

Parameters
sourceNew output source

◆ write()

int64_t BufferedStream::write ( const void * buffer,
size_t length )
overridevirtual
* Write a certain number of bytes
* If the write size does not exceed the BufferedStream buffer size, the write will be automatically flushed
* Otherwise, direct raw stream writing is performed to reduce copy operations
* 
Parameters
bufferUser buffer pointer
lengthUser buffer size
Returns
Actual number of bytes written

Implements sese::io::OutputStream.

References buffer, cap, flush(), len, pos, and source.

Member Data Documentation

◆ buffer

void* sese::io::BufferedStream::buffer = nullptr
private

Cache pointer.

Referenced by BufferedStream(), flush(), preRead(), read(), write(), and ~BufferedStream().

◆ cap

size_t sese::io::BufferedStream::cap
private

Cache capacity.

Referenced by BufferedStream(), getCapacity(), preRead(), read(), and write().

◆ len

size_t sese::io::BufferedStream::len
private

Size of data available for operation.

Referenced by BufferedStream(), clear(), flush(), getLength(), preRead(), read(), and write().

◆ pos

size_t sese::io::BufferedStream::pos
private

Size of processed data.

Referenced by BufferedStream(), clear(), flush(), getPosition(), preRead(), read(), and write().

◆ source

Stream::Ptr sese::io::BufferedStream::source
private

Source stream pointer.

Referenced by BufferedStream(), flush(), preRead(), read(), and write().


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