# stdex: stdex::stream::basic Class Reference

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

> ‍UTF-8 byte-order-mark

More...

`#include <stdex/stream.hpp>`

Inheritance diagram for stdex::stream::basic:

## Public Member Functions

| basic (state_t state=state_t::ok)
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.
virtual void | flush ()
| Persists volatile element data.
virtual void | close ()
| Closes the stream.
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)

## Protected Attributes

state_t | m_state

## Detailed Description

> ‍UTF-8 byte-order-mark

Basic stream operations

## Member Function Documentation

## close()

virtual void stdex::stream::basic::close | ( |  | ) |

inlinevirtual

Closes the stream.

Reimplemented in stdex::stream::converter, stdex::stream::replicator, stdex::stream::file_window, stdex::stream::cache, stdex::stream::basic_sys, stdex::stream::memory_file, stdex::stream::fifo, and stdex::stream::diag_file.

## flush()

virtual void stdex::stream::basic::flush | ( |  | ) |

inlinevirtual

Persists volatile element data.

Reimplemented in stdex::stream::converter, stdex::stream::replicator, stdex::stream::async_writer< CAPACITY >, stdex::stream::buffer, stdex::stream::file_window, stdex::stream::cache, stdex::stream::basic_sys, and stdex::stream::diag_file.

## read()

virtual size_t stdex::stream::basic::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 in stdex::stream::converter, stdex::stream::async_reader< CAPACITY >, stdex::stream::buffer, stdex::stream::limiter, stdex::stream::window, stdex::stream::file_window, stdex::stream::cache, stdex::stream::basic_sys, stdex::stream::memory_file, stdex::stream::fifo, and stdex::stream::diag_file.

## read_array()

size_t stdex::stream::basic::read_array | ( | _Out_writes_bytes_(size *count) void * | array,
|  | size_t | size,
|  | size_t | count
| ) |  |

inline

Reads an array of data from the stream.

Returns
  Number of read elements

## read_data()

template<class T >

basic & stdex::stream::basic::read_data | ( | T & | data | ) |

inline

Reads one primitive data type.

This method is intended for chaining: e.g. stream.read_data(a).read_data(b).read_data(c)... Since it would make it impossible to detect if any of the read_data(a) or read_data(b) failed should read_data(c) succeed, the method skips reading if stream state is not ok.

Parameters

  [in] | data | Where to store read data

Returns
  This stream

## read_remainder()

virtual std::vector< uint8_t > stdex::stream::basic::read_remainder | ( | size_t | max_length = `SIZE_MAX` | ) |

inlinevirtual

Reads and returns remainder of the stream.

Parameters

  [in] | max_length | Byte limit of data to read

Returns
  Data read

Reimplemented in stdex::stream::basic_file.

## read_str()

template<class _Elem , class _Traits = std::char_traits<_Elem>, class _Ax = std::allocator<_Elem>>

basic & stdex::stream::basic::read_str | ( | std::basic_string< _Elem, _Traits, _Ax > & | data | ) |

inline

Reads length-prefixed string from the stream.

This method is intended for chaining: e.g. stream.read_str(a).read_str(b).read_str(c)... Since it would make it impossible to detect if any of the read_str(a) or read_str(b) failed should read_str(c) succeed, the method skips reading if stream state is not ok.

Parameters

  [in] | data | String to read to

Returns
  This stream

## readln() [1/3]

template<class _Traits = std::char_traits<char>, class _Ax = std::allocator<char>>

size_t stdex::stream::basic::readln | ( | std::basic_string< char, _Traits, _Ax > & | str | ) |

inline

Reads stream to the end-of-line or end-of-file.

Returns
  Number of read characters

## readln() [2/3]

template<class _Traits = std::char_traits<wchar_t>, class _Ax = std::allocator<wchar_t>>

size_t stdex::stream::basic::readln | ( | std::basic_string< wchar_t, _Traits, _Ax > & | wstr | ) |

inline

Reads stream to the end-of-line or end-of-file.

Returns
  Number of read characters

## readln() [3/3]

template<class _Traits = std::char_traits<wchar_t>, class _Ax = std::allocator<wchar_t>>

size_t stdex::stream::basic::readln | ( | std::basic_string< wchar_t, _Traits, _Ax > & | wstr,
|  | charset_id | charset
| ) |  |

inline

Reads stream to the end-of-line or end-of-file.

Returns
  Number of read characters

## readln_and_attach() [1/2]

template<class _Elem , class _Traits = std::char_traits<_Elem>, class _Ax = std::allocator<_Elem>>

size_t stdex::stream::basic::readln_and_attach | ( | std::basic_string< _Elem, _Traits, _Ax > & | str | ) |

inline

Reads stream to the end-of-line or end-of-file and append to str.

Returns
  Total number of chars in str

## readln_and_attach() [2/2]

