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

‍UTF-8 byte-order-mark

More...

#include <stdex/stream.hpp>

Inheritance diagram for stdex::stream::basic:
stdex::stream::basic_file stdex::stream::basic_sys stdex::stream::converter stdex::stream::fifo stdex::stream::replicator stdex::stream::socket stdex::stream::cache stdex::stream::diag_file stdex::stream::file stdex::stream::file_window stdex::stream::memory_file stdex::stream::file stdex::base64_reader stdex::base64_writer stdex::stream::async_reader< CAPACITY > stdex::stream::async_writer< CAPACITY > stdex::stream::buffer stdex::stream::limiter stdex::stream_hasher< T >

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 >
basicread_data (T &data)
 Reads one primitive data type.
 
template<class T >
basicwrite_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 T_from , class T_to , class _Traits = std::char_traits<T_to>, class _Ax = std::allocator<T_to>>
size_t readln (std::basic_string< T_to, _Traits, _Ax > &wstr, charset_encoder< T_from, T_to > &encoder)
 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 T_from , class T_to , class _Traits = std::char_traits<T_to>, class _Ax = std::allocator<T_to>>
size_t readln_and_attach (std::basic_string< T_to, _Traits, _Ax > &wstr, 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 *wstr, 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 *wstr, 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 _Traits = std::char_traits<T_from>, class _Ax = std::allocator<T_from>>
size_t write_array (const std::basic_string< T_from, _Traits, _Ax > &wstr, charset_encoder< T_from, T_to > &encoder)
 Writes array of characters to the stream.
 
template<class _Elem , class _Traits = std::char_traits<_Elem>, class _Ax = std::allocator<_Elem>>
basicread_str (std::basic_string< _Elem, _Traits, _Ax > &data)
 Reads length-prefixed string from the stream.
 
template<class T >
basicwrite_str (const T *data)
 Writes string to the stream length-prefixed.
 
template<class _Elem , class _Traits = std::char_traits<_Elem>, class _Ax = std::allocator<_Elem>>
basicwrite_str (const std::basic_string< _Elem, _Traits, _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.
 
basicoperator>> (int8_t &data)
 
basicoperator<< (const int8_t data)
 
basicoperator>> (int16_t &data)
 
basicoperator<< (const int16_t data)
 
basicoperator>> (int32_t &data)
 
basicoperator<< (const int32_t data)
 
basicoperator>> (int64_t &data)
 
basicoperator<< (const int64_t data)
 
basicoperator>> (uint8_t &data)
 
basicoperator<< (const uint8_t data)
 
basicoperator>> (uint16_t &data)
 
basicoperator<< (const uint16_t data)
 
basicoperator>> (uint32_t &data)
 
basicoperator<< (const uint32_t data)
 
basicoperator>> (uint64_t &data)
 
basicoperator<< (const uint64_t data)
 
basicoperator>> (float &data)
 
basicoperator<< (const float data)
 
basicoperator>> (double &data)
 
basicoperator<< (const double data)
 
basicoperator>> (char &data)
 
basicoperator<< (const char data)
 
template<class _Elem , class _Traits = std::char_traits<_Elem>, class _Ax = std::allocator<_Elem>>
basicoperator>> (std::basic_string< _Elem, _Traits, _Ax > &data)
 
template<class T >
basicoperator<< (const T *data)
 
template<class _Elem , class _Traits = std::char_traits<_Elem>, class _Ax = std::allocator<_Elem>>
basicoperator<< (const std::basic_string< _Elem, _Traits, _Ax > &data)
 
template<class _Ty , class _Alloc = std::allocator<_Ty>>
basicoperator<< (const std::vector< _Ty, _Alloc > &data)
 
template<class _Ty , class _Alloc = std::allocator<_Ty>>
basicoperator>> (std::vector< _Ty, _Alloc > &data)
 
template<class _Kty , class _Pr = std::less<_Kty>, class _Alloc = std::allocator<_Kty>>
basicoperator<< (const std::set< _Kty, _Pr, _Alloc > &data)
 
template<class _Kty , class _Pr = std::less<_Kty>, class _Alloc = std::allocator<_Kty>>
basicoperator>> (std::set< _Kty, _Pr, _Alloc > &data)
 
template<class _Kty , class _Pr = std::less<_Kty>, class _Alloc = std::allocator<_Kty>>
basicoperator<< (const std::multiset< _Kty, _Pr, _Alloc > &data)
 
template<class _Kty , class _Pr = std::less<_Kty>, class _Alloc = std::allocator<_Kty>>
basicoperator>> (std::multiset< _Kty, _Pr, _Alloc > &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

◆ flush()

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

◆ 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]dataBuffer to store read data
[in]lengthByte 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::base64_reader, stdex::stream_hasher< T >, 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::socket, 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]dataWhere 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_lengthByte 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]dataString 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 T_from , class T_to , class _Traits = std::char_traits<T_to>, class _Ax = std::allocator<T_to>>
size_t stdex::stream::basic::readln ( std::basic_string< T_to, _Traits, _Ax > &  wstr,
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() [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)
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 T_from , class T_to , class _Traits = std::char_traits<T_to>, class _Ax = std::allocator<T_to>>
size_t stdex::stream::basic::readln_and_attach ( std::basic_string< T_to, _Traits, _Ax > &  wstr,
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)
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]dataBuffer to write data from
[in]lengthNumber of bytes to write
Returns
Number of bytes succesfully written. On error, stream state is set to state_t::fail.

Reimplemented in stdex::base64_writer, stdex::stream_hasher< T >, 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::socket, 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]

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

Writes array of characters to the stream.

Parameters
[in]wstrString to write
[in]num_charsString code unit count limit
[in]encoderEncoder for encoding string
Returns
Number of code units written

◆ write_array() [3/4]

template<class T_from , class T_to , class _Traits = std::char_traits<T_from>, class _Ax = std::allocator<T_from>>
size_t stdex::stream::basic::write_array ( const std::basic_string< T_from, _Traits, _Ax > &  wstr,
charset_encoder< T_from, T_to > &  encoder 
)
inline

Writes array of characters to the stream.

Parameters
[in]wstrString to write
[in]encoderEncoder 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 *  wstr,
charset_encoder< T_from, T_to > &  encoder 
)
inline

Writes array of characters to the stream.

Parameters
[in]wstrString to write. Must be zero-terminated.
[in]encoderEncoder 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]dataData 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 _Elem , class _Traits = std::char_traits<_Elem>, class _Ax = std::allocator<_Elem>>
basic & stdex::stream::basic::write_str ( const std::basic_string< _Elem, _Traits, _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]dataString 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]dataString 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: