CollectionIterator: remove friendship with VariantImpl

This commit is contained in:
Benoit Blanchon
2025-07-11 18:36:51 +02:00
parent a5164f7fe3
commit 2e20ce0795
2 changed files with 10 additions and 14 deletions

View File

@ -74,7 +74,7 @@ inline void VariantImpl::removeOne(iterator it) {
coll->head = next; coll->head = next;
if (next == NULL_SLOT) if (next == NULL_SLOT)
coll->tail = prev.id(); coll->tail = prev.id();
freeVariant({it->data(), it.currentId_}); freeVariant({it->data(), it.slotId()});
} }
inline void VariantImpl::removePair(VariantImpl::iterator it) { inline void VariantImpl::removePair(VariantImpl::iterator it) {

View File

@ -8,26 +8,21 @@
#include <ArduinoJson/Polyfills/assert.hpp> #include <ArduinoJson/Polyfills/assert.hpp>
#include <ArduinoJson/Variant/VariantImpl.hpp> #include <ArduinoJson/Variant/VariantImpl.hpp>
#include <stddef.h> // size_t
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
struct VariantData;
class ResourceManager;
class VariantImpl;
class CollectionIterator { class CollectionIterator {
friend class VariantImpl;
public: public:
CollectionIterator() {} CollectionIterator() {}
CollectionIterator(SlotId slotId, ResourceManager* resources)
: value_(resources->getVariant(slotId), resources), slotId_(slotId) {}
void next() { void next() {
ARDUINOJSON_ASSERT(!done()); ARDUINOJSON_ASSERT(!done());
auto nextId = value_.data()->next; auto nextId = value_.data()->next;
auto resources = value_.resources(); auto resources = value_.resources();
value_ = VariantImpl(resources->getVariant(nextId), resources); value_ = VariantImpl(resources->getVariant(nextId), resources);
currentId_ = nextId; slotId_ = nextId;
} }
const VariantImpl& operator*() const { const VariantImpl& operator*() const {
@ -50,12 +45,13 @@ class CollectionIterator {
return !operator==(other); return !operator==(other);
} }
private: SlotId slotId() const {
CollectionIterator(SlotId slotId, ResourceManager* resources) return slotId_;
: value_(resources->getVariant(slotId), resources), currentId_(slotId) {} }
private:
VariantImpl value_; VariantImpl value_;
SlotId currentId_ = NULL_SLOT; SlotId slotId_ = NULL_SLOT;
}; };
ARDUINOJSON_END_PRIVATE_NAMESPACE ARDUINOJSON_END_PRIVATE_NAMESPACE