Added JSON::Value::extend()
This commit is contained in:
parent
4a621ea5c0
commit
b27a74c884
2 changed files with 24 additions and 3 deletions
18
lib/json.cpp
18
lib/json.cpp
|
@ -612,6 +612,24 @@ JSON::Value &JSON::Value::assignFrom(const Value &rhs, const std::set<std::strin
|
||||||
return *this;
|
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.
|
/// Sets this JSON::Value to be equal to the given JSON::Value.
|
||||||
JSON::Value &JSON::Value::operator=(const JSON::Value &rhs){
|
JSON::Value &JSON::Value::operator=(const JSON::Value &rhs){
|
||||||
null();
|
null();
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
static const std::set<std::string> emptyset;
|
||||||
|
|
||||||
/// JSON-related classes and functions
|
/// JSON-related classes and functions
|
||||||
namespace JSON{
|
namespace JSON{
|
||||||
|
|
||||||
|
@ -50,10 +52,11 @@ namespace JSON{
|
||||||
// comparison operators
|
// comparison operators
|
||||||
bool operator==(const Value &rhs) const;
|
bool operator==(const Value &rhs) const;
|
||||||
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 compareExcept(const Value &rhs, const std::set<std::string> &skip = emptyset) const;
|
||||||
bool compareOnly(const Value &rhs, const std::set<std::string> &check) const;
|
bool compareOnly(const Value &rhs, const std::set<std::string> &check = emptyset) const;
|
||||||
// assignment operators
|
// 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 Value &rhs);
|
||||||
Value &operator=(const std::string &rhs);
|
Value &operator=(const std::string &rhs);
|
||||||
Value &operator=(const char *rhs);
|
Value &operator=(const char *rhs);
|
||||||
|
|
Loading…
Add table
Reference in a new issue