join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::JsonReader Class Reference

JSON reader class. More...

#include <json.hpp>

Inheritance diagram for join::JsonReader:
Collaboration diagram for join::JsonReader:

Public Member Functions

 JsonReader (Value &root)
 default constructor.
 
 JsonReader (const JsonReader &other)=delete
 copy constructor.
 
JsonReaderoperator= (const JsonReader &other)=delete
 copy assignment.
 
 JsonReader (JsonReader &&other)=delete
 move constructor.
 
JsonReaderoperator= (JsonReader &&other)=delete
 move assignment.
 
virtual ~JsonReader ()=default
 destroy instance.
 
template<JsonReadMode ReadMode = JsonReadMode::None>
int deserialize (const char *document, size_t length)
 deserialize a document.
 
int deserialize (const char *document, size_t length) override
 deserialize a document.
 
template<JsonReadMode ReadMode = JsonReadMode::None>
int deserialize (const char *first, const char *last)
 deserialize a document.
 
int deserialize (const char *first, const char *last) override
 deserialize a document.
 
template<JsonReadMode ReadMode = JsonReadMode::None>
int deserialize (const std::string &document)
 deserialize a document.
 
int deserialize (const std::string &document) override
 deserialize a document.
 
template<JsonReadMode ReadMode = JsonReadMode::None>
int deserialize (std::stringstream &document)
 deserialize a document.
 
int deserialize (std::stringstream &document) override
 deserialize a document.
 
template<JsonReadMode ReadMode = JsonReadMode::None>
int deserialize (std::istringstream &document)
 deserialize a document.
 
int deserialize (std::istringstream &document) override
 deserialize a document.
 
template<JsonReadMode ReadMode = JsonReadMode::None>
int deserialize (std::fstream &document)
 deserialize a document.
 
int deserialize (std::fstream &document) override
 deserialize a document.
 
template<JsonReadMode ReadMode = JsonReadMode::None>
int deserialize (std::ifstream &document)
 deserialize a document.
 
int deserialize (std::ifstream &document) override
 deserialize a document.
 
template<JsonReadMode ReadMode = JsonReadMode::None>
int deserialize (std::iostream &document)
 deserialize a document.
 
int deserialize (std::iostream &document) override
 deserialize a document.
 
template<JsonReadMode ReadMode = JsonReadMode::None>
int deserialize (std::istream &document)
 deserialize a document.
 
int deserialize (std::istream &document) override
 deserialize a document.
 
- Public Member Functions inherited from join::StreamReader
 StreamReader (Value &root)
 default constructor.
 
 StreamReader (const StreamReader &other)=delete
 copy constructor.
 
StreamReaderoperator= (const StreamReader &other)=delete
 copy assignment.
 
 StreamReader (StreamReader &&other)=delete
 move constructor.
 
StreamReaderoperator= (StreamReader &&other)=delete
 move assignment.
 
virtual ~StreamReader ()=default
 destroy instance.
 

Protected Member Functions

template<JsonReadMode ReadMode, typename ViewType >
int read (ViewType &document)
 parse a document.
 
template<JsonReadMode ReadMode, typename ViewType >
int readValue (ViewType &document)
 parse a JSON value.
 
template<typename ViewType >
int readNull (ViewType &document)
 parse a null value.
 
template<typename ViewType >
int readTrue (ViewType &document)
 parse a true value.
 
template<typename ViewType >
int readFalse (ViewType &document)
 parse a false value.
 
template<typename ViewType >
int readInf (ViewType &document, bool negative)
 parse an infinity value.
 
template<typename ViewType >
int readNan (ViewType &document, bool negative)
 parse a nan value.
 
void umul192 (uint64_t hi, uint64_t lo, uint64_t significand, uint64_t &high, uint64_t &middle, uint64_t &low) noexcept
 multiply 192 bits unsigned integer by 64 bits unsigned integer.
 
bool strtodFast (uint64_t significand, int64_t exponent, double &value)
 convert double using fast path.
 
bool strtodSlow (const std::string &num, double &d)
 convert double using strtod.
 
template<typename ViewType >
int readNumber (ViewType &document)
 parse a number value.
 
template<typename ViewType >
int readHex (ViewType &document, uint32_t &u)
 parse a 4-digit hexadecimal sequence..
 
void encodeUtf8 (uint32_t codepoint, std::string &output)
 encode a Unicode codepoint to UTF-8.
 
template<typename ViewType >
int readUnicode (ViewType &document, std::string &output)
 parse unicode.
 
template<typename ViewType >
int readEscaped (ViewType &document, std::string &output)
 parse escaped sequence.
 
template<typename ViewType >
int readString (ViewType &document, bool isKey=false)
 parse UTF8.
 
