JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
jsonv::ast_node Class Referencefinal

Represents an entry in a JSON AST. More...

#include <jsonv/ast.hpp>

Classes

class  array_begin
 The beginning of an kind::array ([). More...
 
class  array_end
 The end of an kind::array (]). More...
 
class  base
 
class  basic_dynamic_size_token
 
class  basic_fixed_size_token
 
class  basic_string_token
 
class  decimal
 
class  document_end
 The end of a document. More...
 
class  document_start
 The start of a document. More...
 
class  error
 
class  integer
 
class  key_canonical
 
class  key_escaped
 
class  literal_false
 
class  literal_null
 
class  literal_true
 
class  object_begin
 The beginning of an kind::object ({). More...
 
class  object_end
 The end of an kind::object (}). More...
 
class  string_canonical
 
class  string_escaped
 

Public Types

using storage_type = std::variant< document_end, document_start, object_begin, object_end, array_begin, array_end, string_canonical, string_escaped, key_canonical, key_escaped, literal_true, literal_false, literal_null, integer, decimal, error >
 

Public Member Functions

 ast_node (const storage_type &value)
 
template<typename T , typename... TArgs>
 ast_node (std::in_place_type_t< T > type, TArgs &&... args)
 
const storage_type & storage () const
 Get the std::variant that backs this type.
 
template<typename FVisitor >
auto visit (FVisitor &&visitor) const
 Convenience function for calling std::visit on the underlying storage of this node.
 
template<typename FVisitor >
auto visit_key (FVisitor &&visitor) const
 Convenience function for calling std::visit on a key (see as_key).
 
ast_node_type type () const
 Get the ast_node_type that tells the underlying type of this instance.
 
string_view token_raw () const
 Get a view of the raw token.
 
template<typename T >
const T & as () const
 Get the underlying data of this node as T.
 
std::variant< key_canonical, key_escapedas_key () const
 Get the underlying data of this node as one of the key types: key_canonical or key_escaped.
 

Detailed Description

Represents an entry in a JSON AST.

See also
parse_index

Definition at line 159 of file ast.hpp.

Member Typedef Documentation

◆ storage_type

Constructor & Destructor Documentation

◆ ast_node() [1/2]

jsonv::ast_node::ast_node ( const storage_type &  value)
inline

Definition at line 437 of file ast.hpp.

◆ ast_node() [2/2]

template<typename T , typename... TArgs>
jsonv::ast_node::ast_node ( std::in_place_type_t< T >  type,
TArgs &&...  args 
)
inlineexplicit

Definition at line 442 of file ast.hpp.

Member Function Documentation

◆ as()

template<typename T >
const T & jsonv::ast_node::as ( ) const
inline

Get the underlying data of this node as T.

Exceptions
std::bad_variant_accessif the requested T is different from the type of this instance.

Definition at line 485 of file ast.hpp.

◆ as_key()

std::variant< key_canonical, key_escaped > jsonv::ast_node::as_key ( ) const
inline

Get the underlying data of this node as one of the key types: key_canonical or key_escaped.

Exceptions
std::bad_variant_accessif the type of this instance is neither key_canonical nor key_escaped.

Definition at line 493 of file ast.hpp.

+ Here is the call graph for this function:

◆ storage()

const storage_type & jsonv::ast_node::storage ( ) const
inline

Get the std::variant that backs this type.

See also
visit

Definition at line 449 of file ast.hpp.

◆ token_raw()

string_view jsonv::ast_node::token_raw ( ) const
inline

Get a view of the raw token.

For example, "true", "{", or "1234". Note that this includes the complete source, so string types such as ast_node_type::string_canonical include the opening and closing quotations.

Definition at line 476 of file ast.hpp.

+ Here is the call graph for this function:

◆ type()

ast_node_type jsonv::ast_node::type ( ) const
inline

Get the ast_node_type that tells the underlying type of this instance.

Definition at line 469 of file ast.hpp.

+ Here is the call graph for this function:

◆ visit()

template<typename FVisitor >
auto jsonv::ast_node::visit ( FVisitor &&  visitor) const
inline

Convenience function for calling std::visit on the underlying storage of this node.

Definition at line 456 of file ast.hpp.

◆ visit_key()

template<typename FVisitor >
auto jsonv::ast_node::visit_key ( FVisitor &&  visitor) const
inline

Convenience function for calling std::visit on a key (see as_key).

Definition at line 463 of file ast.hpp.

+ Here is the call graph for this function:

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