forked from bblanchon/ArduinoJson
Add VariantData::addElement()
This commit is contained in:
@ -297,7 +297,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
// Returns a reference to the new element.
|
||||
// https://arduinojson.org/v6/api/jsondocument/add/
|
||||
FORCE_INLINE JsonVariant add() {
|
||||
return JsonVariant(&pool_, variantAddElement(&data_, &pool_));
|
||||
return JsonVariant(&pool_, data_.addElement(&pool_));
|
||||
}
|
||||
|
||||
// Appends a value to the root array.
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
VariantData* collectionAddElement(CollectionData* array, MemoryPool* pool);
|
||||
template <typename T>
|
||||
T parseNumber(const char* s);
|
||||
void slotRelease(VariantSlot* slot, MemoryPool* pool);
|
||||
@ -63,6 +64,11 @@ class VariantData {
|
||||
}
|
||||
}
|
||||
|
||||
VariantData* addElement(MemoryPool* pool) {
|
||||
auto array = isNull() ? &toArray() : asArray();
|
||||
return collectionAddElement(array, pool);
|
||||
}
|
||||
|
||||
bool asBoolean() const {
|
||||
switch (type()) {
|
||||
case VALUE_IS_BOOLEAN:
|
||||
|
@ -13,7 +13,6 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
bool collectionCopy(CollectionData* dst, const CollectionData* src,
|
||||
MemoryPool* pool);
|
||||
VariantData* collectionAddElement(CollectionData* array, MemoryPool* pool);
|
||||
void collectionRemoveElement(CollectionData* data, size_t index,
|
||||
MemoryPool* pool);
|
||||
template <typename TAdaptedString>
|
||||
@ -129,8 +128,7 @@ inline VariantData* variantGetElement(const VariantData* var, size_t index) {
|
||||
inline VariantData* variantAddElement(VariantData* var, MemoryPool* pool) {
|
||||
if (!var)
|
||||
return nullptr;
|
||||
auto array = var->isNull() ? &var->toArray() : var->asArray();
|
||||
return collectionAddElement(array, pool);
|
||||
return var->addElement(pool);
|
||||
}
|
||||
|
||||
inline NO_INLINE VariantData* variantGetOrAddElement(VariantData* var,
|
||||
|
Reference in New Issue
Block a user