@@ -23,7 +23,7 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
23
23
JsonArray () : data_(0 ), resources_(0 ) {}
24
24
25
25
// INTERNAL USE ONLY
26
- JsonArray (detail::ArrayData * data, detail::ResourceManager* resources)
26
+ JsonArray (detail::VariantData * data, detail::ResourceManager* resources)
27
27
: data_(data), resources_(resources) {}
28
28
29
29
// Returns a JsonVariant pointing to the array.
@@ -55,31 +55,32 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
55
55
template <typename T, detail::enable_if_t <
56
56
detail::is_same<T, JsonVariant>::value, int > = 0 >
57
57
JsonVariant add () const {
58
- return JsonVariant (detail::ArrayData ::addElement (data_, resources_),
58
+ return JsonVariant (detail::VariantData ::addElement (data_, resources_),
59
59
resources_);
60
60
}
61
61
62
62
// Appends a value to the array.
63
63
// https://arduinojson.org/v7/api/jsonarray/add/
64
64
template <typename T>
65
65
bool add (const T& value) const {
66
- return detail::ArrayData ::addValue (data_, value, resources_);
66
+ return detail::VariantData ::addValue (data_, value, resources_);
67
67
}
68
68
69
69
// Appends a value to the array.
70
70
// https://arduinojson.org/v7/api/jsonarray/add/
71
71
template <typename T,
72
72
detail::enable_if_t <!detail::is_const<T>::value, int > = 0 >
73
73
bool add (T* value) const {
74
- return detail::ArrayData ::addValue (data_, value, resources_);
74
+ return detail::VariantData ::addValue (data_, value, resources_);
75
75
}
76
76
77
77
// Returns an iterator to the first element of the array.
78
78
// https://arduinojson.org/v7/api/jsonarray/begin/
79
79
iterator begin () const {
80
- if (!data_)
80
+ auto array = detail::VariantData::asArray (data_);
81
+ if (!array)
81
82
return iterator ();
82
- return iterator (data_ ->createIterator (resources_), resources_);
83
+ return iterator (array ->createIterator (resources_), resources_);
83
84
}
84
85
85
86
// Returns an iterator following the last element of the array.
@@ -106,13 +107,14 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
106
107
// Removes the element at the specified iterator.
107
108
// https://arduinojson.org/v7/api/jsonarray/remove/
108
109
void remove (iterator it) const {
109
- detail::ArrayData::remove (data_, it.iterator_ , resources_);
110
+ detail::ArrayData::remove (detail::VariantData::asArray (data_), it.iterator_ ,
111
+ resources_);
110
112
}
111
113
112
114
// Removes the element at the specified index.
113
115
// https://arduinojson.org/v7/api/jsonarray/remove/
114
116
void remove (size_t index) const {
115
- detail::ArrayData ::removeElement (data_, index, resources_);
117
+ detail::VariantData ::removeElement (data_, index, resources_);
116
118
}
117
119
118
120
// Removes the element at the specified index.
@@ -127,7 +129,7 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
127
129
// Removes all the elements of the array.
128
130
// https://arduinojson.org/v7/api/jsonarray/clear/
129
131
void clear () const {
130
- detail::ArrayData::clear (data_, resources_);
132
+ detail::ArrayData::clear (detail::VariantData::asArray ( data_) , resources_);
131
133
}
132
134
133
135
// Gets or sets the element at the specified index.
@@ -150,25 +152,25 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
150
152
}
151
153
152
154
operator JsonVariantConst () const {
153
- return JsonVariantConst (collectionToVariant ( data_) , resources_);
155
+ return JsonVariantConst (data_, resources_);
154
156
}
155
157
156
158
// Returns true if the reference is unbound.
157
159
// https://arduinojson.org/v7/api/jsonarray/isnull/
158
160
bool isNull () const {
159
- return data_ == 0 ;
161
+ return ! data_ || !data_-> isArray () ;
160
162
}
161
163
162
164
// Returns true if the reference is bound.
163
165
// https://arduinojson.org/v7/api/jsonarray/isnull/
164
166
operator bool () const {
165
- return data_ != 0 ;
167
+ return ! isNull () ;
166
168
}
167
169
168
170
// Returns the depth (nesting level) of the array.
169
171
// https://arduinojson.org/v7/api/jsonarray/nesting/
170
172
size_t nesting () const {
171
- return detail::VariantData::nesting (collectionToVariant ( data_) , resources_);
173
+ return detail::VariantData::nesting (data_, resources_);
172
174
}
173
175
174
176
// Returns the number of elements in the array.
@@ -205,14 +207,14 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
205
207
}
206
208
207
209
detail::VariantData* getData () const {
208
- return collectionToVariant ( data_) ;
210
+ return data_;
209
211
}
210
212
211
213
detail::VariantData* getOrCreateData () const {
212
- return collectionToVariant ( data_) ;
214
+ return data_;
213
215
}
214
216
215
- detail::ArrayData * data_;
217
+ detail::VariantData * data_;
216
218
detail::ResourceManager* resources_;
217
219
};
218
220
0 commit comments