#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 Stream & | operator<< (bool b) |
virtual Stream & | operator<< (char ch) |
virtual Stream & | operator<< (uint8 ch) |
virtual Stream & | operator<< (int16 number) |
virtual Stream & | operator<< (uint16 number) |
virtual Stream & | operator<< (int32 number) |
virtual Stream & | operator<< (uint32 number) |
virtual Stream & | operator<< (uint64 number) |
virtual Stream & | operator<< (int64 number) |
virtual Stream & | operator<< (float number) |
virtual Stream & | operator<< (double number) |
virtual Stream & | operator<< (AZStd::string &text) |
virtual Stream & | operator<< (const char *text) |
virtual Stream & | operator>> (bool &b) |
virtual Stream & | operator>> (char &ch) |
virtual Stream & | operator>> (uint8 &ch) |
virtual Stream & | operator>> (int16 &number) |
virtual Stream & | operator>> (uint16 &number) |
virtual Stream & | operator>> (int32 &number) |
virtual Stream & | operator>> (uint32 &number) |
virtual Stream & | operator>> (int64 &number) |
virtual Stream & | operator>> (uint64 &number) |
virtual Stream & | operator>> (float &number) |
virtual Stream & | operator>> (double &number) |
virtual Stream & | operator>> (AZStd::string &text) |
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.
|
inline |
Constructor.
|
inline |
Destructor. Automatically closes the file.
|
overridevirtual |
Close the file.
Implements MCore::File.
|
overridevirtual |
Flush the file. All cached (not yet written) data will be forced to written when calling this method.
Implements MCore::File.
|
overridevirtual |
Seek ahead a given number of bytes. This can be used to skip a given number of upcoming bytes in the file.
numBytes | The number of bytes to seek ahead. |
Implements MCore::File.
|
overridevirtual |
|
overridevirtual |
Check if we reached the end of the file or not.
Implements MCore::File.
|
overridevirtual |
Check if the file has been opened already.
Implements MCore::File.
uint8 * MCore::MemoryFile::GetMemoryStart | ( | ) | const |
Get the memory start address, where the data is stored.
|
overridevirtual |
Reads and returns the next byte/character in the file. So this will increase the position in the file with one.
Implements MCore::File.
|
overridevirtual |
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.
|
overridevirtual |
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.
fileName | The full or relative path/file name of the disk file to load into this memory file. |
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.
memoryStart | The memory position of the first byte in the file, or nullptr when you want to automatically allocate memory. |
length | The length in bytes of the file. So the size in bytes of the memory block. |
|
overridevirtual |
Read a given amount of data from the file.
data | The pointer where to store the read data. |
length | The size in bytes of the data to read. |
Implements MCore::File.
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.
fileName | The full or relative path/file name of the disk file to be created. |
|
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.
offset | The offset in bytes (the position) in the file to seek to. |
Implements MCore::File.
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.
newSizeInBytes | The size in bytes to allocate on top of the required allocation size. |
|
overridevirtual |
Writes a given amount of data to the file.
data | The pointer to the data to write. |
length | The size in bytes of the data to write. |
Implements MCore::File.
|
overridevirtual |
Write a character or byte in the file.
value | The character or byte to write. |
Implements MCore::File.