autojson  0.1
A JSON parser base on the automaton provided by json.org
 All Classes Files Functions Typedefs Enumerations Enumerator Pages
JsonParser.hh
1 /*
2  autojson: A JSON parser base on the automaton provided by json.org
3  Copyright (C) 2014 Wan Wai Ho
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  as published by the Free Software Foundation version 2
8  of the License.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #ifndef JSONPARSER_HH_INCLUDED
22 #define JSONPARSER_HH_INCLUDED
23 
24 #include "Reactor.hh"
25 #include <memory>
26 #include <vector>
27 
28 namespace ajs {
29 
35 {
36 public :
37  template <typename R, typename DestType>
38  JsonParser(const R& reactor, DestType& t) :
39  m_reactor(new R(reactor)),
40  m_parser(new_JSON_checker(5))
41  {
42  ParseState p {m_reactor.get(), &t};
43  m_stack.push_back(p);
44  }
45 
46 
47  void Parse(const char *json, std::size_t len);
48 
49 private :
50  static void Callback(void *user, JSON_event type, const char *data, size_t len);
51 
52 private :
53  std::unique_ptr<Reactor> m_reactor;
54  std::vector<ParseState> m_stack;
55  JSON_checker m_parser;
56 };
57 
58 } // end of namespace
59 
60 #endif
Definition: JsonParser.hh:34
Definition: JSON_checker.h:66
JSON_checker new_JSON_checker(int depth)
Definition: JSON_checker.c:238
JSON_event
Definition: JSON_checker.h:21
Definition: Reactor.hh:42