Add VariantData::removeElement()

This commit is contained in:
Benoit Blanchon
2023-05-25 10:26:01 +02:00
parent 68a167b167
commit 585795d002
2 changed files with 7 additions and 3 deletions

View File

@ -15,6 +15,8 @@
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
VariantData* collectionAddElement(CollectionData* array, MemoryPool* pool);
void collectionRemoveElement(CollectionData* data, size_t index,
MemoryPool* pool);
template <typename T>
T parseNumber(const char* s);
void slotRelease(VariantSlot* slot, MemoryPool* pool);
@ -275,6 +277,10 @@ class VariantData {
flags_ = uint8_t((flags_ & OWNED_KEY_BIT) | (src.flags_ & ~OWNED_KEY_BIT));
}
void removeElement(size_t index, MemoryPool* pool) {
collectionRemoveElement(asArray(), index, pool);
}
template <typename TAdaptedString>
void removeMember(TAdaptedString key, MemoryPool* pool) {
collectionRemoveMember(asObject(), key, pool);

View File

@ -13,8 +13,6 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
bool collectionCopy(CollectionData* dst, const CollectionData* src,
MemoryPool* pool);
void collectionRemoveElement(CollectionData* data, size_t index,
MemoryPool* pool);
template <typename TVisitor>
inline typename TVisitor::result_type variantAccept(const VariantData* var,
@ -157,7 +155,7 @@ inline void variantRemoveElement(VariantData* var, size_t index,
MemoryPool* pool) {
if (!var)
return;
collectionRemoveElement(var->asArray(), index, pool);
var->removeElement(index, pool);
}
template <typename TAdaptedString>