CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
Json::Reader Class Reference

Unserialize a JSON document into a Value. More...

#include <reader.h>

Classes

class  ErrorInfo
 
class  Token
 

Public Types

typedef char Char
 
typedef const CharLocation
 

Public Member Functions

std::string getFormatedErrorMessages () const
 Returns a user friendly string that list errors in the parsed document. More...
 
bool parse (const std::string &document, Value &root, bool collectComments=true)
 Read a Value from a JSON document. More...
 
bool parse (const char *beginDoc, const char *endDoc, Value &root, bool collectComments=true)
 Read a Value from a JSON document. More...
 
bool parse (std::istream &is, Value &root, bool collectComments=true)
 Parse from input stream. More...
 
 Reader ()
 Constructs a Reader allowing all features for parsing. More...
 
 Reader (const Features &features)
 Constructs a Reader allowing the specified feature set for parsing. More...
 

Private Types

typedef std::deque< ErrorInfoErrors
 
typedef std::stack< Value * > Nodes
 
enum  TokenType {
  tokenEndOfStream = 0, tokenObjectBegin, tokenObjectEnd, tokenArrayBegin,
  tokenArrayEnd, tokenString, tokenNumber, tokenTrue,
  tokenFalse, tokenNull, tokenArraySeparator, tokenMemberSeparator,
  tokenComment, tokenError
}
 

Private Member Functions

void addComment (Location begin, Location end, CommentPlacement placement)
 
bool addError (const std::string &message, Token &token, Location extra=0)
 
bool addErrorAndRecover (const std::string &message, Token &token, TokenType skipUntilToken)
 
ValuecurrentValue ()
 
bool decodeDouble (Token &token)
 
bool decodeNumber (Token &token)
 
bool decodeString (Token &token)
 
bool decodeString (Token &token, std::string &decoded)
 
bool decodeUnicodeCodePoint (Token &token, Location &current, Location end, unsigned int &unicode)
 
bool decodeUnicodeEscapeSequence (Token &token, Location &current, Location end, unsigned int &unicode)
 
bool expectToken (TokenType type, Token &token, const char *message)
 
void getLocationLineAndColumn (Location location, int &line, int &column) const
 
std::string getLocationLineAndColumn (Location location) const
 
Char getNextChar ()
 
bool match (Location pattern, int patternLength)
 
bool readArray (Token &token)
 
bool readComment ()
 
bool readCppStyleComment ()
 
bool readCStyleComment ()
 
void readNumber ()
 
bool readObject (Token &token)
 
bool readString ()
 
bool readToken (Token &token)
 
bool readValue ()
 
bool recoverFromError (TokenType skipUntilToken)
 
void skipCommentTokens (Token &token)
 
void skipSpaces ()
 
void skipUntilSpace ()
 

Private Attributes

Location begin_
 
bool collectComments_
 
std::string commentsBefore_
 
Location current_
 
std::string document_
 
Location end_
 
Errors errors_
 
Features features_
 
ValuelastValue_
 
Location lastValueEnd_
 
Nodes nodes_
 

Detailed Description

Unserialize a JSON document into a Value.

Definition at line 16 of file reader.h.

Member Typedef Documentation

typedef char Json::Reader::Char

Definition at line 19 of file reader.h.

typedef std::deque<ErrorInfo> Json::Reader::Errors
private

Definition at line 108 of file reader.h.

typedef const Char* Json::Reader::Location

Definition at line 20 of file reader.h.

typedef std::stack<Value *> Json::Reader::Nodes
private

Definition at line 154 of file reader.h.

Member Enumeration Documentation

Enumerator
tokenEndOfStream 
tokenObjectBegin 
tokenObjectEnd 
tokenArrayBegin 
tokenArrayEnd 
tokenString 
tokenNumber 
tokenTrue 
tokenFalse 
tokenNull 
tokenArraySeparator 
tokenMemberSeparator 
tokenComment 
tokenError 

Definition at line 74 of file reader.h.

Constructor & Destructor Documentation

Json::Reader::Reader ( )

Constructs a Reader allowing all features for parsing.

Json::Reader::Reader ( const Features features)

Constructs a Reader allowing the specified feature set for parsing.

Member Function Documentation

