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 jsoncollector {
12  namespace Json {
13 
17  class JSON_API Reader {
18  public:
19  typedef char Char;
20  typedef const Char *Location;
21 
25  Reader();
26 
30  Reader(const Features &features);
31 
42  bool parse(const std::string &document, Value &root, bool collectComments = true);
43 
54  bool parse(const char *beginDoc, const char *endDoc, Value &root, bool collectComments = true);
55 
58  bool parse(std::istream &is, Value &root, bool collectComments = true);
59 
65  std::string getFormatedErrorMessages() const;
66 
67  private:
68  enum TokenType {
69  tokenEndOfStream = 0,
82  tokenError
83  };
84 
85  class Token {
86  public:
90  };
91 
92  class ErrorInfo {
93  public:
97  };
98 
99  typedef std::deque<ErrorInfo> Errors;
100 
101  bool expectToken(TokenType type, Token &token, const char *message);
102  bool readToken(Token &token);
103  void skipSpaces();
104  bool match(Location pattern, int patternLength);
105  bool readComment();
106  bool readCStyleComment();
107  bool readCppStyleComment();
108  bool readString();
109  void readNumber();
110  bool readValue();
111  bool readObject(Token &token);
112  bool readArray(Token &token);
113  bool decodeNumber(Token &token);
114  bool decodeString(Token &token);
115  bool decodeString(Token &token, std::string &decoded);
116  bool decodeDouble(Token &token);
117  bool decodeUnicodeCodePoint(Token &token, Location &current, Location end, unsigned int &unicode);
118  bool decodeUnicodeEscapeSequence(Token &token, Location &current, Location end, unsigned int &unicode);
119  bool addError(const std::string &message, Token &token, Location extra = nullptr);
120  bool recoverFromError(TokenType skipUntilToken);
121  bool addErrorAndRecover(const std::string &message, Token &token, TokenType skipUntilToken);
122  void skipUntilSpace();
123  Value &currentValue();
124  Char getNextChar();
125  void getLocationLineAndColumn(Location location, int &line, int &column) const;
126  std::string getLocationLineAndColumn(Location location) const;
127  void addComment(Location begin, Location end, CommentPlacement placement);
128  void skipCommentTokens(Token &token);
129 
130  typedef std::stack<Value *> Nodes;
142  };
143 
168  std::istream &operator>>(std::istream &, Value &);
169 
170  } // namespace Json
171 } // namespace jsoncollector
172 #endif // CPPTL_JSON_READER_H_INCLUDED
vector< string > parse(string line, const string &delimiter)
std::stack< Value * > Nodes
Definition: reader.h:130
Unserialize a JSON document into a Value.
Definition: reader.h:17
Configuration passed to reader and writer. This configuration object can be used to force the Reader ...
Definition: features.h:13
std::vector< float > features(const reco::PreId &ecal, const reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools)
std::deque< ErrorInfo > Errors
Definition: reader.h:99
#define JSON_API
Definition: config.h:40
const Char * Location
Definition: reader.h:20
std::string commentsBefore_
Definition: reader.h:139
std::istream & operator>>(std::istream &, Value &)
Read from &#39;sin&#39; into &#39;root&#39;.
Represents a JSON value.
Definition: value.h:101
JSON (JavaScript Object Notation).
Definition: DataPoint.h:26