CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::FileDataStream Class Referencefinal

A data stream that reads or writes data into a file. More...

#include <CeresEngine/Foundation/IO/Stream.hpp>

Inheritance diagram for CeresEngine::FileDataStream:
CeresEngine::IDataStream CeresEngine::IInputStream CeresEngine::IOutputStream CeresEngine::IStream CeresEngine::IStream

Public Member Functions

 FileDataStream (const FilePath &path, bool writing=false)
 Creates a new file stream by opening the file at the given path.
 
 FileDataStream (const FileDataStream &other)
 Creates a new file data stream by opening the same file as other.
 
 FileDataStream (FileDataStream &&other) noexcept
 Creates a new file data stream by moving the already open stream other.
 
 ~FileDataStream () final
 Destroys the data stream and closes the file.
 
const FilePathgetPath () const noexcept
 The path to the file open in the stream.
 
FILEgetStream () const noexcept
 The open stream descriptor.
 
bool isSeekable (Seek mode=Seek::Start) const noexcept final
 Checks if the stream is seekable.
 
void seek (std::streamsize position, Seek mode=Seek::Start) final
 Changes the position of the data stream.
 
bool isTellable () const noexcept final
 Checks if the stream knows it's current absolute position.
 
size_t tell () final
 Gets the absolute stream position, in bytes.
 
bool isSizeKnown () const noexcept final
 Checks if the stream knows the size of the data.
 
size_t size () final
 Gets the number of bytes available on the stream.
 
bool isReadable () const noexcept final
 Checks if the stream is readable.
 
size_t read (void *data, size_t n) final
 Reads data from the data stream to a buffer of raw memory data with length n.
 
bool isWritable () const noexcept final
 Checks if the stream is writable.
 
size_t write (const void *data, size_t n) final
 Writes data to the data stream from a buffer of raw memory data with length n.
 
- Public Member Functions inherited from CeresEngine::IInputStream
template<typename T >
size_t read (const MemoryView< T > &memoryView)
 Reads data from the strea into a memory view.
 
template<typename T >
size_t read (const StridedMemoryView< T > &memoryView)
 Reads data from the stream into a strided memory view.
 
Optional< StringreadString ()
 Reads data from the buffer as a C++ String.
 
template<typename T >
requires std::is_trivially_copyable_v<T>
Optional< Tread ()
 Reads a trivially copyable obhect from the stream.
 
virtual bool invalidate ()
 In the stream is buffered, invalidates any buffered read data from the stream.
 
- Public Member Functions inherited from CeresEngine::IStream
 IStream ()=default
 
 IStream (const IStream &) noexcept=delete
 
IStreamoperator= (const IStream &) noexcept=delete
 
 IStream (IStream &&) noexcept=default
 
IStreamoperator= (IStream &&) noexcept=default
 
virtual ~IStream () noexcept=default
 
void skip (const size_t n)
 Skips n bytes from the data stream.
 
- Public Member Functions inherited from CeresEngine::IOutputStream
template<typename T >
size_t write (const MemoryView< const T > &memoryView)
 Writes data from a memory view to the stream.
 
template<typename T >
size_t write (const StridedMemoryView< const T > &memoryView)
 Writes data from a strided memory view to the stream.
 
size_t writeString (const StringView string)
 Writes a string to the data stream.
 
template<typename T >
requires std::is_trivially_copyable_v<T>
bool write (T value)
 Writes a trivially copyable object to the stream.
 
virtual bool flush ()
 In the stream is buffered, invalidates any buffered write data from to stream.
 

Private Attributes

FilePath path
 The path to the file open in the stream.
 
FILEstream = nullptr
 The open stream descriptor.
 

Additional Inherited Members

- Public Types inherited from CeresEngine::IStream
enum class  Seek { Start = SEEK_SET , Current = SEEK_CUR , End = SEEK_END }
 An enumeration that describes how a data stream should be seeked. More...
 

Detailed Description

A data stream that reads or writes data into a file.

Constructor & Destructor Documentation

◆ FileDataStream() [1/3]

CeresEngine::FileDataStream::FileDataStream ( const FilePath path,
bool  writing = false 
)
explicit

Creates a new file stream by opening the file at the given path.

Parameters
pathThe file path to be open

◆ FileDataStream() [2/3]

