Fast input memory stream. More...
Public Member Functions | |
InputMemoryStream () noexcept | |
Constructor. | |
InputMemoryStream (const char *pFilename) noexcept | |
Constructor with a data file. | |
InputMemoryStream (Filename *pFilename) noexcept | |
Constructor with a data file. | |
InputMemoryStream (const void *pBuffer, uintptr_t uBufferSize, uint_t bDontFree=0) noexcept | |
Constructor with a input data buffer. | |
~InputMemoryStream () | |
Destructor. | |
uint_t | Open (const char *pFilename) noexcept |
Load data from a file. | |
uint_t | Open (Filename *pFilename) noexcept |
Load data from a file. | |
void | Open (const void *pBuffer, uintptr_t uBufferSize, uint_t bDontFree=0) noexcept |
Use data from a application supplied buffer. | |
void | Clear (void) noexcept |
Release all allocated memory. | |
void | SkipForward (uintptr_t uOffset) noexcept |
Move the read pointer forward in the stream. | |
void | SkipBack (uintptr_t uOffset) noexcept |
Move the read pointer backward in the stream. | |
void | SetMark (uintptr_t uOffset) noexcept |
Move the read pointer to a location in the stream. | |
const uint8_t * | GetPtr (void) const noexcept |
Return the current pointer into the data stream. | |
uintptr_t | GetMark (void) const noexcept |
Return the current offset into the data stream. | |
uintptr_t | GetSize (void) const noexcept |
Return the amount of data stored in the stream. | |
uint_t | IsEmpty (void) const noexcept |
Return TRUE if there is no data remaining to parse in the stream. | |
uintptr_t | BytesRemaining (void) const noexcept |
Return the amount of data remaining to parse in the stream. | |
void | GetString (char *pOutput, uintptr_t uOutputSize) noexcept |
Parse a UTF-8 "C" string from the data stream. | |
void | GetString (String *pOutput) noexcept |
Parse a UTF-8 "C" string from the data stream. | |
void | GetCString (char *pOutput, uintptr_t uOutputSize) noexcept |
Parse a UTF-8 "C" string from the data stream. | |
void | GetPString (char *pOutput, uintptr_t uOutputSize) noexcept |
Parse a UTF-8 "P" string from the data stream. | |
uint8_t | GetByte (void) noexcept |
Return an 8 bit value from the data stream. | |
uint16_t | GetShort (void) noexcept |
Return a 16 bit little endian value from the data stream. | |
uint16_t | GetBigShort (void) noexcept |
Return a 16 bit big endian value from the data stream. | |
uint32_t | GetWord32 (void) noexcept |
Return a 32 bit little endian value from the data stream. | |
uint32_t | GetBigWord32 (void) noexcept |
Return a 32 bit big endian value from the data stream. | |
uint64_t | GetWord64 (void) noexcept |
Return a 64 bit little endian value from the data stream. | |
uint64_t | GetBigWord64 (void) noexcept |
Return a 64 bit big endian value from the data stream. | |
float | GetFloat (void) noexcept |
Return a 32 bit little endian float from the data stream. | |
float | GetBigFloat (void) noexcept |
Return a 32 bit big endian float from the data stream. | |
double | GetDouble (void) noexcept |
Return a 64 bit little endian float from the data stream. | |
double | GetBigDouble (void) noexcept |
Return a 64 bit big endian float from the data stream. | |
uintptr_t | Get (void *pOutput, uintptr_t uOutputSize) noexcept |
Return an unmodified array of bytes from the input stream. | |
uint_t | Get (RGBWord8_t *pOutput) noexcept |
Extract an R,G,B color from the input stream. | |
uint_t | Get (RGBAWord8_t *pOutput) noexcept |
Extract an R,G,B,A color from the input stream. | |
uint_t | Get (Vector2D_t *pOutput) noexcept |
Extract a Vector2D_t from the input stream. | |
uint_t | Get (Vector3D_t *pOutput) noexcept |
Extract a Vector3D_t from the input stream. | |
uint_t | Get (Vector4D_t *pOutput) noexcept |
Extract a Vector4D_t from the input stream. | |
uint_t | Get (RGBFloat_t *pOutput) noexcept |
uint_t | Get (RGBAFloat_t *pOutput) noexcept |
void | ParseBeyondWhiteSpace (void) noexcept |
Skip past white space in the input stream. | |
uint_t | IsStringMatch (const char *pInput) noexcept |
Test if the next bytes in the stream match. | |
uint_t | IsStringMatchCase (const char *pInput) noexcept |
Case insensitive test if the next bytes in the stream match. | |
uint_t | IsDataMatch (const uint8_t *pInput, uintptr_t uLength) noexcept |
Test if the next bytes in the stream match. | |
Protected Attributes | |
const uint8_t * | m_pWork |
Pointer to the input. | |
const uint8_t * | m_pEndOfBuffer |
Pointer to the end of the buffer. | |
const uint8_t * | m_pData |
Pointer to the first data buffer. | |
uintptr_t | m_uBufferSize |
Size of the buffer. | |
uint_t | m_bDontFree |
TRUE if the memory isn't released on Clear() | |
Private Member Functions | |
InputMemoryStream (const InputMemoryStream &)=delete | |
InputMemoryStream & | operator= (const InputMemoryStream &)=delete |
InputMemoryStream (InputMemoryStream &&)=delete | |
InputMemoryStream & | operator= (InputMemoryStream &&)=delete |
Fast input memory stream.
When parsing a data file, it's much faster to load the entire file into memory and once the data is loaded, sequentially read in the data.
At the onset, the size of the input is known, either through loading in a data file or being given a pointer to a buffer of data and its length, from this, bounds checking is performed as subsequent calls to this class will return requested data until the data has been exhausted.
Multibyte data such as uint32_t will be assumed to be in Little Endian format.
|
privatedelete |
|
privatedelete |
|
noexcept |
Constructor.
Initializes a stream for input. No memory is allocated at this time
|
noexcept |
Constructor with a data file.
Upon construction, open and load in the data file for immediate parsing. Errors can occur and if loading fails or memory isn't allocated, the class will be given an empty buffer and no data will be streamed.
pFilename | Pointer to a Burgerlib filename to a file to load into memory |
|
noexcept |
Constructor with a data file.
Upon construction, open and load in the data file for immediate parsing. Errors can occur and if loading fails or memory isn't allocated, the class will be given an empty buffer and no data will be streamed.
pFilename | Pointer to a Burgerlib Filename to a file to load into memory |
|
noexcept |
Constructor with a input data buffer.
Upon construction, point to the passed data buffer. If the buffer pointer is NULL or there is a zero length buffer, the class will be given an empty buffer and no data will be streamed.
pBuffer | Pointer to an array of bytes to stream from |
uBufferSize | Length of the array in bytes |
bDontFree | FALSE (Default) will have the class call Burger::Free(const void *) on the input pointer on class shutdown. TRUE will disable this behavior. |
Burger::InputMemoryStream::~InputMemoryStream | ( | ) |
Destructor.
Releases all allocated memory.
|
inlinenoexcept |
Return the amount of data remaining to parse in the stream.
If there is any data that hasn't been parsed remaining in the data stream, return the size in bytes. Zero if no data remains.
|
noexcept |
Release all allocated memory.
If there was any memory allocated to load the input stream, release it and reset the class to a "power up" state. After this function call, this class will have empty buffers and all calls to receive data will return nothing
|
inlinenoexcept |
|
noexcept |
Extract an R,G,B,A color from the input stream.
Use the next four bytes as Red, Green, Blue and Alpha (In that order) and store it in the output RGBAWord8_t structure.
pOutput | Pointer to a buffer to store the output |
|
inlinenoexcept |
|
noexcept |
Extract an R,G,B color from the input stream.
Use the next three bytes as Red, Green and Blue (In that order) and store it in the output RGBWord8_t structure.
pOutput | Pointer to a buffer to store the output |
|
noexcept |
Extract a Vector2D_t from the input stream.
Use the next eight bytes as a little endian pair of 32 bit floating point values and store it in the output Vector2D_t structure.
pOutput | Pointer to a buffer to store the output |
|
noexcept |
Extract a Vector3D_t from the input stream.
Use the next twelve bytes as a little endian triplet of 32 bit floating point values and store it in the output Vector3D_t structure.
pOutput | Pointer to a buffer to store the output |
|
noexcept |
Extract a Vector4D_t from the input stream.
Use the next sixteen bytes as a little endian quad of 32 bit floating point values and store it in the output Vector4D_t structure.
pOutput | Pointer to a buffer to store the output |
|
noexcept |
Return an unmodified array of bytes from the input stream.
pOutput | Pointer to buffer to receive data. NULL will perform no data transfer |
uOutputSize | Number of bytes to transfer, ignored if pOutput is NULL |
|
noexcept |
Return a 64 bit big endian float from the data stream.
|
noexcept |
Return a 32 bit big endian float from the data stream.
|
noexcept |
Return a 16 bit big endian value from the data stream.
|
noexcept |
Return a 32 bit big endian value from the data stream.
|
noexcept |
Return a 64 bit big endian value from the data stream.
|
noexcept |
Return an 8 bit value from the data stream.
|
noexcept |
Parse a UTF-8 "C" string from the data stream.
Parse the input until an end of line is found. End of lines are either a '\0' or end of data.
The output buffer is guaranteed to have a terminating zero. If the line is too large, it will be truncated.
pOutput | Buffer to receive the "C" style UTF-8 data string. NULL will disable the string copy, however the string will be "parsed" from the input |
uOutputSize | Size of the buffer pOutput |
|
noexcept |
Return a 64 bit little endian float from the data stream.
|
noexcept |
Return a 32 bit little endian float from the data stream.
|
inlinenoexcept |
Return the current offset into the data stream.
Calculate and return the number of bytes from the start of the stream the current read mark is located
|
noexcept |
Parse a UTF-8 "P" string from the data stream.
Read a single byte from the stream to get the length of the string and then copy those bytes into the buffer.
The output buffer is guaranteed to have a terminating zero. If the line is too large, it will be truncated.
pOutput | Buffer to receive the "C" style UTF-8 data string. NULL will disable the string copy, however the string will be "parsed" from the input |
uOutputSize | Size of the buffer pOutput |
|
inlinenoexcept |
Return the current pointer into the data stream.
Return the current read pointer to the input byte stream.
|
noexcept |
Return a 16 bit little endian value from the data stream.
|
inlinenoexcept |
Return the amount of data stored in the stream.
Calculate and return the number of bytes of valid data that is stored in the data stream.
|
noexcept |
Parse a UTF-8 "C" string from the data stream.
Parse the input until an end of line is found. End of lines are either a '\0' or a '\n'. For compatibility with cross platform text files, '\r' and '\r\n' are acceptable end of line tokens.
The output buffer is guaranteed to have a terminating zero. If the line is too large, it will be truncated.
pOutput | Buffer to receive the "C" style UTF-8 data string. NULL will disable the string copy, however the string will be "parsed" from the input |
uOutputSize | Size of the buffer pOutput |
|
noexcept |
Parse a UTF-8 "C" string from the data stream.
Parse the input until an end of line is found. End of lines are either a '\0' or end of data.
The output String will be sized to contain the new string.
pOutput | Buffer to receive the "C" style UTF-8 data string. |
|
noexcept |
Return a 32 bit little endian value from the data stream.
|
noexcept |
Return a 64 bit little endian value from the data stream.
|
noexcept |
Test if the next bytes in the stream match.
Given an array of bytes, test if the data is the next value in the stream and if true, remove the data from the stream and return TRUE
pInput | Pointer to an array of bytes to test against |
uLength | Length of the data in bytes. |
|
inlinenoexcept |
|
noexcept |
Test if the next bytes in the stream match.
Given a "C" string, test if the string is the next value in the stream and if true, remove the string and return TRUE
pInput | Pointer to a "C" string to match |
|
noexcept |
Case insensitive test if the next bytes in the stream match.
Given a "C" string, test if the string with case insensitivity is the next value in the stream and if true, remove the string and return TRUE
pInput | Pointer to a "C" string to match |
|
noexcept |
Load data from a file.
Open, read and close a file that will contain the contents of the new input data stream.
pFilename | Burgerlib format filename |
|
noexcept |
Use data from a application supplied buffer.
If the buffer pointer is NULL or there is a zero length buffer, the class will be given an empty buffer and no data will be streamed. The data is assumed to be able to be freed by Burger::Free(const void *), if this is not the case, pass TRUE in bDontFree to disable this feature.
pBuffer | Pointer to an array of bytes to stream from |
uBufferSize | Length of the array in bytes |
bDontFree | FALSE (Default) will have the class call Burger::Free(const void *) on the input pointer on class shutdown. TRUE will disable this behavior. |
|
noexcept |
Load data from a file.
Open, read and close a file that will contain the contents of the new input data stream.
pFilename | Pointer to a Filename instance |
|
privatedelete |
|
privatedelete |
|
noexcept |
Skip past white space in the input stream.
If the bytes in the input stream are spaces or tabs, skip over them.
|
noexcept |
Move the read pointer to a location in the stream.
Move the read pointer to the passed offset and all further read calls will proceed from this location.
uOffset | Offset in bytes to read from |
|
noexcept |
Move the read pointer backward in the stream.
Move the read pointer backward the number of bytes requested. If the offset goes beyond the start of the buffer, it will be clamped to the start of the data stream.
uOffset | Offset in bytes to skip backward |
|
noexcept |
Move the read pointer forward in the stream.
Move the read pointer forward the number of bytes requested. If the offset goes beyond the end of the buffer, it will be clamped to the end of the data stream.
uOffset | Offset in bytes to skip forward |
|
protected |
|
protected |
Pointer to the first data buffer.
|
protected |
Pointer to the end of the buffer.
|
protected |
Pointer to the input.
|
protected |
Size of the buffer.