Rudiments
Public Member Functions | List of all members
bytebuffer Class Reference

Inherits output.

Inherited by stringbuffer, ucs2stringbuffer, and wstringbuffer.

Public Member Functions

 bytebuffer ()
 
 bytebuffer (size_t initialsize)
 
 bytebuffer (byte_t *initialcontents, size_t initialsize)
 
 bytebuffer (bytebuffer &v)
 
bytebufferoperator= (bytebuffer &v)
 
virtual ~bytebuffer ()
 
off64_t setPositionRelativeToBeginning (off64_t offset)
 
off64_t setPositionRelativeToCurrent (off64_t offset)
 
off64_t setPositionRelativeToEnd (off64_t offset)
 
off64_t getPosition ()
 
ssize_t write (const byte_t *data, size_t size)
 
ssize_t write (const char *string, size_t length)
 
ssize_t write (const char *string)
 
ssize_t write (const wchar_t *string, size_t length)
 
ssize_t write (const wchar_t *string)
 
ssize_t writeUcs2 (const ucs2_t *string, size_t length)
 
ssize_t writeUcs2 (const ucs2_t *string)
 
ssize_t write (char character)
 
ssize_t write (wchar_t character)
 
ssize_t writeUcs2 (ucs2_t character)
 
ssize_t write (int16_t number)
 
ssize_t write (int32_t number)
 
ssize_t write (int64_t number)
 
ssize_t write (byte_t character)
 
ssize_t write (uint16_t number)
 
ssize_t write (uint32_t number)
 
ssize_t write (uint64_t number)
 
ssize_t write (float number)
 
ssize_t write (double number)
 
bytebufferappend (const byte_t *data, size_t size)
 
bytebufferappend (const char *string, size_t length)
 
bytebufferappend (const char *string)
 
bytebufferappend (const wchar_t *string, size_t length)
 
bytebufferappend (const wchar_t *string)
 
bytebufferappendUcs2 (const ucs2_t *string, size_t length)
 
bytebufferappendUcs2 (const ucs2_t *string)
 
bytebufferappend (char character)
 
bytebufferappend (wchar_t character)
 
bytebufferappendUcs2 (ucs2_t character)
 
bytebufferappend (int16_t number)
 
bytebufferappend (int32_t number)
 
bytebufferappend (int64_t number)
 
bytebufferappend (byte_t character)
 
bytebufferappend (uint16_t number)
 
bytebufferappend (uint32_t number)
 
bytebufferappend (uint64_t number)
 
bytebufferappend (float number)
 
bytebufferappend (double number)
 
virtual void truncate (size_t pos)
 
virtual void truncate ()
 
ssize_t read (byte_t *data, size_t size)
 
bool clear ()
 
bool clear (size_t initialsize)
 
bool clear (byte_t *initialcontents, size_t initialsize)
 
const byte_t * getBuffer ()
 
size_t getSize ()
 
size_t getActualSize ()
 
size_t getInitialSize ()
 
byte_t * detachBuffer ()
 
- Public Member Functions inherited from output
 output ()
 
virtual ~output ()
 
virtual ssize_t write (const byte_t *string, size_t size, int32_t sec, int32_t usec)
 
virtual ssize_t write (const char *string, int32_t sec, int32_t usec)
 
virtual ssize_t write (const char *string, size_t length, int32_t sec, int32_t usec)
 
virtual ssize_t write (char character, int32_t sec, int32_t usec)
 
virtual ssize_t write (const wchar_t *string, int32_t sec, int32_t usec)
 
virtual ssize_t write (const wchar_t *string, size_t length, int32_t sec, int32_t usec)
 
virtual ssize_t write (wchar_t character, int32_t sec, int32_t usec)
 
virtual ssize_t writeUcs2 (const ucs2_t *string, int32_t sec, int32_t usec)
 
virtual ssize_t writeUcs2 (const ucs2_t *string, size_t length, int32_t sec, int32_t usec)
 
virtual ssize_t writeUcs2 (ucs2_t character, int32_t sec, int32_t usec)
 
