Open 3D Engine EMotionFX Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
MCore::DiskFile Class Reference

#include <DiskFile.h>

Inherits MCore::File.

Public Types

enum  { TYPE_ID = 0x0000001 }
 
enum  EMode {
  READ = 0 , WRITE = 1 , READWRITE = 2 , READWRITECREATE = 3 ,
  APPEND = 4 , READWRITEAPPEND = 5
}
 

Public Member Functions

 DiskFile ()
 
virtual ~DiskFile ()
 
uint32 GetType () const override
 
virtual bool Open (const char *fileName, EMode mode)
 
void Close () override
 
void Flush () override
 
bool GetIsEOF () const override
 
uint8 GetNextByte () override
 
size_t GetPos () const override
 
bool WriteByte (uint8 value) override
 
bool Forward (size_t numBytes) override
 
bool Seek (size_t offset) override
 
size_t Write (const void *data, size_t length) override
 
size_t Read (void *data, size_t length) override
 
bool GetIsOpen () const override
 
size_t GetFileSize () const override
 
EMode GetFileMode () const
 
const AZStd::string & GetFileName () const
 
- Public Member Functions inherited from MCore::File
 File ()
 
virtual ~File ()
 
virtual void Close ()=0
 
virtual void Flush ()=0
 
virtual bool GetIsEOF () const =0
 
virtual uint8 GetNextByte ()=0
 
virtual size_t GetPos () const =0
 
virtual size_t GetFileSize () const =0
 
virtual bool WriteByte (uint8 value)=0
 
virtual bool Forward (size_t numBytes)=0
 
virtual bool Seek (size_t offset)=0
 
virtual size_t Read (void *data, size_t length)=0
 
virtual size_t Write (const void *data, size_t length)=0
 
virtual bool GetIsOpen () const =0
 
- Public Member Functions inherited from MCore::Stream
 Stream ()
 
virtual ~Stream ()
 
virtual uint32 GetType () const =0
 
virtual size_t Read (void *data, size_t length)
 
virtual size_t Write (const void *data, size_t length)
 
virtual Streamoperator<< (bool b)
 
virtual Streamoperator<< (char ch)
 
virtual Streamoperator<< (uint8 ch)
 
virtual Streamoperator<< (int16 number)
 
virtual Streamoperator<< (uint16 number)
 
virtual Streamoperator<< (int32 number)
 
virtual Streamoperator<< (uint32 number)
 
virtual Streamoperator<< (uint64 number)
 
virtual Streamoperator<< (int64 number)
 
virtual Streamoperator<< (float number)
 
virtual Streamoperator<< (double number)
 
virtual Streamoperator<< (AZStd::string &text)
 
virtual Streamoperator<< (const char *text)
 
virtual Streamoperator>> (bool &b)
 
virtual Streamoperator>> (char &ch)
 
virtual Streamoperator>> (uint8 &ch)
 
virtual Streamoperator>> (int16 &number)
 
virtual Streamoperator>> (uint16 &number)
 
virtual Streamoperator>> (int32 &number)
 
virtual Streamoperator>> (uint32 &number)
 
virtual Streamoperator>> (int64 &number)
 
virtual Streamoperator>> (uint64 &number)
 
virtual Streamoperator>> (float &number)
 
virtual Streamoperator>> (double &number)
 
virtual Streamoperator>> (AZStd::string &text)
 

Protected Attributes

AZStd::string m_fileName
 
FILE * m_file
 
EMode m_fileMode
 

Detailed Description

A standard file as we normally think of. In other words, a file stored on the harddisk or a CD or any other comparable medium. This is for binary files only. If you plan to read text files, please use the MCore::DiskTextFile class.

Member Enumeration Documentation

◆ EMode

File opening modes. Do not use a combination of these modes. Just pick one.

Enumerator
READ 

open for reading, if the file doesn't exist the Open method will fail.

WRITE 

open for writing, if the file already exists it will be overwritten.

READWRITE 

opens the file for both reading and writing, the file must already exist else the Open method will fail.

READWRITECREATE 

opens the file for both reading and writing, if the file exists already it will be overwritten.

APPEND 

opens for writing at the end of the file, will create a new file if it doesn't yet exist.

READWRITEAPPEND 

opens for reading and appending (writing), creates the file when it doesn't exist.

Constructor & Destructor Documentation

◆ DiskFile()

MCore::DiskFile::DiskFile ( )

The constructor.

◆ ~DiskFile()

