Added more get/put methods to json objects

This commit is contained in:
MihailRis 2023-11-10 21:26:09 +03:00
parent 65eb851fd8
commit b9ed7a2b28
2 changed files with 19 additions and 0 deletions

View File

@ -247,6 +247,13 @@ JArray& JArray::put(number_t value) {
return *this;
}
JArray& JArray::put(float value) {
valvalue val;
val.num = value;
values.push_back(new Value(valtype::number, val));
return *this;
}
JArray& JArray::put(bool value) {
valvalue val;
val.boolean = value;
@ -286,6 +293,12 @@ void JObject::num(std::string key, number_t& dst) const {
dst = found->second->value.num;
}
void JObject::num(std::string key, float& dst) const {
auto found = map.find(key);
if (found != map.end())
dst = found->second->value.num;
}
void JObject::num(std::string key, int& dst) const {
auto found = map.find(key);
if (found != map.end())
@ -326,6 +339,9 @@ JObject& JObject::put(string key, int value) {
return put(key, (number_t)value);
}
JObject& JObject::put(string key, float value) {
return put(key, (number_t)value);
}
JObject& JObject::put(string key, number_t value) {
auto found = map.find(key);

View File

@ -72,6 +72,7 @@ namespace json {
JArray& put(uint value);
JArray& put(int value);
JArray& put(float value);
JArray& put(number_t value);
JArray& put(std::string value);
JArray& put(JObject* value);
@ -86,6 +87,7 @@ namespace json {
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, number_t& dst) const;
JObject* obj(std::string key) const;
@ -94,6 +96,7 @@ namespace json {
JObject& put(std::string key, uint value);
JObject& put(std::string key, int value);
JObject& put(std::string key, float value);
JObject& put(std::string key, number_t value);
JObject& put(std::string key, std::string value);
JObject& put(std::string key, JObject* value);