@@ -88,7 +88,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
88
88
// https://arduinojson.org/v7/api/jsondocument/clear/
89
89
void clear () {
90
90
resources_.clear ();
91
- data_.reset () ;
91
+ data_.type = detail::VariantType::Null ;
92
92
}
93
93
94
94
// Returns true if the root is of the specified type.
@@ -120,13 +120,13 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
120
120
// Returns the depth (nesting level) of the array.
121
121
// https://arduinojson.org/v7/api/jsondocument/nesting/
122
122
size_t nesting () const {
123
- return data_ .nesting (&resources_ );
123
+ return getVariantImpl () .nesting ();
124
124
}
125
125
126
126
// Returns the number of elements in the root array or object.
127
127
// https://arduinojson.org/v7/api/jsondocument/size/
128
128
size_t size () const {
129
- return data_ .size (&resources_ );
129
+ return getVariantImpl () .size ();
130
130
}
131
131
132
132
// Copies the specified document.
@@ -165,7 +165,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
165
165
template <typename TChar>
166
166
ARDUINOJSON_DEPRECATED (" use doc[\" key\" ].is<T>() instead" )
167
167
bool containsKey (TChar* key) const {
168
- return data_ .getMember (detail::adaptString (key), &resources_ ) != 0 ;
168
+ return getVariantImpl () .getMember (detail::adaptString (key)) != 0 ;
169
169
}
170
170
171
171
// DEPRECATED: use obj[key].is<T>() instead
@@ -174,7 +174,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
174
174
detail::enable_if_t <detail::IsString<TString>::value, int > = 0 >
175
175
ARDUINOJSON_DEPRECATED (" use doc[key].is<T>() instead" )
176
176
bool containsKey (const TString& key) const {
177
- return data_ .getMember (detail::adaptString (key), &resources_ ) != 0 ;
177
+ return getVariantImpl () .getMember (detail::adaptString (key)) != 0 ;
178
178
}
179
179
180
180
// DEPRECATED: use obj[key].is<T>() instead
@@ -212,7 +212,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
212
212
detail::enable_if_t <detail::IsString<TString>::value, int > = 0 >
213
213
JsonVariantConst operator [](const TString& key) const {
214
214
return JsonVariantConst (
215
- data_ .getMember (detail::adaptString (key), &resources_ ), &resources_);
215
+ getVariantImpl () .getMember (detail::adaptString (key)), &resources_);
216
216
}
217
217
218
218
// Gets a root object's member.
@@ -223,7 +223,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
223
223
int > = 0 >
224
224
JsonVariantConst operator [](TChar* key) const {
225
225
return JsonVariantConst (
226
- data_ .getMember (detail::adaptString (key), &resources_ ), &resources_);
226
+ getVariantImpl () .getMember (detail::adaptString (key)), &resources_);
227
227
}
228
228
229
229
// Gets or sets a root array's element.
@@ -237,7 +237,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
237
237
// Gets a root array's member.
238
238
// https://arduinojson.org/v7/api/jsondocument/subscript/
239
239
JsonVariantConst operator [](size_t index) const {
240
- return JsonVariantConst (data_ .getElement (index, &resources_ ), &resources_);
240
+ return JsonVariantConst (getVariantImpl () .getElement (index), &resources_);
241
241
}
242
242
243
243
// Gets or sets a root object's member.
@@ -267,31 +267,30 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
267
267
template <typename T, detail::enable_if_t <
268
268
detail::is_same<T, JsonVariant>::value, int > = 0 >
269
269
JsonVariant add () {
270
- return JsonVariant (data_ .addElement (&resources_ ), &resources_);
270
+ return JsonVariant (getVariantImpl () .addElement (), &resources_);
271
271
}
272
272
273
273
// Appends a value to the root array.
274
274
// https://arduinojson.org/v7/api/jsondocument/add/
275
275
template <typename TValue>
276
276
bool add (const TValue& value) {
277
- return data_ .addValue (value, &resources_ );
277
+ return getVariantImpl () .addValue (value);
278
278
}
279
279
280
280
// Appends a value to the root array.
281
281
// https://arduinojson.org/v7/api/jsondocument/add/
282
282
template <typename TChar,
283
283
detail::enable_if_t <!detail::is_const<TChar>::value, int > = 0 >
284
284
bool add (TChar* value) {
285
- return data_ .addValue (value, &resources_ );
285
+ return getVariantImpl () .addValue (value);
286
286
}
287
287
288
288
// Removes an element of the root array.
289
289
// https://arduinojson.org/v7/api/jsondocument/remove/
290
290
template <typename T,
291
291
detail::enable_if_t <detail::is_integral<T>::value, int > = 0 >
292
292
void remove (T index) {
293
- detail::VariantData::removeElement (getData (), size_t (index),
294
- getResourceManager ());
293
+ getVariantImpl ().removeElement (size_t (index));
295
294
}
296
295
297
296
// Removes a member of the root object.
@@ -301,17 +300,16 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
301
300
!detail::is_const<TChar>::value,
302
301
int > = 0 >
303
302
void remove (TChar* key) {
304
- detail::VariantData::removeMember (getData (), detail::adaptString (key),
305
- getResourceManager ());
303
+ getVariantImpl ().removeMember (detail::adaptString (key));
306
304
}
307
305
308
306
// Removes a member of the root object.
309
307
// https://arduinojson.org/v7/api/jsondocument/remove/
310
308
template <typename TString,
311
309
detail::enable_if_t <detail::IsString<TString>::value, int > = 0 >
312
310
void remove (const TString& key) {
313
- detail::VariantData::removeMember (getData (), detail::adaptString (key),
314
- getResourceManager ( ));
311
+ detail::VariantImpl (getData (), getResourceManager ())
312
+ . removeMember ( detail::adaptString (key ));
315
313
}
316
314
317
315
// Removes a member of the root object or an element of the root array.
@@ -391,6 +389,10 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
391
389
}
392
390
393
391
private:
392
+ detail::VariantImpl getVariantImpl () const {
393
+ return detail::VariantImpl (&data_, &resources_);
394
+ }
395
+
394
396
JsonVariant getVariant () {
395
397
return JsonVariant (&data_, &resources_);
396
398
}
0 commit comments