virtual MCore::DiskFile::~DiskFile ( )
virtual

The destructor. Automatically closes the file.

Member Function Documentation

◆ Close()

void MCore::DiskFile::Close ( )
overridevirtual

Close the file.

Implements MCore::File.

◆ Flush()

void MCore::DiskFile::Flush ( )
overridevirtual

Flush the file. All cached (not yet written) data will be forced to written when calling this method.

Implements MCore::File.

◆ Forward()

bool MCore::DiskFile::Forward ( size_t  numBytes)
overridevirtual

Seek ahead a given number of bytes. This can be used to skip a given number of upcoming bytes in the file.

Parameters
numBytesThe number of bytes to seek ahead.
Returns
Returns true when succeeded or false when an error occured (for example when we where trying to read past the end of the file).

Implements MCore::File.

◆ GetFileMode()

EMode MCore::DiskFile::GetFileMode ( ) const

Returns the mode the file has been opened with.

Returns
The mode the file has been opened with. See enum EMode.

◆ GetFileName()

const AZStd::string & MCore::DiskFile::GetFileName ( ) const

Returns the name of the file as it has been opened.

Returns
The string containing the filename as it has been passed to the method Open.

◆ GetFileSize()

size_t MCore::DiskFile::GetFileSize ( ) const
overridevirtual

Returns the size of this file in bytes.

Returns
The filesize in bytes.

Implements MCore::File.

◆ GetIsEOF()

bool MCore::DiskFile::GetIsEOF ( ) const
overridevirtual

Returns true if we reached the end of this file, otherwise false is returned.

Implements MCore::File.

◆ GetIsOpen()

bool MCore::DiskFile::GetIsOpen ( ) const
overridevirtual

Check if the file has been opened already.

Returns
Returns true when the file has been opened, otherwise false.

Implements MCore::File.

◆ GetNextByte()

uint8 MCore::DiskFile::GetNextByte ( )
overridevirtual

Reads and returns the next byte/character in the file. So this will increase the position in the file with one.

Returns
The character or byte read.

Implements MCore::File.

◆ GetPos()

size_t MCore::DiskFile::GetPos ( ) const
overridevirtual

Returns the position in the file.

Returns
The offset in the file in bytes.

Implements MCore::File.

◆ GetType()

uint32 MCore::DiskFile::GetType ( ) const
overridevirtual

Get the unique type ID.

Returns
The type identification number.

Implements MCore::Stream.

◆ Open()

virtual bool MCore::DiskFile::Open ( const char *  fileName,
EMode  mode 
)
virtual

Try to open the file, given a filename and open mode. The file is always opened in binary mode. If you want to load text files, use MCore::DiskTextFile.

Parameters
fileNameThe filename on disk.
modeThe file open mode. See enum EMode for more information. Do NOT use a combination of these modes.
Returns
Returns true when successfully opened the file, otherwise false is returned.

◆ Read()

size_t MCore::DiskFile::Read ( void *  data,
size_t  length 
)
overridevirtual

Read a given amount of data from the file.

Parameters
dataThe pointer where to store the read data.
lengthThe size in bytes of the data to read.
Returns
Returns the number of bytes read.

Implements MCore::File.

◆ Seek()

bool MCore::DiskFile::Seek ( size_t  offset)
overridevirtual

Seek to a given byte position in the file, where 0 would be the beginning of the file. So we're talking about the absolute position in the file. After successfully executing this method the method GetPos will return the given offset.

Parameters
offsetThe offset in bytes (the position) in the file to seek to.
Returns
Returns true when successfully moved to the given position in the file, otherwise false.

Implements MCore::File.

◆ Write()

size_t MCore::DiskFile::Write ( const void *  data,
size_t  length 
)
overridevirtual

Writes a given amount of data to the file.

Parameters
dataThe pointer to the data to write.
lengthThe size in bytes of the data to write.
Returns
Returns the number of written bytes.

Implements MCore::File.

◆ WriteByte()

bool MCore::DiskFile::WriteByte ( uint8  value)
overridevirtual

Write a character or byte in the file.

Parameters
valueThe character or byte to write.
Returns
Returns true when successfully written, otherwise false is returned.

Implements MCore::File.

Member Data Documentation

◆ m_file

FILE* MCore::DiskFile::m_file
protected

The file handle.

◆ m_fileMode

EMode MCore::DiskFile::m_fileMode
protected

The mode we opened the file with.

◆ m_fileName

AZStd::string MCore::DiskFile::m_fileName
protected

The filename


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