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 
17  {
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,
43  Value &root,
44  bool collectComments = true );
45 
56  bool parse( const char *beginDoc, const char *endDoc,
57  Value &root,
58  bool collectComments = true );
59 
62  bool parse( std::istream &is,
63  Value &root,
64  bool collectComments = true );
65 
71  std::string getFormatedErrorMessages() const;
72 
73  private:
74  enum TokenType
75  {
76  tokenEndOfStream = 0,
89  tokenError
90  };
91 
92  class Token
93  {
94  public:
96  Location start_;
97  Location end_;
98  };
99 
100  class ErrorInfo
101  {
102  public:
105  Location extra_;
106  };
107 
108  typedef std::deque<ErrorInfo> Errors;
109 
110  bool expectToken( TokenType type, Token &token, const char *message );
111  bool readToken( Token &token );
112  void skipSpaces();
113  bool match( Location pattern,
114  int patternLength );
115  bool readComment();
116  bool readCStyleComment();
117  bool readCppStyleComment();
118  bool readString();
119  void readNumber();
120  bool readValue();
121  bool readObject( Token &token );
122  bool readArray( Token &token );
123  bool decodeNumber( Token &token );
124  bool decodeString( Token &token );
125  bool decodeString( Token &token, std::string &decoded );
126  bool decodeDouble( Token &token );
127  bool decodeUnicodeCodePoint( Token &token,
128  Location &current,
129  Location end,
130  unsigned int &unicode );
131  bool decodeUnicodeEscapeSequence( Token &token,
132  Location &current,
133  Location end,
134  unsigned int &unicode );
135  bool addError( const std::string &message,
136  Token &token,
137  Location extra = 0 );
138  bool recoverFromError( TokenType skipUntilToken );
139  bool addErrorAndRecover( const std::string &message,
140  Token &token,
141  TokenType skipUntilToken );
142  void skipUntilSpace();
143  Value &currentValue();
144  Char getNextChar();
145  void getLocationLineAndColumn( Location location,
146  int &line,
147  int &column ) const;
148  std::string getLocationLineAndColumn( Location location ) const;
149  void addComment( Location begin,
150  Location end,
151  CommentPlacement placement );
152  void skipCommentTokens( Token &token );
153 
154  typedef std::stack<Value *> Nodes;
155  Nodes nodes_;
156  Errors errors_;
158  Location begin_;
159  Location end_;
160  Location current_;
161  Location lastValueEnd_;
166  };
167 
192  std::istream& operator>>( std::istream&, Value& );
193 
194 } // namespace Json
195 
196 #endif // CPPTL_JSON_READER_H_INCLUDED
type
Definition: HCALResponse.h:21
std::stack< Value * > Nodes
Definition: reader.h:154
#define JSON_API
Definition: config.h:40
Location current_
Definition: reader.h:160
char Char
Definition: reader.h:19
std::string commentsBefore_
Definition: reader.h:163
TokenType type_
Definition: reader.h:95
bool collectComments_
Definition: reader.h:165
Represents a JSON value.
Definition: value.h:111
std::string message_
Definition: reader.h:104
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:108
Location start_
Definition: reader.h:96
Location end_
Definition: reader.h:97
Errors errors_
Definition: reader.h:156
#define end
Definition: vmac.h:37
JSON (JavaScript Object Notation).
Location end_
Definition: reader.h:159
CommentPlacement
Definition: value.h:35
def parse(path, config)
Definition: dumpparser.py:13
std::istream & operator>>(std::istream &, Value &)
Read from &#39;sin&#39; into &#39;root&#39;.
Nodes nodes_
Definition: reader.h:155
#define begin
Definition: vmac.h:30
Unserialize a JSON document into a Value.
Definition: reader.h:16
Features features_
Definition: reader.h:164
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
Location lastValueEnd_
Definition: reader.h:161
const Char * Location
Definition: reader.h:20
std::string document_
Definition: reader.h:157
Location begin_
Definition: reader.h:158
Value * lastValue_
Definition: reader.h:162