Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Ogre::DataChunk Class Reference

Wraps a chunk of memory, storing both size and a pointer to the data. More...

#include <OgreDataChunk.h>

Inheritance diagram for Ogre::DataChunk:

Ogre::SDDataChunk List of all members.

Public Methods

 DataChunk ()
 Default constructor. More...

 DataChunk (void *pData, size_t size)
 Wraps an existing, already-allocated, memory block. More...

virtual ~DataChunk ()
 Default destructor. More...

ucharallocate (size_t size, const uchar *ptr=NULL)
 Allocates the passed number of bytes. More...

DataChunk & clear ()
 Frees all internally allocated memory. More...

size_t getSize () const
 Returns the size of the allocated chunk in bytes. More...

uchargetPtr ()
 Returns a const pointer to the start of the memory. More...

const uchargetPtr () const
 Returns a const pointer to the start of the memory. More...

ulong read (void *buffer, unsigned long size)
 Reads memory from the main buffer into another, incrementing an internal 'current' pointer to allow progressive reads. More...

DataChunk & seek (size_t pos)
 Repositions the internal read pointer to a specified byte. More...

DataChunk & skip (long offset)
 Moves the internal read pointer backwards or forwards by the number of bytes specified. More...

unsigned long readUpTo (void *buffer, size_t size, const char *delim="\n")
 Reads data into the provided buffer until hitting the specified character or reaching the upper limit provided. More...

unsigned long skipUpTo (const char *delim)
 Skips data into the provided buffer until hitting the specified character or reaching the end of the data. More...

bool isEOF ()
 Returns true if the buffer pointer has reached the end of the buffer. More...

String getLine (bool trimAfter=true)
 Returns a String containing the next line of data, optionally trimmed for whitespace. More...


Protected Attributes

ucharmData
ucharmPos
ucharmEnd
size_t mSize

Detailed Description

Wraps a chunk of memory, storing both size and a pointer to the data.

Remarks:
This class simply wraps a chunk of memory. It provides extra info about the size of the data contained within it, simple allocation and free methods, and simple stream-like 'read' methods for parsing through the memory chunk rather like a file.
Note:

By default the DataChunk object will NOT free any memory it has allocated EVEN WHEN DESTROYED.

This is for efficiency since you may just want to reuse the memory as-is rather than copying it elsewhere, and it also allows the DataChunk to be copied safely, i.e. when returned from methods. At some point you should call DataChunk::free to release the memory if you wish.

If you need a DataChunk that frees the allocated memory on destruction, use SDDataChunk instead.

See also:
SDDataChunk


Constructor & Destructor Documentation

Ogre::DataChunk::DataChunk  
 

Default constructor.

Ogre::DataChunk::DataChunk void *    pData,
size_t    size
 

Wraps an existing, already-allocated, memory block.

virtual Ogre::DataChunk::~DataChunk   [inline, virtual]
 

Default destructor.

Note:
The destructor DOES NOT FREE memory.


Member Function Documentation

uchar * Ogre::DataChunk::allocate size_t    size,
const uchar   ptr = NULL
 

Allocates the passed number of bytes.

DataChunk & Ogre::DataChunk::clear  
 

Frees all internally allocated memory.

String Ogre::DataChunk::getLine bool    trimAfter = true
 

Returns a String containing the next line of data, optionally trimmed for whitespace.

Remarks:
This is a convenience method for text chunks only, allowing you to retrieve a String object containing the next line of data. The data is read up to the next newline character and the result trimmed if required.
Parameters:
trimAfter  If true, the line is trimmed for whitespace (as in String.trim(true,true))

const uchar* Ogre::DataChunk::getPtr   const
 

Returns a const pointer to the start of the memory.

const uchar * Ogre::DataChunk::getPtr  
 

Returns a const pointer to the start of the memory.

size_t Ogre::DataChunk::getSize   const
 

Returns the size of the allocated chunk in bytes.

bool Ogre::DataChunk::isEOF  
 

Returns true if the buffer pointer has reached the end of the buffer.

ulong Ogre::DataChunk::read void *    buffer,
unsigned long    size
 

Reads memory from the main buffer into another, incrementing an internal 'current' pointer to allow progressive reads.

Parameters:
buffer  Pointer to buffer to read into
size  Number of bytes to read
Returns:
The number of bytes actually read

ulong Ogre::DataChunk::readUpTo void *    buffer,
size_t    size,
const char *    delim = "\n"
 

Reads data into the provided buffer until hitting the specified character or reaching the upper limit provided.

Remarks:
The terminating character is not included in the data returned, and it is skipped over so the next read will occur after it.
Parameters:
buffer  Pointer to buffer to read into
size  Size of the buffer i.e. max bytes to read
delim  List of delimiters to read up to (default newline)
Returns:
The actual number of characters copied into the buffer.

DataChunk & Ogre::DataChunk::seek size_t    pos
 

Repositions the internal read pointer to a specified byte.

DataChunk & Ogre::DataChunk::skip long    offset
 

Moves the internal read pointer backwards or forwards by the number of bytes specified.

Remarks:
The sign of the parameter determines the direction of the skip.

ulong Ogre::DataChunk::skipUpTo const char *    delim
 

Skips data into the provided buffer until hitting the specified character or reaching the end of the data.

Remarks:
The terminating characters is not included in the data returned, and it is skipped over so the next read will occur after it.
Parameters:
delim  List of delimiters to skip up to.
Returns:
The number of characters that were skipped.


Member Data Documentation

uchar* Ogre::DataChunk::mData [protected]
 

uchar* Ogre::DataChunk::mEnd [protected]
 

uchar* Ogre::DataChunk::mPos [protected]
 

size_t Ogre::DataChunk::mSize [protected]
 

Copyright © 2002 by The OGRE Team