LibCppBinary
Modern cross-platform C++ binary parsing library
Loading...
Searching...
No Matches
Binary::FileStream Class Referenceabstract

Abstract base class representing a file stream. More...

#include <FileStream.h>

Inheritance diagram for Binary::FileStream:
Binary::Stream Binary::StandardFileStream

Public Member Functions

virtual std::string FileName () const =0
 Gets the name of the file.
virtual std::string FilePath () const =0
 Gets the full path to the file on disk.
virtual bool IsOpen () const =0
 Determines whether or not the file is open.
virtual bool FileExists () const =0
 Determines whether or not the file exists on disk.
virtual size_t FileSize () const =0
 Gets the size of the file associated with the stream.
virtual FileMode Mode () const =0
 Determines the mode the file is set to open in.
virtual void Open (FileMode mode)=0
 Opens the file in the specified mode.
virtual void Close ()=0
 Closes the file.
Public Member Functions inherited from Binary::Stream
virtual ~Stream ()=default
 Default destructor; properly destroys the instance.
virtual void Read (DataField *field) const =0
 Reads data from the stream into the specified field.
virtual void Read (DataStructure *structure) const =0
 Reads data from stream into the specified data structure.
virtual std::shared_ptr< ChunkHeaderFindNextChunk (std::string id) const =0
 Finds the next chunk header with the specified ID.
virtual void Write (const DataField *field)=0
 Writes data to the stream from the specified field.
virtual void Write (const DataStructure *structure)=0
 Writes the specified structure to the stream.
virtual size_t Position () const =0
 Gets the current position in the stream.
virtual void SetPosition (size_t position) const =0
 Sets the current position in the stream.
virtual size_t Beginning () const =0
 Gets the beginning position of the file.
virtual size_t End () const =0
 Gets the end position of the file.

Detailed Description

Abstract base class representing a file stream.

Classes that represent a file stream should derive from this class. This class accepts pointers to instances of DataField and other types composed of data fields for reading and writing to and from the binary file.

Member Function Documentation

◆ Close()

virtual void Binary::FileStream::Close ( )
pure virtual

Closes the file.

Postcondition
The stream is closed.
Exceptions
std::runtime_erroror implementation-specific exceptions if the file cannot be closed.

Implemented in Binary::StandardFileStream.

◆ FileExists()

virtual bool Binary::FileStream::FileExists ( ) const
pure virtual

Determines whether or not the file exists on disk.

Returns
True if it exists, otherwise false.

Implemented in Binary::StandardFileStream.

◆ FileName()

virtual std::string Binary::FileStream::FileName ( ) const
pure virtual

Gets the name of the file.

Returns
A string representing the name of the file.

Implemented in Binary::StandardFileStream.

◆ FilePath()

virtual std::string Binary::FileStream::FilePath ( ) const
pure virtual

Gets the full path to the file on disk.

Returns
A string representing the full path to the file.

Implemented in Binary::StandardFileStream.

◆ FileSize()

virtual size_t Binary::FileStream::FileSize ( ) const
pure virtual

Gets the size of the file associated with the stream.

Returns
The size of the file, in bytes.
Exceptions
std::overflow_errorif file size exceeds size_t limits.
std::filesystem::filesystem_errorif file size cannot be determined.

Implemented in Binary::StandardFileStream.

◆ IsOpen()

virtual bool Binary::FileStream::IsOpen ( ) const
pure virtual

Determines whether or not the file is open.

Returns
True if it is open, otherwise false.

Implemented in Binary::StandardFileStream.

◆ Mode()

virtual FileMode Binary::FileStream::Mode ( ) const
pure virtual

Determines the mode the file is set to open in.

Returns
The file mode.

Implemented in Binary::StandardFileStream.

◆ Open()

virtual void Binary::FileStream::Open ( FileMode mode)
pure virtual

Opens the file in the specified mode.

Parameters
modeThe mode to open the file in.
Precondition
File path is set to a valid path for the implementation.
Postcondition
If successful, the stream is open in the specified mode.
Exceptions
std::runtime_erroror implementation-specific exceptions if the file cannot be opened.

Implemented in Binary::StandardFileStream.


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