virtual ssize_t write (int16_t number, int32_t sec, int32_t usec)
 
virtual ssize_t write (int32_t number, int32_t sec, int32_t usec)
 
virtual ssize_t write (int64_t number, int32_t sec, int32_t usec)
 
virtual ssize_t write (byte_t character, int32_t sec, int32_t usec)
 
virtual ssize_t write (uint16_t number, int32_t sec, int32_t usec)
 
virtual ssize_t write (uint32_t number, int32_t sec, int32_t usec)
 
virtual ssize_t write (uint64_t number, int32_t sec, int32_t usec)
 
virtual ssize_t write (float number, int32_t sec, int32_t usec)
 
virtual ssize_t write (double number, int32_t sec, int32_t usec)
 
virtual ssize_t printf (const char *format,...)
 
virtual ssize_t printf (const char *format, va_list *argp)
 
virtual ssize_t printf (const wchar_t *format,...)
 
virtual ssize_t printf (const wchar_t *format, va_list *argp)
 
virtual ssize_t printfUcs2 (const ucs2_t *format,...)
 
virtual ssize_t printfUcs2 (const ucs2_t *format, va_list *argp)
 
void safePrint (byte_t c)
 
void safePrint (const byte_t *str)
 
void safePrint (const byte_t *str, int32_t length)
 
void safePrint (char c)
 
void safePrint (const char *str)
 
void safePrint (const char *str, int32_t length)
 
void printBits (byte_t value)
 
void printBits (uint16_t value)
 
void printBits (uint32_t value)
 
void printBits (uint64_t value)
 
void printBits (char value)
 
void printBits (int16_t value)
 
void printBits (int32_t value)
 
void printBits (int64_t value)
 
void printBits (const byte_t *bits, uint64_t size)
 
void printHex (const byte_t *data, uint64_t size)
 
void printHex (const byte_t *data, uint64_t size, uint16_t indent)
 
- Public Member Functions inherited from object
virtual ~object ()
 

Detailed Description

The bytebuffer class can be used to store binary data of arbitrary length.

It is generally more efficient to reuse the same bytebuffer over and over than to allocate a new one for each operation.

Constructor & Destructor Documentation

◆ bytebuffer() [1/4]

bytebuffer::bytebuffer ( )

Creates an instance of the bytebuffer class with default initial size and increment parameters.

◆ bytebuffer() [2/4]

bytebuffer::bytebuffer ( size_t  initialsize)

Creates an instance of the bytebuffer class with the specified "initialsize".

◆ bytebuffer() [3/4]

bytebuffer::bytebuffer ( byte_t *  initialcontents,
size_t  initialsize 
)

Creates an instance of the bytebuffer class. The buffer "initialcontents" will be attached to the instance and used as the initial contents. This buffer should not be freed by the calling program.

◆ bytebuffer() [4/4]

bytebuffer::bytebuffer ( bytebuffer v)

Creates an instance of the bytebuffer class that is a copy of "v".

◆ ~bytebuffer()

virtual bytebuffer::~bytebuffer ( )
virtual

Deletes this instance of the bytebuffer class.

Member Function Documentation

◆ append() [1/16]

bytebuffer* bytebuffer::append ( byte_t  character)

Appends "character" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ append() [2/16]

bytebuffer* bytebuffer::append ( char  character)

Appends "character" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ append() [3/16]

bytebuffer* bytebuffer::append ( const byte_t *  data,
size_t  size 
)

Appends the first "size" bytes of "data" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ append() [4/16]

bytebuffer* bytebuffer::append ( const char *  string)

Appends "string" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ append() [5/16]

bytebuffer* bytebuffer::append ( const char *  string,
size_t  length 
)

Appends the first "length" characters of "string" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ append() [6/16]

bytebuffer* bytebuffer::append ( const wchar_t *  string)

Appends "string" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ append() [7/16]

bytebuffer* bytebuffer::append ( const wchar_t *  string,
size_t  length 
)

Appends the first "length" characters of "string" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ append() [8/16]

