Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Private Member Functions | List of all members
Burger::InputMemoryStream Class Reference

Fast input memory stream. More...

Inheritance diagram for Burger::InputMemoryStream:
Inheritance graph
[legend]

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
 
InputMemoryStreamoperator= (const InputMemoryStream &)=delete
 
 InputMemoryStream (InputMemoryStream &&)=delete
 
InputMemoryStreamoperator= (InputMemoryStream &&)=delete
 

Detailed Description

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.

See also
OutputMemoryStream or InputRezStream

Constructor & Destructor Documentation

◆ InputMemoryStream() [1/6]

Burger::InputMemoryStream::InputMemoryStream ( const InputMemoryStream & )
privatedelete

◆ InputMemoryStream() [2/6]

Burger::InputMemoryStream::InputMemoryStream ( InputMemoryStream && )
privatedelete

◆ InputMemoryStream() [3/6]

Burger::InputMemoryStream::InputMemoryStream ( )
noexcept

Constructor.


Initializes a stream for input. No memory is allocated at this time

◆ InputMemoryStream() [4/6]

Burger::InputMemoryStream::InputMemoryStream ( const char * pFilename)
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.

Parameters
pFilenamePointer to a Burgerlib filename to a file to load into memory

◆ InputMemoryStream() [5/6]

Burger::InputMemoryStream::InputMemoryStream ( Filename * pFilename)
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.

Parameters
pFilenamePointer to a Burgerlib Filename to a file to load into memory

◆ InputMemoryStream() [6/6]

Burger::InputMemoryStream::InputMemoryStream ( const void * pBuffer,
uintptr_t uBufferSize,
uint_t bDontFree = 0 )
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.

Parameters
pBufferPointer to an array of bytes to stream from
uBufferSizeLength of the array in bytes
bDontFreeFALSE (Default) will have the class call Burger::Free(const void *) on the input pointer on class shutdown. TRUE will disable this behavior.

◆ ~InputMemoryStream()

Burger::InputMemoryStream::~InputMemoryStream ( )

Destructor.


Releases all allocated memory.

Member Function Documentation

◆ BytesRemaining()

uintptr_t Burger::InputMemoryStream::BytesRemaining ( void ) const
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.

Returns
The number of bytes remaining to parse.

◆ Clear()

void BURGER_API Burger::InputMemoryStream::Clear ( void )
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

◆ Get() [1/8]

uint_t Burger::InputMemoryStream::Get ( RGBAFloat_t * pOutput)
inlinenoexcept

◆ Get() [2/8]

uint_t BURGER_API Burger::InputMemoryStream::Get ( RGBAWord8_t * pOutput)
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.

Parameters
pOutputPointer to a buffer to store the output
Returns
Zero if no error, non zero if there isn't enough data in the stream for the output.
See also
Get(RGBWord8_t *)

◆ Get() [3/8]

uint_t Burger::InputMemoryStream::Get ( RGBFloat_t * pOutput)
inlinenoexcept

◆ Get() [4/8]

uint_t BURGER_API Burger::InputMemoryStream::Get ( RGBWord8_t * pOutput)
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.

Parameters
pOutputPointer to a buffer to store the output
Returns
Zero if no error, non zero if there isn't enough data in the stream for the output.
See also
Get(RGBAWord8_t *)

◆ Get() [5/8]

uint_t BURGER_API Burger::InputMemoryStream::Get ( Vector2D_t * pOutput)
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.

Parameters
pOutputPointer to a buffer to store the output
Returns
Zero if no error, non zero if there isn't enough data in the stream for the output.
See also
Get(Vector3D_t *) or Get(Vector4D_t *)

◆ Get() [6/8]

uint_t BURGER_API Burger::InputMemoryStream::Get ( Vector3D_t * pOutput)
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.

Parameters
pOutputPointer to a buffer to store the output
Returns
Zero if no error, non zero if there isn't enough data in the stream for the output.
See also
Get(Vector2D_t *) or Get(Vector4D_t *)

◆ Get() [7/8]

uint_t BURGER_API Burger::InputMemoryStream::Get ( Vector4D_t * pOutput)
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.

Parameters
pOutputPointer to a buffer to store the output
Returns
Zero if no error, non zero if there isn't enough data in the stream for the output.
See also
Get(Vector2D_t *) or Get(Vector3D_t *)

◆ Get() [8/8]

uintptr_t BURGER_API Burger::InputMemoryStream::Get ( void * pOutput,
uintptr_t uOutputSize )
noexcept

Return an unmodified array of bytes from the input stream.


Parameters
pOutputPointer to buffer to receive data. NULL will perform no data transfer
uOutputSizeNumber of bytes to transfer, ignored if pOutput is NULL
Returns
The number of bytes transferred. Is equal to uOutputSize of BytesRemaining(), whichever is less.

◆ GetBigDouble()

double BURGER_API Burger::InputMemoryStream::GetBigDouble ( void )
noexcept

Return a 64 bit big endian float from the data stream.


