Zakero's C++ Header Libraries
A collection of reusable C++ libraries
Public Member Functions | Public Attributes | List of all members
zakero::messagepack::Array Struct Reference

An array of Objects. More...

Public Member Functions

size_t append (Array &) noexcept
 Append an Array. More...
 
size_t append (const Array &) noexcept
 Append an Array. More...
 
size_t append (const bool) noexcept
 Append a boolean value. More...
 
size_t append (const double) noexcept
 Append a 64-bit floating point value. More...
 
size_t append (const Ext &) noexcept
 Append an extension. More...
 
size_t append (const float) noexcept
 Append a 32-bit floating point value. More...
 
size_t append (const int64_t) noexcept
 Append a signed integer value. More...
 
size_t append (const Map &) noexcept
 Append a Map. More...
 
size_t append (const Object &) noexcept
 Append an Object. More...
 
size_t append (const std::string_view) noexcept
 Append a string. More...
 
size_t append (const std::vector< uint8_t > &) noexcept
 Append a vector of binary data. More...
 
size_t append (const uint64_t) noexcept
 Append an unsigned integer value. More...
 
size_t append (Ext &) noexcept
 Append an extension. More...
 
size_t append (Map &) noexcept
 Append a Map. More...
 
size_t append (Object &) noexcept
 Append an Object. More...
 
size_t append (std::vector< uint8_t > &) noexcept
 Append a vector of binary data. More...
 
size_t appendNull () noexcept
 Append a "Null" value. More...
 
void clear () noexcept
 Remove all data from the Array. More...
 
const Objectobject (const size_t index) const noexcept
 Access a data object. More...
 
Objectobject (const size_t index) noexcept
 Access a data object. More...
 
size_t size () const noexcept
 Get the size of the Array. More...
 

Public Attributes

std::vector< Objectobject_vector
 Store the Object data. More...
 

Detailed Description

The role of this structure is to store a collection of Objects in a resizable array. The underling object_vector can be accessed directly or use the helper methods to increase code readability.

Objects can be tested to find out if they are Arrays by using Object::isArray() and converted into an Array with Object::asArray(). An Array can not be converted into an Object. However, an Object can be constructed using an Array.

Member Function Documentation

◆ append() [1/16]

size_t zakero::messagepack::Array::append ( Array array)
noexcept

The array will be appended to the contents of this Array.

Example
sub_array.append(false);
sub_array.append(0x42);
array.append(sub_array);
An array of Objects.
Definition: Zakero_MessagePack.h:272
size_t append(const bool) noexcept
Append a boolean value.
Definition: Zakero_MessagePack.h:1425
Returns
The index location of where the value was stored.
Parameters
arrayThe Array to add

◆ append() [2/16]

size_t zakero::messagepack::Array::append ( const Array array)
noexcept

The array will be appended to the contents of this Array.

Example
sub_array.append(false);
sub_array.append(0x42);
array.append(sub_array);
Returns
The index location of where the value was stored.
Parameters
arrayThe Array to add

◆ append() [3/16]

size_t zakero::messagepack::Array::append ( const bool  value)
noexcept

The value will be appended to the contents of the Array.

Example
array.append(true);
Returns
The index location of where the value was stored.
Parameters
valueThe value to add

◆ append() [4/16]

size_t zakero::messagepack::Array::append ( const double  value)
noexcept

The value will be appended to the contents of the Array.

Example
array.append(double(0.42));
Returns
The index location of where the value was stored.
Parameters
valueThe value to add

◆ append() [5/16]

size_t zakero::messagepack::Array::append ( const Ext ext)
noexcept

The value will be appended to the contents of this Array.

Example
ext.type = 42;
ext.data = std::vector<uint8_t>(42, '*');
array.append(ext);
Extension Data.
Definition: Zakero_MessagePack.h:304
std::vector< uint8_t > data
Extension binary data.
Definition: Zakero_MessagePack.h:305
int8_t type
A unique identifier for the extension.
Definition: Zakero_MessagePack.h:306
Returns
The index location of where the value was stored.
Parameters
extThe Ext to add

◆ append() [6/16]

size_t zakero::messagepack::Array::append ( const float  value)
noexcept

The value will be appended to the contents of the Array.

Example
array.append(float(4.2));
Returns
The index location of where the value was stored.
Parameters
valueThe value to add

◆ append() [7/16]

size_t zakero::messagepack::Array::append ( const int64_t  value)
noexcept

The value will be appended to the contents of the Array.

Example
array.append(int64_t(0));
Returns
The index location of where the value was stored.
Parameters
valueThe value to add

◆ append() [8/16]

size_t zakero::messagepack::Array::append ( const Map map)
noexcept

The value will be appended to the contents of this Array.