template<class _Traits = std::char_traits<wchar_t>, class _Ax = std::allocator<wchar_t>>

size_t stdex::stream::basic::readln_and_attach | ( | std::basic_string< wchar_t, _Traits, _Ax > & | wstr,
|  | charset_id | charset
| ) |  |

inline

Reads stream to the end-of-line or end-of-file and append to str.

Returns
  Total number of chars in str

## skip()

virtual void stdex::stream::basic::skip | ( | fsize_t | amount | ) |

inlinevirtual

Skips given amount of bytes of data on the stream.

Reimplemented in stdex::stream::basic_file, and stdex::stream::file_window.

## write()

virtual size_t stdex::stream::basic::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 in stdex::stream::converter, stdex::stream::replicator, stdex::stream::async_writer< CAPACITY >, stdex::stream::buffer, stdex::stream::limiter, stdex::stream::window, stdex::stream::file_window, stdex::stream::cache, stdex::stream::basic_sys, stdex::stream::memory_file, stdex::stream::fifo, and stdex::stream::diag_file.

## write_array() [1/4]

size_t stdex::stream::basic::write_array | ( | _In_reads_bytes_opt_(size *count) const void * | array,
|  | size_t | size,
|  | size_t | count
| ) |  |

inline

Writes an array of data to the stream.

Returns
  Number of elements written

## write_array() [2/4]

size_t stdex::stream::basic::write_array | ( | _In_reads_or_z_opt_(num_chars) const wchar_t * | wstr,
|  | size_t | num_chars,
|  | charset_id | charset
| ) |  |

inline

Writes array of characters to the stream.

Parameters

  [in] | wstr | String to write
  [in] | num_chars | String code unit count limit
  [in] | charset | Charset to convert string to

Returns
  Number of code units written

## write_array() [3/4]

template<class _Traits = std::char_traits<wchar_t>, class _Ax = std::allocator<wchar_t>>

size_t stdex::stream::basic::write_array | ( | const std::basic_string< wchar_t, _Traits, _Ax > & | wstr,
|  | charset_id | charset
| ) |  |

inline

Writes array of characters to the stream.

Parameters

  [in] | wstr | String to write
  [in] | charset | Charset to convert string to

Returns
  Number of code units written

## write_array() [4/4]

size_t stdex::stream::basic::write_array | ( | const wchar_t * | wstr,
|  | charset_id | charset
| ) |  |

inline

Writes array of characters to the stream.

Parameters

  [in] | wstr | String to write. Must be zero-terminated.
  [in] | charset | Charset to convert string to

Returns
  Number of code units written

## write_data()

template<class T >

basic & stdex::stream::basic::write_data | ( | const T | data | ) |

inline

Writes one primitive data type.

This method is intended for chaining: e.g. stream.write_data(a).write_data(b).write_data(c)... Since it would make it impossible to detect if any of the write_data(a) or write_data(b) failed should write_data(c) succeed, the method skips writing if stream state is not ok.

Parameters

  [in] | data | Data to write

Returns
  This stream

## write_sprintf() [1/2]

size_t stdex::stream::basic::write_sprintf | ( | _Printf_format_string_params_(2) const char * | format,
|  | locale_t | locale,
|  |  | ...
| ) |  |

inline

Writes formatted string to the stream.

Returns
  Number of characters written

## write_sprintf() [2/2]

size_t stdex::stream::basic::write_sprintf | ( | _Printf_format_string_params_(2) const wchar_t * | format,
|  | locale_t | locale,
|  |  | ...
| ) |  |

inline

Writes formatted string to the stream.

Returns
  Number of characters written

## write_str()

template<class T >

basic & stdex::stream::basic::write_str | ( | const T * | data | ) |

inline

Writes string to the stream length-prefixed.

This method is intended for chaining: e.g. stream.write_str(a).write_str(b).write_str(c)... Since it would make it impossible to detect if any of the write_str(a) or write_str(b) failed should write_str(c) succeed, the method skips writing if stream state is not ok.

Parameters

  [in] | data | String to write

Returns
  This stream

## write_stream()

fsize_t stdex::stream::basic::write_stream | ( | basic & | stream,
|  | fsize_t | amount = `fsize_max`
| ) |  |

inline

Writes content of another stream.

Returns
  Number of bytes written

## write_vsprintf() [1/2]

size_t stdex::stream::basic::write_vsprintf | ( | _Printf_format_string_params_(2) const char * | format,
|  | locale_t | locale,
|  | va_list | params
| ) |  |

inline

Writes formatted string to the stream.

Returns
  Number of characters written

## write_vsprintf() [2/2]

size_t stdex::stream::basic::write_vsprintf | ( | _Printf_format_string_params_(2) const wchar_t * | format,
|  | locale_t | locale,
|  | va_list | params
| ) |  |

inline

Writes formatted string to the stream.

Returns
  Number of characters written

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

- include/stdex/stream.hpp