MySQL 9.1.0
Source Code Documentation
Json_dom Class Referenceabstract

JSON DOM abstract base class. More...

#include <json_dom.h>

Inheritance diagram for Json_dom:
[legend]

Public Member Functions

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_containerparent () const
 Get the parent dom to which this dom is attached. More...
 
virtual enum_json_type json_type () const =0
 
virtual bool is_scalar () const
 
virtual bool is_number () const
 
virtual uint32 depth () const =0
 Compute the depth of a document. More...
 
virtual Json_dom_ptr clone () const =0
 Make a deep clone. More...
 
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...
 

Static Public Member Functions

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...
 

Private Member Functions

void set_parent (Json_container *parent)
 Set the parent dom to which this dom is attached. More...
 

Private Attributes

Json_containerm_parent {nullptr}
 Parent pointer. More...
 

Friends

class Json_object
 
class Json_array
 

Detailed Description

JSON DOM abstract base class.

MySQL representation of in-memory JSON objects used by the JSON type Supports access, deep cloning, and updates. See also Json_wrapper and json_binary::Value. Uses heap for space allocation for now. FIXME.

Class hierarchy:

    Json_dom (abstract)
     Json_scalar (abstract)
       Json_string
       Json_number (abstract)
         Json_decimal
         Json_int
         Json_uint
         Json_double
       Json_boolean
       Json_null
       Json_datetime
       Json_opaque
     Json_container (abstract)
       Json_object
       Json_array

At the outset, object and array add/insert/append operations takes a clone unless specified in the method, e.g. add_alias hands the responsibility for the passed in object over to the object.

Constructor & Destructor Documentation

◆ ~Json_dom()

virtual Json_dom::~Json_dom ( )
virtualdefault

Member Function Documentation

◆ clone()

virtual Json_dom_ptr Json_dom::clone ( ) const
pure virtual

Make a deep clone.

The ownership of the returned object is henceforth with the caller.

Returns
a cloned Json_dom object.

Implemented in Json_object, Json_array, Json_string, Json_decimal, Json_double, Json_int, Json_uint, Json_null, Json_datetime, Json_opaque, and Json_boolean.

◆ depth()

virtual uint32 Json_dom::depth ( ) const
pure virtual

Compute the depth of a document.

This is the value which would be returned by the JSON_DEPTH() system function.

  • for scalar values, empty array and empty object: 1
  • for non-empty array: 1+ max(depth of array elements)
  • for non-empty objects: 1+ max(depth of object values)

For example: "abc", [] and {} have depth 1. ["abc", [3]] and {"a": "abc", "b": [3]} have depth 3.

Returns
the depth of the document

Implemented in Json_scalar, Json_object, and Json_array.

◆ get_location()

Json_path Json_dom::get_location ( ) const

Get the path location of this dom, measured from the outermost document it nests inside.

◆ is_number()

virtual bool Json_dom::is_number ( ) const
inlinevirtual
Returns
true of the object is a subclass of Json_number

Reimplemented in Json_number.

◆ is_scalar()

virtual bool Json_dom::is_scalar ( ) const
inlinevirtual
Returns
true if the object is a subclass of Json_scalar

Reimplemented in Json_scalar.

◆ json_type()

virtual enum_json_type Json_dom::json_type ( ) const
pure virtual
Returns
the type corresponding to the actual Json_dom subclass

Implemented in Json_object, Json_array, Json_string, Json_decimal, Json_double, Json_int, Json_uint, Json_null, Json_datetime, Json_opaque, and Json_boolean.

◆ operator delete() [1/2]

void Json_dom::operator delete ( void *  ptr)
noexcept

Deallocate the space used by a Json_dom object.

◆ operator delete() [2/2]

void Json_dom::operator delete ( void *  ptr,
const std::nothrow_t &   
)
noexcept

Nothrow delete.

◆ operator new()

void * Json_dom::operator new ( size_t  size,
const std::nothrow_t &   
)
noexcept

Allocate space on the heap for a Json_dom object.

Returns
pointer to the allocated memory, or NULL if memory could not be allocated (in which case my_error() will have been called with the appropriate error message)

◆ parent()

Json_container * Json_dom::parent ( ) const
inline

Get the parent dom to which this dom is attached.

Returns
the parent dom.

◆ parse() [1/2]

Json_dom_ptr Json_dom::parse ( const char *  text,
size_t  length,
const JsonParseErrorHandler error_handler,
const JsonErrorHandler depth_handler 
)
static

Parse Json text to DOM (using rapidjson).

The text must be valid JSON. The results when supplying an invalid document is undefined. The ownership of the returned object is henceforth with the caller.

If the parsing fails because of a syntax error, the errmsg and offset arguments will be given values that point to a detailed error message and where the syntax error was located. The caller will have to generate an error message with my_error() in this case.

If the parsing fails because of some other error (such as out of memory), errmsg will point to a location that holds the value NULL. In this case, parse() will already have called my_error(), and the caller doesn't need to generate an error message.

Parameters
[in]textthe JSON text
[in]lengththe length of the text
[in]error_handlerPointer to a function that should handle reporting of parsing error.
[in]depth_handlerPointer to a function that should handle error occurred when depth is exceeded.
Returns
the built DOM if JSON text was parseable, else NULL

◆ parse() [2/2]

Json_dom_ptr Json_dom::parse ( const json_binary::Value v)
static

Construct a DOM object based on a binary JSON value.

The ownership of the returned object is henceforth with the caller.

Parameters
vthe binary value to parse
Returns
a DOM representation of the binary value, or NULL on error

◆ seek()

bool Json_dom::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.

Adds a vector element for each match.

See the header comment for Json_wrapper.seek() for a discussion of complexities involving path expression with more than one ellipsis (**) token.

Parameters
[in]paththe (possibly wildcarded) address of the sub-documents
[in]legsthe number of legs to use from path
[out]hitsone element per match
[in]auto_wrapif true, match a tailing [0] to scalar at that position.
[in]only_need_oneTrue if we can stop after finding one match
Returns
false on success, true on error

◆ set_parent()

void Json_dom::set_parent ( Json_container parent)
inlineprivate

Set the parent dom to which this dom is attached.

Parameters
[in]parentthe parent we're being attached to

Friends And Related Function Documentation

◆ Json_array

friend class Json_array
friend

◆ Json_object

friend class Json_object
friend

Member Data Documentation

◆ m_parent

Json_container* Json_dom::m_parent {nullptr}
private

Parent pointer.


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