AppEasy Core SDK
1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
|
Provides stream like read access to a memory buffer. More...
#include <CzDataIO.h>
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. |
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(); }
CzDataInput::CzDataInput | ( | bool | managed | ) | [inline] |
CzDataInput::CzDataInput | ( | ) | [inline] |
virtual CzDataInput::~CzDataInput | ( | ) | [inline, virtual] |
int CzDataInput::CalculateCheckSum | ( | ) |
Calculates the check sum of teh strean.
bool CzDataInput::CountXmlEntities | ( | int & | tags, |
int & | attributes | ||
) |
Count the number of XML tags an attributes entities present in the stream.
[out] | tags | The number of tags found. |
[out] | attributes | The number of attributes found. |
int CzDataInput::FindString | ( | const char * | pString, |
int | str_len | ||
) | const |
Searches forward for a string.
pString | The string to find. |
str_len | The length of the string. |
char CzDataInput::getByte | ( | ) |
Gets the next byte from the stream.
float CzDataInput::getByteAsFloat | ( | ) |
Gets the next byte from the stream as a float.
int CzDataInput::getBytes | ( | char * | data, |
int | count | ||
) |
Gets count bytes from the stream.
[out] | data | If non-null, destination data. |
count | Number of bytes to read. |
int CzDataInput::getBytes | ( | short * | data, |
int | count | ||
) |
Gets count bytes from the stream and writes them into a short buffer.
[out] | data | If non-null, destination data. |
count | Number of bytes to read. |
int CzDataInput::getBytes | ( | int * | data, |
int | count | ||
) |
Gets count bytes from the stream and writes them into an int buffer.
[out] | data | If non-null, destination data. |
count | Number of bytes to read. |
int CzDataInput::getBytes | ( | float * | data, |
int | count | ||
) |
Gets count bytes from the stream and writes them into a float buffer.
[out] | data | If non-null, destination data. |
count | Number of bytes to read. |
int CzDataInput::getChars | ( | char * | data, |
int | count | ||
) |
Gets count chars from the stream and writes them into a char buffer.
[out] | data | If non-null, destination data. |
count | Number of bytes to read. |
char* CzDataInput::getData | ( | ) | [inline] |
float CzDataInput::getFloat | ( | ) |
Gets the next float from the stream.
int CzDataInput::getInt | ( | ) |
Gets the next int from the stream.
int CzDataInput::getInts | ( | int * | data, |
int | count | ||
) |
Gets count ints from the stream and writes them into an int buffer.
[out] | data | If non-null, destination data. |
count | Number of ints to read. |
int CzDataInput::getInts | ( | float * | data, |
int | count | ||
) |
Gets count ints from the stream and writes them into a float buffer.
[out] | data | If non-null, destination data. |
count | Number of ints to read. |
int CzDataInput::getIntSwab | ( | ) |
Gets the next int from the stream, swapping the byte order.
int CzDataInput::getLength | ( | ) | const [inline] |
int CzDataInput::getLineNumber | ( | int | pos | ) | const |
Gets line number of the specified stream position (assumes the stream is text).
pos | The position. |
bool CzDataInput::getNextOccuranceOf | ( | char | chr | ) |
Skips teh stream to the next occurance of the specified character.
chr | The character to find. |
bool CzDataInput::getNextQuotedString | ( | CzString * | pString | ) |
Gets the next quoted string.
[in,out] | pString | If non-null, the string. |
bool CzDataInput::getNextQuotedString | ( | char * | pString, |
int | max_len | ||
) |
Gets the next quoted string, searching max_len chars forward in the stream.
[out] | pString | If non-null, the string. |
max_len | Maximum chars to search forwards. |
bool CzDataInput::getNextQuotedStringAsint | ( | int * | pNum | ) |
Gets the the next quoted string as an integer.
[out] | pNum | If non-null, address of integer variable. |
bool CzDataInput::getNextString | ( | CzString * | pString | ) |
Gets the next string.
[out] | pString | If non-null, the string. |
bool CzDataInput::getNextString | ( | char * | pString, |
int | max_len | ||
) |
Gets the next string, searching max_len chars forward in the stream.
[out] | pString | If non-null, the string. |
max_len | Maximum chars to search forwards. |
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.
tag_start_char | The tag start character. | |
tag_end_char | The tag end character. | |
range | Number of characters to search forwards. | |
[in,out] | start_pos | Stream position where tag starts. |
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.
tag_start_char | The tag start character. | |
tag_end_char | The tag end character. | |
range | Number of characters to search forwards. | |
[in,out] | start_pos | Stream position where tag starts. |
int CzDataInput::getPos | ( | ) | const [inline] |
short CzDataInput::getShort | ( | ) |
Gets the next short from the stream.
Gets the next short from the stream, swapping the byte order.
float CzDataInput::getShortAsFloat | ( | ) |
Gets the next short from the buffer as a float.
int CzDataInput::getShorts | ( | short * | data, |
int | count | ||
) |
Gets count shorts from the stream and writes them into a short buffer.
[out] | data | If non-null, destination data. |
count | Number of shorts to read. |
int CzDataInput::getShorts | ( | int * | data, |
int | count | ||
) |
Gets count shorts from the stream and writes them into an int buffer.
[out] | data | If non-null, destination data. |
count | Number of shorts to read. |
int CzDataInput::getShorts | ( | float * | data, |
int | count | ||
) |
Gets count shorts from the stream and writes them into a float buffer.
[out] | data | If non-null, destination data. |
count | Number of shorts to read. |
short CzDataInput::getShortSwab | ( | ) |
unsigned char CzDataInput::getUByte | ( | ) |
Gets the next byte from the stream as an unsigned byte.
float CzDataInput::getUByteAsFloat | ( | ) |
Gets the next byte from the stream as an unsigned float.
int CzDataInput::getUByteAsInt | ( | ) |
Gets the next byte from the stream as an integer.
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.
[out] | data | If non-null, destination data. |
count | Number of bytes to read. |
int CzDataInput::getUBytes | ( | float * | data, |
int | count | ||
) |
Gets count unsigned bytes from the stream and writes them into a float buffer.
[out] | data | If non-null, destination data. |
count | Number of bytes to read. |
int CzDataInput::getUShort | ( | ) |
Gets the next unsigned short from the stream.
float CzDataInput::getUShortAsFloat | ( | ) |
Gets the next 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.
[out] | data | If non-null, destination data. |
count | Number of shorts to read. |
int CzDataInput::getUShorts | ( | int * | data, |
int | count | ||
) |
Gets count unsigned shorts from the stream and writes them into an int buffer.
[out] | data | If non-null, destination data. |
count | Number of shorts to read. |
int CzDataInput::getUShorts | ( | float * | data, |
int | count | ||
) |
Gets count unsigned shorts from the stream and writes them into a float buffer.
[out] | data | If non-null, destination data. |
count | Number of shorts to read. |
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
length | The stream length. |
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.
[in] | data | If 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.
[in] | data | If non-null, the data. |
length | The length of the data. |
void CzDataInput::setManaged | ( | bool | managed | ) | [inline] |
int CzDataInput::setPos | ( | int | pos | ) |
Sets the stream position.
pos | The 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.
num_bytes | Number of bytes. |
int CzDataInput::SkipToCharInTag | ( | char | chr | ) |
Skip to character in tag.
chr | The character. |
Skip stream to next none whitespace character in an XML tag.
Skips stream to next available whitespace character in an XML tag.
bool CzDataInput::StripXMLComments | ( | ) |
Strip XML comments from the stream.
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.