Added JSON::Value::extend()

This commit is contained in:
Thulinma 2019-12-12 00:19:14 +01:00
parent 4a621ea5c0
commit b27a74c884
2 changed files with 24 additions and 3 deletions

View file

@ -612,6 +612,24 @@ JSON::Value &JSON::Value::assignFrom(const Value &rhs, const std::set<std::strin
return *this;
}
/// Extends this JSON::Value object with the given JSON::Value object, skipping given member(s) recursively.
JSON::Value &JSON::Value::extend(const Value &rhs, const std::set<std::string> &skip){
//Null values turn into objects automatically for sanity reasons
if (myType == EMPTY){myType = OBJECT;}
//Abort if either value is not an object
if (myType != rhs.myType || myType != OBJECT){return *this;}
jsonForEachConst(rhs, i){
if (!skip.count(i.key())){
if (!objVal.count(i.key()) || !i->isObject()){
(*this)[i.key()] = *i;
}else{
(*this)[i.key()].extend(*i, skip);
}
}
}
return *this;
}
/// Sets this JSON::Value to be equal to the given JSON::Value.
JSON::Value &JSON::Value::operator=(const JSON::Value &rhs){
null();

View file

@ -10,6 +10,8 @@
#include <string>
#include <vector>
static const std::set<std::string> emptyset;
/// JSON-related classes and functions
namespace JSON{
@ -50,10 +52,11 @@ namespace JSON{
// comparison operators
bool operator==(const Value &rhs) const;
bool operator!=(const Value &rhs) const;
bool compareExcept(const Value &rhs, const std::set<std::string> &skip) const;
bool compareOnly(const Value &rhs, const std::set<std::string> &check) const;
bool compareExcept(const Value &rhs, const std::set<std::string> &skip = emptyset) const;
bool compareOnly(const Value &rhs, const std::set<std::string> &check = emptyset) const;
// assignment operators
Value &assignFrom(const Value &rhs, const std::set<std::string> &skip);
Value &extend(const Value &rhs, const std::set<std::string> &skip = emptyset);
Value &assignFrom(const Value &rhs, const std::set<std::string> &skip = emptyset);
Value &operator=(const Value &rhs);
Value &operator=(const std::string &rhs);
Value &operator=(const char *rhs);