-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson.h
63 lines (48 loc) · 1.75 KB
/
json.h
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
#ifndef _JSON_CLASS_
#define _JSON_CLASS_
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <stdexcept>
#include "J_array.h"
class J_array;
class Json{
std::set <std::string> keys;
std::map <std::string, double> numbers;
std::map <std::string, std::string> lines;
std::map <std::string, Json> jsons;
std::map <std::string, bool> bools;
std::map <std::string, J_array> arrays;
template<typename Type>
bool add_pr(std::string key, Type value, std::map<std::string, Type>& collection){
if (keys.find(key) != keys.end()) return false;
keys.insert(key);
collection.insert(std::pair<std::string, Type>(key, value));
return true;
}
public:
static bool same(const Json a, const Json b);
friend bool operator==(const Json a, const Json b);
bool add_number(std::string key, double value);
bool add_line(std::string key, std::string value);
bool add_json(std::string key, Json value);
bool add_bool(std::string key, bool value);
bool add_array(std::string key, J_array value);
bool add(std::string key, double value);
bool add(std::string key, std::string value);
bool add(std::string key, Json value);
//bool add(std::string key, bool value);
bool add(std::string key, J_array value);
double get_number(std::string key);
std::string get_line(std::string key);
Json get_json(std::string key);
bool get_bool(std::string key);
J_array get_array(std::string key);
bool erase(std::string key);
unsigned int size();
friend std::ostream& operator<<(std::ostream &os, const Json &json);
friend std::istream& operator>>(std::istream &is, Json &json);
};
bool operator==(const Json a, const Json b);
#endif // _JSON_CLASS_