stdex
Additional custom or not Standard C++ covered algorithms
All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
stdex::stream::basic_file Class Referenceabstract

Basic seekable stream operations. More...

#include <stdex/stream.hpp>

Inheritance diagram for stdex::stream::basic_file:
stdex::stream::basic stdex::stream::cache stdex::stream::diag_file stdex::stream::file stdex::stream::file_window stdex::stream::memory_file stdex::stream::cached_file

Public Member Functions

virtual std::vector< uint8_t > read_remainder (size_t max_length=SIZE_MAX)
 Reads and returns remainder of the stream.
 
virtual fpos_t seek (foff_t offset, seek_t how=seek_t::beg)=0
 Seeks to specified relative file position.
 
fpos_t seekbeg (fpos_t offset)
 Seeks to absolute file position.
 
fpos_t seekcur (foff_t offset)
 Seeks to relative from current file position.
 
fpos_t seekend (foff_t offset)
 Seeks to relative from end file position.
 
virtual void skip (fsize_t amount)
 Skips given amount of bytes of data on the stream.
 
virtual fpos_t tell () const =0
 Returns absolute file position in file or fpos_max if fails. This method does not update stream state.
 
virtual void lock (fpos_t offset, fsize_t length)
 Locks file section for exclusive access.
 
virtual void unlock (fpos_t offset, fsize_t length)
 Unlocks file section for exclusive access.
 
virtual fsize_t size () const =0
 Returns file size Should the file size cannot be determined, the method returns fsize_max and it does not reset the state to failed.
 
virtual void truncate ()=0
 Sets file size - truncates the remainder of file content from the current file position to the end of file.
 
virtual time_point ctime () const
 Returns file creation time.
 
virtual time_point atime () const
 Returns file access time.
 
virtual time_point mtime () const
 Returns file modification time.
 
virtual void set_ctime (time_point date)
 Sets file create time.
 
virtual void set_atime (time_point date)
 Sets file access time.
 
virtual void set_mtime (time_point date)
 Sets file modification time.
 
charset_id read_charset (charset_id default_charset=charset_id::system)
 Attempts to detect text-file charset based on UTF-32, UTF-16 or UTF-8 BOM.
 
