Skip to content

Commit 964e217

Browse files
committed
Split array and object
Backtrack to add set<T>()
1 parent c61d173 commit 964e217

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

src/ArduinoJson/Array/ArrayImpl.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff 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.
80117
constexpr size_t sizeofArray(size_t n) {
81118
return n * sizeof(VariantData);

src/ArduinoJson/Collection/CollectionImpl.hpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff 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-
132111
ARDUINOJSON_END_PRIVATE_NAMESPACE

0 commit comments

Comments
 (0)