Returns
Next 64 bit value from the stream. Zero if there is no data remaining.
See also
GetDouble(void) or GetBigFloat(void)

◆ GetBigFloat()

float BURGER_API Burger::InputMemoryStream::GetBigFloat ( void )
noexcept

Return a 32 bit big endian float from the data stream.


Returns
Next 32 bit value from the stream. Zero if there is no data remaining.
See also
GetFloat(void) or GetBigDouble(void)

◆ GetBigShort()

uint16_t BURGER_API Burger::InputMemoryStream::GetBigShort ( void )
noexcept

Return a 16 bit big endian value from the data stream.


Returns
Next 16 bit value from the stream. Zero if there is no data remaining.
See also
GetShort(void) or GetBigWord32(void)

◆ GetBigWord32()

uint32_t BURGER_API Burger::InputMemoryStream::GetBigWord32 ( void )
noexcept

Return a 32 bit big endian value from the data stream.


Returns
Next 32 bit value from the stream. Zero if there is no data remaining.
See also
GetWord32(void) or GetBigShort(void)

◆ GetBigWord64()

uint64_t BURGER_API Burger::InputMemoryStream::GetBigWord64 ( void )
noexcept

Return a 64 bit big endian value from the data stream.


Returns
Next 64 bit value from the stream. Zero if there is no data remaining.
See also
GetWord64(void) or GetBigWord32(void)

◆ GetByte()

uint8_t BURGER_API Burger::InputMemoryStream::GetByte ( void )
noexcept

Return an 8 bit value from the data stream.


Returns
Next 8 bit value from the stream. Zero if there is no data remaining.

◆ GetCString()

void BURGER_API Burger::InputMemoryStream::GetCString ( char * pOutput,
uintptr_t uOutputSize )
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.

Parameters
pOutputBuffer to receive the "C" style UTF-8 data string. NULL will disable the string copy, however the string will be "parsed" from the input
uOutputSizeSize of the buffer pOutput
See also
GetPString(char *,uintptr_t)

◆ GetDouble()

double BURGER_API Burger::InputMemoryStream::GetDouble ( void )
noexcept

Return a 64 bit little endian float from the data stream.


Returns
Next 64 bit value from the stream. Zero if there is no data remaining.
See also
GetBigDouble(void) or GetFloat(void)

◆ GetFloat()

float BURGER_API Burger::InputMemoryStream::GetFloat ( void )
noexcept

Return a 32 bit little endian float from the data stream.


Returns
Next 32 bit value from the stream. Zero if there is no data remaining.
See also
GetBigFloat(void) or GetDouble(void)

◆ GetMark()

uintptr_t Burger::InputMemoryStream::GetMark ( void ) const
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

Returns
Offset in byte from the beginning of the stream.
See also
GetSize(void) const

◆ GetPString()

void BURGER_API Burger::InputMemoryStream::GetPString ( char * pOutput,
uintptr_t uOutputSize )
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.

Parameters
pOutputBuffer to receive the "C" style UTF-8 data string. NULL will disable the string copy, however the string will be "parsed" from the input
uOutputSizeSize of the buffer pOutput
See also
GetCString(char *,uintptr_t)

◆ GetPtr()

const uint8_t * Burger::InputMemoryStream::GetPtr ( void ) const
inlinenoexcept

Return the current pointer into the data stream.


Return the current read pointer to the input byte stream.

Returns
Current read pointer to the input byte stream.
See also
GetMark(void) const

◆ GetShort()

uint16_t BURGER_API Burger::InputMemoryStream::GetShort ( void )
noexcept

Return a 16 bit little endian value from the data stream.


Returns
Next 16 bit value from the stream. Zero if there is no data remaining.
See also
GetBigShort(void) or GetWord32(void)

◆ GetSize()

uintptr_t Burger::InputMemoryStream::GetSize ( void ) const
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.

Returns
Number of bytes stored in the stream.
See also
GetMark(void) const

◆ GetString() [1/2]

void BURGER_API Burger::InputMemoryStream::GetString ( char * pOutput,
uintptr_t uOutputSize )
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.

Parameters
pOutputBuffer to receive the "C" style UTF-8 data string. NULL will disable the string copy, however the string will be "parsed" from the input
uOutputSizeSize of the buffer pOutput
See also
GetCString(char *,uintptr_t) or GetPString(char *,uintptr_t)

◆ GetString() [2/2]