void Json::Reader::addComment ( Location  begin,
Location  end,
CommentPlacement  placement 
)
private
bool Json::Reader::addError ( const std::string &  message,
Token token,
Location  extra = 0 
)
private
bool Json::Reader::addErrorAndRecover ( const std::string &  message,
Token token,
TokenType  skipUntilToken 
)
private
Value& Json::Reader::currentValue ( )
private
bool Json::Reader::decodeDouble ( Token token)
private
bool Json::Reader::decodeNumber ( Token token)
private
bool Json::Reader::decodeString ( Token token)
private
bool Json::Reader::decodeString ( Token token,
std::string &  decoded 
)
private
bool Json::Reader::decodeUnicodeCodePoint ( Token token,
Location current,
Location  end,
unsigned int &  unicode 
)
private
bool Json::Reader::decodeUnicodeEscapeSequence ( Token token,
Location current,
Location  end,
unsigned int &  unicode 
)
private
bool Json::Reader::expectToken ( TokenType  type,
Token token,
const char *  message 
)
private
std::string Json::Reader::getFormatedErrorMessages ( ) const

Returns a user friendly string that list errors in the parsed document.

Returns
Formatted error message with the list of errors with their location in the parsed document. An empty string is returned if no error occurred during parsing.
void Json::Reader::getLocationLineAndColumn ( Location  location,
int &  line,
int &  column 
) const
private
std::string Json::Reader::getLocationLineAndColumn ( Location  location) const
private
Char Json::Reader::getNextChar ( )
private
bool Json::Reader::match ( Location  pattern,
int  patternLength 
)
private
bool Json::Reader::parse ( const std::string &  document,
Value root,
bool  collectComments = true 
)

Read a Value from a JSON document.

Parameters
documentUTF-8 encoded string containing the document to read.
root[out] Contains the root value of the document if it was successfully parsed.
collectCommentstrue to collect comment and allow writing them back during serialization, false to discard comments. This parameter is ignored if Features::allowComments_ is false.
Returns
true if the document was successfully parsed, false if an error occurred.

Referenced by jsoncollector::JSONSerializer::deserialize(), evf::EvFDaqDirector::getNFilesFromEoLS(), FedRawDataInputSource::grabNextJsonFile(), and evf::EvFDaqDirector::readLastLSEntry().

bool Json::Reader::parse ( const char *  beginDoc,
const char *  endDoc,
Value root,
bool  collectComments = true 
)

Read a Value from a JSON document.

Parameters
documentUTF-8 encoded string containing the document to read.
root[out] Contains the root value of the document if it was successfully parsed.
collectCommentstrue to collect comment and allow writing them back during serialization, false to discard comments. This parameter is ignored if Features::allowComments_ is false.
Returns
true if the document was successfully parsed, false if an error occurred.
bool Json::Reader::parse ( std::istream &  is,
Value root,
bool  collectComments = true 
)

Parse from input stream.

See Also
Json::operator>>(std::istream&, Json::Value&).
bool Json::Reader::readArray ( Token token)
private
bool Json::Reader::readComment ( )
private
bool Json::Reader::readCppStyleComment ( )
private
bool Json::Reader::readCStyleComment ( )
private
void Json::Reader::readNumber ( )
private
bool Json::Reader::readObject ( Token token)
private
bool Json::Reader::readString ( )
private
bool Json::Reader::readToken ( Token token)
private
bool Json::Reader::readValue ( )
private
bool Json::Reader::recoverFromError ( TokenType  skipUntilToken)
private
void Json::Reader::skipCommentTokens ( Token token)
private
void Json::Reader::skipSpaces ( )
private
void Json::Reader::skipUntilSpace ( )
private

Member Data Documentation

Location Json::Reader::begin_
private

Definition at line 158 of file reader.h.

bool Json::Reader::collectComments_
private

Definition at line 165 of file reader.h.

std::string Json::Reader::commentsBefore_
private

Definition at line 163 of file reader.h.

Location Json::Reader::current_
private

Definition at line 160 of file reader.h.

std::string Json::Reader::document_
private

Definition at line 157 of file reader.h.

Location Json::Reader::end_
private

Definition at line 159 of file reader.h.

Errors Json::Reader::errors_
private

Definition at line 156 of file reader.h.

Features Json::Reader::features_
private

Definition at line 164 of file reader.h.

Value* Json::Reader::lastValue_
private

Definition at line 162 of file reader.h.

Location Json::Reader::lastValueEnd_
private

Definition at line 161 of file reader.h.

Nodes Json::Reader::nodes_
private

Definition at line 155 of file reader.h.