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:

Inheritance graph
[legend]
List of all members.

Public Methods

 DataChunk ()
 Default constructor.

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

virtual ~DataChunk ()
 Default destructor.

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

DataChunk & clear ()
 Frees all internally allocated memory.

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

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

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

uchargetCurrentPtr ()
 Returns a pointer to the current position in memory.

const uchargetCurrentPtr () const
 Returns a const pointer to the current position in memory.

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

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

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

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

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

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

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

String getAsString (void) const
 Get the entire contents of the chunk as a string.


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

Definition at line 53 of file OgreDataChunk.h.


Constructor & Destructor Documentation

Ogre::DataChunk::DataChunk  
 

Default constructor.

Definition at line 32 of file OgreDataChunk.cpp.

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

Wraps an existing, already-allocated, memory block.

Definition at line 37 of file OgreDataChunk.cpp.

References mData, mEnd, mPos, and mSize.

virtual Ogre::DataChunk::~DataChunk   [virtual]
 

Default destructor.

Note:
The destructor DOES NOT FREE memory.

Definition at line 74 of file OgreDataChunk.h.


Member Function Documentation

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

Allocates the passed number of bytes.

Definition at line 46 of file OgreDataChunk.cpp.

References mData, mEnd, mPos, mSize, and Ogre::uchar.

Referenced by Ogre::ILImageCodec::decode(), and Ogre::Zip::fileRead().

DataChunk & Ogre::DataChunk::clear  
 

Frees all internally allocated memory.

Definition at line 69 of file OgreDataChunk.cpp.

References mData, and mSize.

Referenced by Ogre::Skeleton::load(), Ogre::Mesh::load(), Ogre::BspLevel::load(), and Ogre::HeightmapTerrainPageSource::loadHeightmap().

String Ogre::DataChunk::getAsString void    const
 

Get the entire contents of the chunk as a string.

Definition at line 196 of file OgreDataChunk.cpp.

References mData, mSize, and Ogre::String.

Referenced by Ogre::GpuProgram::load(), Ogre::D3D9GpuProgram::load(), and Ogre::HighLevelGpuProgram::loadHighLevelImpl().

const uchar* Ogre::DataChunk::getCurrentPtr   const
 

Returns a const pointer to the current position in memory.

const uchar * Ogre::DataChunk::getCurrentPtr  
 

Returns a pointer to the current position in memory.

Definition at line 98 of file OgreDataChunk.cpp.

References mPos, and Ogre::uchar.

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

Definition at line 183 of file OgreDataChunk.cpp.

References readUpTo(), and Ogre::String.

Referenced by Ogre::ParticleSystemManager::parseNewAffector(), Ogre::OverlayManager::parseNewElement(), Ogre::ParticleSystemManager::parseNewEmitter(), Ogre::OverlayManager::parseNewMesh(), Ogre::Quake3ShaderManager::parseNewShaderPass(), Ogre::OverlayManager::parseOverlayFile(), Ogre::ParticleSystemManager::parseScript(), Ogre::MaterialSerializer::parseScript(), Ogre::FontManager::parseScript(), Ogre::Quake3ShaderManager::parseShaderFile(), Ogre::ParticleSystemManager::skipToNextCloseBrace(), Ogre::OverlayManager::skipToNextCloseBrace(), Ogre::ParticleSystemManager::skipToNextOpenBrace(), and Ogre::OverlayManager::skipToNextOpenBrace().

const uchar* Ogre::DataChunk::getPtr   const
 

Returns a const pointer to the start of the memory.

const uchar * Ogre::DataChunk::getPtr  
 

Returns a pointer to the start of the memory.

Definition at line 87 of file OgreDataChunk.cpp.

References mData, and Ogre::uchar.

Referenced by Ogre::D3D9Texture::_loadCubeTex(), Ogre::D3D9Texture::_loadNormTex(), Ogre::D3D9Texture::_loadVolumeTex(), Ogre::Font::createTextureFromFont(), Ogre::ILImageCodec::decode(), Ogre::Zip::fileRead(), Ogre::Quake3Level::initialise(), Ogre::Image::load(), Ogre::Image::loadRawData(), and Ogre::HeightmapTerrainPageSource::requestPage().

size_t Ogre::DataChunk::getSize   const
 

Returns the size of the allocated chunk in bytes.

Definition at line 81 of file OgreDataChunk.cpp.

References mSize.

Referenced by Ogre::D3D9Texture::_loadCubeTex(), Ogre::D3D9Texture::_loadNormTex(), Ogre::D3D9Texture::_loadVolumeTex(), Ogre::Font::createTextureFromFont(), Ogre::ILImageCodec::decode(), Ogre::HeightmapTerrainPageSource::loadHeightmap(), Ogre::Win32Window::writeContentsToFile(), Ogre::SDLWindow::writeContentsToFile(), and Ogre::GLXWindow::writeContentsToFile().