bytebuffer* bytebuffer::append ( double  number)

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ append() [9/16]

bytebuffer* bytebuffer::append ( float  number)

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ append() [10/16]

bytebuffer* bytebuffer::append ( int16_t  number)

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ append() [11/16]

bytebuffer* bytebuffer::append ( int32_t  number)

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ append() [12/16]

bytebuffer* bytebuffer::append ( int64_t  number)

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ append() [13/16]

bytebuffer* bytebuffer::append ( uint16_t  number)

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ append() [14/16]

bytebuffer* bytebuffer::append ( uint32_t  number)

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ append() [15/16]

bytebuffer* bytebuffer::append ( uint64_t  number)

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ append() [16/16]

bytebuffer* bytebuffer::append ( wchar_t  character)

Appends "character" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ appendUcs2() [1/3]

bytebuffer* bytebuffer::appendUcs2 ( const ucs2_t *  string)

Appends "string" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ appendUcs2() [2/3]

bytebuffer* bytebuffer::appendUcs2 ( const ucs2_t *  string,
size_t  length 
)

Appends the first "length" characters of "string" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ appendUcs2() [3/3]

bytebuffer* bytebuffer::appendUcs2 ( ucs2_t  character)

Appends "character" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

◆ clear() [1/3]

bool bytebuffer::clear ( )

Empties the bytebuffer.

Always returns true.

◆ clear() [2/3]

bool bytebuffer::clear ( byte_t *  initialcontents,
size_t  initialsize 
)

Empties the bytebuffer and attaches the buffer "initialcontents" to the instance as the initial contents. This buffer should not be freed by the calling program. Also resets the specified "initialsize".

Always returns true.

◆ clear() [3/3]

bool bytebuffer::clear ( size_t  initialsize)

Empties the bytebuffer and resets the specified "initialsize" parameter.

Always returns true.

◆ detachBuffer()

byte_t* bytebuffer::detachBuffer ( )

Returns a pointer to the buffer currently stored in the bytebuffer, then resets the bytebuffer such that it will no longer use that buffer.

The calling program must deallocate the buffer returned from this method.

◆ getActualSize()

size_t bytebuffer::getActualSize ( )

Returns the actual number of bytes of internal storage used by the bytebuffer, which may be larger than the value returned by getSize() since the buffer grows in extents.

◆ getBuffer()

const byte_t* bytebuffer::getBuffer ( )

Returns the current data stored in the bytebuffer.

◆ getInitialSize()

size_t bytebuffer::getInitialSize ( )

Returns the number of bytes in the original initial exent.

◆ getPosition()

off64_t bytebuffer::getPosition ( )
virtual

Returns the position in the buffer at which the next write will occur.

Reimplemented from output.

Reimplemented in wstringbuffer, ucs2stringbuffer, and stringbuffer.

◆ getSize()

size_t bytebuffer::getSize ( )

Returns the number of bytes currently stored in the bytebuffer.

◆ operator=()

bytebuffer& bytebuffer::operator= ( bytebuffer v)

Makes this instance of the bytebuffer class identical to "v".

◆ read()

ssize_t bytebuffer::read ( byte_t *  data,
size_t  size 
)

Reads "size" bytes from the bytebuffer at the current position into "data". Also increments the current position by "size" bytes. Returns the number of bytes read.

◆ setPositionRelativeToBeginning()

off64_t bytebuffer::setPositionRelativeToBeginning ( off64_t  offset)
virtual

Sets the position (relative to the beginning of the buffer) at which the next read or write will occur to "offset". If the position is set beyond the end of the buffer, the buffer will grow but the data between the current end of the buffer and the new position will be undefined.

Reimplemented from output.

Reimplemented in wstringbuffer, ucs2stringbuffer, and stringbuffer.

◆ setPositionRelativeToCurrent()

off64_t bytebuffer::setPositionRelativeToCurrent ( off64_t  offset)
virtual

Advances the position at which the next read or write will occur by "offset" bytes. If the position is set beyond the end of the buffer, the buffer will grow but the data between the current end of the buffer and the new position will be undefined.

