MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Public Attributes | List of all members
Mezzanine::BinaryTools::BinaryBuffer Class Reference

A way to store and pass binary buffers, for example compiled bytecode. More...

#include <binarybuffer.h>

Public Types

typedef Int8 Byte
 The type of data this buffer can hold, it is intended to be some type one byte in length, but doesn't have to be.
 

Public Member Functions

 BinaryBuffer ()
 Default constructor, set everything to zero. Doesn't allocate anything.
 
 BinaryBuffer (const BinaryBuffer &Other)
 Copy constructor. More...
 
 BinaryBuffer (const String &DataString, bool IsBase64=true)
 Base64 decoding Constructor. More...
 
 BinaryBuffer (Byte *BinaryPointer, Integer PredeterminedSize)
 Verbose constructor, set everything custom on creation. More...
 
 BinaryBuffer (Whole PredeterminedSize)
 Terse constructor, set a custom size and allocates space (filled with gibberish). More...
 
virtual ~BinaryBuffer ()
 Virtual deconstructor calls DeleteBuffer() to clean up whatever has been inserted here. More...
 
void Concatenate (const Byte *OtherBuffer, Whole ByteSize)
 Append another group of arbitrary data onto this one. More...
 
void Concatenate (const BinaryBuffer BufferFromAnotherMother)
 Concatenate another buffer onto this one. More...
 
void CreateBuffer ()
 This will create a buffer with size matching the this->Size and point this->Binary to that Buffer. More...
 
void CreateFromBase64 (const String &EncodedBinaryData)
 This calls deallocates any space, allocates fresh space of the size requestedthen the Decodes the passed and repopulates the Buffer. More...
 
void DeleteBuffer (Whole NewSize=0)
 Deletes whatever Binary points at and assigns Size to 0. More...
 
Whole GetSize () const
 Even though this class is intended to have its internals modifieddirectly in some cases, In normal cases accessor are nice to have. More...
 
BinaryBufferoperator+= (const BinaryBuffer &RH)
 
BinaryBufferoperator= (const BinaryBuffer &RH)
 Assignment Operator. More...
 
Byteoperator[] (Whole Index)
 Access a part of the buffer. More...
 
String ToBase64String ()
 Get the binary buffer as a base64 string. More...
 
String ToString ()
 Get the contents of this crudely converted to a c style string then stuff it in a string. More...
 

Public Attributes

ByteBinary
 A pointer to the actual binary data.
 
Whole Size
 How many bytes is Binary in size. This is set to 0 if Binary is invalid and should be a null pointer.
 

Detailed Description

A way to store and pass binary buffers, for example compiled bytecode.

Originally intended for use with ScriptCompilable as a basic way to store and pass bytecode around. This deletes the passed binary on destruction. To prevent this behavior set the Binary pointer to null.

This is designed to be fairly minimalistic but passing by value causes the buffer to be copied.

Where possible this class performs no speculative allocation unless explicitly requested to. In other words this should have allocated exactly as many bytes are indicated by the member Size, no more and no less. This will tend to not allocate memory unless an operation on it is specified that it does so.

Whenever this needs to allocated memory it will use the Size member for determining the amount to allocate. If that is 0 an InvalidStateException exception is thrown. Bounds checking, if performed, only occurs when MEZZ_DEBUG is enabled.

Definition at line 66 of file binarybuffer.h.

Constructor & Destructor Documentation

Mezzanine::BinaryTools::BinaryBuffer::BinaryBuffer ( const BinaryBuffer Other)

Copy constructor.

Parameters
OtherThe buffer to copy to make

Allocates identical amount of memory as other buffer then copies the other buffer into the allocated space. Each BinaryBuffer retains ownership of their respective buffers.

Definition at line 155 of file binarybuffer.cpp.

Mezzanine::BinaryTools::BinaryBuffer::BinaryBuffer ( const String DataString,
bool  IsBase64 = true 
)
explicit

Base64 decoding Constructor.

Performs exactly one allocation of the amount required to store the decoded base64, Then starts filling it. If there is an error with the data as it is beign process the rest of the Buffer will be filled with gibberish, and everything before the error will be properly decoded.

Parameters
DataStringA Base64 string to be decode and used as a binary buffer, or a string to be used a buffer if IsBase64 is false
IsBase64Is the String passed Base64 encoded

Definition at line 167 of file binarybuffer.cpp.

Mezzanine::BinaryTools::BinaryBuffer::BinaryBuffer ( Byte BinaryPointer,
Integer  PredeterminedSize 
)
inline

Verbose constructor, set everything custom on creation.

If passed a pointer this assumes ownship of that pointer, otherwise this allocates the amount of space requested.

