-
Notifications
You must be signed in to change notification settings - Fork 0
/
JsonCommons.h
79 lines (61 loc) · 1.92 KB
/
JsonCommons.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* JsonCommons.h
*
* Created on: 25 mar 2020
* Author: andr
*/
#ifndef JSONCOMMONS_H_
#define JSONCOMMONS_H_
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
enum JsonValueType {EJsonUnknown = 0, EJsonObject, EJsonString, EJsonNumber, EJsonFloat, EJsonTable};
struct JsonVariant
{
JsonValueType type;
std::string name;
std::string string_value;
int number_value;
float float_value;
virtual std::string value();
virtual void parse(const std::string & text, int &count);
JsonVariant(std::string name, std::string value);
JsonVariant(std::string name, int value);
JsonVariant(std::string name, float value);
JsonVariant(std::string name, JsonValueType type);
virtual ~JsonVariant();
};
class JsonObject;
struct JsonTable : JsonVariant
{
JsonValueType ElemType;
std::vector<std::string > string_values;
std::vector<int > number_values;
std::vector<float > float_values;
std::vector<JsonTable *> table_values;
std::vector<JsonObject *> object_values;
virtual std::string value();
virtual void parse(const std::string & text, int &count);
JsonTable(std::string name, JsonValueType elem_type);
JsonTable(std::string name);
virtual ~JsonTable();
};
struct JsonObject : JsonVariant
{
std::vector<JsonVariant *> values;
virtual std::string value();
virtual void parse(const std::string & text, int &count);
JsonObject(std::string name);
virtual ~JsonObject();
};
char GetFirstToken(const std::string & text, int & count);
std::string GetTextSurroundedBy(const std::string & text, int & count, char c_left, char c_right);
std::string GetString(const std::string & text, int & count);
int GetNumber(const std::string & text, int & count);
float GetFloat(const std::string & text, int & count);
std::string ConvertToString(float value);
int GetLastNumberFromName(std::string str);
JsonValueType CheckType(const std::string & text, int count);
#endif /* JSONCOMMONS_H_ */