nlib
nn::nlib::msgpack::MpObjectAsArray Class Referencefinal

The class for providing access with MpObject stored in an array as an element for MpObject that has an array type. More...

#include "nn/nlib/msgpack/MpObject.h"

Public Types

typedef Nlist< MpObject >::iterator iterator
 A forward iterator.
 
typedef Nlist< MpObject >::const_iterator const_iterator
 Read-only forward iterator.
 
typedef MpObjectreference
 A reference to an element.
 
typedef const MpObjectconst_reference
 Read-only reference to an element.
 
typedef MpObjectpointer
 Pointer to the element.
 
typedef const MpObjectconst_pointer
 Read-only pointer to an element.
 

Public Member Functions

 MpObjectAsArray (MpObject &obj) noexcept
 
iterator begin () noexcept
 Gets the iterator pointing to the first element.
 
iterator end () noexcept
 Gets the iterator pointing beyond the last element.
 
const_iterator begin () const noexcept
 Gets the read-only iterator pointing to the first element.
 
const_iterator end () const noexcept
 Gets the read-only iterator pointing beyond the last element.
 
reference front () noexcept
 Gets a reference to the first element.
 
const_reference front () const noexcept
 Gets a reference to the first element.
 
reference back () noexcept
 Gets a reference to the last element.
 
const_reference back () const noexcept
 Gets a reference to the last element.
 
reference operator[] (size_t n) noexcept
 Gets the nth element. n must be less than the number of stored elements. More...
 
const_reference operator[] (size_t n) const noexcept
 The const decoration version of the above function.
 
size_t GetSize () const noexcept
 Returns the number of stored elements.
 
errno_t Resize (size_t n) noexcept
 Changes the number of elements for an array. More...
 
errno_t PushBack (MpObject &&rhs) noexcept
 Adds an element to the end of an array. The content in rhs is moved. More...
 
errno_t Insert (iterator it, MpObject &&rhs) noexcept
 Inserts rhs immediately before the element found in it. More...
 
errno_t Insert (size_t n, MpObject &&rhs) noexcept
 Inserts rhs immediately before the nth element. More...
 
errno_t Erase (iterator it) noexcept
 Removes the element found in it. More...
 
errno_t Erase (size_t n) noexcept
 Removes the nth element. More...
 
errno_t PopBack () noexcept
 Removes the end element. More...
 

Detailed Description

The class for providing access with MpObject stored in an array as an element for MpObject that has an array type.

Description
The begin() and end() functions are defined for arrays and you can write a loop as follows.
const char* json = R"([1,2,3])";
auto obj = ToMpObject(json);
for (auto& item : obj->AsArray()) {
int val;
item.Unbox(&val);
nlib_printf("%d ", val);
}
nlib_printf("\n");
/*
Output:
1 2 3
*/

Definition at line 440 of file MpObject.h.

Constructor & Destructor Documentation

◆ MpObjectAsArray()

nn::nlib::msgpack::MpObjectAsArray::MpObjectAsArray ( MpObject obj)
inlineexplicitnoexcept
Parameters
[in]objMpObject to be accessed as an array. obj.IsArray() must be true.

Definition at line 452 of file MpObject.h.

Member Function Documentation

◆ Erase() [1/2]

nn::nlib::msgpack::MpObjectAsArray::Erase ( iterator  it)
noexcept

Removes the element found in it.

Parameters
[in]itThe position of the element to remove.
Returns
Returns 0 on success. Any value other than 0 indicates an error.

◆ Erase() [2/2]

nn::nlib::msgpack::MpObjectAsArray::Erase ( size_t  n)
inlinenoexcept

Removes the nth element.

Parameters
[in]nAn integer equal to or greater than 0.
Return values
0Success.
ERANGEIndicates that n is out of the range.

Definition at line 496 of file MpObject.h.

◆ Insert() [1/2]

nn::nlib::msgpack::MpObjectAsArray::Insert ( iterator  it,
MpObject &&  rhs 
)
noexcept

Inserts rhs immediately before the element found in it.

Parameters
[in]itThe position to be inserted.
[in,out]rhsAn element to be inserted.
Returns
Returns 0 on success. Any value other than 0 indicates an error.

◆ Insert() [2/2]

nn::nlib::msgpack::MpObjectAsArray::Insert ( size_t  n,
MpObject &&  rhs 
)
inlinenoexcept

Inserts rhs immediately before the nth element.

Parameters
[in]nThe element insertion position.
[in,out]rhsAn element to be inserted.
Returns
Returns 0 on success. Any value other than 0 indicates an error.

Definition at line 489 of file MpObject.h.

◆ operator[]()

nn::nlib::msgpack::MpObjectAsArray::operator[] ( size_t  n)
inlinenoexcept

Gets the nth element. n must be less than the number of stored elements.

Parameters
[in]nThe position of an element.
Returns
Reference to the nth element.

Definition at line 463 of file MpObject.h.

◆ PopBack()

nn::nlib::msgpack::MpObjectAsArray::PopBack ( )
inlinenoexcept

Removes the end element.

Returns
Returns 0 on success. Any value other than 0 indicates an error.

Definition at line 503 of file MpObject.h.

◆ PushBack()

nn::nlib::msgpack::MpObjectAsArray::PushBack ( MpObject &&  rhs)
inlinenoexcept

Adds an element to the end of an array. The content in rhs is moved.

Parameters
[in,out]rhsAn element to add to the end of an array.
Returns
Returns 0 on success. Any value other than 0 indicates an error.

Definition at line 481 of file MpObject.h.

◆ Resize()

nn::nlib::msgpack::MpObjectAsArray::Resize ( size_t  n)
inlinenoexcept

Changes the number of elements for an array.

Parameters
[in]nSize after resizing.
Returns
Returns 0 on success. Any value other than 0 indicates an error.

Definition at line 472 of file MpObject.h.


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