nlib
|
Object created when MessagePack or JSON is read. More...
#include "nn/nlib/msgpack/MpObject.h"
Public Types | |
enum | ObjectType { kNil = 0, kBoolean, kUint64, kInt64, kFloat, kDouble, kString, kArray, kMap } |
Data type of the object stored in MpObject . More... | |
Public Member Functions | |
errno_t | Resize (uint32_t n) |
Resizes the array, associative array, string, or binary. More... | |
MpObject * | Clone () noexcept const |
Creates a duplicate of the object. More... | |
uint32_t | GetSize () const noexcept |
Returns the size of the array, associative array, string, or binary. More... | |
Using the Array Type (kArray Type) | |
MpObject * | GetArrayItem (size_t n) noexcept |
Specifies an index and gets the object in the array. More... | |
const MpObject * | GetArrayItem (size_t n) const noexcept |
The same as GetArrayItem(size_t n) . | |
MpObject & | operator[] (size_t n) |
For an array, returns a reference to an element of the array. More... | |
MpObject * | SwapArrayItem (size_t n, MpObject *obj) noexcept |
Swaps the content of obj and the content of the object within an array. More... | |
MpObject * | AppendArrayItem () noexcept |
If the object contains an array, adds an element to the end of the array. More... | |
MpObject * | InsertArrayItem (size_t n) noexcept |
If the object contains an array, inserts an element into the location with the specified index in the array. More... | |
errno_t | GetArrayItem (size_t n, MpObject **obj) noexcept |
Specifies an index and gets the object in the array. More... | |
errno_t | GetArrayItem (size_t n, const MpObject **obj) const noexcept |
The same as GetArrayItem(size_t n, MpObject** obj) . | |
errno_t | RemoveArrayItem (size_t n, MpObject *obj) noexcept |
Specifies an index and deletes the corresponding object in the array. More... | |
errno_t | InitArray (uint32_t n) noexcept |
Initializes as an object with an n element array. More... | |
Using the Associative Array Type (kMap Type) | |
const MpObject * | GetMapItem (const nlib_utf8_t *str) const noexcept |
The same as GetMapItem(const nlib_utf8_t* str) . | |
MpObject * | GetMapItem (const nlib_utf8_t *str) noexcept |
Specifies a string and gets the object in the associative array. More... | |
template<class STDSTRING > | |
const MpObject * | GetMapItem (const STDSTRING &str) const noexcept |
The same as GetMapItem(const STDSTRING& str) . | |
template<class STDSTRING > | |
MpObject * | GetMapItem (const STDSTRING &str) noexcept |
Specifies a string and gets the object in the associative array. More... | |
template<class STDSTRING > | |
MpObject * | SwapMapItem (const STDSTRING &key, MpObject *obj) noexcept |
Swaps the content of obj and the content of the object within an associative array. More... | |
MpObject * | SwapMapItem (const nlib_utf8_t *key, MpObject *obj) noexcept |
Swaps the content of obj and the content of the object within an associative array. More... | |
MpObjectKv * | AppendMapItem () noexcept |
Adds an element to the end if the object is storing an associative array. More... | |
errno_t | GetMapItem (size_t n, MpObjectKv **obj) noexcept |
Specifies an index and gets the object in the associative array. More... | |
errno_t | GetMapItem (size_t n, const MpObjectKv **obj) const noexcept |
The same as GetMapItem(size_t n, MpObjectKv** obj) . | |
errno_t | GetMapItem (const nlib_utf8_t *str, size_t n, MpObjectKv **obj) noexcept |
Obtains the pair of a key and value from the associative array by specifying a non-null terminated string as the key. More... | |
errno_t | RemoveMapItem (size_t n, MpObjectKv *kv) noexcept |
Specifies an index and deletes the corresponding key and object in the associative array. More... | |
template<class STDSTRING > | |
errno_t | RemoveMapItem (const STDSTRING &str, MpObjectKv *kv) noexcept |
Specifies a key and deletes the corresponding key and object in the associative array. More... | |
errno_t | InitMap (uint32_t n) noexcept |
Initializes the object as an n element associative array. More... | |
Basic Member Functions | |
MpObject () noexcept | |
Instantiates the object with default parameters (default constructor). Set to the nil type. | |
~MpObject () noexcept | |
Destructor. | |
MpObject & | assign (MpObject &rhs, move_tag) |
Assigns the object by using swap for a move. | |
MpObject (MpObject &rhs, move_tag) | |
Instantiates the object by using swap for a move. | |
MpObject (MpObject &&rhs) | |
Instantiates the object (move constructor). This function is useful when using C++11. | |
MpObject & | operator= (MpObject &&rhs) |
Move assignment operator. This function is useful when using C++11. | |
template<class T > | |
MpObject (const T &x) | |
The constructor for boxing a T -type object. More... | |
void | swap (MpObject &rhs) noexcept |
Swaps the content of the object. More... | |
Using the String Type (STRING Type) | |
nlib_utf8_t * | GetString () noexcept |
Gets a string from an object. | |
const nlib_utf8_t * | GetString () const noexcept |
Gets a string from an object. | |
errno_t | InitString (uint32_t n) noexcept |
Initializes the object as a string. More... | |
errno_t | InitString (const nlib_utf8_t *str, uint32_t n) noexcept |
Initializes the object as a string. More... | |
errno_t | InitString (const nlib_utf8_t *str) noexcept |
Initializes the object as a string. More... | |
Using the Binary Type (BINARY Type) | |
void * | GetBinary (uint32_t *n) noexcept |
Gets binary from an object. | |
const void * | GetBinary (uint32_t *n) const noexcept |
Gets binary from an object. | |
errno_t | InitBinary (uint32_t n) noexcept |
Initializes the object as binary. More... | |
errno_t | InitBinary (const void *p, uint32_t n) noexcept |
Initializes the object as binary. More... | |
Entended Data Type (<tt>kExt</tt> | |
void * | GetExt (int8_t *tp, uint32_t *n) noexcept |
Gets an extended data type from an object. More... | |
const void * | GetExt (int8_t *tp, uint32_t *n) const noexcept |
Gets an extended data type from an object. | |
errno_t | InitExt (int8_t tp, uint32_t n) noexcept |
Initializes an object as the extended data type. More... | |
errno_t | InitExt (int8_t tp, const void *p, uint32_t n) noexcept |
Initializes an object as the extended data type. More... | |
Boxing | |
Boxes numerical values, strings, vectors, and other values, and stores the result as an instance of | |
errno_t | Box (const nlib_utf8_t *str) noexcept |
Boxes the string. More... | |
template<uint32_t n> | |
errno_t | Box (const nlib_utf8_t(&str)[n]) noexcept |
Boxes the string. More... | |
template<class T , uint32_t n> | |
errno_t | Box (const T(&vec)[n]) |
Boxes the array. More... | |
template<class T > | |
errno_t | Box (const T &v) |
Boxes the object. More... | |
template<class T > | |
MpObject & | operator= (const T &x) |
The value is passed into MpObject . More... | |
Unboxing | |
Unboxes numerical values, string, vectors, and other values, and stores the result as an instance of | |
template<class T , size_t n> | |
errno_t | Unbox (T(&a)[n]) const |
Unboxes the object value. More... | |
template<size_t n> | |
errno_t | Unbox (nlib_utf8_t(&str)[n]) const noexcept |
See Unbox(T (&a)[n]) . | |
template<class T > | |
errno_t | Unbox (T *a, size_t n) const |
Unboxes the array data. More... | |
errno_t | Unbox (nlib_utf8_t *str, size_t n) const noexcept |
See the description of Unbox(T* a, size_t n) . | |
template<class T > | |
errno_t | Unbox (T v) const |
Unboxes the object. More... | |
Obtaining and Determining the Type | |
ObjectType | GetType () const noexcept |
Returns the object type. More... | |
bool | IsNil () const noexcept |
Determines whether the stored value is nil . | |
bool | IsBoolean () const noexcept |
Determines whether the stored value is a boolean. | |
bool | IsInteger () const noexcept |
Determines whether the stored value is an integer. | |
bool | IsFloat () const noexcept |
Determines whether the stored value is a single precision float. | |
bool | IsDouble () const noexcept |
Determines whether the stored value is a double. | |
bool | IsString () const noexcept |
Determines whether the stored value is a string. | |
bool | IsBinary () const noexcept |
Determines whether the stored value is binary. | |
bool | IsExt () const noexcept |
Determines whether the stored value is extended data. | |
bool | IsArray () const noexcept |
Determines whether the stored value is an array. | |
bool | IsMap () const noexcept |
Determines whether the stored value is an associative array. | |
Static Public Member Functions | |
static errno_t | ResolveJsonPointer (MpObject **result, MpObject *root, const nlib_utf8_t *json_pointer) noexcept |
Stores MpObject referenced by json_pointer in *result. More... | |
static errno_t | DigByJsonPointer (MpObject **result, MpObject *root, const nlib_utf8_t *json_pointer) noexcept |
Although MpObject is referenced by json_pointer, new MpObject may be added. More... | |
static errno_t | RemoveByJsonPointer (MpObjectKv *removed, MpObject *root, const nlib_utf8_t *json_pointer) noexcept |
Deletes MpObject referenced by json_pointer and stores it in removed. More... | |
Object created when MessagePack or JSON is read.
Box
method, or reading JSON or MessagePack data. The Unbox
method is used to convert to the static object. The various numerical value types, arrays, strings, bool
, nil
, std::pair
, std::vector
, std::map
, and std::string
support the Box
and Unbox
methods by default. C++11 also supports std::array
, std::unordered_map
, and std::tuple
. Box
on a user-defined type. template<class T> errno_t Box(MpObject* obj, const T& v)
template<class T> errno_t Unbox(const MpObject* obj, T* v)
0
must be returned. errno_t
type may return 0
or the following values. Definition at line 95 of file MpObject.h.
Data type of the object stored in MpObject
.
GetType
. Enumerator | |
---|---|
kNil | Represents a |
kBoolean | Represents a boolean type. The internal representation is a |
kUint64 | Represents an unsigned integer type. The internal representation is |
kInt64 | Represents an integer type. The internal representation is |
kFloat | Represents a floating point type. The internal representation is |
kDouble | Represents a floating point type. The internal representation is |
kString | Respresents a byte array (string). |
kArray | Represents an array. The internal representation is an array of |
kMap | Represents an associative array. The internal representation is an array of |
Definition at line 321 of file MpObject.h.
|
inlineexplicit |
The constructor for boxing a T
-type object.
T | The type being boxed. |
[in] | x | The value to box into an MpObject . |
Definition at line 179 of file MpObject.h.
|
noexcept |
If the object contains an array, adds an element to the end of the array.
NULL
if process fails.
|
noexcept |
Adds an element to the end if the object is storing an associative array.
NULL
if process fails.
|
noexcept |
Boxes the string.
[in] | str | String. |
0
on success. All other values are an error.kString
type data.
|
noexcept |
Boxes the string.
n | The size of the array. |
[in] | str | A null-terminated string. |
0
on success. All other values are an error.kString
type data. Definition at line 839 of file MpObject.h.
errno_t nn::nlib::msgpack::MpObject::Box | ( | const T(&) | vec[n] | ) |
Boxes the array.
[in] | vec | Object being boxed. |
T | Element type. |
n | Number of elements. |
0
on success.Type of T | Description |
---|---|
char | Characters up to the NULL character are boxed in an MpObject::kString type as a string. |
All others | Boxed into an MpObject::kArray type as an array. |
Definition at line 848 of file MpObject.h.
|
inline |
Boxes the object.
T | Type of object being boxed. |
[in] | v | Object being boxed. |
0
on success. All other values are an error.T
. The following table illustrates the difference in behavior. Type of T | Description |
---|---|
nil | Stored as an MpObject::kNil type. This process never returns an error. |
bool | Stored as an MpObject::kBoolean type. This process never returns an error. |
Signed Integer | Stored as an MpObject::kInt64 type. This process never returns an error. |
Unsigned Integer | Stored as an MpObject::kUint64 type. This process never returns an error. |
float | Stored as an MpObject::kFloat type. This process never returns an error. |
double | Stored as an MpObject::kDouble type. This process never returns an error. |
std::string | Stored as an MpObject::kString type. |
std::vector | Stored as an MpObject::kArray type. |
Nlist | Stored as an MpObject::kArray type. |
std::pair | Stored as an MpObject::kArray type with a size of 2 . |
std::map | Stored as an MpObject::kMap type. |
std::array | Stored as an MpObject::kArray type. |
std::tuple | Stored as an MpObject::kArray type. |
std::unordered_map | Stored as an MpObject::kMap type. |
char
type arrays. A char
array is boxed as a string. Definition at line 264 of file MpObject.h.
|
noexcept |
Creates a duplicate of the object.
NULL
when duplication fails mid-process.
|
staticnoexcept |
Although MpObject
is referenced by json_pointer, new MpObject
may be added.
[in,out] | result | An object referenced by json_pointer. |
[in] | root | A root object that serves as the starting point for reference with json_pointer. |
[in] | json_pointer | JSON pointer string. |
0 | Indicates that the last reference token for json_pointer could not be traced and new MpObject is created so that it can be traced. |
EEXIST | Indicates that MpObject pointed with json_pointer already exists. |
EINVAL | Indicates that result, root, or json_pointer is NULL . |
EILSEQ | Indicates that the syntax for json_pointer is incorrect. |
ENOENT | Indicates that the reference token other than the last one within json_pointer could not be traced. |
ENOMEM | Indicates memory allocation failed. |
MpObject
by drilling down the JSON tree structure based on a string defined by JSON Pointer (RFC6901). However, if no MpObject
that corresponds to the end of json_pointer exists, new MpObject
will be created. If the function returns 0 or EEXIST
, a pointer to MpObject
that tracing json_pointer has eventually reached is set to *result. MpObject
should be inserted into the array. ENOENT
error occurs. In other words, when manipulating the following two JSON, if "/a/b" is specified for json_pointer, the operation on the first JSON will successfully complete, but the operation on the second JSON will result in an error.
|
inlinenoexcept |
Specifies an index and gets the object in the array.
[in] | n | The array index. |
MpObject
) corresponding to the index.NULL
if processing failed. Definition at line 115 of file MpObject.h.
|
noexcept |
Specifies an index and gets the object in the array.
[in] | n | The array index. |
[out] | obj | Pointer that stores the pointer to the object (MpObject ). |
0
on success. All other values are an error.
|
inlinenoexcept |
Gets an extended data type from an object.
[out] | tp | Integer indicating the data type. |
[out] | n | Size of the binary. |
Definition at line 227 of file MpObject.h.
|
noexcept |
Specifies a string and gets the object in the associative array.
[in] | str | Associative array key string. |
MpObject
).NULL
is retuned if the search has failed.
|
inlinenoexcept |
Specifies a string and gets the object in the associative array.
STDSTRING | A type compatible with std::string |
[in] | str | Associative array key string. |
MpObject
).GetMapItem(size_t n, MpObjectKv** obj)
must be used when the key is not a string. The search is linear. Returns NULL
if processing failed. Definition at line 143 of file MpObject.h.
|
noexcept |
Specifies an index and gets the object in the associative array.
[in] | n | Associative array index. |
[out] | obj | The pointer that contains the pair, MpObjectKv* , of the key and value from the associative array |
0
on success. All other values are an error.
|
inlinenoexcept |
Obtains the pair of a key and value from the associative array by specifying a non-null terminated string as the key.
[in] | str | Associative array key string. |
[in] | n | Length of the string. |
[out] | obj | The pointer that contains the pair, MpObjectKv* , of the key and value from the associative array |
0 | Success. |
EINVAL | Indicates that str or obj is NULL . |
EACCES | Indicates that this object is not an associative array. |
ENOENT | Indicates that no value corresponding to the given key string has been found. |
Definition at line 186 of file MpObject.h.
|
inlinenoexcept |
Returns the size of the array, associative array, string, or binary.
strlen
for a string, except when there is a null character mid-string. Definition at line 358 of file MpObject.h.
|
inlinenoexcept |
|
noexcept |
Initializes as an object with an n element array.
[in] | n | Size of the array to initialize. |
0
on success. All other values are an error.
|
noexcept |
Initializes the object as binary.
[in] | n | Size of the binary. |
0
on success. All other values cause an error.
|
noexcept |
Initializes the object as binary.
[in] | p | Pointer to the binary. |
[in] | n | Size of the binary. |
0
on success. All other values cause an error.
|
noexcept |
Initializes an object as the extended data type.
[in] | tp | Integer indicating the data type. |
[in] | n | Size of the binary. |
0
on success. All other values cause an error.
|
noexcept |
Initializes an object as the extended data type.
[in] | tp | Integer indicating the data type. |
[in] | p | Pointer to the binary. |
[in] | n | Size of the binary. |
0
on success. All other values cause an error.
|
noexcept |
Initializes the object as an n element associative array.
[in] | n | Size of the associative array to initialize. |
0
on success. All other values are an error.
|
noexcept |
Initializes the object as a string.
[in] | n | Length of the string to be initialized (not including the terminating character). |
0
on success. All other values cause an error.
|
noexcept |
Initializes the object as a string.
[in] | str | String |
[in] | n | Length of the string to be initialized (not including the terminating character). |
0
on success. All other values cause an error.
|
inlinenoexcept |
Initializes the object as a string.
[in] | str | String |
0
on success. All other values cause an error. Definition at line 244 of file MpObject.h.
|
noexcept |
If the object contains an array, inserts an element into the location with the specified index in the array.
[in] | n | The array index. |
NULL
if process fails.
|
inline |
The value is passed into MpObject
.
T | Type of object being assigned. |
[in] | x | Value being passed. |
*this
.Definition at line 304 of file MpObject.h.
|
inline |
For an array, returns a reference to an element of the array.
[in] | n | The array index. |
MpObject
.Definition at line 123 of file MpObject.h.
|
noexcept |
Specifies an index and deletes the corresponding object in the array.
[in] | n | The array index. |
[in,out] | obj | If not NULL , the deleted object is stored. |
0
on success. All other values represent an error.
|
staticnoexcept |
Deletes MpObject
referenced by json_pointer and stores it in removed.
[in,out] | removed | A pair of the key and value referenced by json_pointer. |
[in] | root | A root object that serves as the starting point for reference with json_pointer. |
[in] | json_pointer | JSON pointer string. |
0 | Success. |
ECHILD | Indicates that json_pointer was an empty string, and thus root was deleted. |
EINVAL | Indicates that removed, root, or json_pointer is NULL . |
EILSEQ | Indicates that the syntax for json_pointer is incorrect. |
ENOENT | Indicates that the object referenced by json_pointer cannot be found. |
MpObject
by drilling down the JSON tree structure based on a string defined by JSON Pointer (RFC6901). The pair of the deleted key and value is stored in removed. Note that when deleting an element from the array, its index is boxed and stored in removed->first, and each element after that index is shifted toward the beginning of the array to fill the deleted element.
|
noexcept |
Specifies an index and deletes the corresponding key and object in the associative array.
[in] | n | Associative array index. |
[in,out] | kv | If not NULL , a pair of the deleted key and value is stored. |
0
on success. All other values represent an error.
|
inlinenoexcept |
Specifies a key and deletes the corresponding key and object in the associative array.
STDSTRING | A type compatible with std::string |
[in] | key | Associative array key string. |
[in,out] | kv | If not NULL , a pair of the deleted key and value is stored. |
0
on success. All other values represent an error. Definition at line 206 of file MpObject.h.
nn::nlib::msgpack::MpObject::Resize | ( | uint32_t | n | ) |
Resizes the array, associative array, string, or binary.
[in] | n | Size after resizing. |
0
on success. Any value other than 0
indicates an error.
|
staticnoexcept |
Stores MpObject
referenced by json_pointer in *result.
[in,out] | result | An object referenced by json_pointer. |
[in] | root | A root object that serves as the starting point for reference with json_pointer. |
[in] | json_pointer | JSON pointer string. |
0 | if successful. |
EINVAL | Indicates that result, root, or json_pointer is NULL . |
EILSEQ | Indicates that the syntax for json_pointer is incorrect. |
ENOENT | Indicates that the object referenced by json_pointer cannot be found. |
MpObject
by drilling down the JSON tree structure based on a string defined by JSON Pointer (RFC6901). A string comprising strings delimited with '/' is called a reference token, which specifies a location in JSON with a string resembling a file path.
|
inlinenoexcept |
Swaps the content of the object.
[in,out] | rhs | Object to swap. |
MpObject
does not have a defined copy constructor or assignment operator, and requires using swap
to set the object. Definition at line 310 of file MpObject.h.
|
inlinenoexcept |
Swaps the content of obj and the content of the object within an array.
[in] | n | The array index. |
[in,out] | obj | Pointer to the object to swap. |
MpObject
does not have a defined copy constructor or assignment operator, and requires using swap
to set the object. The return value is the pointer to the object in the array. (It contains the original content of the obj parameter.) NULL
is returned if the corresponding element of the array does not exist. Definition at line 147 of file MpObject.h.
|
inlinenoexcept |
Swaps the content of obj and the content of the object within an associative array.
STDSTRING | A type compatible with std::string |
[in] | key | Key string. |
[in,out] | obj | Pointer to the object to swap. |
MpObject
does not have a defined copy constructor or assignment operator, and requires using swap
to set the object. The return value is the pointer to the object in the array. (It contains the original content of the obj parameter.) NULL
is returned if the corresponding element of the associative array does not exist. Definition at line 153 of file MpObject.h.
|
inlinenoexcept |
Swaps the content of obj and the content of the object within an associative array.
[in] | key | Key string. |
[in,out] | obj | Pointer to the object to swap. |
MpObject
does not have a defined copy constructor or assignment operator, and requires using swap
to set the object. The return value is the pointer to the object in the array. (It contains the original content of the obj parameter.) NULL
is returned if the corresponding element of the associative array does not exist. Definition at line 162 of file MpObject.h.
|
inline |
Unboxes the object value.
[out] | a | Array to store the unboxed data. |
T | Type of object after being unboxed. |
n | Number of elements in the array. |
0
on success.Type of T | Description |
---|---|
nlib_utf8_t | Objects of the MpObject::kString type are unboxed to strings. Space to store the terminating null character is required. |
All others | Boxed into an MpObject::kArray type as an array. |
Definition at line 273 of file MpObject.h.
errno_t nn::nlib::msgpack::MpObject::Unbox | ( | T * | a, |
size_t | n | ||
) | const |
Unboxes the array data.
T | Type of the pointer to the object the unboxed array data is written to. |
[out] | a | Pointer to the object the unboxed data is written to. |
[in] | n | Number of elements. |
0
on success. Nonzero when the type is incorrect or an overflow has occurred.Type of T | Description |
---|---|
void | Unboxed as byte array data. |
nlib_utf8_t | Unboxed as character string data. A null character is added, and requires space for null termination. |
Others | Unboxed as an array of objects. |
Definition at line 876 of file MpObject.h.
|
inline |
Unboxes the object.
T | Type of the pointer to the object the unboxed data is written to. |
[out] | v | Pointer to the object the unboxed data is written to. |
0
on success. All other values are an error.T
. The following table illustrates the difference in behavior. Type of T | Description |
---|---|
bool* | Stored as bool if the type is MpObject::kBoolean . |
Pointer to an integer | Stores as an integer if the type is MpObject::kInt64 or MpObject::kUint64 . Does not check for overflows. |
float*, double* | Stores a float value if the types are MpObject::kFloat or MpObject::kDouble . Does not check for overflows. |
std::string* | Set as string object if the type is MpObject::kString . Returns ENOMEM if an exception occurs in assigning the string. |
std::vector* | Stores a vector object if the type is MpObject::kArray . Returns ENOMEM if an exception occurs while resizing the vector. |
Nlist* | Stores an Nlist object if the type is MpObject::kArray . Returns ENOMEM when there is insufficient memory. |
std::pair* | Stores a pair object if the type is MpObject::kArray and has a size of 2 -. |
std::map* | Stores a map object if the type is MpObject::kMap . Returns ENOMEM if an exception occurs when adding a map element. |
std::array* | Stores an array object if the type is MpObject::kArray . |
std::tuple* | Stores a tuple object if the type is MpObject::kArray . |
std::unordered_map* | Stores an unordered_map object if the type is MpObject::kMap . Returns ENOMEM if an exception occurs when adding a unordered_map element. |
EACCESS
when conversion to any type is not possible. If unboxing an array or similar type fails, the conversion results up to the failure are stored. Unboxing to a user-defined data type follows the specification of the type's unboxing function. nlib_utf8_t
-type arrays. A nlib_utf8_t
array is unboxed as a string. Definition at line 292 of file MpObject.h.
© 2012-2017 Nintendo Co., Ltd. All rights reserved.