Reimplemented from output.

Reimplemented in wstringbuffer, ucs2stringbuffer, and stringbuffer.

◆ setPositionRelativeToEnd()

off64_t bytebuffer::setPositionRelativeToEnd ( off64_t  offset)
virtual

Sets the position at which the next read or write will occur to the end of the buffer plus "offset" bytes. Generally, offset will be negative. If it is positive then the buffer will grow, but the data between the current buffer will grow but the data between the current end of the buffer and the new position will be undefined.

Reimplemented from output.

Reimplemented in wstringbuffer, ucs2stringbuffer, and stringbuffer.

◆ truncate() [1/2]

virtual void bytebuffer::truncate ( )
virtual

Truncates the bytebuffer at the current position.

Reimplemented in wstringbuffer, ucs2stringbuffer, and stringbuffer.

◆ truncate() [2/2]

virtual void bytebuffer::truncate ( size_t  pos)
virtual

Truncates the bytebuffer at position "pos".

Reimplemented in wstringbuffer, ucs2stringbuffer, and stringbuffer.

◆ write() [1/16]

ssize_t bytebuffer::write ( byte_t  character)
virtual

Writes "character" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in ucs2stringbuffer, and stringbuffer.

◆ write() [2/16]

ssize_t bytebuffer::write ( char  character)
virtual

Writes "character" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in stringbuffer.

◆ write() [3/16]

ssize_t bytebuffer::write ( const byte_t *  data,
size_t  size 
)
virtual

Writes the first "size" bytes of "data" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in ucs2stringbuffer, and stringbuffer.

◆ write() [4/16]

ssize_t bytebuffer::write ( const char *  string)
virtual

Writes "string" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in stringbuffer.

◆ write() [5/16]

ssize_t bytebuffer::write ( const char *  string,
size_t  length 
)
virtual

Writes the first "length" characters of "string" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in stringbuffer.

◆ write() [6/16]

ssize_t bytebuffer::write ( const wchar_t *  string)
virtual

Writes "string" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer.

◆ write() [7/16]

ssize_t bytebuffer::write ( const wchar_t *  string,
size_t  length 
)
virtual

Writes the first "length" characters of "string" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer.

◆ write() [8/16]

ssize_t bytebuffer::write ( double  number)
virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, ucs2stringbuffer, and stringbuffer.

◆ write() [9/16]

ssize_t bytebuffer::write ( float  number)
virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, ucs2stringbuffer, and stringbuffer.

◆ write() [10/16]

ssize_t bytebuffer::write ( int16_t  number)
virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, ucs2stringbuffer, and stringbuffer.

◆ write() [11/16]

ssize_t bytebuffer::write ( int32_t  number)
virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, ucs2stringbuffer, and stringbuffer.

◆ write() [12/16]

ssize_t bytebuffer::write ( int64_t  number)
virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, ucs2stringbuffer, and stringbuffer.

◆ write() [13/16]

ssize_t bytebuffer::write ( uint16_t  number)
virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, ucs2stringbuffer, and stringbuffer.

◆ write() [14/16]

ssize_t bytebuffer::write ( uint32_t  number)
virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, ucs2stringbuffer, and stringbuffer.

◆ write() [15/16]

ssize_t bytebuffer::write ( uint64_t  number)
virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, ucs2stringbuffer, and stringbuffer.

◆ write() [16/16]

ssize_t bytebuffer::write ( wchar_t  character)
virtual

Writes "character" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer.

◆ writeUcs2() [1/3]

ssize_t bytebuffer::writeUcs2 ( const ucs2_t *  string)
virtual

Writes "string" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in ucs2stringbuffer.

◆ writeUcs2() [2/3]

ssize_t bytebuffer::writeUcs2 ( const ucs2_t *  string,
size_t  length 
)
virtual

Writes the first "length" characters of "string" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in ucs2stringbuffer.

◆ writeUcs2() [3/3]

ssize_t bytebuffer::writeUcs2 ( ucs2_t  character)
virtual

Writes "character" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in ucs2stringbuffer.