ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/rpc/include/json/reader.h
Revision: 1.1
Committed: Thu Jul 19 08:24:56 2007 UTC (19 years, 3 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Log Message:
initial import. the most important changes since Atheme are:
- fixed many memory leaks
- fixed many bugs
- converted to C++ and use more STL containers
- added a (not very enhanced yet) perl module
- greatly improved XML-RPC speed
- added a JSON-RPC module with code from json-cpp
- added a valgrind memcheck module to operserv
- added a more object oriented base64 implementation
- added a specialised unit test framework
- improved stability
- use gettimeofday() if available
- reworked adding/removing commands
- MemoServ IGNORE DEL can now remove indices

File Contents

# User Rev Content
1 pippijn 1.1 //>>>>>>>>>>> reader.h <<<<<<<<<<<//
2     #ifndef READER_H
3     #define READER_H
4    
5     #include <deque>
6     #include <stack>
7     #include <string>
8     #include <iostream>
9    
10     #include "json/value.h"
11    
12     namespace json
13     {
14     class Value;
15    
16     class Reader
17     {
18     public:
19     typedef char const *Location;
20    
21     Reader ();
22    
23     bool parse (const std::string &document, Value &root, bool collectComments = true);
24     bool parse (char const *beginDoc, char const *endDOc, Value &root, bool collectComments = true);
25     bool parse (std::istream &, Value &root, bool collectComments = true);
26    
27     std::string error_msgs () const;
28    
29     private:
30     enum TokenType
31     {
32     tokenEndOfStream = 0,
33     tokenObjectBegin,
34     tokenObjectEnd,
35     tokenArrayBegin,
36     tokenArrayEnd,
37     tokenString,
38     tokenNumber,
39     tokenTrue,
40     tokenFalse,
41     tokenNull,
42     tokenArraySeparator,
43     tokenMemberSeparator,
44     tokenComment,
45     tokenError
46     };
47    
48     class Token
49     {
50     public:
51     TokenType type_;
52     Location start_;
53     Location end_;
54     };
55    
56     class ErrorInfo
57     {
58     public:
59     Token token_;
60     std::string message_;
61     Location extra_;
62     };
63    
64     typedef std::deque<ErrorInfo> Errors;
65    
66     bool expectToken (TokenType type, Token &token, char const *message);
67     bool readToken (Token &token);
68     void skipSpaces ();
69     bool match (Location pattern,
70     int patternLength);
71     bool readComment ();
72     bool readCStyleComment ();
73     bool readCppStyleComment ();
74     bool readString ();
75     void readNumber ();
76     bool readValue ();
77     bool readObject ();
78     bool readArray ();
79     bool decodeNumber (Token &token);
80     bool decodeString (Token &token);
81     bool decodeString (Token &token, std::string &decoded);
82     bool decodeDouble (Token &token);
83     bool decodeUnicodeEscapeSequence (Token &token,
84     Location &current,
85     Location end,
86     unsigned &unicode);
87     bool addError (const std::string &message,
88     Token &token,
89     Location extra = 0);
90     bool recoverFromError (TokenType skipUntilToken);
91     bool addErrorAndRecover (const std::string &message,
92     Token &token,
93     TokenType skipUntilToken);
94     void skipUntilSpace ();
95     Value &currentValue ();
96     char getNextChar ();
97     void getLocationLineAndColumn (Location location,
98     int &line,
99     int &column) const;
100     std::string getLocationLineAndColumn (Location location) const;
101     void addComment (Location begin,
102     Location end,
103     CommentPlacement placement);
104     void skipCommentTokens (Token &token);
105    
106     typedef std::stack<Value *> Nodes;
107     Nodes nodes_;
108     Errors errors_;
109     std::string document_;
110     Location begin_;
111     Location end_;
112     Location current_;
113     Location lastValueEnd_;
114     Value *lastValue_;
115     std::string commentsBefore_;
116     bool collectComments_;
117     };
118    
119     std::istream& operator >> (std::istream&, Value&);
120    
121     } // namespace json
122    
123     #endif // READER_H