csMemFile Class Reference
Essentially a raw memory buffer which implements the abstract iFile interface. More...
#include <csutil/memfile.h>
Inheritance diagram for csMemFile:
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... | |
DISPOSITION_CS_FREE | |
Deallocate with cs_free(). | |
DISPOSITION_DELETE | |
Deallocate with delete[]. | |
DISPOSITION_FREE = DISPOSITION_CS_FREE | |
Deallocate with platform_free() or cs_free(), depending on whether malloc override is disabled or not. | |
DISPOSITION_IGNORE | |
Ignore; assume that outside agent owns buffer. | |
DISPOSITION_PLATFORM_FREE | |
Deallocate with platform_free(). | |
Public Member Functions | |
virtual bool | AtEOF () |
Returns true if the stream is at end-of-file, else false. | |
csMemFile (iDataBuffer *buf, bool readOnly) | |
Construct a memory file from an existing data buffer. | |
csMemFile (char *, size_t, Disposition=DISPOSITION_DELETE) | |
Construct a memory file from an existing memory buffer and free later. | |
csMemFile (const char *, size_t) | |
Construct a memory file from an existing memory buffer but do not free. | |
csMemFile () | |
Construct an empty memory file. | |
virtual void | Flush () |
Flush stream. | |
virtual csPtr< iDataBuffer > | GetAllData (bool nullterm=false) |
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". | |
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. | |
Protected Attributes | |
csRef< iDataBuffer > | buffer |
bool | copyOnWrite |
size_t | cursor |
size_t | size |
Detailed Description
Essentially a raw memory buffer which implements the abstract iFile interface.
Definition at line 34 of file memfile.h.
Member Enumeration Documentation
Disposition of memory buffer at destruction time.
- Enumerator:
-
DISPOSITION_DELETE Deallocate with delete[]. DISPOSITION_PLATFORM_FREE Deallocate with platform_free(). DISPOSITION_IGNORE Ignore; assume that outside agent owns buffer. DISPOSITION_CS_FREE Deallocate with cs_free(). DISPOSITION_FREE Deallocate with platform_free() or cs_free(), depending on whether malloc override is disabled or not.
Constructor & Destructor Documentation
csMemFile::csMemFile | ( | ) |
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.
- Parameters:
-
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. Iffalse
, 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.
Member Function Documentation
virtual bool csMemFile::AtEOF | ( | ) | [virtual] |
virtual void csMemFile::Flush | ( | ) | [virtual] |
virtual csPtr<iDataBuffer> csMemFile::GetAllData | ( | bool | nullterm = false |
) | [virtual] |
Request whole content of the file as a single data buffer.
- Parameters:
-
nullterm Set this to true if you want a null char to be appended to the buffer (e.g. for use with string functions.)
- Remarks:
- Null-termination might have a performance penalty (depending upon where the file is stored.) Use only when needed.
- Returns:
- The complete data contained in the file; or an invalidated pointer if this object does not support this function (e.g. write-only VFS files). Check for an invalidated result via csRef<>::IsValid(). Do not modify the contained data!
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] |
virtual size_t csMemFile::GetPos | ( | ) | [virtual] |
virtual size_t csMemFile::GetSize | ( | ) | [virtual] |
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.
- Parameters:
-
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.
- Returns:
- The number of bytes actually read. If an error occurs, zero is returned. Invoke GetStatus() to retrieve the error code.
Implements iFile.
virtual bool csMemFile::SetPos | ( | size_t | newpos | ) | [virtual] |
Set new file pointer.
- Parameters:
-
newpos New position in file.
- Returns:
- True if the operation succeeded, else false.
Implements iFile.
virtual size_t csMemFile::Write | ( | const char * | Data, | |
size_t | DataSize | |||
) | [virtual] |
Write DataSize bytes from the buffer at which Data points.
- Parameters:
-
Data Pointer to the data to be written. DataSize Number of bytes to write.
- Returns:
- The number of bytes actually written. If an error occurs, zero is returned. Invoke GetStatus() to retrieve the error code.
Implements iFile.
The documentation for this class was generated from the following file:
- csutil/memfile.h
Generated for Crystal Space by doxygen 1.4.7