Added JSON::Value::append() which returns a reference to a newly appended element

This commit is contained in:
Thulinma 2021-07-26 22:50:04 +02:00
parent 7d95a75492
commit 64ad0ad4a9
2 changed files with 13 additions and 0 deletions

View file

@ -1212,6 +1212,18 @@ void JSON::Value::append(const JSON::Value &rhs){
arrVal.push_back(new JSON::Value(rhs)); arrVal.push_back(new JSON::Value(rhs));
} }
/// Appends a null value to the end of this JSON::Value array.
/// Turns this value into an array if it is not already one.
/// Returns a reference to the appended element.
JSON::Value & JSON::Value::append(){
if (myType != ARRAY){
null();
myType = ARRAY;
}
arrVal.push_back(new JSON::Value());
return **arrVal.rbegin();
}
/// Prepends the given value to the beginning of this JSON::Value array. /// Prepends the given value to the beginning of this JSON::Value array.
/// Turns this value into an array if it is not already one. /// Turns this value into an array if it is not already one.
void JSON::Value::prepend(const JSON::Value &rhs){ void JSON::Value::prepend(const JSON::Value &rhs){

View file

@ -92,6 +92,7 @@ namespace JSON{
std::string toString() const; std::string toString() const;
std::string toPrettyString(size_t indent = 0) const; std::string toPrettyString(size_t indent = 0) const;
void append(const Value &rhs); void append(const Value &rhs);
Value & append();
void prepend(const Value &rhs); void prepend(const Value &rhs);
void shrink(uint32_t size); void shrink(uint32_t size);
void removeMember(const std::string &name); void removeMember(const std::string &name);