jjSTREAM class JJ2+
A buffer of bytes for storing data and exchanging it with files
Data is appended at the end and read from the front, which removes it. push() and pop() store and restore values of primitive types, strings and other streams in binary form; write(), get() and getLine() work with raw bytes. A stream can be saved to a file and created from one.
Constructors
Functions
- void clear() C++
- Removes all contents of the stream
- bool discard(uint count)
- Removes
countbytes from the front of the stream - bool get(string&out value, uint count = 1)
- Reads
countbytes from the front of the stream into a string - bool get(jjSTREAM&out value, uint count = 1)
- Reads
countbytes from the front of the stream and appends them to another stream - bool getLine(string&out value, const string&in delim = '\n')
- Reads text from the front of the stream up to a delimiter
- uint getSize() const C++
- Returns the number of bytes left in the stream
- bool isEmpty() const C++
- Returns whether no bytes are left in the stream
- bool pop(bool&out value)
- Reads a boolean value from the front of the stream
- bool pop(uint8&out value) C++
- Reads an unsigned 8-bit value from the front of the stream
- bool pop(int8&out value) C++
- Reads a signed 8-bit value from the front of the stream
- bool pop(uint16&out value) C++
- Reads an unsigned 16-bit value from the front of the stream
- bool pop(int16&out value) C++
- Reads a signed 16-bit value from the front of the stream
- bool pop(uint32&out value) C++
- Reads an unsigned 32-bit value from the front of the stream
- bool pop(int32&out value) C++
- Reads a signed 32-bit value from the front of the stream
- bool pop(uint64&out value) C++
- Reads an unsigned 64-bit value from the front of the stream
- bool pop(int64&out value) C++
- Reads a signed 64-bit value from the front of the stream
- bool pop(float&out value) C++
- Reads a single-precision float from the front of the stream
- bool pop(double&out value) C++
- Reads a double-precision float from the front of the stream
- bool pop(string&out value)
- Reads a string stored by
push()from the front of the stream - bool pop(jjSTREAM&out value)
- Reads a stream stored by
push()from the front of the stream and appends it to another stream - bool push(bool value)
- Appends a boolean value to the stream
- bool push(uint8 value) C++
- Appends an unsigned 8-bit value to the stream
- bool push(int8 value) C++
- Appends a signed 8-bit value to the stream
- bool push(uint16 value) C++
- Appends an unsigned 16-bit value to the stream
- bool push(int16 value) C++
- Appends a signed 16-bit value to the stream
- bool push(uint32 value) C++
- Appends an unsigned 32-bit value to the stream
- bool push(int32 value) C++
- Appends a signed 32-bit value to the stream
- bool push(uint64 value) C++
- Appends an unsigned 64-bit value to the stream
- bool push(int64 value) C++
- Appends a signed 64-bit value to the stream
- bool push(float value) C++
- Appends a single-precision float to the stream
- bool push(double value) C++
- Appends a double-precision float to the stream
- bool push(const string&in value) C++
- Appends a string to the stream, preceded by its length
- bool push(const jjSTREAM&in value) C++
- Appends the unread contents of another stream, preceded by their length
- bool save(const string&in filename) const
- Saves the contents of the stream to a file and returns whether it succeeded
- bool write(const string&in value)
- Appends the bytes of a string to the stream
- bool write(const jjSTREAM&in value) C++
- Appends the unread bytes of another stream, without storing their length; always returns
true
Operators
Constructor documentation
Function documentation
bool jjSTREAM:: getLine(string&out value,
const string&in delim = '\n')
Reads text from the front of the stream up to a delimiter
The text before delim is stored in value, and both are removed from the stream. If the delimiter isn't found, the rest of the stream becomes the line and the stream ends up empty. Returns false only if the stream is empty or delim is empty.
bool jjSTREAM:: push(bool value)
Appends a boolean value to the stream
Every push() overload appends its value in binary form and returns true: 1 byte for bool, int8 and uint8, 2 bytes for the 16-bit types, 4 bytes for int, uint and float, 8 bytes for the 64-bit types and double. Strings and streams take 4 bytes of length followed by their bytes. Read the values back with pop() in the same order and types.
bool jjSTREAM:: save(const string&in filename) const
Saves the contents of the stream to a file and returns whether it succeeded
The file is written next to the game's data; names that point outside that directory are rejected. The stream itself is left unchanged. Always fails while the level runs inside the level editor.