json, toml parsers/writers update
This commit is contained in:
+18
-2
@@ -19,14 +19,15 @@ namespace json {
|
||||
extern std::string stringify(JObject* obj, bool nice, std::string indent);
|
||||
|
||||
enum class valtype {
|
||||
object, array, number, string, boolean
|
||||
object, array, number, integer, string, boolean
|
||||
};
|
||||
|
||||
union valvalue {
|
||||
JObject* obj;
|
||||
JArray* arr;
|
||||
std::string* str;
|
||||
double num;
|
||||
double decimal;
|
||||
int64_t integer;
|
||||
bool boolean;
|
||||
};
|
||||
|
||||
@@ -45,6 +46,7 @@ namespace json {
|
||||
|
||||
std::string str(size_t index) const;
|
||||
double num(size_t index) const;
|
||||
int64_t integer(size_t num) const;
|
||||
JObject* obj(size_t index) const;
|
||||
JArray* arr(size_t index) const;
|
||||
bool flag(size_t index) const;
|
||||
@@ -55,12 +57,17 @@ namespace json {
|
||||
|
||||
JArray& put(uint value);
|
||||
JArray& put(int value);
|
||||
JArray& put(uint64_t value);
|
||||
JArray& put(int64_t value);
|
||||
JArray& put(float value);
|
||||
JArray& put(double value);
|
||||
JArray& put(std::string value);
|
||||
JArray& put(JObject* value);
|
||||
JArray& put(JArray* value);
|
||||
JArray& put(bool value);
|
||||
|
||||
JArray& putArray();
|
||||
JObject& putObj();
|
||||
};
|
||||
|
||||
class JObject {
|
||||
@@ -68,10 +75,15 @@ namespace json {
|
||||
std::unordered_map<std::string, Value*> map;
|
||||
~JObject();
|
||||
|
||||
std::string getStr(std::string key, const std::string& def) const;
|
||||
double getNum(std::string key, double def) const;
|
||||
int64_t getInteger(std::string key, int64_t def) const;
|
||||
void str(std::string key, std::string& dst) const;
|
||||
void num(std::string key, int& dst) const;
|
||||
void num(std::string key, float& dst) const;
|
||||
void num(std::string key, uint& dst) const;
|
||||
void num(std::string key, int64_t& dst) const;
|
||||
void num(std::string key, uint64_t& dst) const;
|
||||
void num(std::string key, ubyte& dst) const;
|
||||
void num(std::string key, double& dst) const;
|
||||
JObject* obj(std::string key) const;
|
||||
@@ -80,6 +92,8 @@ namespace json {
|
||||
|
||||
JObject& put(std::string key, uint value);
|
||||
JObject& put(std::string key, int value);
|
||||
JObject& put(std::string key, int64_t value);
|
||||
JObject& put(std::string key, uint64_t value);
|
||||
JObject& put(std::string key, float value);
|
||||
JObject& put(std::string key, double value);
|
||||
JObject& put(std::string key, const char* value);
|
||||
@@ -87,7 +101,9 @@ namespace json {
|
||||
JObject& put(std::string key, JObject* value);
|
||||
JObject& put(std::string key, JArray* value);
|
||||
JObject& put(std::string key, bool value);
|
||||
|
||||
JArray& putArray(std::string key);
|
||||
JObject& putObj(std::string key);
|
||||
|
||||
bool has(std::string key);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user