CeresEngine::FileDataStream::FileDataStream ( const FileDataStream other)

Creates a new file data stream by opening the same file as other.

Parameters
otherThe stream to open the same file as

◆ FileDataStream() [3/3]

CeresEngine::FileDataStream::FileDataStream ( FileDataStream &&  other)
noexcept

Creates a new file data stream by moving the already open stream other.

Parameters
otherThe stream to be moved

◆ ~FileDataStream()

CeresEngine::FileDataStream::~FileDataStream ( )
final

Destroys the data stream and closes the file.

Member Function Documentation

◆ getPath()

const FilePath & CeresEngine::FileDataStream::getPath ( ) const
inlinenoexcept

The path to the file open in the stream.

◆ getStream()

FILE * CeresEngine::FileDataStream::getStream ( ) const
inlinenoexcept

The open stream descriptor.

◆ isReadable()

bool CeresEngine::FileDataStream::isReadable ( ) const
inlinefinalvirtualnoexcept

Checks if the stream is readable.

If this method returns true, read() is safe to be called on this stream.

Reimplemented from CeresEngine::IInputStream.

◆ isSeekable()

bool CeresEngine::FileDataStream::isSeekable ( Seek  mode = Seek::Start) const
inlinefinalvirtualnoexcept

Checks if the stream is seekable.

If this method returns true, seek() is safe to be called on this stream.

Reimplemented from CeresEngine::IStream.

◆ isSizeKnown()

bool CeresEngine::FileDataStream::isSizeKnown ( ) const
inlinefinalvirtualnoexcept

Checks if the stream knows the size of the data.

If this method returns true, size() is safe to be called on this stream.

Reimplemented from CeresEngine::IStream.

◆ isTellable()

bool CeresEngine::FileDataStream::isTellable ( ) const
inlinefinalvirtualnoexcept

Checks if the stream knows it's current absolute position.

If this method returns true, tell() is safe to be called on this stream.

Reimplemented from CeresEngine::IStream.

◆ isWritable()

bool CeresEngine::FileDataStream::isWritable ( ) const
inlinefinalvirtualnoexcept

Checks if the stream is writable.

If this method returns true, write() is safe to be called on this stream.

Reimplemented from CeresEngine::IOutputStream.

◆ read()

size_t CeresEngine::FileDataStream::read ( void data,
size_t  n 
)
finalvirtual

Reads data from the data stream to a buffer of raw memory data with length n.

Note
This method is only callable if isReadable() returns true.
Parameters
dataThe memory location to which read data should be placed.
nThe maximum number of bytes to be read from the data stream.
Returns
The number of bytes actually read. Can be smaller than n. If 0, indicates that the stream has ended.

Reimplemented from CeresEngine::IInputStream.

◆ seek()

void CeresEngine::FileDataStream::seek ( std::streamsize  position,
Seek  mode = Seek::Start 
)
finalvirtual

Changes the position of the data stream.

Note
This method is only callable if isSeekable() returns true.
Parameters
positionThe position to set the data stream to.
modeThe mode to change the data stream position.

Reimplemented from CeresEngine::IStream.

◆ size()

size_t CeresEngine::FileDataStream::size ( )
finalvirtual

Gets the number of bytes available on the stream.

Note
This method is only callable if isSizeKnown() returns true.

Reimplemented from CeresEngine::IStream.

◆ tell()

size_t CeresEngine::FileDataStream::tell ( )
finalvirtual

Gets the absolute stream position, in bytes.

Note
This method is only callable if isTellable() returns true.

Reimplemented from CeresEngine::IStream.

◆ write()

size_t CeresEngine::FileDataStream::write ( const void data,
size_t  n 
)
finalvirtual

Writes data to the data stream from a buffer of raw memory data with length n.

Note
This method is only callable if isWritable() returns true.
Parameters
dataThe memory location to which written data should be copied from.
nThe maximum number of bytes to be write to the data stream.
Returns
The number of bytes actually written. Can be smaller than n, in that case the write operation must be repeated to ensure that all data was written. If 0, indicates that the stream has ended.

Reimplemented from CeresEngine::IOutputStream.

Member Data Documentation

◆ path

FilePath CeresEngine::FileDataStream::path
private

The path to the file open in the stream.

◆ stream

FILE* CeresEngine::FileDataStream::stream = nullptr
private

The open stream descriptor.


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