bool Ogre::DataChunk::isEOF   const
 

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

Definition at line 174 of file OgreDataChunk.cpp.

References mEnd, and mPos.

Referenced by Ogre::MeshSerializerImpl::importMesh(), Ogre::SkeletonSerializer::importSkeleton(), Ogre::ParticleSystemManager::parseNewAffector(), Ogre::OverlayManager::parseNewElement(), Ogre::ParticleSystemManager::parseNewEmitter(), Ogre::OverlayManager::parseNewMesh(), Ogre::Quake3ShaderManager::parseNewShaderPass(), Ogre::OverlayManager::parseOverlayFile(), Ogre::ParticleSystemManager::parseScript(), Ogre::MaterialSerializer::parseScript(), Ogre::FontManager::parseScript(), Ogre::Quake3ShaderManager::parseShaderFile(), Ogre::SkeletonSerializer::readAnimation(), Ogre::SkeletonSerializer::readAnimationTrack(), Ogre::MeshSerializerImpl::readEdgeList(), Ogre::MeshSerializerImpl_v1_2::readGeometry(), Ogre::MeshSerializerImpl::readGeometry(), Ogre::MeshSerializerImpl::readGeometryVertexDeclaration(), Ogre::MeshSerializerImpl::readMesh(), Ogre::MeshSerializerImpl::readSubMesh(), Ogre::MeshSerializerImpl::readSubMeshNameTable(), Ogre::ParticleSystemManager::skipToNextCloseBrace(), Ogre::OverlayManager::skipToNextCloseBrace(), Ogre::ParticleSystemManager::skipToNextOpenBrace(), and Ogre::OverlayManager::skipToNextOpenBrace().

size_t Ogre::DataChunk::read void *    buffer,
size_t    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

Definition at line 110 of file OgreDataChunk.cpp.

References mEnd, and mPos.

Referenced by Ogre::Serializer::readBools(), Ogre::MeshSerializerImpl::readGeometryVertexBuffer(), Ogre::Serializer::readInts(), Ogre::Serializer::readLongs(), Ogre::Serializer::readReals(), Ogre::Serializer::readShorts(), and Ogre::Serializer::readString().

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

Definition at line 143 of file OgreDataChunk.cpp.

References mEnd, and mPos.

Referenced by getLine(), Ogre::Quake3ShaderManager::parseShaderFile(), and Ogre::Serializer::readString().

DataChunk & Ogre::DataChunk::seek size_t    pos
 

Repositions the internal read pointer to a specified byte.

Definition at line 125 of file OgreDataChunk.cpp.

References mData, mPos, and mSize.

Referenced by Ogre::MeshSerializer::importMesh().

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.

Definition at line 133 of file OgreDataChunk.cpp.

References mData, mEnd, and mPos.

Referenced by Ogre::SkeletonSerializer::readAnimation(), Ogre::SkeletonSerializer::readAnimationTrack(), Ogre::MeshSerializerImpl::readEdgeList(), Ogre::MeshSerializerImpl_v1_2::readGeometry(), Ogre::MeshSerializerImpl::readGeometry(), Ogre::MeshSerializerImpl::readGeometryVertexDeclaration(), Ogre::MeshSerializerImpl::readMesh(), Ogre::MeshSerializerImpl::readSubMesh(), and Ogre::MeshSerializerImpl::readSubMeshNameTable().

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

Definition at line 161 of file OgreDataChunk.cpp.

References mEnd, and mPos.

Referenced by Ogre::FontManager::parseScript().


Member Data Documentation

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

Definition at line 56 of file OgreDataChunk.h.

Referenced by allocate(), clear(), DataChunk(), getAsString(), getPtr(), seek(), skip(), and Ogre::SDDataChunk::~SDDataChunk().

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

Definition at line 58 of file OgreDataChunk.h.

Referenced by allocate(), DataChunk(), isEOF(), read(), readUpTo(), skip(), and skipUpTo().

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

Definition at line 57 of file OgreDataChunk.h.

Referenced by allocate(), DataChunk(), getCurrentPtr(), isEOF(), read(), readUpTo(), seek(), skip(), and skipUpTo().

size_t Ogre::DataChunk::mSize [protected]
 

Definition at line 59 of file OgreDataChunk.h.

Referenced by allocate(), clear(), DataChunk(), getAsString(), getSize(), and seek().


The documentation for this class was generated from the following files:

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:50:51 2004