Fast output memory stream. More...
Classes | |
struct | Chunk_t |
Data chunk for OutputMemoryStream. More... | |
Public Member Functions | |
OutputMemoryStream () noexcept | |
Default constructor. | |
~OutputMemoryStream () | |
Destructor. | |
OutputMemoryStream (const OutputMemoryStream &rInput) noexcept | |
Copy constructor. | |
OutputMemoryStream & | operator= (const OutputMemoryStream &rInput) noexcept |
Assignment operator. | |
OutputMemoryStream (OutputMemoryStream &&rInput) noexcept | |
OutputMemoryStream & | operator= (OutputMemoryStream &&rInput) noexcept |
void | Clear (void) noexcept |
Release all allocated memory. | |
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 in the stream. | |
eError | GetError (void) const noexcept |
Return non zero if the stream is corrupt. | |
eError | SetMark (uintptr_t uMark) noexcept |
Set the current write mark. | |
uintptr_t | GetMark (void) const noexcept |
Return the current write mark. | |
eError | SaveFile (const char *pFilename) const noexcept |
Save the data into a file. | |
eError | SaveFile (Filename *pFilename) const noexcept |
Save the data into a file. | |
eError | Save (String *pOutput) const noexcept |
Save the data into a String. | |
eError | Flatten (void *pOutput, uintptr_t uLength) const noexcept |
Flatten the data into a single buffer. | |
void * | Flatten (uintptr_t *pLength) const noexcept |
Flatten the data into a single buffer. | |
eError | Append (char iChar) noexcept |
Add a text character to the data stream. | |
eError | Append (const char *pString) noexcept |
Add a UTF-8 "C" string to the data stream. | |
eError | AppendCString (const char *pString) noexcept |
Add a UTF-8 "C" string to the data stream. | |
eError | Append (const String *pString) noexcept |
Add a UTF-8 "C" string to the data stream. | |
eError | AppendPString (const char *pString) noexcept |
Add a UTF-8 "P" string to the data stream. | |
eError | Append (uint8_t uInput) noexcept |
Add a single byte to the end of the data stream. | |
eError | Append (uint16_t uInput) noexcept |
Add a 16 bit value to the end of the data stream. | |
eError | Append (uint32_t uInput) noexcept |
Add a 32 bit value to the end of the data stream. | |
eError | Append (uint64_t uInput) noexcept |
Add a 64 bit value to the end of the data stream. | |
eError | Append (float fInput) noexcept |
Add a 32 bit floating point value to the end of the data stream. | |
eError | Append (double dInput) noexcept |
Add a 64 bit floating point value to the end of the data stream. | |
eError | Append (const RGBWord8_t *pInput) noexcept |
Add an R, G, B color to the end of the data stream. | |
eError | Append (const RGBAWord8_t *pInput) noexcept |
Add an R, G, B, A color to the end of the data stream. | |
eError | Append (const Vector3D_t *pInput) noexcept |
Add an X, Y, Z floating point value to the end of the data stream. | |
eError | Append (const Vector4D_t *pInput) noexcept |
Add an X, Y, Z, W floating point value to the end of the data stream. | |
eError | Append (const RGBFloat_t *pInput) noexcept |
Add an R, G, B floating point value to the end of the data stream. | |
eError | Append (const RGBAFloat_t *pInput) noexcept |
Add an R, G, B, A floating point value to the end of the data stream. | |
eError | Append (const void *pData, uintptr_t uSize) noexcept |
Add an array of bytes to the data stream. | |
eError | BigEndianAppend (uint16_t uInput) noexcept |
Add a 16 bit value to the end of the data stream. | |
eError | BigEndianAppend (uint32_t uInput) noexcept |
Add a 32 bit value to the end of the data stream. | |
eError | BigEndianAppend (uint64_t uInput) noexcept |
Add a 64 bit value to the end of the data stream. | |
eError | BigEndianAppend (float fInput) noexcept |
Add a 32 bit floating point value to the end of the data stream. | |
eError | BigEndianAppend (double dInput) noexcept |
Add a 64 bit floating point value to the end of the data stream. | |
eError | AppendAscii (uint16_t uInput) noexcept |
Convert a 16 bit unsigned integer to text and append it. | |
eError | AppendAscii (uint32_t uInput) noexcept |
Convert a 32 bit unsigned integer to text and append it. | |
eError | AppendAscii (uint64_t uInput) noexcept |
Convert a 64 bit unsigned integer to text and append it. | |
eError | AppendAscii (int16_t iInput) noexcept |
Convert a 16 bit signed integer to text and append it. | |
eError | AppendAscii (int32_t iInput) noexcept |
Convert a 32 bit signed integer to text and append it. | |
eError | AppendAscii (int64_t iInput) noexcept |
Convert a 64 bit signed integer to text and append it. | |
eError | AppendAscii (float fInput) noexcept |
Convert a 32 bit floating point number to text and append it. | |
eError | AppendAscii (double dInput) noexcept |
Convert a 64 bit floating point number to text and append it. | |
eError | AppendTabs (uint_t uTabCount) noexcept |
Insert a number of tabs into the data stream. | |
uint_t | Compare (const void *pInput, uintptr_t uLength) const noexcept |
Compare data to the data in the stream. | |
eError | Overwrite (const void *pInput, uintptr_t uLength, uintptr_t uOffset) noexcept |
Overwrite data in the stream. | |
Static Public Attributes | |
static const uintptr_t | kChunkSize |
Size of each data chunk. | |
Private Attributes | |
Chunk_t * | m_pRoot |
Pointer to the first chunk. | |
Chunk_t * | m_pCurrent |
Pointer to the current chunk. | |
uintptr_t | m_uIndex |
Number of bytes used the current chunk. | |
uintptr_t | m_uFileSize |
Number of bytes stored in the stream. | |
eError | m_uError |
Did an error occur? | |
Fast output memory stream.
When generating a new data file, it's much faster to stream the data into memory and once the data is written, store it out to disk.
If the size of the output file is not known, allocating a buffer large enough to hold the data is educated guesswork. This class solves this problem twofold, firstly, it allocates in reasonable sized chunks to prevent out of memory situations due to allocating very large memory blocks and not succeeding due to fragmentation. Secondly, it will allow writing to a byte stream so data alignment at the stream level is not necessary and large data is always stored in little endian format so files created this way will be cross platform.
|
noexcept |
Default constructor.
Initializes a stream for output. No memory is allocated at this time
Burger::OutputMemoryStream::~OutputMemoryStream | ( | ) |
Destructor.
Releases all memory. This does NOT save anything to disk
|
noexcept |
Copy constructor.
Can default to error condition if out of memory.
|
noexcept |
|
noexcept |
Add a text character to the data stream.
Assume the character is from a text stream, so if it's a '\n', convert it to the proper type for the target operating system such as '\n' for Linux, '\r' for MacOS and '\n\r' for Windows.
iChar | Single byte of a UTF-8 text file stream |
|
noexcept |
Add a UTF-8 "C" string to the data stream.
If the string has any '\n' in it, they will be converted to the proper type for the target operating system such as '\n' for Linux, '\r' for MacOS and '\n\r' for Windows.
pString | "C" UTF-8 data string. nullptr will perform no action and return no error. |
|
inlinenoexcept |
Add an R, G, B, A floating point value to the end of the data stream.
Append four 32 bit floats to the end of the data stream and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
Data is stored in little endian format
pInput | Pointer to an R, G, B and A value to append to the stream |
|
noexcept |
Add an R, G, B, A color to the end of the data stream.
Append four bytes to the end of the data stream and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
pInput | Pointer to an R, G, B and A color value to append to the stream |
|
inlinenoexcept |
Add an R, G, B floating point value to the end of the data stream.
Append three 32 bit floats to the end of the data stream and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
Data is stored in little endian format
pInput | Pointer to an R, B, and G value to append to the stream |
|
noexcept |
Add an R, G, B color to the end of the data stream.
Append three bytes to the end of the data stream and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
pInput | Pointer to an R, G and B color value to append to the stream |
Add a UTF-8 "C" string to the data stream.
The data stream will have a zero terminated "C" string obtained from the String class instance.
The terminating zero will be included in the stream, if this is not desired, call Append(const char *) instead with the pointer from the String::GetPtr() const function.
pString | Pointer to a String class |
|
noexcept |
Add an X, Y, Z floating point value to the end of the data stream.
Append three 32 bit floats to the end of the data stream and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
Data is stored in little endian format
pInput | Pointer to an X, Y, and Z value to append to the stream |
|
noexcept |
Add an X, Y, Z, W floating point value to the end of the data stream.
Append four 32 bit floats to the end of the data stream and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
Data is stored in little endian format
pInput | Pointer to an X, Y, Z and W value to append to the stream |
|
noexcept |
Add an array of bytes to the data stream.
Given a buffer pointer and a length, append the byte stream to the output stream.
pData | Pointer to the data to append to the stream. nullptr performs no operation |
uSize | Number of bytes to append to the stream. Zero performs no operation |
|
noexcept |
Add a 64 bit floating point value to the end of the data stream.
Append eight bytes to the end of the data stream in little endian format and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
dInput | 64 bits of data to append to the stream |
|
noexcept |
Add a 32 bit floating point value to the end of the data stream.
Append four bytes to the end of the data stream in little endian format and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
fInput | 32 bits of data to append to the stream |
|
noexcept |
Add a 16 bit value to the end of the data stream.
Append two bytes to the end of the data stream in little endian format and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
uInput | 16 bits of data to append to the stream |
|
noexcept |
Add a 32 bit value to the end of the data stream.
Append four bytes to the end of the data stream in little endian format and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
uInput | 32 bits of data to append to the stream |
|
noexcept |
Add a 64 bit value to the end of the data stream.
Append eight bytes to the end of the data stream in little endian format and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
uInput | 64 bits of data to append to the stream |
|
noexcept |
Add a single byte to the end of the data stream.
Append a single byte to the end of the data stream and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
uInput | Byte of data to append to the stream |
|
noexcept |
Convert a 64 bit floating point number to text and append it.
Convert a 64 bit floating pointer number into ASCII and append the resulting string to the end of the stream. If the memory allocation fails, a non-zero error code will be returned.
dInput | 64 bit floating point value to append to the stream as ASCII |
|
noexcept |
Convert a 32 bit floating point number to text and append it.
Convert a 32 bit floating pointer number into ASCII and append the resulting string to the end of the stream. If the memory allocation fails, a non-zero error code will be returned.
fInput | 32 bit floating point value to append to the stream as ASCII |
|
noexcept |
Convert a 16 bit signed integer to text and append it.
Convert a 16 bit signed integer into ASCII and append the resulting string to the end of the stream. If the memory allocation fails, a non-zero error code will be returned.
iInput | 16 bit value to append to the stream as ASCII |
|
noexcept |
Convert a 32 bit signed integer to text and append it.
Convert a 32 bit signed integer into ASCII and append the resulting string to the end of the stream. If the memory allocation fails, a non-zero error code will be returned.
iInput | 32 bit value to append to the stream as ASCII |
|
noexcept |
Convert a 64 bit signed integer to text and append it.
Convert a 64 bit signed integer into ASCII and append the resulting string to the end of the stream. If the memory allocation fails, a non-zero error code will be returned.
iInput | 64 bit value to append to the stream as ASCII |
|
noexcept |
Convert a 16 bit unsigned integer to text and append it.
Convert a 16 bit unsigned integer into ASCII and append the resulting string to the end of the stream. If the memory allocation fails, a non-zero error code will be returned.
uInput | 16 bit value to append to the stream as ASCII |
|
noexcept |
Convert a 32 bit unsigned integer to text and append it.
Convert a 32 bit unsigned integer into ASCII and append the resulting string to the end of the stream. If the memory allocation fails, a non-zero error code will be returned.
uInput | 32 bit value to append to the stream as ASCII |
|
noexcept |
Convert a 64 bit unsigned integer to text and append it.
Convert a 64 bit unsigned integer into ASCII and append the resulting string to the end of the stream. If the memory allocation fails, a non-zero error code will be returned.
uInput | 64 bit value to append to the stream as ASCII |
|
noexcept |
Add a UTF-8 "C" string to the data stream.
The data stream will have a zero terminated "C" string.
The terminating zero will be included in the stream, if this is not desired, call Append(const char *) instead
pString | "C" UTF-8 data string. nullptr will insert a zero length string |
|
noexcept |
Add a UTF-8 "P" string to the data stream.
The data stream will be first given a byte with the length of the string, followed by the string. If the string is greater than 255 bytes in length, it will be truncated in the stream.
pString | "C" UTF-8 data string. nullptr will perform no action and return no error. |
|
noexcept |
Insert a number of tabs into the data stream.
For some text files, tabs are needed for formatting. Insert a number of tabs into the stream.
uTabCount | 0 or more tabs to insert |
|
noexcept |
Add a 64 bit floating point value to the end of the data stream.
Append eight bytes to the end of the data stream in big endian format and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
dInput | 64 bits of data to append to the stream |
|
noexcept |
Add a 32 bit floating point value to the end of the data stream.
Append four bytes to the end of the data stream in big endian format and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
fInput | 32 bits of data to append to the stream |
|
noexcept |
Add a 16 bit value to the end of the data stream.
Append two bytes to the end of the data stream in big endian format and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
uInput | 16 bits of data to append to the stream |
|
noexcept |
Add a 32 bit value to the end of the data stream.
Append four bytes to the end of the data stream in big endian format and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
uInput | 32 bits of data to append to the stream |
|
noexcept |
Add a 64 bit value to the end of the data stream.
Append eight bytes to the end of the data stream in big endian format and allocate memory if necessary. If the memory allocation fails, a non-zero error code will be returned.
uInput | 64 bits of data to append to the stream |
|
noexcept |
Release all allocated memory.
If there was any memory allocated to store the output stream, release it and reset the class to a "power up" state. After this function call, this class can be recycled to create a new output stream
|
noexcept |
Compare data to the data in the stream.
Given a buffer of data, do a byte for byte compare with the data in the stream and return FALSE if the data matches and non-zero if the data does not.
pInput | Pointer to the buffer to match |
uLength | Size of the buffer to match |
|
noexcept |
Flatten the data into a single buffer.
Allocate a buffer and fill it with the data in the stream. When the buffer is no longer needed, release it with a call to Burger::Free()
pLength | Size of the buffer returned |
|
noexcept |
Flatten the data into a single buffer.
Fill a supplied buffer with the contents of the byte stream
pOutput | Pointer to a buffer to copy the data into |
uLength | Size of the buffer |
|
inlinenoexcept |
Return non zero if the stream is corrupt.
During data writing, memory may need to be allocated. If an allocation failed, the error state is set and can only be cleared with a call to Clear() which resets the state to empty.
|
noexcept |
Return the current write mark.
Calculate the current offset from the beginning of the stream where the next data will be written, return that value.
|
inlinenoexcept |
Return the amount of data stored in the stream.
Calculate and return the number of bytes of valid data that has been stored in the data stream.
|
inlinenoexcept |
|
noexcept |
Assignment operator.
Can default to error condition if out of memory.
|
noexcept |
|
noexcept |
Overwrite data in the stream.
Given a buffer of data, replace the data in the stream and return zero if no error and non-zero if there is an attempted buffer overrun.
pInput | Pointer to the buffer to match |
uLength | Size of the buffer to match |
uOffset | Offset into the data to begin the overwrite |
|
noexcept |
|
noexcept |
Save the data into a file.
Open, write and close a file that will contain the contents of the entire data stream.
pFilename | Burgerlib format filename |
|
noexcept |
Save the data into a file.
Open, write and close a file that will contain the contents of the entire data stream.
pFilename | Burgerlib filename |
|
noexcept |
Set the current write mark.
Set the write mark. If it's beyond the existing write buffer, expand the buffer to accommodate and adjust the buffer length.
Size of each data chunk.
|
private |
Pointer to the current chunk.
|
private |
Pointer to the first chunk.
|
private |
Did an error occur?
|
private |
Number of bytes stored in the stream.
|
private |
Number of bytes used the current chunk.