-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathjson_evented.h
More file actions
39 lines (33 loc) · 1020 Bytes
/
Copy pathjson_evented.h
File metadata and controls
39 lines (33 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
#include <functional>
#include <string>
class JsonObserver {
public:
virtual ~JsonObserver() = default;
virtual void onObjectStart() = 0;
virtual void onObjectEnd() = 0;
virtual void onArrayStart() = 0;
virtual void onArrayEnd() = 0;
virtual void onNumber(int value) = 0;
virtual void onNumber(double value) = 0;
virtual void onBool(bool value) = 0;
virtual void onNull() = 0;
virtual void onString(const std::string& value) = 0;
virtual void onObjectKey(const std::string& key) = 0;
virtual void onObjectValueStart() = 0;
virtual void onObjectValueEnd() = 0;
};
class JsonVisitor {
public:
using NextChar = std::function<int()>;
bool parse(const std::string& input, JsonObserver& observer);
template <typename Stream>
bool parse(Stream& stream, JsonObserver& observer) {
auto nextChar = [&stream]() -> int {
return stream.read();
};
return parseImpl(nextChar, observer);
}
private:
bool parseImpl(NextChar nextChar, JsonObserver& observer);
};