/src/arduinojson/src/ArduinoJson/Object/ObjectImpl.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | // ArduinoJson - https://arduinojson.org |
2 | | // Copyright © 2014-2024, Benoit BLANCHON |
3 | | // MIT License |
4 | | |
5 | | #pragma once |
6 | | |
7 | | #include <ArduinoJson/Object/ObjectData.hpp> |
8 | | #include <ArduinoJson/Variant/VariantCompare.hpp> |
9 | | #include <ArduinoJson/Variant/VariantData.hpp> |
10 | | |
11 | | ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE |
12 | | |
13 | | template <typename TAdaptedString> |
14 | | inline VariantData* ObjectData::getMember( |
15 | 0 | TAdaptedString key, const ResourceManager* resources) const { |
16 | 0 | auto it = findKey(key, resources); |
17 | 0 | if (it.done()) |
18 | 0 | return nullptr; |
19 | 0 | it.next(resources); |
20 | 0 | return it.data(); |
21 | 0 | } |
22 | | |
23 | | template <typename TAdaptedString> |
24 | | VariantData* ObjectData::getOrAddMember(TAdaptedString key, |
25 | 0 | ResourceManager* resources) { |
26 | 0 | auto data = getMember(key, resources); |
27 | 0 | if (data) |
28 | 0 | return data; |
29 | 0 | return addMember(key, resources); |
30 | 0 | } |
31 | | |
32 | | template <typename TAdaptedString> |
33 | | inline ObjectData::iterator ObjectData::findKey( |
34 | 0 | TAdaptedString key, const ResourceManager* resources) const { |
35 | 0 | if (key.isNull()) |
36 | 0 | return iterator(); |
37 | 0 | bool isKey = true; |
38 | 0 | for (auto it = createIterator(resources); !it.done(); it.next(resources)) { |
39 | 0 | if (isKey && stringEquals(key, adaptString(it->asString()))) |
40 | 0 | return it; |
41 | 0 | isKey = !isKey; |
42 | 0 | } |
43 | 0 | return iterator(); |
44 | 0 | } |
45 | | |
46 | | template <typename TAdaptedString> |
47 | | inline void ObjectData::removeMember(TAdaptedString key, |
48 | | ResourceManager* resources) { |
49 | | remove(findKey(key, resources), resources); |
50 | | } |
51 | | |
52 | | template <typename TAdaptedString> |
53 | | inline VariantData* ObjectData::addMember(TAdaptedString key, |
54 | 2.10k | ResourceManager* resources) { |
55 | 2.10k | auto keySlot = resources->allocVariant(); |
56 | 2.10k | if (!keySlot) |
57 | 0 | return nullptr; |
58 | | |
59 | 2.10k | auto valueSlot = resources->allocVariant(); |
60 | 2.10k | if (!valueSlot) |
61 | 0 | return nullptr; |
62 | | |
63 | 2.10k | if (!keySlot->setString(key, resources)) |
64 | 0 | return nullptr; |
65 | | |
66 | 2.10k | CollectionData::appendPair(keySlot, valueSlot, resources); |
67 | | |
68 | 2.10k | return valueSlot.ptr(); |
69 | 2.10k | } ArduinoJson::V710HB42::detail::VariantData* ArduinoJson::V710HB42::detail::ObjectData::addMember<ArduinoJson::V710HB42::detail::StringNode*>(ArduinoJson::V710HB42::detail::StringNode*, ArduinoJson::V710HB42::detail::ResourceManager*) Line | Count | Source | 54 | 2.10k | ResourceManager* resources) { | 55 | 2.10k | auto keySlot = resources->allocVariant(); | 56 | 2.10k | if (!keySlot) | 57 | 0 | return nullptr; | 58 | | | 59 | 2.10k | auto valueSlot = resources->allocVariant(); | 60 | 2.10k | if (!valueSlot) | 61 | 0 | return nullptr; | 62 | | | 63 | 2.10k | if (!keySlot->setString(key, resources)) | 64 | 0 | return nullptr; | 65 | | | 66 | 2.10k | CollectionData::appendPair(keySlot, valueSlot, resources); | 67 | | | 68 | 2.10k | return valueSlot.ptr(); | 69 | 2.10k | } |
Unexecuted instantiation: ArduinoJson::V710HB42::detail::VariantData* ArduinoJson::V710HB42::detail::ObjectData::addMember<ArduinoJson::V710HB42::detail::JsonStringAdapter>(ArduinoJson::V710HB42::detail::JsonStringAdapter, ArduinoJson::V710HB42::detail::ResourceManager*) |
70 | | |
71 | | // Returns the size (in bytes) of an object with n members. |
72 | 0 | constexpr size_t sizeofObject(size_t n) { |
73 | 0 | return 2 * n * sizeof(VariantData); |
74 | 0 | } |
75 | | |
76 | | ARDUINOJSON_END_PRIVATE_NAMESPACE |