AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzDataInput Class Reference

Provides stream like read access to a memory buffer. More...

#include <CzDataIO.h>

List of all members.

Public Member Functions

 CzDataInput (bool managed)
 CzDataInput ()
virtual ~CzDataInput ()
bool Init (int length)
 Initialises the stream object.
virtual void Release ()
 Releases the stream object.
char * getData ()
void setData (char *data)
 Sets the stream data.
void setData (char *data, int length)
 Sets the stream data and its length.
void setManaged (bool managed)
bool isManaged () const
int Skip (int num_bytes)
 Moves the stream pointer back and forth.
int setPos (int pos)
 Sets the stream position.
int getPos () const
int getLength () const
bool isEOF () const
int Remaining () const
char getByte ()
 Gets the next byte from the stream.
float getByteAsFloat ()
 Gets the next byte from the stream as a float.
unsigned char getUByte ()
 Gets the next byte from the stream as an unsigned byte.
int getUByteAsInt ()
 Gets the next byte from the stream as an integer.
float getUByteAsFloat ()
 Gets the next byte from the stream as an unsigned float.
int getBytes (char *data, int count)
 Gets count bytes from the stream.
int getBytes (short *data, int count)
 Gets count bytes from the stream and writes them into a short buffer.
int getBytes (int *data, int count)
 Gets count bytes from the stream and writes them into an int buffer.
int getBytes (float *data, int count)
 Gets count bytes from the stream and writes them into a float buffer.
int getUBytes (unsigned char *data, int count)
int getUBytes (int *data, int count)
 Gets count unsigned bytes from the stream and writes them into an int buffer.
int getUBytes (float *data, int count)
 Gets count unsigned bytes from the stream and writes them into a float buffer.
int getChars (char *data, int count)
 Gets count chars from the stream and writes them into a char buffer.
short getShort ()
 Gets the next short from the stream.
short getShortSwab ()
float getShortAsFloat ()
 Gets the next short from the buffer as a float.
int getUShort ()
 Gets the next unsigned short from the stream.
float getUShortAsFloat ()
 Gets the next unsigned short as a float.
int getShorts (short *data, int count)
 Gets count shorts from the stream and writes them into a short buffer.
int getShorts (int *data, int count)
 Gets count shorts from the stream and writes them into an int buffer.
int getShorts (float *data, int count)
 Gets count shorts from the stream and writes them into a float buffer.
int getUShorts (unsigned short *data, int count)
 Gets count unsigned shorts from the stream and writes them into an unsigned short buffer.
int getUShorts (int *data, int count)
 Gets count unsigned shorts from the stream and writes them into an int buffer.
int getUShorts (float *data, int count)
 Gets count unsigned shorts from the stream and writes them into a float buffer.
int getInt ()
 Gets the next int from the stream.
int getIntSwab ()
 Gets the next int from the stream, swapping the byte order.
int getInts (int *data, int count)
 Gets count ints from the stream and writes them into an int buffer.
int getInts (float *data, int count)
 Gets count ints from the stream and writes them into a float buffer.
float getFloat ()
 Gets the next float from the stream.
bool getNextString (CzString *pString)
 Gets the next string.
bool getNextString (char *pString, int max_len)
 Gets the next string, searching max_len chars forward in the stream.
bool getNextQuotedStringAsint (int *pNum)
 Gets the the next quoted string as an integer.
bool getNextQuotedString (CzString *pString)
 Gets the next quoted string.
bool getNextQuotedString (char *pString, int max_len)
 Gets the next quoted string, searching max_len chars forward in the stream.
bool getNextOccuranceOf (char chr)
 Skips teh stream to the next occurance of the specified character.
int getNextTag (char tag_start_char, char tag_end_char, int range, int &start_pos)
 Gets the next tag marked by tag_start_char and tag_end_char tag chars.
int getNextTagOrValue (char tag_start_char, char tag_end_char, int range, int &start_pos)
 Gets the next tag marked by tag_start_char and tag_end_char tag chars or value.
int FindString (const char *pString, int str_len) const
 Searches forward for a string.
int SkipToWhitespaceInTag ()
 Skips stream to next available whitespace character in an XML tag.
