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::MemoryFile Class Reference

#include <MemoryFile.h>

Inherits MCore::File.

Public Types

enum  { TYPE_ID = 0x0000002 }
 

Public Member Functions

 MemoryFile ()
 
 ~MemoryFile ()
 
uint32 GetType () const override
 
bool Open (uint8 *memoryStart=nullptr, size_t length=0)
 
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
 
uint8 * GetMemoryStart () const
 
size_t GetPreAllocSize () const
 
void SetPreAllocSize (size_t newSizeInBytes)
 
bool LoadFromDiskFile (const char *fileName)
 
bool SaveToDiskFile (const char *fileName)
 
- 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)
 

Detailed Description

A file stored in memory, located at a given position with a known length in bytes. It is also possible to write to the file. In this case, when writing past the end of the file, new memory will be allocated.

Constructor & Destructor Documentation

◆ MemoryFile()

MCore::MemoryFile::MemoryFile ( )
inline

Constructor.

◆ ~MemoryFile()

MCore::MemoryFile::~MemoryFile ( )
inline

Destructor. Automatically closes the file.

Member Function Documentation

◆ Close()

void MCore::MemoryFile::Close ( )
overridevirtual

Close the file.

Implements MCore::File.

◆ Flush()

void MCore::MemoryFile::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::MemoryFile::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.

◆ GetFileSize()

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

Returns the size of this file in bytes.

Returns
The filesize in bytes.

Implements MCore::File.

◆ GetIsEOF()

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

Check if we reached the end of the file or not.

Returns
Returns true when we have returned the end of the file. Otherwise false is returned.

Implements MCore::File.

◆ GetIsOpen()

bool MCore::MemoryFile::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.

◆ GetMemoryStart()

uint8 * MCore::MemoryFile::GetMemoryStart ( ) const

Get the memory start address, where the data is stored.

Returns
The memory start address that points to the start of the file.

◆ GetNextByte()

uint8 MCore::MemoryFile::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::MemoryFile::GetPos ( ) const
overridevirtual

Returns the position in the file.

Returns
The offset in the file in bytes.

Implements MCore::File.

◆ GetPreAllocSize()

size_t MCore::MemoryFile::GetPreAllocSize ( ) const

Get the pre-allocation size, which is the number of bytes that are allocated extra when writing to the file and the data wouldn't fit in the file anymore. On default this value is 1024. This can reduce the number of reallocations being performed significantly.

Returns
The pre-allocation size, in bytes.

◆ GetType()

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

Get the unique type ID.

Returns
The type identification number.

Implements MCore::Stream.

◆ LoadFromDiskFile()

bool MCore::MemoryFile::LoadFromDiskFile ( const char *  fileName)

Load memory file from disk. The memory file object should be newly created or not containing any data yet when calling this function. Also please make sure that the memory file is opened.

Parameters
fileNameThe full or relative path/file name of the disk file to load into this memory file.
Returns
True when loading worked fine, false if any error occurred. All errors that happen will be logged.

◆ Open()

bool MCore::MemoryFile::Open ( uint8 *  memoryStart = nullptr,
size_t  length = 0 
)

Open the file from a given memory location, with a given length in bytes. If you want to create a new block of memory that can grow, like creating a new file on disk, you can pass nullptr as memory start address, and as length the initial memory block size you want to be allocated, or 0 if it should start empty.

Parameters
memoryStartThe memory position of the first byte in the file, or nullptr when you want to automatically allocate memory.
lengthThe length in bytes of the file. So the size in bytes of the memory block.
Returns
Returns true when the file could be opened, otherwise false.

◆ Read()

size_t MCore::MemoryFile::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
The number of bytes read.

Implements MCore::File.

◆ SaveToDiskFile()

bool MCore::MemoryFile::SaveToDiskFile ( const char *  fileName)

Save the memory file to disk. The memory file object should contain data yet when calling this function else the resulting disk file will be empty. Also please make sure that the memory file is opened.

Parameters
fileNameThe full or relative path/file name of the disk file to be created.
Returns
True when saving worked fine, false if any error occurred. All errors that happen will be logged.

◆ Seek()

bool MCore::MemoryFile::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.

◆ SetPreAllocSize()

void MCore::MemoryFile::SetPreAllocSize ( size_t  newSizeInBytes)

Set the pre-allocation size, which is the number of bytes that are allocated extra when writing to the file and the data wouldn't fit in the file anymore. On default this value is 1024. This can reduce the number of reallocations being performed significantly.

Parameters
newSizeInBytesThe size in bytes to allocate on top of the required allocation size.

◆ Write()

size_t MCore::MemoryFile::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::MemoryFile::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.


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