template<JsonReadMode ReadMode, typename ViewType >
int readArray (ViewType &document)
 parse an array value.
 
template<JsonReadMode ReadMode, typename ViewType >
int readObject (ViewType &document)
 parse an object value.
 
template<JsonReadMode ReadMode, typename ViewType >
std::enable_if<!(ReadMode &JsonReadMode::ParseComments), int >::type skipWhitespaces (ViewType &document)
 skip whitespaces.
 
template<JsonReadMode ReadMode, typename ViewType >
std::enable_if<(ReadMode &JsonReadMode::ParseComments), int >::type skipWhitespaces (ViewType &document)
 skip whitespaces with comment parsing.
 
constexpr bool isUpperAlpha (char c) noexcept
 check if upper case alphanumeric character.
 
constexpr bool isLowerAlpha (char c) noexcept
 check if lower case alphanumeric character.
 
constexpr bool isDigit (char c) noexcept
 check if digit.
 
constexpr bool isSign (char c) noexcept
 check if sign.
 
- Protected Member Functions inherited from join::StreamReader
virtual int setNull () override
 set null value.
 
virtual int setBool (bool value) override
 set boolean value.
 
virtual int setInt (int32_t value) override
 set integer value.
 
virtual int setUint (uint32_t value) override
 set unsigned integer value.
 
virtual int setInt64 (int64_t value) override
 set 64 bits integer value.
 
virtual int setUint64 (uint64_t value) override
 set unsigned 64 bits integer value.
 
virtual int setDouble (double value) override
 set real value.
 
virtual int setString (const std::string &value) override
 set string value.
 
virtual int startArray (uint32_t size=0) override
 start array.
 
virtual int stopArray () override
 stop array.
 
virtual int startObject (uint32_t size=0) override
 start object.
 
virtual int setKey (const std::string &key) override
 set key.
 
virtual int stopObject () override
 stop object.
 
virtual int setValue (Value &&value)
 set value.
 
- Protected Member Functions inherited from join::SaxHandler
 SaxHandler ()=default
 default constructor.
 
 SaxHandler (const SaxHandler &other)=default
 copy constructor.
 
SaxHandleroperator= (const SaxHandler &other)=default
 copy assignment.
 
 SaxHandler (SaxHandler &&other)=default
 move constructor.
 
SaxHandleroperator= (SaxHandler &&other)=default
 move assignment.
 
virtual ~SaxHandler ()=default
 destroy instance.
 

Additional Inherited Members

- Protected Attributes inherited from join::StreamReader
std::stack< Value * > _stack
 stack.
 
std::string _curkey
 current key.
 
Value_root
 root.
 
- Static Protected Attributes inherited from join::StreamReader
static constexpr size_t _maxdepth = 19
 max stack depth.
 

Detailed Description

JSON reader class.

Constructor & Destructor Documentation

◆ JsonReader() [1/3]

join::JsonReader::JsonReader ( Value & root)
inline

default constructor.

Parameters
rootValue to write.

◆ JsonReader() [2/3]

join::JsonReader::JsonReader ( const JsonReader & other)
delete

copy constructor.

Parameters
otherobject to copy.

◆ JsonReader() [3/3]

join::JsonReader::JsonReader ( JsonReader && other)
delete

move constructor.

Parameters
otherobject to move.

◆ ~JsonReader()

virtual join::JsonReader::~JsonReader ( )
virtualdefault

destroy instance.

Member Function Documentation

◆ deserialize() [1/18]

template<JsonReadMode ReadMode = JsonReadMode::None>
int join::JsonReader::deserialize ( const char * document,
size_t length )
inlinevirtual

deserialize a document.

Parameters
documentdocument to parse.
lengthThe length of the document to parse.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [2/18]

int join::JsonReader::deserialize ( const char * document,
size_t length )
inlineoverridevirtual

deserialize a document.

Parameters
documentdocument to parse.
lengthThe length of the document to parse.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [3/18]

template<JsonReadMode ReadMode = JsonReadMode::None>
int join::JsonReader::deserialize ( const char * first,
const char * last )
inlinevirtual

deserialize a document.

Parameters
firstThe first character of the document to parse.
lastThe last character of the document to parse.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [4/18]

int join::JsonReader::deserialize ( const char * first,
const char * last )
inlineoverridevirtual

deserialize a document.

Parameters
firstThe first character of the document to parse.
lastThe last character of the document to parse.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [5/18]

template<JsonReadMode ReadMode = JsonReadMode::None>
int join::JsonReader::deserialize ( const std::string & document)
inlinevirtual

deserialize a document.

Parameters
documentdocument to deserialize.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [6/18]

int join::JsonReader::deserialize ( const std::string & document)
inlineoverridevirtual

deserialize a document.

Parameters
documentdocument to deserialize.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [7/18]