int SkipToNoneWhitespaceInTag ()
 Skip stream to next none whitespace character in an XML tag.
int SkipToCharInTag (char chr)
 Skip to character in tag.
int getLineNumber (int pos) const
 Gets line number of the specified stream position (assumes the stream is text).
int CalculateCheckSum ()
 Calculates the check sum of teh strean.
bool StripXMLComments ()
 Strip XML comments from the stream.
bool CountXmlEntities (int &tags, int &attributes)
 Count the number of XML tags an attributes entities present in the stream.

Protected Attributes

char * Data
 Streams data.
int Position
 Current position in stream.
int Length
 Length of stream (actual allocated memory sie is aligned to 32 bytes)
bool EndOfFile
 true if end of stream reached
bool Managed
 If true data buffer will not be released when object deleted.

Detailed Description

Provides stream like read access to a memory buffer.

From the perspective of AppEasy a stream is data that can be read from or written to. When data is read from a stream, the position at which we read the next lot of data moves to the end of the previously read data. Streams have a stream pointer / position which marks the place where new data will be read or written.

AppEasy provides two simple classes that allow you to treat memory as though it was a stream. This can come in very useful when serialising binary data or parsing data located in a memory buffer.

Two classes are provided which provide support for input and output:

Lets take a look at an example showing how to use :

// Create and initialise an input stream of 1024 bytes
CzDataInput *stream  = new CzDataInput();
stream->Init(1024);

// Read some data into the stream
if (!file->Read(stream->getData(), size))
    return -1;

// Do something with the data
while (!in->isEOF())
{
    char b = getByte();
}

Constructor & Destructor Documentation

CzDataInput::CzDataInput ( bool  managed) [inline]
virtual CzDataInput::~CzDataInput ( ) [inline, virtual]

Member Function Documentation

Calculates the check sum of teh strean.

Returns:
The calculated check sum.
bool CzDataInput::CountXmlEntities ( int &  tags,
int &  attributes 
)

Count the number of XML tags an attributes entities present in the stream.

Parameters:
[out]tagsThe number of tags found.
[out]attributesThe number of attributes found.
Returns:
The total number of XML entities.
int CzDataInput::FindString ( const char *  pString,
int  str_len 
) const

Searches forward for a string.

Parameters:
pStringThe string to find.
str_lenThe length of the string.
Returns:
The length of the found string or < 0 for not found.

Gets the next byte from the stream.

Returns:
The byte.

Gets the next byte from the stream as a float.

Returns:
The byte as float.
int CzDataInput::getBytes ( char *  data,
int  count 
)

Gets count bytes from the stream.

Parameters:
[out]dataIf non-null, destination data.
countNumber of bytes to read.
Returns:
The number of bytes read or 0 for EOF.
int CzDataInput::getBytes ( short *  data,
int  count 
)

Gets count bytes from the stream and writes them into a short buffer.

Parameters:
[out]dataIf non-null, destination data.
countNumber of bytes to read.
Returns:
The number of bytes read or 0 for EOF.
int CzDataInput::getBytes ( int *  data,
int  count 
)

Gets count bytes from the stream and writes them into an int buffer.

Parameters:
[out]dataIf non-null, destination data.
countNumber of bytes to read.
Returns:
The number of bytes read or 0 for EOF.
int CzDataInput::getBytes ( float *  data,
int  count 
)

Gets count bytes from the stream and writes them into a float buffer.

Parameters:
[out]dataIf non-null, destination data.
countNumber of bytes to read.
Returns:
The number of bytes read or 0 for EOF.
int CzDataInput::getChars ( char *  data,
int  count 
)

Gets count chars from the stream and writes them into a char buffer.

Parameters:
[out]dataIf non-null, destination data.
countNumber of bytes to read.
Returns:
The number chars read or 0 for EOF.
char* CzDataInput::getData ( ) [inline]

Gets the next float from the stream.

Returns:
The float.

Gets the next int from the stream.

Returns:
The int.
int CzDataInput::getInts ( int *  data,
int  count 
)

Gets count ints from the stream and writes them into an int buffer.

