MySQL 8.4.2
Source Code Documentation
|
Represents a JSON container value of type "object" (ECMA), type J_OBJECT here. More...
#include <json_dom.h>
Public Types | |
typedef Json_object_map::const_iterator | const_iterator |
Constant iterator over the elements in the JSON object. More... | |
Public Member Functions | |
Json_object () | |
enum_json_type | json_type () const override |
bool | add_clone (const std::string &key, const Json_dom *value) |
Insert a clone of the value into the object. More... | |
bool | add_alias (const std::string &key, Json_dom *value) |
Insert the value into the object. More... | |
bool | add_alias (const std::string &key, Json_dom_ptr value) |
Insert the value into the object. More... | |
bool | consume (Json_object_ptr other) |
Transfer all of the key/value pairs in the other object into this object. More... | |
Json_dom * | get (const std::string &key) const |
Return the value at key. More... | |
Json_dom * | get (const MYSQL_LEX_CSTRING &key) const |
bool | remove (const std::string &key) |
Remove the child element addressed by key. More... | |
size_t | cardinality () const |
uint32 | depth () const override |
Compute the depth of a document. More... | |
Json_dom_ptr | clone () const override |
Make a deep clone. More... | |
void | replace_dom_in_container (const Json_dom *oldv, Json_dom_ptr newv) override |
Replace oldv contained inside this container array or object) with newv. More... | |
void | clear () |
Remove all elements in the object. More... | |
const_iterator | begin () const |
Returns a const_iterator that refers to the first element. More... | |
const_iterator | end () const |
Returns a const_iterator that refers past the last element. More... | |
bool | merge_patch (Json_object_ptr patch) |
Implementation of the MergePatch function specified in RFC 7396: More... | |
Public Member Functions inherited from Json_dom | |
virtual | ~Json_dom ()=default |
void * | operator new (size_t size, const std::nothrow_t &) noexcept |
Allocate space on the heap for a Json_dom object. More... | |
void | operator delete (void *ptr) noexcept |
Deallocate the space used by a Json_dom object. More... | |
void | operator delete (void *ptr, const std::nothrow_t &) noexcept |
Nothrow delete. More... | |
Json_container * | parent () const |
Get the parent dom to which this dom is attached. More... | |
virtual bool | is_scalar () const |
virtual bool | is_number () const |
Json_path | get_location () const |
Get the path location of this dom, measured from the outermost document it nests inside. More... | |
bool | seek (const Json_seekable_path &path, size_t legs, Json_dom_vector *hits, bool auto_wrap, bool only_need_one) |
Finds all of the json sub-documents which match the path expression. More... | |
Private Attributes | |
Json_object_map | m_map |
Map to hold the object elements. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from Json_dom | |
static Json_dom_ptr | parse (const char *text, size_t length, const JsonParseErrorHandler &error_handler, const JsonErrorHandler &depth_handler) |
Parse Json text to DOM (using rapidjson). More... | |
static Json_dom_ptr | parse (const json_binary::Value &v) |
Construct a DOM object based on a binary JSON value. More... | |
Represents a JSON container value of type "object" (ECMA), type J_OBJECT here.
typedef Json_object_map::const_iterator Json_object::const_iterator |
Constant iterator over the elements in the JSON object.
Each element is represented as a std::pair where first is a std::string that represents the key name, and second is a pointer to a Json_dom that represents the value.
Json_object::Json_object | ( | ) |
|
inline |
Insert the value into the object.
If the key already exists in the object, the existing value is replaced ("last value wins").
Ownership of the value is effectively transferred to the object and the value will be deallocated by the object so only add values that can be deallocated safely (no stack variables please!)
New code should prefer add_alias(const std::string&, Json_dom_ptr) to this function, because that makes the transfer of ownership more explicit. This function might be removed in the future.
[in] | key | the JSON key of to be added |
[in] | value | a JSON value: the key's value |
false | on success |
true | on failure |
bool Json_object::add_alias | ( | const std::string & | key, |
Json_dom_ptr | value | ||
) |
Insert the value into the object.
If the key already exists in the object, the existing value is replaced ("last value wins").
The ownership of the value is transferred to the object.
[in] | key | the key of the value to be added |
[in] | value | the value to add |
|
inline |
Insert a clone of the value into the object.
If the key already exists in the object, the existing value is replaced ("last value wins").
[in] | key | the JSON element key of to be added |
[in] | value | a JSON value: the element key's value |
false | on success |
true | on failure |
|
inline |
Returns a const_iterator that refers to the first element.
size_t Json_object::cardinality | ( | ) | const |
|
inline |
Remove all elements in the object.
|
overridevirtual |
Make a deep clone.
The ownership of the returned object is henceforth with the caller.
Implements Json_dom.
bool Json_object::consume | ( | Json_object_ptr | other | ) |
Transfer all of the key/value pairs in the other object into this object.
The other object is deleted. If this object and the other object share a key, then the two values of the key are merged.
[in] | other | a pointer to the object which will be consumed |
false | on success |
true | on failure |
|
overridevirtual |
Compute the depth of a document.
This is the value which would be returned by the JSON_DEPTH() system function.
For example: "abc", [] and {} have depth 1. ["abc", [3]] and {"a": "abc", "b": [3]} have depth 3.
Implements Json_dom.
|
inline |
Returns a const_iterator that refers past the last element.
Json_dom * Json_object::get | ( | const MYSQL_LEX_CSTRING & | key | ) | const |
Json_dom * Json_object::get | ( | const std::string & | key | ) | const |
Return the value at key.
The value is not cloned, so make one if you need it. Do not delete the returned value, please! If the key is not present, return a null pointer.
[in] | key | the key of the element whose value we want |
|
inlineoverridevirtual |
Implements Json_dom.
bool Json_object::merge_patch | ( | Json_object_ptr | patch | ) |
Implementation of the MergePatch function specified in RFC 7396:
define MergePatch(Target, Patch): if Patch is an Object: if Target is not an Object: Target = {} # Ignore the contents and set it to an empty Object for each Key/Value pair in Patch: if Value is null: if Key exists in Target: remove the Key/Value pair from Target else: Target[Key] = MergePatch(Target[Key], Value) return Target else: return Patch
patch | the object that describes the patch |
false | on success |
true | on memory allocation error |
bool Json_object::remove | ( | const std::string & | key | ) |
Remove the child element addressed by key.
The removed child is deleted.
key | the key of the element to remove |
true | if an element was removed |
false | if there was no element with that key |
|
overridevirtual |
Replace oldv contained inside this container array or object) with newv.
If this container does not contain oldv, calling the method is a no-op.
[in] | oldv | the value to be replaced |
[in] | newv | the new value to put in the container |
Implements Json_container.
|
private |
Map to hold the object elements.