template<JsonReadMode ReadMode = JsonReadMode::None>
int join::JsonReader::deserialize ( std::fstream & document)
inlinevirtual

deserialize a document.

Parameters
documentdocument to deserialize.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [8/18]

int join::JsonReader::deserialize ( std::fstream & document)
inlineoverridevirtual

deserialize a document.

Parameters
documentdocument to deserialize.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [9/18]

template<JsonReadMode ReadMode = JsonReadMode::None>
int join::JsonReader::deserialize ( std::ifstream & document)
inlinevirtual

deserialize a document.

Parameters
documentdocument to deserialize.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [10/18]

int join::JsonReader::deserialize ( std::ifstream & document)
inlineoverridevirtual

deserialize a document.

Parameters
documentdocument to deserialize.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [11/18]

template<JsonReadMode ReadMode = JsonReadMode::None>
int join::JsonReader::deserialize ( std::iostream & document)
inlinevirtual

deserialize a document.

Parameters
documentdocument to deserialize.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [12/18]

int join::JsonReader::deserialize ( std::iostream & document)
inlineoverridevirtual

deserialize a document.

Parameters
documentdocument to deserialize.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [13/18]

template<JsonReadMode ReadMode = JsonReadMode::None>
int join::JsonReader::deserialize ( std::istream & document)
inlinevirtual

deserialize a document.

Parameters
documentdocument to deserialize.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [14/18]

int join::JsonReader::deserialize ( std::istream & document)
inlineoverridevirtual

deserialize a document.

Parameters
documentdocument to deserialize.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [15/18]

template<JsonReadMode ReadMode = JsonReadMode::None>
int join::JsonReader::deserialize ( std::istringstream & document)
inlinevirtual

deserialize a document.

Parameters
documentdocument to deserialize.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [16/18]

int join::JsonReader::deserialize ( std::istringstream & document)
inlineoverridevirtual

deserialize a document.

Parameters
documentdocument to deserialize.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [17/18]

template<JsonReadMode ReadMode = JsonReadMode::None>
int join::JsonReader::deserialize ( std::stringstream & document)
inlinevirtual

deserialize a document.

Parameters
documentdocument to deserialize.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ deserialize() [18/18]

int join::JsonReader::deserialize ( std::stringstream & document)
inlineoverridevirtual

deserialize a document.

Parameters
documentdocument to deserialize.
Returns
0 on success, -1 otherwise.

Implements join::StreamReader.

◆ encodeUtf8()

void join::JsonReader::encodeUtf8 ( uint32_t codepoint,
std::string & output )
inlineprotected

encode a Unicode codepoint to UTF-8.

Parameters
codepointunicode codepoint to encode.
outputparse output string.

◆ isDigit()

bool join::JsonReader::isDigit ( char c)
inlineconstexprprotectednoexcept

check if digit.

Parameters
ccharacter to check.
Returns
true if digit, false otherwise.

◆ isLowerAlpha()

bool join::JsonReader::isLowerAlpha ( char c)
inlineconstexprprotectednoexcept

check if lower case alphanumeric character.

Parameters
ccharacter to check.
Returns
true if lower case alphanumeric character, false otherwise.

◆ isSign()

bool join::JsonReader::isSign ( char c)
inlineconstexprprotectednoexcept

check if sign.

Parameters
ccharacter to check.
Returns
true if sign, false otherwise.

◆ isUpperAlpha()

bool join::JsonReader::isUpperAlpha ( char c)
inlineconstexprprotectednoexcept

check if upper case alphanumeric character.

Parameters
ccharacter to check.
Returns
true if upper case alphanumeric character, false otherwise.

◆ operator=() [1/2]

JsonReader & join::JsonReader::operator= ( const JsonReader & other)
delete

copy assignment.

Parameters
otherobject to copy.
Returns
a reference of the current object.

◆ operator=() [2/2]

JsonReader & join::JsonReader::operator= ( JsonReader && other)
delete

move assignment.

Parameters
otherobject to move.
Returns
a reference of the current object.

◆ read()

template<JsonReadMode ReadMode, typename ViewType >
int join::JsonReader::read ( ViewType & document)
inlineprotected

parse a document.

Parameters
documentdocument to parse.
Returns
0 on success, -1 otherwise.

◆ readArray()

template<JsonReadMode ReadMode, typename ViewType >
int join::JsonReader::readArray ( ViewType & document)
inlineprotected

parse an array value.

Parameters
documentdocument to parse.
Returns
0 on success, -1 otherwise.

◆ readEscaped()

template<typename ViewType >
int join::JsonReader::readEscaped ( ViewType & document,
std::string & output )
inlineprotected

parse escaped sequence.

Parameters
documentdocument to parse.
outputparse output string.
Returns
0 on success, -1 otherwise.