Parameters:
[out]dataIf non-null, destination data.
countNumber of ints to read.
Returns:
The number of ints read or 0 for EOF.
int CzDataInput::getInts ( float *  data,
int  count 
)

Gets count ints from the stream and writes them into a float buffer.

Parameters:
[out]dataIf non-null, destination data.
countNumber of ints to read.
Returns:
The number of ints read or 0 for EOF.

Gets the next int from the stream, swapping the byte order.

Returns:
The int.
int CzDataInput::getLength ( ) const [inline]
int CzDataInput::getLineNumber ( int  pos) const

Gets line number of the specified stream position (assumes the stream is text).

Parameters:
posThe position.
Returns:
The line number.
bool CzDataInput::getNextOccuranceOf ( char  chr)

Skips teh stream to the next occurance of the specified character.

Parameters:
chrThe character to find.
Returns:
true if it succeeds, false if it fails.

Gets the next quoted string.

Parameters:
[in,out]pStringIf non-null, the string.
Returns:
true if it succeeds, false if it fails.
bool CzDataInput::getNextQuotedString ( char *  pString,
int  max_len 
)

Gets the next quoted string, searching max_len chars forward in the stream.

Parameters:
[out]pStringIf non-null, the string.
max_lenMaximum chars to search forwards.
Returns:
true if it succeeds, false if it fails.

Gets the the next quoted string as an integer.

Parameters:
[out]pNumIf non-null, address of integer variable.
Returns:
true if it succeeds, false if it fails.
bool CzDataInput::getNextString ( CzString pString)

Gets the next string.

Parameters:
[out]pStringIf non-null, the string.
Returns:
true if it succeeds, false if it fails.
bool CzDataInput::getNextString ( char *  pString,
int  max_len 
)

Gets the next string, searching max_len chars forward in the stream.

Parameters:
[out]pStringIf non-null, the string.
max_lenMaximum chars to search forwards.
Returns:
true if it succeeds, false if it fails.
int CzDataInput::getNextTag ( char  tag_start_char,
char  tag_end_char,
int  range,
int &  start_pos 
)

Gets the next tag marked by tag_start_char and tag_end_char tag chars.

For example, if tag_start_char = "<" and tag_end_char = ">" then the next XML tag will be found.

Parameters:
tag_start_charThe tag start character.
tag_end_charThe tag end character.
rangeNumber of characters to search forwards.
[in,out]start_posStream position where tag starts.
Returns:
Length of tag or < 0 for not found.
int CzDataInput::getNextTagOrValue ( char  tag_start_char,
char  tag_end_char,
int  range,
int &  start_pos 
)

Gets the next tag marked by tag_start_char and tag_end_char tag chars or value.

For example, if tag_start_char = "<" and tag_end_char = ">" then the next XML tag will be found.

Parameters:
tag_start_charThe tag start character.
tag_end_charThe tag end character.
rangeNumber of characters to search forwards.
[in,out]start_posStream position where tag starts.
Returns:
Length of tag or < 0 for not found.
int CzDataInput::getPos ( ) const [inline]

Gets the next short from the stream.

Gets the next short from the stream, swapping the byte order.

Returns:
The short.

Gets the next short from the buffer as a float.

Returns:
The short as a float.
int CzDataInput::getShorts ( short *  data,
int  count 
)

Gets count shorts from the stream and writes them into a short buffer.

Parameters:
[out]dataIf non-null, destination data.
countNumber of shorts to read.
Returns:
The number of shorts read or 0 for EOF.
int CzDataInput::getShorts ( int *  data,
int  count 
)

Gets count shorts from the stream and writes them into an int buffer.

Parameters:
[out]dataIf non-null, destination data.
countNumber of shorts to read.
Returns:
The number of shorts read or 0 for EOF.
int CzDataInput::getShorts ( float *  data,
int  count 
)

Gets count shorts from the stream and writes them into a float buffer.

Parameters:
[out]dataIf non-null, destination data.
countNumber of shorts to read.
Returns:
The number of shorts read or 0 for EOF.
unsigned char CzDataInput::getUByte ( )

Gets the next byte from the stream as an unsigned byte.

Returns:
The unsigned byte.

Gets the next byte from the stream as an unsigned float.

Returns:
The byte as an unsigned float.

