File tree Expand file tree Collapse file tree 6 files changed +19
-30
lines changed
Expand file tree Collapse file tree 6 files changed +19
-30
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ class JsonArrayIterator {
3535 : iterator_(iterator), resources_(resources) {}
3636
3737 JsonVariant operator *() {
38- return JsonVariant (iterator_.data (), resources_);
38+ return JsonVariant (iterator_.value ( resources_) );
3939 }
4040 Ptr<JsonVariant> operator ->() {
4141 return operator *();
@@ -69,7 +69,7 @@ class JsonArrayConstIterator {
6969 : iterator_(iterator), resources_(resources) {}
7070
7171 JsonVariantConst operator *() const {
72- return JsonVariantConst (iterator_.data (), resources_);
72+ return JsonVariantConst (iterator_.value ( resources_) );
7373 }
7474 Ptr<JsonVariantConst> operator ->() {
7575 return operator *();
Original file line number Diff line number Diff line change @@ -19,6 +19,11 @@ inline void CollectionIterator::next(const ResourceManager* resources) {
1919 currentId_ = nextId;
2020}
2121
22+ inline VariantImpl CollectionIterator::value (ResourceManager* resources) const {
23+ ARDUINOJSON_ASSERT (slot_ != nullptr );
24+ return VariantImpl (slot_, resources);
25+ }
26+
2227inline VariantImpl::iterator VariantImpl::createIterator () const {
2328 if (!data_ || !data_->isCollection ())
2429 return iterator ();
@@ -107,8 +112,7 @@ inline size_t VariantImpl::nesting() const {
107112 return 0 ;
108113 size_t maxChildNesting = 0 ;
109114 for (auto it = createIterator (); !it.done (); it.next (resources_)) {
110- VariantImpl variant (it.data (), resources_);
111- size_t childNesting = variant.nesting ();
115+ auto childNesting = it.value (resources_).nesting ();
112116 if (childNesting > maxChildNesting)
113117 maxChildNesting = childNesting;
114118 }
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
1313
1414struct VariantData ;
1515class ResourceManager ;
16+ class VariantImpl ;
1617
1718class CollectionIterator {
1819 friend class VariantImpl ;
@@ -22,6 +23,8 @@ class CollectionIterator {
2223
2324 void next (const ResourceManager* resources);
2425
26+ VariantImpl value (ResourceManager* resources) const ;
27+
2528 bool done () const {
2629 return slot_ == nullptr ;
2730 }
@@ -34,21 +37,6 @@ class CollectionIterator {
3437 return slot_ != other.slot_ ;
3538 }
3639
37- VariantData* operator ->() {
38- ARDUINOJSON_ASSERT (slot_ != nullptr );
39- return data ();
40- }
41-
42- VariantData& operator *() {
43- ARDUINOJSON_ASSERT (slot_ != nullptr );
44- return *data ();
45- }
46-
47- const VariantData& operator *() const {
48- ARDUINOJSON_ASSERT (slot_ != nullptr );
49- return *data ();
50- }
51-
5240 VariantData* data () {
5341 return slot_;
5442 }
Original file line number Diff line number Diff line change @@ -26,8 +26,7 @@ class PrettyJsonSerializer : public JsonSerializer<TWriter> {
2626 nesting_++;
2727 while (!it.done ()) {
2828 indent ();
29- VariantImpl (it.data (), base::resources_).accept (*this );
30-
29+ it.value (base::resources_).accept (*this );
3130 it.next (base::resources_);
3231 base::write (it.done () ? " \r\n " : " ,\r\n " );
3332 }
@@ -49,7 +48,7 @@ class PrettyJsonSerializer : public JsonSerializer<TWriter> {
4948 while (!it.done ()) {
5049 if (isKey)
5150 indent ();
52- VariantImpl ( it.data (), base::resources_).accept (*this );
51+ it.value ( base::resources_).accept (*this );
5352 it.next (base::resources_);
5453 if (isKey)
5554 base::write (" : " );
Original file line number Diff line number Diff line change @@ -18,10 +18,9 @@ class JsonPair {
1818 JsonPair (detail::VariantImpl::iterator iterator,
1919 detail::ResourceManager* resources) {
2020 if (!iterator.done ()) {
21- detail::VariantImpl variant (iterator.data (), resources);
22- key_ = variant.asString ();
21+ key_ = iterator.value (resources).asString ();
2322 iterator.next (resources);
24- value_ = JsonVariant (iterator.data (), resources);
23+ value_ = JsonVariant (iterator.value ( resources) );
2524 }
2625 }
2726
@@ -47,10 +46,9 @@ class JsonPairConst {
4746 JsonPairConst (detail::VariantImpl::iterator iterator,
4847 detail::ResourceManager* resources) {
4948 if (!iterator.done ()) {
50- detail::VariantImpl variant (iterator.data (), resources);
51- key_ = variant.asString ();
49+ key_ = iterator.value (resources).asString ();
5250 iterator.next (resources);
53- value_ = JsonVariantConst (iterator.data (), resources);
51+ value_ = JsonVariantConst (iterator.value ( resources) );
5452 }
5553 }
5654
Original file line number Diff line number Diff line change @@ -34,8 +34,8 @@ inline VariantImpl::iterator VariantImpl::findKey(TAdaptedString key) const {
3434 return iterator ();
3535 bool isKey = true ;
3636 for (auto it = createIterator (); !it.done (); it.next (resources_)) {
37- VariantImpl variant (it. data (), resources_);
38- if (isKey && stringEquals (key, adaptString (variant .asString ())))
37+ if (isKey &&
38+ stringEquals (key, adaptString (it. value (resources_) .asString ())))
3939 return it;
4040 isKey = !isKey;
4141 }
You can’t perform that action at this time.
0 commit comments