stdex Additional custom or not Standard C++ covered algorithms

Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
stdex::stream::basic Class Reference

Basic stream operations. 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 successful.
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 T , class TR = std::char_traits<T>, class AX = std::allocator<T>>
size_t | readln (std::basic_string< T, TR, AX > &str)
| Reads stream to the end-of-line or end-of-file.
template<class T_from , class T_to , class TR = std::char_traits<T_to>, class AX = std::allocator<T_to>>
size_t | readln (std::basic_string< T_to, TR, AX > &str, charset_encoder< T_from, T_to > &encoder)
| Reads stream to the end-of-line or end-of-file.
template<class T , class TR = std::char_traits<T>, class AX = std::allocator<T>>
size_t | readln_and_attach (std::basic_string< T, TR, AX > &str)
| Reads stream to the end-of-line or end-of-file and append to str.
template<class T_from , class T_to , class TR = std::char_traits<T_to>, class AX = std::allocator<T_to>>
size_t | readln_and_attach (std::basic_string< T_to, TR, AX > &str, charset_encoder< T_from, T_to > &encoder)
| 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.
template<class T_from , class T_to >
size_t | write_array (const T_from *str, charset_encoder< T_from, T_to > &encoder)
| Writes array of characters to the stream.
template<class T_from , class T_to >
size_t | write_array (_In_reads_or_z_opt_(num_chars) const T_from *str, size_t num_chars, charset_encoder< T_from, T_to > &encoder)
| Writes array of characters to the stream.
template<class T_from , class T_to , class TR = std::char_traits<T_from>, class AX = std::allocator<T_from>>
size_t | write_array (const std::basic_string< T_from, TR, AX > &str, charset_encoder< T_from, T_to > &encoder)
| Writes array of characters to the stream.
template<class T , class TR = std::char_traits<T>, class AX = std::allocator<T>>
basic & | read_str (std::basic_string< T, TR, 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.
template<class T , class TR = std::char_traits<T>, class AX = std::allocator<T>>
basic & | write_str (const std::basic_string< T, TR, AX > &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, UTF-16 or UTF-32 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 T , class TR = std::char_traits<T>, class AX = std::allocator<T>>
basic & | operator>> (std::basic_string< T, TR, AX > &data)
template<class T >
basic & | operator<< (const T *data)
template<class T , class TR = std::char_traits<T>, class AX = std::allocator<T>>
basic & | operator<< (const std::basic_string< T, TR, AX > &data)
template<class T , class AX = std::allocator<T>>
basic & | operator<< (const std::vector< T, AX > &data)
template<class T , class AX = std::allocator<T>>
basic & | operator>> (std::vector< T, AX > &data)
template<class KEY , class PR = std::less<KEY>, class AX = std::allocator<KEY>>
basic & | operator<< (const std::set< KEY, PR, AX > &data)
template<class KEY , class PR = std::less<KEY>, class AX = std::allocator<KEY>>
basic & | operator>> (std::set< KEY, PR, AX > &data)
template<class KEY , class PR = std::less<KEY>, class AX = std::allocator<KEY>>
basic & | operator<< (const std::multiset< KEY, PR, AX > &data)
template<class KEY , class PR = std::less<KEY>, class AX = std::allocator<KEY>>
basic & | operator>> (std::multiset< KEY, PR, AX > &data)

## Protected Attributes
state_t | m_state

## Detailed Description

Basic stream operations.

> ‍UTF-8 byte-order-mark

## Member Function Documentation

## ◆ close()

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

Closes the stream.

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

## ◆ flush()

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

Persists volatile element data.

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

## ◆ read()

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

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 successfully 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::base64_reader, stdex::stream::async_reader< N_cap >, stdex::stream::basic_sys, stdex::stream::buffer, stdex::stream::cache, stdex::stream::converter, stdex::stream::diag_file, stdex::stream::fifo, stdex::stream::file_window, stdex::stream::limiter, stdex::stream::memory_file, stdex::stream::socket, stdex::stream::window, stdex::stream_hasher< T >, and stdex::zlib_reader.

## ◆ 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 | ) |
| inline virtual

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 T , class TR = std::char_traits<T>, class AX = std::allocator<T>>

basic & stdex::stream::basic::read_str | ( | std::basic_string< T, TR, 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/2]

template<class T , class TR = std::char_traits<T>, class AX = std::allocator<T>>

size_t stdex::stream::basic::readln | ( | std::basic_string< T, TR, AX > & | str | ) |
| inline

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

Returns
  Number of read characters

## ◆ readln() [2/2]

template<class T_from , class T_to , class TR = std::char_traits<T_to>, class AX = std::allocator<T_to>>

size_t stdex::stream::basic::readln | ( | std::basic_string< T_to, TR, AX > & | str,
|  | charset_encoder< T_from, T_to > & | encoder )
| inline

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

Returns
  Number of read characters

## ◆ readln_and_attach() [1/2]

template<class T , class TR = std::char_traits<T>, class AX = std::allocator<T>>

size_t stdex::stream::basic::readln_and_attach | ( | std::basic_string< T, TR, 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 T_from , class T_to , class TR = std::char_traits<T_to>, class AX = std::allocator<T_to>>

size_t stdex::stream::basic::readln_and_attach | ( | std::basic_string< T_to, TR, AX > & | str,
|  | charset_encoder< T_from, T_to > & | encoder )
| 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 | ) |
| inline virtual

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 )
| inline virtual

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 successfully written. On error, stream state is set to state_t::fail.

Reimplemented in stdex::base64_writer, stdex::stream::async_writer< N_cap >, stdex::stream::basic_sys, stdex::stream::buffer, stdex::stream::cache, stdex::stream::converter, stdex::stream::diag_file, stdex::stream::fifo, stdex::stream::file_window, stdex::stream::limiter, stdex::stream::memory_file, stdex::stream::replicator, stdex::stream::socket, stdex::stream::window, stdex::stream_hasher< T >, and stdex::zlib_writer.

## ◆ 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]

template<class T_from , class T_to >

size_t stdex::stream::basic::write_array | ( | _In_reads_or_z_opt_(num_chars) const T_from * | str,
|  | size_t | num_chars,
|  | charset_encoder< T_from, T_to > & | encoder )
| inline

Writes array of characters to the stream.

Parameters

  [in] | str | String to write
  [in] | num_chars | String code unit count limit
  [in] | encoder | Encoder for encoding string

Returns
  Number of code units written

## ◆ write_array() [3/4]

template<class T_from , class T_to , class TR = std::char_traits<T_from>, class AX = std::allocator<T_from>>

size_t stdex::stream::basic::write_array | ( | const std::basic_string< T_from, TR, AX > & | str,
|  | charset_encoder< T_from, T_to > & | encoder )
| inline

Writes array of characters to the stream.

Parameters

  [in] | str | String to write
  [in] | encoder | Encoder for encoding string

Returns
  Number of code units written

## ◆ write_array() [4/4]

template<class T_from , class T_to >

size_t stdex::stream::basic::write_array | ( | const T_from * | str,
|  | charset_encoder< T_from, T_to > & | encoder )
| inline

Writes array of characters to the stream.

Parameters

  [in] | str | String to write. Must be zero-terminated.
  [in] | encoder | Encoder for encoding string

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() [1/2]

template<class T , class TR = std::char_traits<T>, class AX = std::allocator<T>>

basic & stdex::stream::basic::write_str | ( | const std::basic_string< T, TR, AX > & | 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_str() [2/2]

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