# stdex: stdex::stream::limiter Class Reference

Loading...
Searching...
No Matches
stdex::stream::limiter Class Reference

Limits reading from/writing to stream to a predefined number of bytes. More...

`#include <stdex/stream.hpp>`

Inheritance diagram for stdex::stream::limiter:

## Public Member Functions

| limiter (basic &source, fsize_t _read_limit=0, fsize_t _write_limit=0)
virtual size_t | read (_Out_writes_bytes_to_opt_(length, return) void *data, size_t length)
| Reads block of data from the stream.
virtual size_t | write (_In_reads_bytes_opt_(length) const void *data, size_t length)
| Writes block of data to the stream.
Public Member Functions inherited from stdex::stream::converter
| converter (basic &source)
virtual void | close ()
| Closes the stream.
virtual void | flush ()
| Persists volatile element data.
Public Member Functions inherited from stdex::stream::basic
| basic (state_t state=state_t::ok)
virtual void | skip (fsize_t amount)
| Skips given amount of bytes of data on the stream.
state_t | state () const
| Returns stream state after last operation.
bool | ok () const
| Returns true if the stream state is clean i.e. previous operation was succesful.
virtual std::vector< uint8_t > | read_remainder (size_t max_length=SIZE_MAX)
| Reads and returns remainder of the stream.
uint8_t | read_byte ()
| Reads one byte of data.
void | write_byte (uint8_t byte, fsize_t amount=1)
| Writes a byte of data.
template<class T >
basic & | read_data (T &data)
| Reads one primitive data type.
template<class T >
basic & | write_data (const T data)
| Writes one primitive data type.
template<class _Traits = std::char_traits<char>, class _Ax = std::allocator<char>>
size_t | readln (std::basic_string< char, _Traits, _Ax > &str)
| Reads stream to the end-of-line or end-of-file.
template<class _Traits = std::char_traits<wchar_t>, class _Ax = std::allocator<wchar_t>>
size_t | readln (std::basic_string< wchar_t, _Traits, _Ax > &wstr)
| Reads stream to the end-of-line or end-of-file.
template<class _Traits = std::char_traits<wchar_t>, class _Ax = std::allocator<wchar_t>>
size_t | readln (std::basic_string< wchar_t, _Traits, _Ax > &wstr, charset_id charset)
| Reads stream to the end-of-line or end-of-file.
template<class _Elem , class _Traits = std::char_traits<_Elem>, class _Ax = std::allocator<_Elem>>
size_t | readln_and_attach (std::basic_string< _Elem, _Traits, _Ax > &str)
| Reads stream to the end-of-line or end-of-file and append to str.
template<class _Traits = std::char_traits<wchar_t>, class _Ax = std::allocator<wchar_t>>
size_t | readln_and_attach (std::basic_string< wchar_t, _Traits, _Ax > &wstr, charset_id charset)
| Reads stream to the end-of-line or end-of-file and append to str.
size_t | read_array (_Out_writes_bytes_(size *count) void *array, size_t size, size_t count)
| Reads an array of data from the stream.
size_t | write_array (_In_reads_bytes_opt_(size *count) const void *array, size_t size, size_t count)
| Writes an array of data to the stream.
size_t | write_array (const wchar_t *wstr, charset_id charset)
| Writes array of characters to the stream.
size_t | write_array (_In_reads_or_z_opt_(num_chars) const wchar_t *wstr, size_t num_chars, charset_id charset)
| Writes array of characters to the stream.
template<class _Traits = std::char_traits<wchar_t>, class _Ax = std::allocator<wchar_t>>
size_t | write_array (const std::basic_string< wchar_t, _Traits, _Ax > &wstr, charset_id charset)
| Writes array of characters to the stream.
template<class _Elem , class _Traits = std::char_traits<_Elem>, class _Ax = std::allocator<_Elem>>
basic & | read_str (std::basic_string< _Elem, _Traits, _Ax > &data)
| Reads length-prefixed string from the stream.
template<class T >
basic & | write_str (const T *data)
| Writes string to the stream length-prefixed.
fsize_t | write_stream (basic &stream, fsize_t amount=fsize_max)
| Writes content of another stream.
void | write_charset (charset_id charset)
| Writes UTF8 or UTF-16 byte-order-mark.
size_t | write_sprintf (_Printf_format_string_params_(2) const char *format, locale_t locale,...)
| Writes formatted string to the stream.
size_t | write_sprintf (_Printf_format_string_params_(2) const wchar_t *format, locale_t locale,...)
| Writes formatted string to the stream.
size_t | write_vsprintf (_Printf_format_string_params_(2) const char *format, locale_t locale, va_list params)
| Writes formatted string to the stream.
size_t | write_vsprintf (_Printf_format_string_params_(2) const wchar_t *format, locale_t locale, va_list params)
| Writes formatted string to the stream.
basic & | operator>> (int8_t &data)
basic & | operator<< (const int8_t data)
basic & | operator>> (int16_t &data)
basic & | operator<< (const int16_t data)
basic & | operator>> (int32_t &data)
basic & | operator<< (const int32_t data)
basic & | operator>> (int64_t &data)
basic & | operator<< (const int64_t data)
basic & | operator>> (uint8_t &data)
basic & | operator<< (const uint8_t data)
basic & | operator>> (uint16_t &data)
basic & | operator<< (const uint16_t data)
basic & | operator>> (uint32_t &data)
basic & | operator<< (const uint32_t data)
basic & | operator>> (uint64_t &data)
basic & | operator<< (const uint64_t data)
basic & | operator>> (float &data)
basic & | operator<< (const float data)
basic & | operator>> (double &data)
basic & | operator<< (const double data)
basic & | operator>> (char &data)
basic & | operator<< (const char data)
template<class _Elem , class _Traits = std::char_traits<_Elem>, class _Ax = std::allocator<_Elem>>
basic & | operator>> (std::basic_string< _Elem, _Traits, _Ax > &data)
template<class T >
basic & | operator<< (const T *data)

## Public Attributes

fsize_t | read_limit
| Number of bytes left that may be read from the stream.
fsize_t | write_limit
| Number of bytes left, that can be written to the stream.

## Additional Inherited Members

Protected Member Functions inherited from stdex::stream::converter
void | init (basic &source)
void | done ()
Protected Attributes inherited from stdex::stream::converter
basic * | m_source
Protected Attributes inherited from stdex::stream::basic
state_t | m_state

## Detailed Description

Limits reading from/writing to stream to a predefined number of bytes.

## Member Function Documentation

## read()

virtual size_t stdex::stream::limiter::read | ( | _Out_writes_bytes_to_opt_(length, return) void * | data,
|  | size_t | length
| ) |  |

inlinevirtual

Reads block of data from the stream.

Parameters

  [out] | data | Buffer to store read data
  [in] | length | Byte limit of data to read

Returns
  Number of bytes succesfully read. On EOF, 0 is returned and stream state is set to state_t::eof. On error, 0 is returned and stream state is set to state_t::fail. On null reads (length == 0), 0 is returned and stream state is set to state_t::ok.

Reimplemented from stdex::stream::converter.

Reimplemented in stdex::stream::window.

## write()

virtual size_t stdex::stream::limiter::write | ( | _In_reads_bytes_opt_(length) const void * | data,
|  | size_t | length
| ) |  |

inlinevirtual

Writes block of data to the stream.

Parameters

  [in] | data | Buffer to write data from
  [in] | length | Number of bytes to write

Returns
  Number of bytes succesfully written. On error, stream state is set to state_t::fail.

Reimplemented from stdex::stream::converter.

Reimplemented in stdex::stream::window.

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

- include/stdex/stream.hpp