52 lines
930 B
C++
52 lines
930 B
C++
#pragma once
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
|
|
enum JSONNodeType {
|
|
JSON_UNKNOWN = -1,
|
|
JSON_OBJECT,
|
|
JSON_LIST,
|
|
JSON_KEY,
|
|
JSON_NUMBER,
|
|
JSON_STRING,
|
|
};
|
|
|
|
struct JSONKeyValue;
|
|
struct JSONNode {
|
|
JSONNodeType type;
|
|
union {
|
|
long double ld;
|
|
char *s;
|
|
std::vector<JSONNode> *list;
|
|
std::vector<JSONKeyValue> *object;
|
|
} v;
|
|
|
|
JSONNode &operator[](std::string key);
|
|
JSONNode &operator[](size_t index);
|
|
|
|
void Free(void);
|
|
|
|
long double &Number(void);
|
|
long double Number(long double def);
|
|
char *&String(void);
|
|
char *String(char *def);
|
|
std::vector<JSONNode> *&List(void);
|
|
std::vector<JSONKeyValue> *&Object(void);
|
|
|
|
std::string const Name(void);
|
|
|
|
void PrettyPrint(std::string indent, bool last);
|
|
};
|
|
|
|
struct JSONKeyValue {
|
|
char *name;
|
|
JSONNode node;
|
|
|
|
void PrettyPrint(std::string indent, bool last);
|
|
};
|
|
|
|
JSONNode JSONParseFile(char *file);
|
|
JSONNode JSONParseString(std::string string);
|
|
|