Orcus
json_parser_thread.hpp
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 */
7
8#ifndef INCLUDED_ORCUS_JSON_PARSER_THREAD_HPP
9#define INCLUDED_ORCUS_JSON_PARSER_THREAD_HPP
10
11#include "orcus/env.hpp"
12
13#include <memory>
14#include <vector>
15#include <ostream>
16
17namespace orcus {
18
19class string_pool;
20
21namespace json {
22
23struct ORCUS_PSR_DLLPUBLIC parser_stats
24{
25 size_t token_buffer_size_threshold;
26};
27
28enum class parse_token_t
29{
30 unknown,
31 begin_parse,
32 end_parse,
33 begin_array,
34 end_array,
35 begin_object,
36 object_key,
37 end_object,
38 boolean_true,
39 boolean_false,
40 null,
41 string,
42 number,
44};
45
46struct ORCUS_PSR_DLLPUBLIC parse_token
47{
48 parse_token_t type;
49
50 union
51 {
52 struct
53 {
54 const char* p;
55 size_t len;
56
57 } string_value;
58
59 struct
60 {
61 const char* p;
62 size_t len;
63 std::ptrdiff_t offset;
64
65 } error_value;
66
67 double numeric_value;
68 };
69
71 parse_token(parse_token_t _type);
72 parse_token(parse_token_t _type, const char* p, size_t len);
73 parse_token(parse_token_t _type, const char* p, size_t len, std::ptrdiff_t offset);
74 parse_token(double value);
75
76 parse_token(const parse_token& other);
77
78 parse_token& operator= (parse_token) = delete;
79
80 bool operator== (const parse_token& other) const;
81 bool operator!= (const parse_token& other) const;
82};
83
84typedef std::vector<parse_token> parse_tokens_t;
85
86ORCUS_PSR_DLLPUBLIC std::ostream& operator<< (std::ostream& os, const parse_tokens_t& tokens);
87
88class ORCUS_PSR_DLLPUBLIC parser_thread
89{
90 struct impl;
91 std::unique_ptr<impl> mp_impl;
92
93public:
94 parser_thread(const char* p, size_t n, size_t min_token_size);
95 parser_thread(const char* p, size_t n, size_t min_token_size, size_t max_token_size);
97
98 void start();
99
108 bool next_tokens(parse_tokens_t& tokens);
109
110 parser_stats get_stats() const;
111
112 void swap_string_pool(string_pool& pool);
113};
114
115}}
116
117#endif
118
119/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: json_parser_base.hpp:19
Definition: json_parser_thread.hpp:89
bool next_tokens(parse_tokens_t &tokens)
Definition: string_pool.hpp:23
Definition: tokens.hpp:22
Definition: json_parser_thread.hpp:47
Definition: json_parser_thread.hpp:24