File tree Expand file tree Collapse file tree 2 files changed +37
-21
lines changed
Expand file tree Collapse file tree 2 files changed +37
-21
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,43 @@ inline void VariantImpl::removeElement(size_t index) {
7676 removeElement (at (index));
7777}
7878
79+ template <typename T>
80+ inline bool VariantImpl::addValue (const T& value) {
81+ if (!isArray ())
82+ return false ;
83+ auto slot = allocVariant ();
84+ if (!slot)
85+ return false ;
86+ JsonVariant variant (slot.ptr (), resources_);
87+ if (!variant.set (value)) {
88+ freeVariant (slot);
89+ return false ;
90+ }
91+ appendOne (slot);
92+ return true ;
93+ }
94+
95+ inline bool VariantImpl::copyArray (const VariantImpl& src) {
96+ ARDUINOJSON_ASSERT (isNull ());
97+
98+ if (!data_)
99+ return false ;
100+
101+ data_->toArray ();
102+
103+ for (auto it = src.createIterator (); !it.done (); it.move ()) {
104+ auto slot = allocVariant ();
105+ auto element = VariantImpl (slot.ptr (), resources_);
106+ if (!element.copyVariant (*it)) {
107+ freeVariant (slot);
108+ return false ;
109+ }
110+ appendOne (slot);
111+ }
112+
113+ return true ;
114+ }
115+
79116// Returns the size (in bytes) of an array with n elements.
80117constexpr size_t sizeofArray (size_t n) {
81118 return n * sizeof (VariantData);
Original file line number Diff line number Diff line change @@ -108,25 +108,4 @@ inline size_t VariantImpl::size() const {
108108 return count;
109109}
110110
111- inline bool VariantImpl::copyCollection (const VariantImpl& src) {
112- ARDUINOJSON_ASSERT (src.type () & VariantTypeBits::CollectionMask);
113- ARDUINOJSON_ASSERT (isNull ());
114-
115- if (!data_)
116- return false ;
117-
118- data_->toCollection (src.type ());
119-
120- for (auto it = src.createIterator (); !it.done (); it.move ()) {
121- auto slot = allocVariant ();
122- auto impl = VariantImpl (slot.ptr (), resources_);
123- if (!impl.copyVariant (*it)) {
124- freeVariant (slot);
125- return false ;
126- }
127- appendOne (slot);
128- }
129- return true ;
130- }
131-
132111ARDUINOJSON_END_PRIVATE_NAMESPACE
You can’t perform that action at this time.
0 commit comments