|
|
@@ -23,51 +23,6 @@ inline void CollectionData::addSlot(VariantSlot* slot) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-inline VariantData* CollectionData::addMember(StringNode* key,
|
|
|
- ResourceManager* resources) {
|
|
|
- ARDUINOJSON_ASSERT(key != nullptr);
|
|
|
- auto slot = resources->allocVariant();
|
|
|
- if (!slot)
|
|
|
- return nullptr;
|
|
|
-
|
|
|
- slot->setKey(key);
|
|
|
- addSlot(slot);
|
|
|
- return slot->data();
|
|
|
-}
|
|
|
-
|
|
|
-template <typename TAdaptedString>
|
|
|
-inline VariantData* CollectionData::addMember(TAdaptedString key,
|
|
|
- ResourceManager* resources) {
|
|
|
- ARDUINOJSON_ASSERT(!key.isNull());
|
|
|
- auto slot = resources->allocVariant();
|
|
|
- if (!slot)
|
|
|
- return nullptr;
|
|
|
- if (key.isLinked())
|
|
|
- slot->setKey(key.data());
|
|
|
- else {
|
|
|
- auto storedKey = resources->saveString(key);
|
|
|
- if (!storedKey)
|
|
|
- return nullptr;
|
|
|
- slot->setKey(storedKey);
|
|
|
- }
|
|
|
- addSlot(slot);
|
|
|
- return slot->data();
|
|
|
-}
|
|
|
-
|
|
|
-template <typename TAdaptedString>
|
|
|
-inline VariantData* CollectionData::getMember(TAdaptedString key) const {
|
|
|
- return slotData(getSlot(key));
|
|
|
-}
|
|
|
-
|
|
|
-template <typename TAdaptedString>
|
|
|
-VariantData* CollectionData::getOrAddMember(TAdaptedString key,
|
|
|
- ResourceManager* resources) {
|
|
|
- auto slot = getSlot(key);
|
|
|
- if (slot)
|
|
|
- return slot->data();
|
|
|
- return addMember(key, resources);
|
|
|
-}
|
|
|
-
|
|
|
inline void CollectionData::clear(ResourceManager* resources) {
|
|
|
for (auto slot = head_; slot; slot = slot->next())
|
|
|
slotRelease(slot, resources);
|
|
|
@@ -75,34 +30,6 @@ inline void CollectionData::clear(ResourceManager* resources) {
|
|
|
tail_ = 0;
|
|
|
}
|
|
|
|
|
|
-inline bool CollectionData::copyFrom(const CollectionData& src,
|
|
|
- ResourceManager* resources) {
|
|
|
- clear(resources);
|
|
|
-
|
|
|
- for (VariantSlot* s = src.head(); s; s = s->next()) {
|
|
|
- ARDUINOJSON_ASSERT(s->key() != 0);
|
|
|
- JsonString key(s->key(),
|
|
|
- s->ownsKey() ? JsonString::Copied : JsonString::Linked);
|
|
|
- auto var = addMember(adaptString(key), resources);
|
|
|
- if (!variantCopyFrom(var, s->data(), resources))
|
|
|
- return false;
|
|
|
- }
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-template <typename TAdaptedString>
|
|
|
-inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const {
|
|
|
- if (key.isNull())
|
|
|
- return 0;
|
|
|
- VariantSlot* slot = head_;
|
|
|
- while (slot) {
|
|
|
- if (stringEquals(key, adaptString(slot->key())))
|
|
|
- break;
|
|
|
- slot = slot->next();
|
|
|
- }
|
|
|
- return slot;
|
|
|
-}
|
|
|
-
|
|
|
inline VariantSlot* CollectionData::getPreviousSlot(VariantSlot* target) const {
|
|
|
VariantSlot* current = head_;
|
|
|
while (current) {
|
|
|
@@ -129,12 +56,6 @@ inline void CollectionData::removeSlot(VariantSlot* slot,
|
|
|
slotRelease(slot, resources);
|
|
|
}
|
|
|
|
|
|
-template <typename TAdaptedString>
|
|
|
-inline void CollectionData::removeMember(TAdaptedString key,
|
|
|
- ResourceManager* resources) {
|
|
|
- removeSlot(getSlot(key), resources);
|
|
|
-}
|
|
|
-
|
|
|
inline size_t CollectionData::memoryUsage() const {
|
|
|
size_t total = 0;
|
|
|
for (VariantSlot* s = head_; s; s = s->next()) {
|
|
|
@@ -165,27 +86,4 @@ inline void CollectionData::movePointers(ptrdiff_t variantDistance) {
|
|
|
slot->data()->movePointers(variantDistance);
|
|
|
}
|
|
|
|
|
|
-inline bool objectEquals(const CollectionData& lhs, const CollectionData& rhs) {
|
|
|
- size_t count = 0;
|
|
|
- for (auto a = lhs.head(); a; a = a->next()) {
|
|
|
- auto b = rhs.getMember(adaptString(a->key()));
|
|
|
- if (!b)
|
|
|
- return false;
|
|
|
- if (compare(a->data(), b) != COMPARE_RESULT_EQUAL)
|
|
|
- return false;
|
|
|
- count++;
|
|
|
- }
|
|
|
- return count == rhs.size();
|
|
|
-}
|
|
|
-
|
|
|
-inline bool objectEquals(const CollectionData* lhs, const CollectionData* rhs) {
|
|
|
- if (lhs == rhs)
|
|
|
- return true;
|
|
|
-
|
|
|
- if (!lhs || !rhs)
|
|
|
- return false;
|
|
|
-
|
|
|
- return objectEquals(*lhs, *rhs);
|
|
|
-}
|
|
|
-
|
|
|
ARDUINOJSON_END_PRIVATE_NAMESPACE
|