nlib
|
Object created when MessagePack or JSON is read. More...
#include "nn/nlib/msgpack/MpObject.h"
Public Types | |
enum | ObjectType { NIL = 0, BOOLEAN, UINT64, INT64, FLOAT, DOUBLE , ARRAY, MAP , RAW = STRING } |
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 |
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 | |
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... | |
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 | InitArray (uint32_t n) noexcept |
Initializes as an object with an n element array. More... | |
Using the Associative Array Type (MAP Type) | |
MpObject * | GetMapItem (const char *str) noexcept |
Specifies a string and gets the object in the associative array. More... | |
const MpObject * | GetMapItem (const char *str) const noexcept |
The same as GetMapItem(const char* str) . | |
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 char *str, MpObject *obj) noexcept |
Swaps the content of obj and the content of the object within an associative array. More... | |
MpObject * | AppendArrayItem () noexcept |
Adds an element to the end if the object is storing an 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 | 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 (<tt>STRING</tt> Type) | |
char * | GetString () noexcept |
Gets a string from an object. | |
const char * | 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 char *str, uint32_t n) noexcept |
Initializes the object as a string. More... | |
errno_t | InitString (const char *str) noexcept |
Initializes the object as a string. More... | |
Using the Binary Type (<tt>BINARY</tt> 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>EXT</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 char *str) noexcept |
Boxes the string. More... | |
template<uint32_t n> | |
errno_t | Box (const char(&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 (char(&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 (char *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. | |
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 82 of file MpObject.h.
Data type of the object stored in MpObject
.
GetType
. Enumerator | |
---|---|
NIL | Represents a |
BOOLEAN | Represents a boolean type. The internal representation is a |
UINT64 | Represents an unsigned integer type. The internal representation is |
INT64 | Represents an integer type. The internal representation is |
FLOAT | Represents a floating point type. The internal representation is |
DOUBLE | Represents a floating point type. The internal representation is |
ARRAY | Represents an array. The internal representation is an array of |
MAP | Represents an associative array. The internal representation is an array of |
RAW | Respresents a byte array (string). |
Definition at line 282 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 159 of file MpObject.h.
|
noexcept |
Adds an element to the end if the object is storing an 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.RAW
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.RAW
type data. Definition at line 785 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::RAW type as a string. |
All others | Boxed into an MpObject::ARRAY type as an array. |
Definition at line 794 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::NIL type. This process never returns an error. |
bool | Stored as an MpObject::BOOLEAN type. This process never returns an error. |
Signed Integer | Stored as an MpObject::INT64 type. This process never returns an error. |
Unsigned Integer | Stored as an MpObject::UINT64 type. This process never returns an error. |
float | Stored as an MpObject::FLOAT type. This process never returns an error. |
double | Stored as an MpObject::DOUBLE type. This process never returns an error. |
std::string | Stored as an MpObject::RAW type. |
std::vector | Stored as an MpObject::ARRAY type. |
Nlist | Stored as an MpObject::ARRAY type. |
std::pair | Stored as an MpObject::ARRAY type with a size of 2 . |
std::map | Stored as an MpObject::ARRAY type. |
std::array | Stored as an MpObject::ARRAY type. |
std::tuple | Stored as an MpObject::ARRAY type. |
std::unordered_map | Stored as an MpObject::ARRAY type. |
char
type arrays. A char
array is boxed as a string. Definition at line 225 of file MpObject.h.
|
noexcept |
Creates a duplicate of the object.
NULL
when duplication fails mid-process.
|
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 96 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 188 of file MpObject.h.
|
noexcept |
Specifies a string and gets the object in the associative array.
[in] | str | Associative array key string. |
MpObjectKv
).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.
|
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. |
MpObjectKv
).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 124 of file MpObject.h.
|
noexcept |
Specifies an index and gets the object in the associative array.
[in] | n | Associative array index. |
[out] | obj | Pointer that stores the pointer to the object (MpObjectKv ). |
0
on success. All other values are an error.
|
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 304 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 205 of file MpObject.h.
|
inline |
The value is passed into MpObject
.
T | Type of object being assigned. |
[in] | x | Value being passed. |
*this
.Definition at line 265 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 104 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.
|
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 271 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 128 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 134 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 143 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 |
---|---|
char | Objects of the MpObject::RAW type are unboxed to strings. Space to store the terminating null character is required. |
All others | Boxed into an MpObject::ARRAY type as an array. |
Definition at line 234 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. |
char | 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 822 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::BOOLEAN . |
Pointer to an integer | Stores as an integer if the type is MpObject::INT64 or MpObject::UINT64 . Does not check for overflows. |
float*, double* | Stores a float value if the types are MpObject::FLOAT or MpObject::DOUBLE . Does not check for overflows. |
std::string* | Set as string object if the type is MpObject::RAW . Returns ENOMEM if an exception occurs in assigning the string. |
std::vector* | Stores a vector object if the type is MpObject::ARRAY . Returns ENOMEM if an exception occurs while resizing the vector. |
Nlist* | Stores an Nlist object if the type is MpObject::ARRAY . Returns ENOMEM when there is insufficient memory. |
std::pair* | Stores a pair object if the type is MpObject::ARRAY and has a size of 2 -. |
std::map* | Stores a map object if the type is MpObject::MAP . Returns ENOMEM if an exception occurs when adding a map element. |
std::array* | Stores an array object if the type is MpObject::ARRAY . |
std::tuple* | Stores a tuple object if the type is MpObject::ARRAY . |
std::unordered_map* | Stores an unordered_map object if the type is MpObject::MAP . 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. char
-type arrays. A char
array is unboxed as a string. Definition at line 253 of file MpObject.h.
© 2012-2016 Nintendo Co., Ltd. All rights reserved.