CMS 3D CMS Logo

reader.h
Go to the documentation of this file.
1 #ifndef CPPTL_JSON_READER_H_INCLUDED
2 #define CPPTL_JSON_READER_H_INCLUDED
3 
4 #include "features.h"
5 #include "value.h"
6 #include <deque>
7 #include <stack>
8 #include <string>
9 #include <iostream>
10 
11 namespace Json {
12 
16  class JSON_API Reader {
17  public:
18  typedef char Char;
19  typedef const Char *Location;
20 
24  Reader();
25 
29  Reader(const Features &features);
30 
41  bool parse(const std::string &document, Value &root, bool collectComments = true);
42 
53  bool parse(const char *beginDoc, const char *endDoc, Value &root, bool collectComments = true);
54 
57  bool parse(std::istream &is, Value &root, bool collectComments = true);
58 
64  std::string getFormatedErrorMessages() const;
65 
66  private:
67  enum TokenType {
68  tokenEndOfStream = 0,
81  tokenError
82  };
83 
84  class Token {
85  public:
89  };
90 
91  class ErrorInfo {
92  public:
96  };
97 
98  typedef std::deque<ErrorInfo> Errors;
99 
100  bool expectToken(TokenType type, Token &token, const char *message);
101  bool readToken(Token &token);
102  void skipSpaces();
103  bool match(Location pattern, int patternLength);
104  bool readComment();
105  bool readCStyleComment();
106  bool readCppStyleComment();
107  bool readString();
108  void readNumber();
109  bool readValue();
110  bool readObject(Token &token);
111  bool readArray(Token &token);
112  bool decodeNumber(Token &token);
113  bool decodeString(Token &token);
114  bool decodeString(Token &token, std::string &decoded);
115  bool decodeDouble(Token &token);
116  bool decodeUnicodeCodePoint(Token &token, Location &current, Location end, unsigned int &unicode);
117  bool decodeUnicodeEscapeSequence(Token &token, Location &current, Location end, unsigned int &unicode);
118  bool addError(const std::string &message, Token &token, Location extra = nullptr);
119  bool recoverFromError(TokenType skipUntilToken);
120  bool addErrorAndRecover(const std::string &message, Token &token, TokenType skipUntilToken);
121  void skipUntilSpace();
122  Value &currentValue();
123  Char getNextChar();
124  void getLocationLineAndColumn(Location location, int &line, int &column) const;
125  std::string getLocationLineAndColumn(Location location) const;
126  void addComment(Location begin, Location end, CommentPlacement placement);
127  void skipCommentTokens(Token &token);
128 
129  typedef std::stack<Value *> Nodes;
141  };
142 
167  std::istream &operator>>(std::istream &, Value &);
168 
169 } // namespace Json
170 
171 #endif // CPPTL_JSON_READER_H_INCLUDED
Json::Reader::tokenFalse
Definition: reader.h:76
features.h
Json::CommentPlacement
CommentPlacement
Definition: value.h:34
Json::Reader::Token::start_
Location start_
Definition: reader.h:87
Json::Reader::Token
Definition: reader.h:84
Json::Reader::current_
Location current_
Definition: reader.h:135
postprocess-scan-build.features
features
Definition: postprocess-scan-build.py:8
Json::Reader::nodes_
Nodes nodes_
Definition: reader.h:130
betterConfigParser.unicode
unicode
Definition: betterConfigParser.py:13
Json::Features
Configuration passed to reader and writer. This configuration object can be used to force the Reader ...
Definition: features.h:12
Json::Reader::Char
char Char
Definition: reader.h:18
Json::Reader::features_
Features features_
Definition: reader.h:139
Json::Reader::tokenComment
Definition: reader.h:80
Json::Reader::ErrorInfo
Definition: reader.h:91
Json::Reader
Unserialize a JSON document into a Value.
Definition: reader.h:16
end
#define end
Definition: vmac.h:39
Json::Reader::collectComments_
bool collectComments_
Definition: reader.h:140
Json::Reader::ErrorInfo::extra_
Location extra_
Definition: reader.h:95
Json::Reader::tokenTrue
Definition: reader.h:75
Json::Reader::tokenMemberSeparator
Definition: reader.h:79
Json::Reader::lastValueEnd_
Location lastValueEnd_
Definition: reader.h:136
Json::Reader::Token::type_
TokenType type_
Definition: reader.h:86
Json::Reader::Nodes
std::stack< Value * > Nodes
Definition: reader.h:129
Json
JSON (JavaScript Object Notation).
Definition: EvFDaqDirector.h:44
Json::Reader::ErrorInfo::token_
Token token_
Definition: reader.h:93
Json::Reader::document_
std::string document_
Definition: reader.h:132
Json::Reader::end_
Location end_
Definition: reader.h:134
Json::Reader::tokenObjectBegin
Definition: reader.h:69
Json::Reader::commentsBefore_
std::string commentsBefore_
Definition: reader.h:138
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
dumpparser.parse
def parse(path, config)
Definition: dumpparser.py:13
Json::Reader::tokenNumber
Definition: reader.h:74
Json::Reader::begin_
Location begin_
Definition: reader.h:133
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
Json::Reader::TokenType
TokenType
Definition: reader.h:67
root
Definition: RooFitFunction.h:10
topSingleLeptonDQM_PU_cfi.pattern
pattern
Definition: topSingleLeptonDQM_PU_cfi.py:39
Json::Reader::Location
const typedef Char * Location
Definition: reader.h:19
Json::operator>>
std::istream & operator>>(std::istream &, Value &)
Read from 'sin' into 'root'.
Json::Reader::tokenArrayBegin
Definition: reader.h:71
Json::Reader::Token::end_
Location end_
Definition: reader.h:88
Json::Reader::tokenObjectEnd
Definition: reader.h:70
JSON_API
#define JSON_API
Definition: config.h:40
Json::Reader::errors_
Errors errors_
Definition: reader.h:131
Json::Reader::tokenArrayEnd
Definition: reader.h:72
type
type
Definition: HCALResponse.h:21
GeomDetEnumerators::Location
Location
Definition: GeomDetEnumerators.h:9
Json::Reader::lastValue_
Value * lastValue_
Definition: reader.h:137
EcalCondDBWriter_cfi.location
location
Definition: EcalCondDBWriter_cfi.py:63
Json::Reader::ErrorInfo::message_
std::string message_
Definition: reader.h:94
mps_splice.line
line
Definition: mps_splice.py:76
Json::Reader::tokenNull
Definition: reader.h:77
begin
#define begin
Definition: vmac.h:32
value.h
Json::Reader::tokenString
Definition: reader.h:73
Json::Value
Represents a JSON value.
Definition: value.h:99
Json::Reader::Errors
std::deque< ErrorInfo > Errors
Definition: reader.h:98
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316
Json::Reader::tokenArraySeparator
Definition: reader.h:78