Skip to content

Commit 2e20ce0

Browse files
committed
CollectionIterator: remove friendship with VariantImpl
1 parent a5164f7 commit 2e20ce0

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

src/ArduinoJson/Collection/CollectionImpl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ inline void VariantImpl::removeOne(iterator it) {
7474
coll->head = next;
7575
if (next == NULL_SLOT)
7676
coll->tail = prev.id();
77-
freeVariant({it->data(), it.currentId_});
77+
freeVariant({it->data(), it.slotId()});
7878
}
7979

8080
inline void VariantImpl::removePair(VariantImpl::iterator it) {

src/ArduinoJson/Collection/CollectionIterator.hpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,21 @@
88
#include <ArduinoJson/Polyfills/assert.hpp>
99
#include <ArduinoJson/Variant/VariantImpl.hpp>
1010

11-
#include <stddef.h> // size_t
12-
1311
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
1412

15-
struct VariantData;
16-
class ResourceManager;
17-
class VariantImpl;
18-
1913
class CollectionIterator {
20-
friend class VariantImpl;
21-
2214
public:
2315
CollectionIterator() {}
2416

17+
CollectionIterator(SlotId slotId, ResourceManager* resources)
18+
: value_(resources->getVariant(slotId), resources), slotId_(slotId) {}
19+
2520
void next() {
2621
ARDUINOJSON_ASSERT(!done());
2722
auto nextId = value_.data()->next;
2823
auto resources = value_.resources();
2924
value_ = VariantImpl(resources->getVariant(nextId), resources);
30-
currentId_ = nextId;
25+
slotId_ = nextId;
3126
}
3227

3328
const VariantImpl& operator*() const {
@@ -50,12 +45,13 @@ class CollectionIterator {
5045
return !operator==(other);
5146
}
5247

53-
private:
54-
CollectionIterator(SlotId slotId, ResourceManager* resources)
55-
: value_(resources->getVariant(slotId), resources), currentId_(slotId) {}
48+
SlotId slotId() const {
49+
return slotId_;
50+
}
5651

52+
private:
5753
VariantImpl value_;
58-
SlotId currentId_ = NULL_SLOT;
54+
SlotId slotId_ = NULL_SLOT;
5955
};
6056

6157
ARDUINOJSON_END_PRIVATE_NAMESPACE

0 commit comments

Comments
 (0)