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
std::stack< Value * > Nodes
Definition: reader.h:129
vector< string > parse(string line, const string &delimiter)
Location current_
Definition: reader.h:135
char Char
Definition: reader.h:18
std::string commentsBefore_
Definition: reader.h:138
TokenType type_
Definition: reader.h:86
bool collectComments_
Definition: reader.h:140
Represents a JSON value.
Definition: value.h:99
std::string message_
Definition: reader.h:94
Configuration passed to reader and writer. This configuration object can be used to force the Reader ...
Definition: features.h:12
std::deque< ErrorInfo > Errors
Definition: reader.h:98
Location start_
Definition: reader.h:87
std::vector< float > features(const reco::PreId &ecal, const reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools)
#define JSON_API
Definition: config.h:40
Location end_
Definition: reader.h:88
Errors errors_
Definition: reader.h:131
JSON (JavaScript Object Notation).
Location end_
Definition: reader.h:134
CommentPlacement
Definition: value.h:34
std::istream & operator>>(std::istream &, Value &)
Read from &#39;sin&#39; into &#39;root&#39;.
Nodes nodes_
Definition: reader.h:130
Unserialize a JSON document into a Value.
Definition: reader.h:16
Features features_
Definition: reader.h:139
Location lastValueEnd_
Definition: reader.h:136
const Char * Location
Definition: reader.h:19
std::string document_
Definition: reader.h:132
Location begin_
Definition: reader.h:133
Value * lastValue_
Definition: reader.h:137