Example
map.set(Object{42}, Object{std::string("foo")});
array.append(map);
A Key/Value collection of Objects.
Definition: Zakero_MessagePack.h:313
std::error_code set(Object &, Object &) noexcept
Set a key/value pair.
Definition: Zakero_MessagePack.h:3108
Returns
The index location of where the value was stored.
Parameters
mapThe Map to add

◆ append() [9/16]

size_t zakero::messagepack::Array::append ( const Object object)
noexcept

The value will be appended to the contents of this Array.

Example
const zakero::messagepack::Object object{int8_t(42)};
array.append(object);
A Data Object.
Definition: Zakero_MessagePack.h:337
Returns
The index location of where the value was stored.
Parameters
objectThe object to add

◆ append() [10/16]

size_t zakero::messagepack::Array::append ( const std::string_view  value)
noexcept

The value will be appended to the contents of the Array.

Example
array.append("Hello, World!");
Returns
The index location of where the value was stored.
Parameters
valueThe value to add

◆ append() [11/16]

size_t zakero::messagepack::Array::append ( const std::vector< uint8_t > &  value)
noexcept

The value will be appended to the contents of the Array.

Example
const std::vector<uint8_t> data = { 0xde, 0xad, 0xca, 0xfe };
array.append(data);
Returns
The index location of where the value was stored.
Parameters
valueThe value to add

◆ append() [12/16]

size_t zakero::messagepack::Array::append ( const uint64_t  value)
noexcept

The value will be appended to the contents of the Array.

Example
array.append(uint64_t(0));
Returns
The index location of where the value was stored.
Parameters
valueThe value to add

◆ append() [13/16]

size_t zakero::messagepack::Array::append ( Ext ext)
noexcept

The value will be appended to the contents of this Array.

Example
ext.type = 42;
ext.data = std::vector<uint8_t>(42, '*');
array.append(ext);
Returns
The index location of where the value was stored.
Parameters
extThe Ext to add

◆ append() [14/16]

size_t zakero::messagepack::Array::append ( Map map)
noexcept

The value will be appended to the contents of this Array.

Example
map.set(Object{42}, Object{std::string("foo")});
array.append(map);
Returns
The index location of where the value was stored.
Parameters
mapThe Map to add

◆ append() [15/16]

size_t zakero::messagepack::Array::append ( Object object)
noexcept

The value will be appended to the contents of this Array.

Example
array.append( Object{ int8_t(42) } );
Returns
The index location of where the value was stored.
Parameters
objectThe object to add

◆ append() [16/16]

size_t zakero::messagepack::Array::append ( std::vector< uint8_t > &  value)
noexcept

The value will be appended to the contents of the Array.

Example
std::vector<uint8_t> data = { 0xde, 0xad, 0xca, 0xfe };
array.append(data);
Returns
The index location of where the value was stored.
Parameters
valueThe value to add

◆ appendNull()

size_t zakero::messagepack::Array::appendNull ( )
noexcept

A "Null" value will be appended to the contents of this Array.

Example
array.appendNull();
size_t appendNull() noexcept
Append a "Null" value.
Definition: Zakero_MessagePack.h:2738
Returns
The index location of where the value was stored.

◆ clear()

zakero::messagepack::Array::clear ( )
inlinenoexcept

Remove all data from the Array.

◆ object() [1/2]

zakero::messagepack::Array::object ( const size_t  index) const
inlinenoexcept

After data has been added to the Array, that data can still be access by using its index value. The data object's type will be the C++ datatype, not the MessagePack format type.

The returned Object is Read-Only.

Example
size_t index_foo = array.append(int64_t(0));
size_t index_bar = array.append(int64_t(0));
int64_t val = rand();
if(array.object(index_foo) > val)
{
std::cout << "Foo Bigger\n";
}
if(array.object(index_bar) > val)
{
std::cout << "Bar Bigger\n";
}
Object & object(const size_t index) noexcept
Access a data object.
Definition: Zakero_MessagePack.h:291
Returns
The data object.
Parameters
indexThe index of the data object.

◆ object() [2/2]

zakero::messagepack::Array::object ( const size_t  index)
inlinenoexcept

After data has been added to the Array, that data can still be access by using its index value. The data object's type will be the C++ datatype, not the MessagePack format type.

The returned Object can be modified as needed.

Example
size_t index_foo = array.append(int64_t(0));
size_t index_bar = array.append(int64_t(0));
int64_t val = rand();
array.object(index_foo) = val;
if(val & 1)
{
// Change to string
array.object(index_bar) = "That's odd...";
}
else
{
// Change to boolean
array.object(index_bar) = true;
}
Returns
The data object.
Parameters
indexThe index of the data object.

◆ size()

zakero::messagepack::Array::size ( ) const
inlinenoexcept
Returns
The Array size.

Member Data Documentation

◆ object_vector

zakero::messagepack::Array::object_vector

The object_vector is used to store all the Qbjects in the Array.


The documentation for this struct was generated from the following file: