forked from bblanchon/ArduinoJson
Added JsonDocument::remove()
and JsonVariant::remove()
This commit is contained in:
@ -124,6 +124,25 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
|
||||
return getUpstreamElement().getElement(index);
|
||||
}
|
||||
|
||||
FORCE_INLINE void remove(size_t index) const {
|
||||
getUpstreamElement().remove(index);
|
||||
}
|
||||
// remove(char*) const
|
||||
// remove(const char*) const
|
||||
// remove(const __FlashStringHelper*) const
|
||||
template <typename TChar>
|
||||
FORCE_INLINE typename enable_if<IsString<TChar*>::value>::type remove(
|
||||
TChar* key) const {
|
||||
getUpstreamElement().remove(key);
|
||||
}
|
||||
// remove(const std::string&) const
|
||||
// remove(const String&) const
|
||||
template <typename TString>
|
||||
FORCE_INLINE typename enable_if<IsString<TString>::value>::type remove(
|
||||
const TString& key) const {
|
||||
getUpstreamElement().remove(key);
|
||||
}
|
||||
|
||||
private:
|
||||
FORCE_INLINE VariantRef getUpstreamElement() const {
|
||||
return _array.getElement(_index);
|
||||
|
@ -223,6 +223,25 @@ class JsonDocument : public Visitable {
|
||||
return addElement().set(value);
|
||||
}
|
||||
|
||||
FORCE_INLINE void remove(size_t index) {
|
||||
_data.remove(index);
|
||||
}
|
||||
// remove(char*)
|
||||
// remove(const char*)
|
||||
// remove(const __FlashStringHelper*)
|
||||
template <typename TChar>
|
||||
FORCE_INLINE typename enable_if<IsString<TChar*>::value>::type remove(
|
||||
TChar* key) {
|
||||
_data.remove(adaptString(key));
|
||||
}
|
||||
// remove(const std::string&)
|
||||
// remove(const String&)
|
||||
template <typename TString>
|
||||
FORCE_INLINE typename enable_if<IsString<TString>::value>::type remove(
|
||||
const TString& key) {
|
||||
_data.remove(adaptString(key));
|
||||
}
|
||||
|
||||
protected:
|
||||
JsonDocument(MemoryPool pool) : _pool(pool) {
|
||||
_data.setNull();
|
||||
|
@ -71,6 +71,25 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
||||
return getUpstreamMember().size();
|
||||
}
|
||||
|
||||
FORCE_INLINE void remove(size_t index) const {
|
||||
getUpstreamMember().remove(index);
|
||||
}
|
||||
// remove(char*) const
|
||||
// remove(const char*) const
|
||||
// remove(const __FlashStringHelper*) const
|
||||
template <typename TChar>
|
||||
FORCE_INLINE typename enable_if<IsString<TChar *>::value>::type remove(
|
||||
TChar *key) const {
|
||||
getUpstreamMember().remove(key);
|
||||
}
|
||||
// remove(const std::string&) const
|
||||
// remove(const String&) const
|
||||
template <typename TString>
|
||||
FORCE_INLINE typename enable_if<IsString<TString>::value>::type remove(
|
||||
const TString &key) const {
|
||||
getUpstreamMember().remove(key);
|
||||
}
|
||||
|
||||
template <typename TValue>
|
||||
FORCE_INLINE typename VariantTo<TValue>::type to() {
|
||||
return getOrAddUpstreamMember().template to<TValue>();
|
||||
|
@ -169,6 +169,15 @@ class VariantData {
|
||||
return type() == VALUE_IS_NULL;
|
||||
}
|
||||
|
||||
void remove(size_t index) {
|
||||
if (isArray()) _content.asCollection.remove(index);
|
||||
}
|
||||
|
||||
template <typename TAdaptedString>
|
||||
void remove(TAdaptedString key) {
|
||||
if (isObject()) _content.asCollection.remove(key);
|
||||
}
|
||||
|
||||
void setBoolean(bool value) {
|
||||
setType(VALUE_IS_BOOLEAN);
|
||||
_content.asInteger = static_cast<UInt>(value);
|
||||
|
@ -310,9 +310,28 @@ class VariantRef : public VariantRefBase<VariantData>,
|
||||
template <typename TString>
|
||||
FORCE_INLINE VariantRef getOrAddMember(const TString &) const;
|
||||
|
||||
FORCE_INLINE void remove(size_t index) const {
|
||||
if (_data) _data->remove(index);
|
||||
}
|
||||
// remove(char*) const
|
||||
// remove(const char*) const
|
||||
// remove(const __FlashStringHelper*) const
|
||||
template <typename TChar>
|
||||
FORCE_INLINE typename enable_if<IsString<TChar *>::value>::type remove(
|
||||
TChar *key) const {
|
||||
if (_data) _data->remove(adaptString(key));
|
||||
}
|
||||
// remove(const std::string&) const
|
||||
// remove(const String&) const
|
||||
template <typename TString>
|
||||
FORCE_INLINE typename enable_if<IsString<TString>::value>::type remove(
|
||||
const TString &key) const {
|
||||
if (_data) _data->remove(adaptString(key));
|
||||
}
|
||||
|
||||
private:
|
||||
MemoryPool *_pool;
|
||||
};
|
||||
}; // namespace ARDUINOJSON_NAMESPACE
|
||||
|
||||
class VariantConstRef : public VariantRefBase<const VariantData>,
|
||||
public VariantOperators<VariantConstRef>,
|
||||
|
Reference in New Issue
Block a user