#include <baljsn_jsontokenizer.h>
This class implements a mechanism that makes the organization and values of a non-scalar bdljsn::Json object available as a series of tokens. Some tokens have associated values. See Tokens .
See baljsn_jsontokenizer
◆ allocator_type
◆ TokenType
| Enumerator |
|---|
| e_BEGIN | |
| e_ELEMENT_NAME | |
| e_START_OBJECT | |
| e_END_OBJECT | |
| e_START_ARRAY | |
| e_END_ARRAY | |
| e_ELEMENT_VALUE | |
| e_ERROR | |
◆ JsonTokenizer() [1/3]
| baljsn::JsonTokenizer::JsonTokenizer |
( |
| ) |
|
|
inline |
Create a JsonTokenizer object. Optionally specify an allocator (e.g., the address of a bslma::Allocator object) to supply memory; otherwise, the default allocator is used. No tokens can be generated until a source bdljsn::Json object is specified via the reset method.
◆ JsonTokenizer() [2/3]
| baljsn::JsonTokenizer::JsonTokenizer |
( |
const allocator_type & |
allocator | ) |
|
|
inlineexplicit |
◆ JsonTokenizer() [3/3]
Create a JsonTokenizer object that can supply a series of tokens describing the specified json object. Optionally specify an allocator (e.g., the address of a bslma::Allocator object) to supply memory; otherwise, the default allocator is used.
- Precondition
- The behavior is undefined unless
json->isArray() or json->isObject().
- Note
- Note that
json can also be specified via the reset method.
◆ ~JsonTokenizer()
| baljsn::JsonTokenizer::~JsonTokenizer |
( |
| ) |
|
◆ advanceToNextToken()
| int baljsn::JsonTokenizer::advanceToNextToken |
( |
| ) |
|
Move to the next token in the source object. Return 0 on success and a non-zero value otherwise. The return value is non-zero when there are no more tokens in the source object.
- Precondition
- The behavior is undefined unless a source object was specified on construction and/or a call to
reset.
◆ get_allocator()
Return the allocator used by this object to supply memory.
- Note
- Note that if no allocator was supplied at construction the default allocator in effect at construction is used.
◆ print()
| static bsl::ostream & baljsn::JsonTokenizer::print |
( |
bsl::ostream & |
stream, |
|
|
TokenType |
value, |
|
|
int |
level = 0, |
|
|
int |
spacesPerLevel = 4 |
|
) |
| |
|
static |
Write the string representation of the specified enumeration value to the specified output stream, and return a reference to stream. Optionally specify an initial indentation level, whose absolute value is incremented recursively for nested objects. If level is specified, optionally specify spacesPerLevel, whose absolute value indicates the number of spaces per indentation level for this and all of its nested objects. If level is negative, suppress indentation of the first line. If spacesPerLevel is negative, format the entire output on one line, suppressing all but the initial indentation (as governed by level). See toAscii for what constitutes the string representation of a JsonTokenizer::TokenType value.
◆ reset()
| int baljsn::JsonTokenizer::reset |
( |
const bdljsn::Json * |
json | ) |
|
Reset this tokenizer to use the specified json as a source object for tokens. All state associated with a previously specified source object (if any) is discarded.
- Precondition
- The behavior is undefined unless
json->isArray() or json->isObject().
◆ toAscii()
| static const char * baljsn::JsonTokenizer::toAscii |
( |
TokenType |
value | ) |
|
|
static |
Return the non-modifiable string representation corresponding to the specified enumeration value, if it exists, and a unique (error) string otherwise. The string representation of value matches its corresponding enumerator name with the "e_" prefix elided. For example:
@ e_ELEMENT_VALUE
Definition baljsn_jsontokenizer.h:370
will print the following on standard output:
- Note
- Note that specifying a
value that does not match any of the enumerators will result in a string representation that is distinct from any of those corresponding to the enumerators, but is otherwise unspecified.
◆ tokenType()
Return the type of the current token.
◆ value() [1/2]
Load into the specified data the value of the current token. Return 0 on success and a non-zero value otherwise.
- Precondition
- The behavior is undefined unless
e_ELEMENT_NAME == tokenType().
◆ value() [2/2]
| int baljsn::JsonTokenizer::value |
( |
const bdljsn::Json ** |
data | ) |
const |
|
inline |
Load into the specified data the value of the current token. Return 0 on success and a non-zero value otherwise.
- Precondition
- The behavior is undefined unless
e_ELEMENT_VALUE == tokenType().
◆ JsonTokenizer_Visitor
The documentation for this class was generated from the following file: