![]() |
Public API Reference |
![]() |
Essentially a raw memory buffer which implements the abstract iFile interface. More...
#include <csutil/memfile.h>
Public Types | |
enum | Disposition { DISPOSITION_DELETE, DISPOSITION_PLATFORM_FREE, DISPOSITION_IGNORE, DISPOSITION_CS_FREE, DISPOSITION_FREE = DISPOSITION_CS_FREE } |
Disposition of memory buffer at destruction time. More... | |
Public Member Functions | |
virtual bool | AtEOF () |
Returns true if the stream is at end-of-file, else false. | |
csMemFile () | |
Construct an empty memory file. | |
csMemFile (const char *, size_t) | |
Construct a memory file from an existing memory buffer but do not free. | |
csMemFile (char *, size_t, Disposition=DISPOSITION_DELETE) | |
Construct a memory file from an existing memory buffer and free later. | |
csMemFile (iDataBuffer *buf, bool readOnly) | |
Construct a memory file from an existing data buffer. | |
void | Empty () |
Make file empty. | |
virtual void | Flush () |
Flush stream. | |
virtual csPtr< iDataBuffer > | GetAllData (bool nullterm=false) |
Request whole content of the file as a single data buffer. | |
csPtr< iDataBuffer > | GetAllData (CS::Memory::iAllocator *) |
Request whole content of the file as a single data buffer. | |
virtual const char * | GetData () const |
Returns a pointer to the memory buffer. | |
virtual const char * | GetName () |
Returns "#csMemFile". | |
csPtr< iFile > | GetPartialView (size_t offset, size_t size=(size_t)~0) |
Request whole or part of the content of the file as a file object. | |
virtual size_t | GetPos () |
Query current file pointer. | |
virtual size_t | GetSize () |
Query file size. | |
virtual int | GetStatus () |
Check (and clear) file last error status. | |
virtual size_t | Read (char *Data, size_t DataSize) |
Read DataSize bytes and place them into the buffer at which Data points. | |
virtual bool | SetPos (size_t newpos) |
Set new file pointer. | |
virtual size_t | Write (const char *Data, size_t DataSize) |
Write DataSize bytes from the buffer at which Data points. | |
virtual | ~csMemFile () |
Destructor. |
Essentially a raw memory buffer which implements the abstract iFile interface.
Disposition of memory buffer at destruction time.
Construct an empty memory file.
csMemFile::csMemFile | ( | const char * | , |
size_t | |||
) |
Construct a memory file from an existing memory buffer but do not free.
csMemFile::csMemFile | ( | char * | , |
size_t | , | ||
Disposition | = DISPOSITION_DELETE |
||
) |
Construct a memory file from an existing memory buffer and free later.
Note that when writing to the buffer, the original buffer may be discarded and a new one created due required resizing.
csMemFile::csMemFile | ( | iDataBuffer * | buf, |
bool | readOnly | ||
) |
Construct a memory file from an existing data buffer.
buf | The data buffer to use. |
readOnly | Whether to treat the buffer as read-only. If true , writing to the memory file will create a copy of the buffer. If false , changes will affect the buffer. Note that when writing to the buffer, the original buffer may be discarded and a new one created due required resizing. |
virtual csMemFile::~csMemFile | ( | ) | [virtual] |
Destructor.
virtual bool csMemFile::AtEOF | ( | ) | [virtual] |
Returns true if the stream is at end-of-file, else false.
Implements iFile.
void csMemFile::Empty | ( | ) |
Make file empty.
virtual void csMemFile::Flush | ( | ) | [virtual] |
Flush stream.
Implements iFile.
virtual csPtr<iDataBuffer> csMemFile::GetAllData | ( | bool | nullterm = false | ) | [virtual] |
Request whole content of the file as a single data buffer.
nullterm | Set this to true if you want a null char to be appended to the buffer (e.g. for use with string functions.) |
Implements iFile.
csPtr<iDataBuffer> csMemFile::GetAllData | ( | CS::Memory::iAllocator * | allocator | ) | [virtual] |
Request whole content of the file as a single data buffer.
Uses the allocator allocator if memory allocations are necessary.
Implements iFile.
virtual const char* csMemFile::GetData | ( | ) | const [virtual] |
Returns a pointer to the memory buffer.
May return 0 if memory file is empty. Use GetSize() for size info.
virtual const char* csMemFile::GetName | ( | ) | [virtual] |
Returns "#csMemFile".
Implements iFile.
csPtr<iFile> csMemFile::GetPartialView | ( | size_t | offset, |
size_t | size = (size_t)~0 |
||
) | [virtual] |
Request whole or part of the content of the file as a file object.
offset | Offset of data to return. |
size | Size of data to return. If ~0 all the data starting at offset up to the end of the file is returned. |
Implements iFile.
virtual size_t csMemFile::GetPos | ( | ) | [virtual] |
Query current file pointer.
Implements iFile.
virtual size_t csMemFile::GetSize | ( | ) | [virtual] |
Query file size.
Implements iFile.
virtual int csMemFile::GetStatus | ( | ) | [virtual] |
virtual size_t csMemFile::Read | ( | char * | Data, |
size_t | DataSize | ||
) | [virtual] |
Read DataSize bytes and place them into the buffer at which Data points.
Data | Pointer to the buffer into which the data should be read. The buffer should be at least DataSize bytes in size. |
DataSize | Number of bytes to read. |
Implements iFile.
virtual bool csMemFile::SetPos | ( | size_t | newpos | ) | [virtual] |
Set new file pointer.
newpos | New position in file. |
Implements iFile.
virtual size_t csMemFile::Write | ( | const char * | Data, |
size_t | DataSize | ||
) | [virtual] |
Write DataSize bytes from the buffer at which Data points.
Data | Pointer to the data to be written. |
DataSize | Number of bytes to write. |
Implements iFile.