Parameters
BinaryPointerA pointer to the first byte in memory, if this is null the buffer is created. Ownership of this Pointer will be assumed.
PredeterminedSizeThe size to set on creation.

Definition at line 110 of file binarybuffer.h.

Mezzanine::BinaryTools::BinaryBuffer::BinaryBuffer ( Whole  PredeterminedSize)
inlineexplicit

Terse constructor, set a custom size and allocates space (filled with gibberish).

Parameters
PredeterminedSizeThe size to set on creation.

Definition at line 117 of file binarybuffer.h.

Mezzanine::BinaryTools::BinaryBuffer::~BinaryBuffer ( )
virtual

Virtual deconstructor calls DeleteBuffer() to clean up whatever has been inserted here.

If you do not want the Buffer pointed to by the pointer Binary assign Binary to 0 and this deconstructor will delete with erase nothing.

Definition at line 197 of file binarybuffer.cpp.

Member Function Documentation

void Mezzanine::BinaryTools::BinaryBuffer::Concatenate ( const Byte OtherBuffer,
Whole  ByteSize 
)

Append another group of arbitrary data onto this one.

Allocates space equal to the size of both buffers, Copies this Buffers data into it, then copies the other buffers data, then deallocates any space this buffer may have had allocated preivously.

Parameters
OtherBufferA pointer to a region of memory to be copied
ByteSizeHow big in bytes is the Buffer

Definition at line 254 of file binarybuffer.cpp.

void Mezzanine::BinaryTools::BinaryBuffer::Concatenate ( const BinaryBuffer  BufferFromAnotherMother)

Concatenate another buffer onto this one.

This calls Concatenate(const Byte*, Whole)

Parameters
BufferFromAnotherMotherA buffer to copy and append onto this one.

Definition at line 266 of file binarybuffer.cpp.

void Mezzanine::BinaryTools::BinaryBuffer::CreateBuffer ( )

This will create a buffer with size matching the this->Size and point this->Binary to that Buffer.

Warning
This does not delete an old buffer, delete that before calling this.

Definition at line 208 of file binarybuffer.cpp.

void Mezzanine::BinaryTools::BinaryBuffer::CreateFromBase64 ( const String EncodedBinaryData)

This calls deallocates any space, allocates fresh space of the size requestedthen the Decodes the passed and repopulates the Buffer.

Parameters
EncodedBinaryDataThe Base64 string containing binary data.

Definition at line 236 of file binarybuffer.cpp.

void Mezzanine::BinaryTools::BinaryBuffer::DeleteBuffer ( Whole  NewSize = 0)

Deletes whatever Binary points at and assigns Size to 0.

Parameters
NewSizeIf you don't want to just clear the buffer, but rather want to set size to a value and set a new size, you can do that with this

Definition at line 200 of file binarybuffer.cpp.

Whole Mezzanine::BinaryTools::BinaryBuffer::GetSize ( ) const

Even though this class is intended to have its internals modifieddirectly in some cases, In normal cases accessor are nice to have.

Returns
Get the size as a whole

Definition at line 276 of file binarybuffer.cpp.

BinaryBuffer & Mezzanine::BinaryTools::BinaryBuffer::operator+= ( const BinaryBuffer RH)

An easier way to call Concatenate(const Byte*, Whole)

Parameters
RHThe other Buffer to copy/append.
Returns
A Reference to this buffer to allow operator chaining.

Definition at line 270 of file binarybuffer.cpp.

BinaryBuffer & Mezzanine::BinaryTools::BinaryBuffer::operator= ( const BinaryBuffer RH)

Assignment Operator.

This deletes the buffer if it is not null, and allocates a fresh one of the size in RH, then copies it.

Parameters
RHThe item on the right hand side
Returns
A reference to the newly assigned binary buffer.

Definition at line 182 of file binarybuffer.cpp.

BinaryBuffer::Byte & Mezzanine::BinaryTools::BinaryBuffer::operator[] ( Whole  Index)

Access a part of the buffer.

Parameters
IndexHow from from the 0 aligned beginning of the buffer would you like to access.
Returns
A Reference to the specific Byte the Index passed refers to
Note
When compiled as Debug this can throw a MemoryOutOfBoundsException if the index is to high (or cast from a negative

Definition at line 245 of file binarybuffer.cpp.

String Mezzanine::BinaryTools::BinaryBuffer::ToBase64String ( )

Get the binary buffer as a base64 string.

Returns
a String contain a base6 encoded version of the binary

Definition at line 218 of file binarybuffer.cpp.

String Mezzanine::BinaryTools::BinaryBuffer::ToString ( )

Get the contents of this crudely converted to a c style string then stuff it in a string.

Returns
A String with the value stored in binary copied into it.

Definition at line 227 of file binarybuffer.cpp.


The documentation for this class was generated from the following files: