|
JSON Voorhees
Killer JSON for C++
|
A reader instance reads from some form of JSON source (probably a string) and converts it into a JSON ast_node sequence. More...
#include <jsonv/reader.hpp>
Public Member Functions | |
| reader (parse_index index) | |
| Create a reader which reads from the given index. | |
| reader (const value *value) | |
| Create a reader which reads from an in-memory value. | |
| reader (const reader &)=delete | |
| reader & | operator= (const reader &)=delete |
| reader (reader &&) noexcept=default | |
| reader & | operator= (reader &&) noexcept=default |
| bool | good () const |
| Check if this reader is still good to read from. | |
| const ast_node & | current () const |
| Get the current AST node this reader is pointing at. | |
| template<typename TAstNode > | |
| TAstNode | current_as () const |
Get the current AST node as a specific TAstNode subtype, calling expect beforehand. | |
| const path & | current_path () const |
| Get the path to the current node this reader is pointing at. | |
| bool | next_token () noexcept |
| Go to the next token. | |
| bool | next_structure () noexcept |
| Go to one past the end of the current structure. | |
| bool | next_key () noexcept |
| Go to the next object key or end-of-object. | |
| reader (string_view source) | |
| reader (string_view source, const parse_options &parse_options) | |
| reader (const char *source) | |
| reader (const char *source, const parse_options &parse_options) | |
| reader (std::string &&source) | |
| reader (std::string &&source, const parse_options &parse_options) | |
| void | expect (ast_node_type type) |
| void | expect (std::initializer_list< ast_node_type > types) |
A reader instance reads from some form of JSON source (probably a string) and converts it into a JSON ast_node sequence.
Readers normalize access to JSON source for conversion to some other format. They can be provided with pre-parsed JSON through a parse_index or value. They can be provided with a std::string or string_view directly. This allows extractor implementations to operate on all forms of JSON without worrying about the implementation.
Definition at line 39 of file reader.hpp.
Create a reader which reads from an in-memory value.
| value | The value to read from. This must remain valid for the lifetime of the reader. |
|
explicit |
Create a reader which reads from JSON source.
| source | The JSON source code to parse from. This must stay in memory for the duration of this instance's use. If source is an rvalue reference to a std::string instance, the source is moved to the reader's implementation to keep alive. |
| parse_options | If specified, use these options to parse source. If unspecified, use the default values of parse_options for parse_index::parse. |
Get the current AST node this reader is pointing at.
| std::invalid_argument | if this instance is not good. |
Get the current AST node as a specific TAstNode subtype, calling expect beforehand.
| std::invalid_argument | if this instance is not good. |
| extraction_error | if the current node does not match TAstNode::type(). |
Definition at line 100 of file reader.hpp.
Get the path to the current node this reader is pointing at.
This is used in the generation of error messages to describe the location of something that could not be extracted.
| std::invalid_argument | if this instance is not good. |
| void jsonv::reader::expect | ( | ast_node_type | type | ) |
Check that the current AST node has the given type or is one of the expected types. Using this leads to a slightly more informative error message than current.as<T>() call.
| extraction_error | if the current node does not match the expected type or types. |
| std::invalid_argument | if this instance is not good. |
| bool jsonv::reader::good | ( | ) | const |
Check if this reader is still good to read from.
This will be true if this instance has not been moved-from and has not reached EOF. If this is false, current or current_path will throw an exception.
|
noexcept |
Go to the next object key or end-of-object.
true if the reader is still good to read from current. | std::invalid_argument | if the reader is not currently at the start of a key. |
|
noexcept |
Go to one past the end of the current structure.
This is meant to be used when parsing an object or array
true if the reader is still good to read from current.
|
noexcept |
Go to the next token.
true if the reader is still good to read from current.