Added JSON::Value::append() which returns a reference to a newly appended element
This commit is contained in:
parent
7d95a75492
commit
64ad0ad4a9
2 changed files with 13 additions and 0 deletions
12
lib/json.cpp
12
lib/json.cpp
|
@ -1212,6 +1212,18 @@ void JSON::Value::append(const 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.
|
||||
/// Turns this value into an array if it is not already one.
|
||||
void JSON::Value::prepend(const JSON::Value &rhs){
|
||||
|
|
|
@ -92,6 +92,7 @@ namespace JSON{
|
|||
std::string toString() const;
|
||||
std::string toPrettyString(size_t indent = 0) const;
|
||||
void append(const Value &rhs);
|
||||
Value & append();
|
||||
void prepend(const Value &rhs);
|
||||
void shrink(uint32_t size);
|
||||
void removeMember(const std::string &name);
|
||||
|
|
Loading…
Add table
Reference in a new issue