CrystalSpace

Public API Reference

csMemFile Class Reference

Essentially a raw memory buffer which implements the abstract iFile interface. More...

#include <csutil/memfile.h>

Inheritance diagram for csMemFile:

List of all members.

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 (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.
void Empty ()
 Make file empty.
virtual void Flush ()
 Flush stream.
csPtr< iDataBufferGetAllData (CS::Memory::iAllocator *)
 Request whole content of the file as a single data buffer.
virtual csPtr< iDataBufferGetAllData (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".
csPtr< iFileGetPartialView (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.

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.

Definition at line 39 of file memfile.h.


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. 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.


Member Function Documentation

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.

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.

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 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]

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.

Parameters:
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.
Returns:
A file object operating on a part of the original file.
Remarks:
Note that the returned file will not support writing.

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]

Check (and clear) file last error status.

See also:
VFS_STATUS_ACCESSDENIED

Implements iFile.

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:

Generated for Crystal Space 2.1 by doxygen 1.6.1