BDE 4.39.x Production Release
Loading...
Searching...
No Matches
baljsn::JsonTokenizer Class Reference

#include <baljsn_jsontokenizer.h>

Detailed Description

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

Public Types

enum  TokenType {
  e_BEGIN = 1 , e_ELEMENT_NAME , e_START_OBJECT , e_END_OBJECT ,
  e_START_ARRAY , e_END_ARRAY , e_ELEMENT_VALUE , e_ERROR
}
 
typedef bsl::allocator allocator_type
 

Public Member Functions

 JsonTokenizer ()
 
 JsonTokenizer (const allocator_type &allocator)
 
 JsonTokenizer (const bdljsn::Json *json, const allocator_type &allocator=allocator_type())
 
 ~JsonTokenizer ()
 
int advanceToNextToken ()
 
int reset (const bdljsn::Json *json)
 
TokenType tokenType () const
 
int value (bsl::string_view *data) const
 
int value (const bdljsn::Json **data) const
 
allocator_type get_allocator () const
 

Static Public Member Functions

static bsl::ostream & print (bsl::ostream &stream, TokenType value, int level=0, int spacesPerLevel=4)
 
static const char * toAscii (TokenType value)
 

Friends

class JsonTokenizer_Visitor
 

Member Typedef Documentation

◆ allocator_type

Member Enumeration Documentation

◆ TokenType

Enumerator
e_BEGIN 
e_ELEMENT_NAME 
e_START_OBJECT 
e_END_OBJECT 
e_START_ARRAY 
e_END_ARRAY 
e_ELEMENT_VALUE 
e_ERROR 

Constructor & Destructor Documentation

◆ 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]

baljsn::JsonTokenizer::JsonTokenizer ( const bdljsn::Json json,
const allocator_type allocator = allocator_type() 
)
inline

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 ( )

Destroy this object.

Member Function Documentation

◆ 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()

JsonTokenizer::allocator_type baljsn::JsonTokenizer::get_allocator ( ) const
inline

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:

bsl::cout << DstPolicy::toAscii(JsonTokenizer::e_ELEMENT_VALUE);
@ e_ELEMENT_VALUE
Definition baljsn_jsontokenizer.h:370

will print the following on standard output:

ELEMENT_VALUE
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()

JsonTokenizer::TokenType baljsn::JsonTokenizer::tokenType ( ) const
inline

Return the type of the current token.

◆ value() [1/2]

int baljsn::JsonTokenizer::value ( bsl::string_view 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_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().

Friends And Related Symbol Documentation

◆ JsonTokenizer_Visitor

friend class JsonTokenizer_Visitor
friend

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