-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.hpp
84 lines (62 loc) · 1.51 KB
/
import.hpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef TOKOX_CPP_JSON_IMPORT_HPP
#define TOKOX_CPP_JSON_IMPORT_HPP
#include <stdexcept>
#include "object.hpp"
namespace tokox::json
{
class parse_error : public std::exception
{
public:
enum error_type
{
INCORRECT_VALUE,
VALUE_OUT_OF_RANGE,
REPEATED_MAP_KEY,
UNEXPECTED_END,
VALUE_NOT_IMPLEMENTED
};
parse_error(const error_type _type): type(_type) {}
const char* what() const noexcept override
{
switch (type)
{
case INCORRECT_VALUE:
return "Incorrect value!";
case VALUE_OUT_OF_RANGE:
return "Value out of range!";
case REPEATED_MAP_KEY:
return "Repeated map key!";
case UNEXPECTED_END:
return "Unexpected end!";
case VALUE_NOT_IMPLEMENTED:
return "Value not implemented!";
default:
return "Unknown error!";
}
}
private:
error_type type;
};
constexpr const size_t float_prec = 32;
template<class IT>
object parse(IT& it, IT end);
object parse(const std::string& json_str);
object parse(std::istream& json_stream);
object& parse(object& obj, const std::string& json_str);
object& parse(object& obj, std::istream& json_stream);
std::istream& operator>>(std::istream& json_stream, object& obj);
template<class IT>
object parse_null(IT& it, IT end);
template<class IT>
object parse_bool(IT& it, IT end);
template<class IT>
object parse_number(IT& it, IT end);
template<class IT>
object parse_string(IT& it, IT end);
template<class IT>
object parse_vector(IT& it, IT end);
template<class IT>
object parse_map(IT& it, IT end);
}
#include "import.cpp"
#endif