@@ -23,7 +23,7 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
2323 JsonArray () : data_(0 ), resources_(0 ) {}
2424
2525 // INTERNAL USE ONLY
26- JsonArray (detail::ArrayData * data, detail::ResourceManager* resources)
26+ JsonArray (detail::VariantData * data, detail::ResourceManager* resources)
2727 : data_(data), resources_(resources) {}
2828
2929 // Returns a JsonVariant pointing to the array.
@@ -55,31 +55,32 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
5555 template <typename T, detail::enable_if_t <
5656 detail::is_same<T, JsonVariant>::value, int > = 0 >
5757 JsonVariant add () const {
58- return JsonVariant (detail::ArrayData ::addElement (data_, resources_),
58+ return JsonVariant (detail::VariantData ::addElement (data_, resources_),
5959 resources_);
6060 }
6161
6262 // Appends a value to the array.
6363 // https://arduinojson.org/v7/api/jsonarray/add/
6464 template <typename T>
6565 bool add (const T& value) const {
66- return detail::ArrayData ::addValue (data_, value, resources_);
66+ return detail::VariantData ::addValue (data_, value, resources_);
6767 }
6868
6969 // Appends a value to the array.
7070 // https://arduinojson.org/v7/api/jsonarray/add/
7171 template <typename T,
7272 detail::enable_if_t <!detail::is_const<T>::value, int > = 0 >
7373 bool add (T* value) const {
74- return detail::ArrayData ::addValue (data_, value, resources_);
74+ return detail::VariantData ::addValue (data_, value, resources_);
7575 }
7676
7777 // Returns an iterator to the first element of the array.
7878 // https://arduinojson.org/v7/api/jsonarray/begin/
7979 iterator begin () const {
80- if (!data_)
80+ auto array = detail::VariantData::asArray (data_);
81+ if (!array)
8182 return iterator ();
82- return iterator (data_ ->createIterator (resources_), resources_);
83+ return iterator (array ->createIterator (resources_), resources_);
8384 }
8485
8586 // Returns an iterator following the last element of the array.
@@ -106,13 +107,14 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
106107 // Removes the element at the specified iterator.
107108 // https://arduinojson.org/v7/api/jsonarray/remove/
108109 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_);
110112 }
111113
112114 // Removes the element at the specified index.
113115 // https://arduinojson.org/v7/api/jsonarray/remove/
114116 void remove (size_t index) const {
115- detail::ArrayData ::removeElement (data_, index, resources_);
117+ detail::VariantData ::removeElement (data_, index, resources_);
116118 }
117119
118120 // Removes the element at the specified index.
@@ -127,7 +129,7 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
127129 // Removes all the elements of the array.
128130 // https://arduinojson.org/v7/api/jsonarray/clear/
129131 void clear () const {
130- detail::ArrayData::clear (data_, resources_);
132+ detail::ArrayData::clear (detail::VariantData::asArray ( data_) , resources_);
131133 }
132134
133135 // Gets or sets the element at the specified index.
@@ -150,25 +152,25 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
150152 }
151153
152154 operator JsonVariantConst () const {
153- return JsonVariantConst (collectionToVariant ( data_) , resources_);
155+ return JsonVariantConst (data_, resources_);
154156 }
155157
156158 // Returns true if the reference is unbound.
157159 // https://arduinojson.org/v7/api/jsonarray/isnull/
158160 bool isNull () const {
159- return data_ == 0 ;
161+ return ! data_ || !data_-> isArray () ;
160162 }
161163
162164 // Returns true if the reference is bound.
163165 // https://arduinojson.org/v7/api/jsonarray/isnull/
164166 operator bool () const {
165- return data_ != 0 ;
167+ return ! isNull () ;
166168 }
167169
168170 // Returns the depth (nesting level) of the array.
169171 // https://arduinojson.org/v7/api/jsonarray/nesting/
170172 size_t nesting () const {
171- return detail::VariantData::nesting (collectionToVariant ( data_) , resources_);
173+ return detail::VariantData::nesting (data_, resources_);
172174 }
173175
174176 // Returns the number of elements in the array.
@@ -205,14 +207,14 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
205207 }
206208
207209 detail::VariantData* getData () const {
208- return collectionToVariant ( data_) ;
210+ return data_;
209211 }
210212
211213 detail::VariantData* getOrCreateData () const {
212- return collectionToVariant ( data_) ;
214+ return data_;
213215 }
214216
215- detail::ArrayData * data_;
217+ detail::VariantData * data_;
216218 detail::ResourceManager* resources_;
217219};
218220
0 commit comments