Gets the next byte from the stream as an integer.

Returns:
The byte as an int.
int CzDataInput::getUBytes ( unsigned char *  data,
int  count 
)
int CzDataInput::getUBytes ( int *  data,
int  count 
)

Gets count unsigned bytes from the stream and writes them into an int buffer.

Parameters:
[out]dataIf non-null, destination data.
countNumber of bytes to read.
Returns:
The number of bytes read or 0 for EOF.
int CzDataInput::getUBytes ( float *  data,
int  count 
)

Gets count unsigned bytes from the stream and writes them into a float buffer.

Parameters:
[out]dataIf non-null, destination data.
countNumber of bytes to read.
Returns:
The number of bytes read or 0 for EOF.

Gets the next unsigned short from the stream.

Returns:
The unsigned short.

Gets the next unsigned short as a float.

Returns:
The unsigned short as a float.
int CzDataInput::getUShorts ( unsigned short *  data,
int  count 
)

Gets count unsigned shorts from the stream and writes them into an unsigned short buffer.

Parameters:
[out]dataIf non-null, destination data.
countNumber of shorts to read.
Returns:
The number of shorts read or 0 for EOF.
int CzDataInput::getUShorts ( int *  data,
int  count 
)

Gets count unsigned shorts from the stream and writes them into an int buffer.

Parameters:
[out]dataIf non-null, destination data.
countNumber of shorts to read.
Returns:
The number of shorts read or 0 for EOF.
int CzDataInput::getUShorts ( float *  data,
int  count 
)

Gets count unsigned shorts from the stream and writes them into a float buffer.

Parameters:
[out]dataIf non-null, destination data.
countNumber of shorts to read.
Returns:
The number of shorts read or 0 for EOF.
bool CzDataInput::Init ( int  length)

Initialises the stream object.

Allocates a memory buffer of the specified length and sets the stream market to the start

Parameters:
lengthThe stream length.
Returns:
true if it succeeds, false if it fails.
bool CzDataInput::isEOF ( ) const [inline]
bool CzDataInput::isManaged ( ) const [inline]
void CzDataInput::Release ( ) [virtual]

Releases the stream object.

Deletes the memory associated with the stream

int CzDataInput::Remaining ( ) const [inline]
void CzDataInput::setData ( char *  data)

Sets the stream data.

Sets the data stream, taking ownership of the supplied data. If the stream already has data assigned then it will be deleted.

Parameters:
[in]dataIf non-null, the data stream.
void CzDataInput::setData ( char *  data,
int  length 
)

Sets the stream data and its length.

Sets the data stream, taking ownership of the supplied data. The length of the stream is also set to the supplied length. If the stream already has data assigned then it will be deleted.

Parameters:
[in]dataIf non-null, the data.
lengthThe length of the data.
void CzDataInput::setManaged ( bool  managed) [inline]
int CzDataInput::setPos ( int  pos)

Sets the stream position.

Parameters:
posThe stream position.
Returns:
Stream position.
int CzDataInput::Skip ( int  num_bytes)

Moves the stream pointer back and forth.

Skips te supplied number of bytes in the stream, num_bytes can be negative. Attempted to skip past the start or end of teh stream will cause EOF.

Parameters:
num_bytesNumber of bytes.
Returns:
Stream position.
int CzDataInput::SkipToCharInTag ( char  chr)

Skip to character in tag.

Parameters:
chrThe character.
Returns:
Stream position of character or < 0 not found.

Skip stream to next none whitespace character in an XML tag.

Returns:
Stream position of none whitespace or < 0 not found.

Skips stream to next available whitespace character in an XML tag.

Returns:
Stream position of whitespace or < 0 not found.

Strip XML comments from the stream.

Returns:
true if it succeeds, false if it fails.

Member Data Documentation

char* CzDataInput::Data [protected]

Streams data.

bool CzDataInput::EndOfFile [protected]

true if end of stream reached

int CzDataInput::Length [protected]

Length of stream (actual allocated memory sie is aligned to 32 bytes)

bool CzDataInput::Managed [protected]

If true data buffer will not be released when object deleted.

int CzDataInput::Position [protected]

Current position in stream.


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