- Public Member Functions inherited from stdex::stream::basic
 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.
 
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.
 
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 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>>
basicread_str (std::basic_string< T, TR, 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 T , class TR = std::char_traits<T>, class AX = std::allocator<T>>
basicwrite_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.
 
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 T , class TR = std::char_traits<T>, class AX = std::allocator<T>>
basicoperator>> (std::basic_string< T, TR, AX > &data)
 
template<class T >
basicoperator<< (const T *data)
 
template<class T , class TR = std::char_traits<T>, class AX = std::allocator<T>>
basicoperator<< (const std::basic_string< T, TR, AX > &data)
 
template<class T , class AX = std::allocator<T>>
basicoperator<< (const std::vector< T, AX > &data)
 
template<class T , class AX = std::allocator<T>>
basicoperator>> (std::vector< T, AX > &data)
 
template<class KEY , class PR = std::less<KEY>, class AX = std::allocator<KEY>>
basicoperator<< (const std::set< KEY, PR, AX > &data)
 
template<class KEY , class PR = std::less<KEY>, class AX = std::allocator<KEY>>
basicoperator>> (std::set< KEY, PR, AX > &data)
 
template<class KEY , class PR = std::less<KEY>, class AX = std::allocator<KEY>>
basicoperator<< (const std::multiset< KEY, PR, AX > &data)
 
template<class KEY , class PR = std::less<KEY>, class AX = std::allocator<KEY>>
basicoperator>> (std::multiset< KEY, PR, AX > &data)
 

Additional Inherited Members

- Protected Attributes inherited from stdex::stream::basic
state_t m_state
 

Detailed Description

Basic seekable stream operations.

Member Function Documentation

◆ atime()

virtual time_point stdex::stream::basic_file::atime ( ) const
inlinevirtual

Returns file access time.

Reimplemented in stdex::stream::cache, and stdex::stream::file.

◆ ctime()

virtual time_point stdex::stream::basic_file::ctime ( ) const
inlinevirtual

Returns file creation time.

Reimplemented in stdex::stream::cache, and stdex::stream::file.

◆ lock()

virtual void stdex::stream::basic_file::lock ( fpos_t offset,
fsize_t length )
inlinevirtual

Locks file section for exclusive access.

Reimplemented in stdex::stream::cache, stdex::stream::diag_file, stdex::stream::file, and stdex::stream::file_window.

◆ mtime()

virtual time_point stdex::stream::basic_file::mtime ( ) const
inlinevirtual

Returns file modification time.

Reimplemented in stdex::stream::cache, and stdex::stream::file.

◆ read_charset()

charset_id stdex::stream::basic_file::read_charset ( charset_id default_charset = charset_id::system)
inline

Attempts to detect text-file charset based on UTF-32, UTF-16 or UTF-8 BOM.

Parameters
[in]default_charsetFallback charset to return when no BOM detected.

◆ read_remainder()

virtual std::vector< uint8_t > stdex::stream::basic_file::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 from stdex::stream::basic.

◆ seek()

virtual fpos_t stdex::stream::basic_file::seek ( foff_t offset,
seek_t how = seek_t::beg )
pure virtual

Seeks to specified relative file position.

Returns
Absolute file position after seek, or fpos_max if seek failed.

Implemented in stdex::stream::cache, stdex::stream::diag_file, stdex::stream::file, stdex::stream::file_window, and stdex::stream::memory_file.

◆ seekbeg()

fpos_t stdex::stream::basic_file::seekbeg ( fpos_t offset)
inline

Seeks to absolute file position.

Returns
Absolute file position after seek

◆ seekcur()

fpos_t stdex::stream::basic_file::seekcur ( foff_t offset)
inline

Seeks to relative from current file position.

Returns
Absolute file position after seek

◆ seekend()

fpos_t stdex::stream::basic_file::seekend ( foff_t offset)
inline

Seeks to relative from end file position.

Returns
Absolute file position after seek

◆ set_atime()

virtual void stdex::stream::basic_file::set_atime ( time_point date)
inlinevirtual

Sets file access time.

Reimplemented in stdex::stream::cache, and stdex::stream::file.

◆ set_ctime()

virtual void stdex::stream::basic_file::set_ctime ( time_point date)
inlinevirtual

Sets file create time.

Reimplemented in stdex::stream::cache, and stdex::stream::file.

◆ set_mtime()

virtual void stdex::stream::basic_file::set_mtime ( time_point date)
inlinevirtual

Sets file modification time.

Reimplemented in stdex::stream::cache, and stdex::stream::file.

◆ size()

virtual fsize_t stdex::stream::basic_file::size ( ) const
pure virtual

Returns file size Should the file size cannot be determined, the method returns fsize_max and it does not reset the state to failed.

Implemented in stdex::stream::cache, stdex::stream::diag_file, stdex::stream::file, stdex::stream::file_window, and stdex::stream::memory_file.

◆ skip()

virtual void stdex::stream::basic_file::skip ( fsize_t amount)
inlinevirtual

Skips given amount of bytes of data on the stream.

Reimplemented from stdex::stream::basic.

Reimplemented in stdex::stream::file_window.

◆ tell()

virtual fpos_t stdex::stream::basic_file::tell ( ) const
pure virtual

Returns absolute file position in file or fpos_max if fails. This method does not update stream state.

Returns
Absolute file position or fpos_max if position cannot be determined.

Implemented in stdex::stream::cache, stdex::stream::diag_file, stdex::stream::file, stdex::stream::file_window, and stdex::stream::memory_file.

◆ truncate()

virtual void stdex::stream::basic_file::truncate ( )
pure virtual

Sets file size - truncates the remainder of file content from the current file position to the end of file.

Implemented in stdex::stream::cache, stdex::stream::diag_file, stdex::stream::file, stdex::stream::file_window, and stdex::stream::memory_file.

◆ unlock()

virtual void stdex::stream::basic_file::unlock ( fpos_t offset,
fsize_t length )
inlinevirtual

Unlocks file section for exclusive access.

Reimplemented in stdex::stream::cache, stdex::stream::diag_file, stdex::stream::file, and stdex::stream::file_window.


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