MySQL 8.0.39
Source Code Documentation
Json_array Class Referencefinal

Represents a JSON array container, i.e. More...

#include <json_dom.h>

Inheritance diagram for Json_array:
[legend]

Public Types

using const_iterator = decltype(m_v)::const_iterator
 Constant iterator over the elements in the JSON array. More...
 

Public Member Functions

 Json_array ()
 
enum_json_type json_type () const override
 
bool append_clone (const Json_dom *value)
 Append a clone of the value to the end of the array. More...
 
bool append_alias (Json_dom *value)
 Append the value to the end of the array. More...
 
bool append_alias (Json_dom_ptr value)
 Append the value to the end of the array and take over the ownership of the value. More...
 
bool consume (Json_array_ptr other)
 Moves all of the elements in the other array to the end of this array. More...
 
bool insert_clone (size_t index, const Json_dom *value)
 Insert a clone of the value at position index of the array. More...
 
bool insert_alias (size_t index, Json_dom_ptr value)
 Insert the value at position index of the array. More...
 
bool remove (size_t index)
 Remove the value at this index. More...
 
size_t size () const
 The cardinality of the array (number of values). More...
 
uint32 depth () const override
 Compute the depth of a document. More...
 
Json_dom_ptr clone () const override
 Make a deep clone. More...
 
Json_domoperator[] (size_t index) const
 Get the value at position index. More...
 
void clear ()
 Remove the values in the array. 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...
 
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 sort (const CHARSET_INFO *cs=nullptr)
 Sort the array. More...
 
bool binary_search (Json_dom *val)
 Check if the given value appears in the array. More...
 
void remove_duplicates (const CHARSET_INFO *cs)
 Sort array and remove duplicate elements. 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_containerparent () 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...
 

Public Attributes

friend Json_dom
 

Private Attributes

std::vector< Json_dom_ptr, Malloc_allocator< Json_dom_ptr > > m_v
 Holds the array values. 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 JsonDocumentDepthHandler &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...
 

Detailed Description

Represents a JSON array container, i.e.

type J_ARRAY here.

Member Typedef Documentation

◆ const_iterator

Constant iterator over the elements in the JSON array.

Constructor & Destructor Documentation

◆ Json_array()

Json_array::Json_array ( )

Member Function Documentation

◆ append_alias() [1/2]

bool Json_array::append_alias ( Json_dom value)
inline

Append the value to the end of the array.

Ownership of the value is effectively transferred to the array and the value will be deallocated by the array so only append values that can be deallocated safely (no stack variables please!)

New code should prefer append_alias(Json_dom_ptr) to this function, because that makes the transfer of ownership more explicit. This function might be removed in the future.

Parameters
[in]valuea JSON value to be appended
Return values
falseon success
trueon failure

◆ append_alias() [2/2]

bool Json_array::append_alias ( Json_dom_ptr  value)
inline

Append the value to the end of the array and take over the ownership of the value.

Parameters
valuethe JSON value to be appended
Returns
false on success, true on failure

◆ append_clone()

bool Json_array::append_clone ( const Json_dom value)
inline

Append a clone of the value to the end of the array.

Parameters
[in]valuea JSON value to be appended
Return values
falseon success
trueon failure

◆ begin()

const_iterator Json_array::begin ( ) const
inline

Returns a const_iterator that refers to the first element.

◆ binary_search()

bool Json_array::binary_search ( Json_dom val)

Check if the given value appears in the array.

Parameters
valvalue to look for
Returns
true value is found false otherwise

◆ clear()

void Json_array::clear ( )
inline

Remove the values in the array.

◆ clone()

Json_dom_ptr Json_array::clone ( ) const
overridevirtual

Make a deep clone.

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

Returns
a cloned Json_dom object.

Implements Json_dom.

◆ consume()

bool Json_array::consume ( Json_array_ptr  other)

Moves all of the elements in the other array to the end of this array.

The other array is deleted.

Parameters
[in]othera pointer to the array which will be consumed
Return values
falseon success
trueon failure

◆ depth()

uint32 Json_array::depth ( ) const
overridevirtual

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

Implements Json_dom.

◆ end()

const_iterator Json_array::end ( ) const
inline

Returns a const_iterator that refers past the last element.

◆ insert_alias()

bool Json_array::insert_alias ( size_t  index,
Json_dom_ptr  value 
)

Insert the value at position index of the array.

If beyond the end, insert at the end.

Ownership of the value is effectively transferred to the array and the value will be deallocated by the array so only append values that can be deallocated safely (no stack variables please!)

Parameters
[in]indexthe position at which to insert
[in]valuea JSON value to be inserted
Return values
falseon success
trueon failure

◆ insert_clone()

bool Json_array::insert_clone ( size_t  index,
const Json_dom value 
)
inline

Insert a clone of the value at position index of the array.

If beyond the end, insert at the end.

Parameters
[in]indexthe position at which to insert
[in]valuea JSON value to be inserted
Return values
falseon success
trueon failure

◆ json_type()

enum_json_type Json_array::json_type ( ) const
inlineoverridevirtual
Returns
the type corresponding to the actual Json_dom subclass

Implements Json_dom.

◆ operator[]()

Json_dom * Json_array::operator[] ( size_t  index) const
inline

Get the value at position index.

The value has not been cloned so it is the responsibility of the user to make a copy if needed. Do not try to deallocate the returned value - it is owned by the array and will be deallocated by it in time. It is admissible to modify its contents (in place; without a clone being taken) if it is a compound.

Parameters
[in]indexthe array index
Returns
the value at index

◆ remove()

bool Json_array::remove ( size_t  index)

Remove the value at this index.

A no-op if index is larger than size. Deletes the value.

Parameters
[in]indexthe index of the value to remove
Returns
true if a value was removed, false otherwise.

◆ remove_duplicates()

void Json_array::remove_duplicates ( const CHARSET_INFO cs)

Sort array and remove duplicate elements.

Used by multi-value index implementation.

◆ replace_dom_in_container()

void Json_array::replace_dom_in_container ( const Json_dom oldv,
Json_dom_ptr  newv 
)
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.

Parameters
[in]oldvthe value to be replaced
[in]newvthe new value to put in the container

Implements Json_container.

◆ size()

size_t Json_array::size ( ) const
inline

The cardinality of the array (number of values).

Returns
the size

◆ sort()

void Json_array::sort ( const CHARSET_INFO cs = nullptr)

Sort the array.

Member Data Documentation

◆ Json_dom

friend Json_array::Json_dom

◆ m_v

std::vector<Json_dom_ptr, Malloc_allocator<Json_dom_ptr> > Json_array::m_v
private

Holds the array values.


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