Orcus
Loading...
Searching...
No Matches
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 "env.hpp"
12#include "types.hpp"
13
14#include <memory>
15#include <vector>
16#include <ostream>
17#include <variant>
18
19namespace orcus {
20
21class string_pool;
22
23namespace json {
24
25struct ORCUS_PSR_DLLPUBLIC parser_stats
26{
27 size_t token_buffer_size_threshold;
28};
29
30enum class parse_token_t
31{
32 unknown,
33 begin_parse,
34 end_parse,
35 begin_array,
36 end_array,
37 begin_object,
38 object_key,
39 end_object,
40 boolean_true,
41 boolean_false,
42 null,
43 string,
44 number,
46};
47
48struct ORCUS_PSR_DLLPUBLIC parse_token
49{
50 using value_type = std::variant<std::string_view, parse_error_value_t, double>;
51
52 parse_token_t type;
53 value_type value;
54
56 parse_token(parse_token_t _type);
57 parse_token(parse_token_t _type, std::string_view s);
58 parse_token(std::string_view s, std::ptrdiff_t offset);
59 parse_token(double value);
60
61 parse_token(const parse_token& other);
62
63 parse_token& operator= (parse_token) = delete;
64
65 bool operator== (const parse_token& other) const;
66 bool operator!= (const parse_token& other) const;
67};
68
69typedef std::vector<parse_token> parse_tokens_t;
70
71ORCUS_PSR_DLLPUBLIC std::ostream& operator<< (std::ostream& os, const parse_tokens_t& tokens);
72
73class ORCUS_PSR_DLLPUBLIC parser_thread
74{
75 struct impl;
76 std::unique_ptr<impl> mp_impl;
77
78public:
79 parser_thread(const char* p, size_t n, size_t min_token_size);
80 parser_thread(const char* p, size_t n, size_t min_token_size, size_t max_token_size);
82
83 void start();
84
93 bool next_tokens(parse_tokens_t& tokens);
94
95 parser_stats get_stats() const;
96
97 void swap_string_pool(string_pool& pool);
98};
99
100}}
101
102#endif
103
104/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition json_parser_thread.hpp:74
bool next_tokens(parse_tokens_t &tokens)
Definition exception.hpp:94
Definition string_pool.hpp:26
Definition tokens.hpp:30
Definition json_parser_thread.hpp:49
Definition json_parser_thread.hpp:26