Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
sese::io::FileStream Class Referencefinal

File stream class. More...

#include <FileStream.h>

Inheritance diagram for sese::io::FileStream:
sese::io::Stream sese::io::Closeable sese::io::PeekableStream sese::io::InputStream sese::io::OutputStream

Public Types

using Ptr = std::shared_ptr<FileStream>
 
- Public Types inherited from sese::io::Stream
typedef std::shared_ptr< StreamPtr
 
- Public Types inherited from sese::io::InputStream
typedef std::shared_ptr< InputStreamPtr
 
- Public Types inherited from sese::io::OutputStream
typedef std::shared_ptr< OutputStreamPtr
 
- Public Types inherited from sese::io::PeekableStream
typedef std::shared_ptr< PeekableStreamPtr
 

Public Member Functions

 ~FileStream () override=default
 
int64_t read (void *buffer, size_t length) override
 
int64_t write (const void *buffer, size_t length) override
 
void close () override
 
int64_t peek (void *buffer, size_t length) override
 
int64_t trunc (size_t length) override
 
bool eof () const
 
int64_t getSeek () const
 
int32_t setSeek (int64_t offset, int32_t whence) const
 
int32_t setSeek (int64_t offset, Seek type) const
 
int32_t flush () const
 
int32_t getFd () const
 
- Public Member Functions inherited from sese::io::InputStream
virtual ~InputStream () noexcept=default
 
- Public Member Functions inherited from sese::io::OutputStream
virtual ~OutputStream () noexcept=default
 
int64_t write (const std::string_view &buffer)
 
int64_t write (const text::StringView &buffer)
 
template<typename T >
int64_t write (std::vector< T > &buffer)
 
template<typename T , size_t N>
int64_t write (std::array< T, N > &buffer)
 
- Public Member Functions inherited from sese::io::Closeable
virtual ~Closeable ()=default
 
- Public Member Functions inherited from sese::io::PeekableStream
virtual ~PeekableStream ()=default
 

Static Public Member Functions

static FileStream::Ptr create (const std::string &file_path, const char *mode) noexcept
 
static FileStream::Ptr createWithPath (const system::Path &path, const char *mode) noexcept
 
static Result< Ptr, ErrorCodecreateEx (const std::string &file_path, const char *mode) noexcept
 

Static Public Attributes

static constexpr auto B_READ = "rb"
 
static constexpr auto B_WRITE_TRUNC = "wb"
 
static constexpr auto B_WRITE_APPEND = "ab"
 
static constexpr auto B_TRUNC = "wb+"
 
static constexpr auto B_APPEND = "ab+"
 
static constexpr auto T_READ = "rt"
 
static constexpr auto T_WRITE_TRUNC = "wt"
 
static constexpr auto T_WRITE_APPEND = "at"
 
static constexpr auto T_TRUNC = "wt+"
 
static constexpr auto T_APPEND = "at+"
 

Private Member Functions

 FileStream () noexcept=default
 

Private Attributes

FILE * file = nullptr
 

Detailed Description

File stream class.

Member Typedef Documentation

◆ Ptr

using sese::io::FileStream::Ptr = std::shared_ptr<FileStream>

Constructor & Destructor Documentation

◆ ~FileStream()

sese::io::FileStream::~FileStream ( )
overridedefault

◆ FileStream()

sese::io::FileStream::FileStream ( )
privatedefaultnoexcept

Member Function Documentation

◆ close()

void FileStream::close ( )
overridevirtual

Implements sese::io::Closeable.

References file.

◆ create()

FileStream::Ptr FileStream::create ( const std::string & file_path,
const char * mode )
staticnoexcept

◆ createEx()

sese::Result< FileStream::Ptr, sese::ErrorCode > FileStream::createEx ( const std::string & file_path,
const char * mode )
staticnoexcept

◆ createWithPath()

FileStream::Ptr FileStream::createWithPath ( const system::Path & path,
const char * mode )
staticnoexcept

Open a file in UNIX-LIKE style

Parameters
pathUNIX-LIKE path
modeOpen mode
Return values
nullptrFailed to open

References create().

◆ eof()

bool FileStream::eof ( ) const
nodiscard

This function is used to determine if the end of the file has been reached

Warning
This requires an initial read failure to obtain a valid value
Returns
Result

References file.

◆ flush()

int32_t FileStream::flush ( ) const
nodiscard

References file.

◆ getFd()

int32_t FileStream::getFd ( ) const
nodiscard

References file.

◆ getSeek()

int64_t FileStream::getSeek ( ) const
nodiscard

References file.

◆ peek()

int64_t FileStream::peek ( void * buffer,
size_t length )
overridevirtual

Read content without stepping

Parameters
bufferBuffer
lengthBuffer size
Returns
Actual size read

Implements sese::io::PeekableStream.

References sese::io::CUR, read(), and setSeek().

◆ read()

int64_t FileStream::read ( void * buffer,
size_t length )
overridevirtual

Implements sese::io::InputStream.

References file.

Referenced by peek().

◆ setSeek() [1/2]

int32_t FileStream::setSeek ( int64_t offset,
int32_t whence ) const
nodiscard

References file.

Referenced by peek(), and trunc().

◆ setSeek() [2/2]

int32_t FileStream::setSeek ( int64_t offset,
Seek type ) const
nodiscard

References file.

◆ trunc()

int64_t FileStream::trunc ( size_t length)
overridevirtual

Step only, without reading content

Parameters
lengthStep size
Returns
Actual step size

Implements sese::io::PeekableStream.

References sese::io::CUR, file, and setSeek().

◆ write()

int64_t FileStream::write ( const void * buffer,
size_t length )
overridevirtual

Implements sese::io::OutputStream.

References file.

Member Data Documentation

◆ B_APPEND

auto sese::io::FileStream::B_APPEND = "ab+"
staticconstexpr

◆ B_READ

◆ B_TRUNC

auto sese::io::FileStream::B_TRUNC = "wb+"
staticconstexpr

◆ B_WRITE_APPEND

auto sese::io::FileStream::B_WRITE_APPEND = "ab"
staticconstexpr

◆ B_WRITE_TRUNC

auto sese::io::FileStream::B_WRITE_TRUNC = "wb"
staticconstexpr

◆ file

FILE* sese::io::FileStream::file = nullptr
private

◆ T_APPEND

auto sese::io::FileStream::T_APPEND = "at+"
staticconstexpr

◆ T_READ

auto sese::io::FileStream::T_READ = "rt"
staticconstexpr

◆ T_TRUNC

auto sese::io::FileStream::T_TRUNC = "wt+"
staticconstexpr

◆ T_WRITE_APPEND

auto sese::io::FileStream::T_WRITE_APPEND = "at"
staticconstexpr

◆ T_WRITE_TRUNC

auto sese::io::FileStream::T_WRITE_TRUNC = "wt"
staticconstexpr

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