void BURGER_API Burger::InputMemoryStream::GetString ( String * 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.

Parameters
pOutputBuffer to receive the "C" style UTF-8 data string.
See also
GetCString(char *,uintptr_t),GetPString(char *,uintptr_t)

◆ GetWord32()

uint32_t BURGER_API Burger::InputMemoryStream::GetWord32 ( void )
noexcept

Return a 32 bit little endian value from the data stream.


Returns
Next 32 bit value from the stream. Zero if there is no data remaining.
See also
GetBigWord32(void) or GetShort(void)

◆ GetWord64()

uint64_t BURGER_API Burger::InputMemoryStream::GetWord64 ( void )
noexcept

Return a 64 bit little endian value from the data stream.


Returns
Next 64 bit value from the stream. Zero if there is no data remaining.
See also
GetBigWord64(void) or GetWord32(void)

◆ IsDataMatch()

uint_t BURGER_API Burger::InputMemoryStream::IsDataMatch ( const uint8_t * pInput,
uintptr_t uLength )
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

Note
A length of 0 will return TRUE in all cases and remove no data from the stream.
Parameters
pInputPointer to an array of bytes to test against
uLengthLength of the data in bytes.
Returns
TRUE if it was a match, FALSE if not

◆ IsEmpty()

uint_t Burger::InputMemoryStream::IsEmpty ( void ) const
inlinenoexcept

Return TRUE if there is no data remaining to parse in the stream.


If there is any data that hasn't been parsed remaining in the data stream, return TRUE, otherwise return FALSE

Returns
TRUE if no data remains. FALSE if there is more data to parse.

◆ IsStringMatch()

uint_t BURGER_API Burger::InputMemoryStream::IsStringMatch ( const char * pInput)
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

Parameters
pInputPointer to a "C" string to match
Returns
TRUE if it was a match, FALSE if not
See also
IsStringMatchCase(const char *)

◆ IsStringMatchCase()

uint_t BURGER_API Burger::InputMemoryStream::IsStringMatchCase ( const char * pInput)
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

Parameters
pInputPointer to a "C" string to match
Returns
TRUE if it was a match, FALSE if not
See also
IsStringMatch(const char *)

◆ Open() [1/3]

uint_t BURGER_API Burger::InputMemoryStream::Open ( const char * pFilename)
noexcept

Load data from a file.


Open, read and close a file that will contain the contents of the new input data stream.

Parameters
pFilenameBurgerlib format filename
Returns
Error code with zero being no error, non-zero is an error condition

◆ Open() [2/3]

void BURGER_API Burger::InputMemoryStream::Open ( const void * pBuffer,
uintptr_t uBufferSize,
uint_t bDontFree = 0 )
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.

Parameters
pBufferPointer to an array of bytes to stream from
uBufferSizeLength of the array in bytes
bDontFreeFALSE (Default) will have the class call Burger::Free(const void *) on the input pointer on class shutdown. TRUE will disable this behavior.

◆ Open() [3/3]

uint_t BURGER_API Burger::InputMemoryStream::Open ( Filename * pFilename)
noexcept

Load data from a file.


Open, read and close a file that will contain the contents of the new input data stream.

Parameters
pFilenamePointer to a Filename instance
Returns
Error code with zero being no error, non-zero is an error condition

◆ operator=() [1/2]

InputMemoryStream & Burger::InputMemoryStream::operator= ( const InputMemoryStream & )
privatedelete

◆ operator=() [2/2]

InputMemoryStream & Burger::InputMemoryStream::operator= ( InputMemoryStream && )
privatedelete

◆ ParseBeyondWhiteSpace()

void BURGER_API Burger::InputMemoryStream::ParseBeyondWhiteSpace ( void )
noexcept

Skip past white space in the input stream.


If the bytes in the input stream are spaces or tabs, skip over them.

Note
This function only skips over data in the stream, if may set the stream to the end if there are only spaces and tabs remaining.

◆ SetMark()

void BURGER_API Burger::InputMemoryStream::SetMark ( uintptr_t uOffset)
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.

Note
If the value is larger than the end of the data, the mark will be clamped to the end if the data
Parameters
uOffsetOffset in bytes to read from
See also
GetMark(void) const, SkipBack(uintptr_t) or SkipForward(uintptr_t)

◆ SkipBack()

void BURGER_API Burger::InputMemoryStream::SkipBack ( uintptr_t uOffset)
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.

Parameters
uOffsetOffset in bytes to skip backward
See also
GetMark(void) const, SkipForward(uintptr_t) or SetMark(uintptr_t)

◆ SkipForward()

void BURGER_API Burger::InputMemoryStream::SkipForward ( uintptr_t uOffset)
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.

Parameters
uOffsetOffset in bytes to skip forward
See also
GetMark(void) const, SkipBack(uintptr_t) or SetMark(uintptr_t)

Member Data Documentation

◆ m_bDontFree

uint_t Burger::InputMemoryStream::m_bDontFree
protected

TRUE if the memory isn't released on Clear()

◆ m_pData

const uint8_t* Burger::InputMemoryStream::m_pData
protected

Pointer to the first data buffer.

◆ m_pEndOfBuffer

const uint8_t* Burger::InputMemoryStream::m_pEndOfBuffer
protected

Pointer to the end of the buffer.

◆ m_pWork

const uint8_t* Burger::InputMemoryStream::m_pWork
protected

Pointer to the input.

◆ m_uBufferSize

uintptr_t Burger::InputMemoryStream::m_uBufferSize
protected

Size of the buffer.