◆ readFalse()

template<typename ViewType >
int join::JsonReader::readFalse ( ViewType & document)
inlineprotected

parse a false value.

Parameters
documentdocument to parse.
Returns
0 on success, -1 otherwise.

◆ readHex()

template<typename ViewType >
int join::JsonReader::readHex ( ViewType & document,
uint32_t & u )
inlineprotected

parse a 4-digit hexadecimal sequence..

Parameters
documentdocument to parse.
uoutput variable to store the parsed hexadecimal value.
Returns
0 on success, -1 otherwise.

◆ readInf()

template<typename ViewType >
int join::JsonReader::readInf ( ViewType & document,
bool negative )
inlineprotected

parse an infinity value.

Parameters
documentdocument to parse.
Returns
0 on success, -1 otherwise.

◆ readNan()

template<typename ViewType >
int join::JsonReader::readNan ( ViewType & document,
bool negative )
inlineprotected

parse a nan value.

Parameters
documentdocument to parse.
Returns
0 on success, -1 otherwise.

◆ readNull()

template<typename ViewType >
int join::JsonReader::readNull ( ViewType & document)
inlineprotected

parse a null value.

Parameters
documentdocument to parse.
Returns
0 on success, -1 otherwise.

◆ readNumber()

template<typename ViewType >
int join::JsonReader::readNumber ( ViewType & document)
inlineprotected

parse a number value.

Parameters
documentdocument to parse.
Returns
0 on success, -1 otherwise.

◆ readObject()

template<JsonReadMode ReadMode, typename ViewType >
int join::JsonReader::readObject ( ViewType & document)
inlineprotected

parse an object value.

Parameters
documentdocument to parse.
Returns
0 on success, -1 otherwise.

◆ readString()

template<typename ViewType >
int join::JsonReader::readString ( ViewType & document,
bool isKey = false )
inlineprotected

parse UTF8.

Parameters
documentdocument to parse.
outputparse output string.
Returns
0 on success, -1 otherwise.

parse a string value.

Parameters
documentdocument to parse.
isKeyindicate whether the string to parse is a key or not.
Returns
0 on success, -1 otherwise.

◆ readTrue()

template<typename ViewType >
int join::JsonReader::readTrue ( ViewType & document)
inlineprotected

parse a true value.

Parameters
documentdocument to parse.
Returns
0 on success, -1 otherwise.

◆ readUnicode()

template<typename ViewType >
int join::JsonReader::readUnicode ( ViewType & document,
std::string & output )
inlineprotected

parse unicode.

Parameters
documentdocument to parse.
outputparse output string.
Returns
0 on success, -1 otherwise.

◆ readValue()

template<JsonReadMode ReadMode, typename ViewType >
int join::JsonReader::readValue ( ViewType & document)
inlineprotected

parse a JSON value.

Parameters
documentdocument to parse.
Returns
0 on success, -1 otherwise.

◆ skipWhitespaces() [1/2]

template<JsonReadMode ReadMode, typename ViewType >
std::enable_if<!(ReadMode &JsonReadMode::ParseComments), int >::type join::JsonReader::skipWhitespaces ( ViewType & document)
inlineprotected

skip whitespaces.

Parameters
documentdocument to parse.
Returns
0 on success, -1 otherwise.

◆ skipWhitespaces() [2/2]

template<JsonReadMode ReadMode, typename ViewType >
std::enable_if<(ReadMode &JsonReadMode::ParseComments), int >::type join::JsonReader::skipWhitespaces ( ViewType & document)
inlineprotected

skip whitespaces with comment parsing.

Parameters
documentdocument to parse.
Returns
0 on success, -1 otherwise.

◆ strtodFast()

bool join::JsonReader::strtodFast ( uint64_t significand,
int64_t exponent,
double & value )
inlineprotected

convert double using fast path.

Parameters
significandsignificand digits.
exponentexponent.
valueconverted value.
Returns
true on success, false otherwise.

◆ strtodSlow()

bool join::JsonReader::strtodSlow ( const std::string & num,
double & d )
inlineprotected

convert double using strtod.

Parameters
numnumber to convert.
valueconverted value.
Returns
true on success, false otherwise.

◆ umul192()

void join::JsonReader::umul192 ( uint64_t hi,
uint64_t lo,
uint64_t significand,
uint64_t & high,
uint64_t & middle,
uint64_t & low )
inlineprotectednoexcept

multiply 192 bits unsigned integer by 64 bits unsigned integer.

Parameters
hihigh 64 bits of the 128-bit multiplicand.
lolow 64 bits of the 128-bit multiplicand.
significand64-bit multiplier.
highhigh 64 bits of the 192-bit result.
middlemiddle 64 bits of the 192-bit result.
lowlow 64 bits of the 192-bit result.

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