forked from TylerGlaiel/GON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgon.h
76 lines (58 loc) · 2.1 KB
/
gon.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
//Glaiel Object Notation
//its json, minus the crap!
#pragma once
#include <string>
#include <map>
#include <vector>
struct TokenStream;
class GonObject {
std::map<std::string, size_t> children_map;
std::vector<GonObject> children_array;
std::string string_data;
int64_t int_data;
double float_data;
bool bool_data;
static GonObject LoadFromTokens(TokenStream& Tokens);
static void DefaultErrorCallback(const char* msg);
public:
enum class Type {
Null,
String,
Number,
Object,
Array,
Bool
};
Type type;
std::string name;
static GonObject null_gon;
using ErrorCallback = void(*)(const char*);
static ErrorCallback error_callback;
public:
static GonObject Load(const std::string& filename);
static GonObject LoadFromBuffer(std::string buffer);
GonObject();
//throw error if accessing wrong type, otherwise return correct type
std::string String() const;
int Int() const;
uint32_t UInt() const;
double Number() const;
bool Bool() const;
//returns a default value if the field doesn't exist or is the wrong type
std::string String(const std::string& _default) const;
int Int(int _default) const;
double Number(double _default) const;
bool Bool(bool _default) const;
bool Contains(const std::string& child) const;
bool Contains(int child) const;
bool Exists() const; //true if non-null
//returns null_gon if the field does not exist.
const GonObject& operator[](const std::string& child) const;
//returns self if index is not an array,
//all objects can be considered an array of size 1 with themselves as the member
const GonObject& operator[](int childindex) const;
size_t Length() const;
void DebugOut();
void Save(const std::string& outfilename);
std::string getOutStr();
};