• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bblanchon / ArduinoJson / 18593280678

17 Oct 2025 12:52PM UTC coverage: 99.417% (+0.02%) from 99.399%
18593280678

push

github

bblanchon
ResourceManager: move out-of-class definitions back in the class

24 of 24 new or added lines in 1 file covered. (100.0%)

5 existing lines in 3 files now uncovered.

3925 of 3948 relevant lines covered (99.42%)

10567.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.73
/src/ArduinoJson/Object/ObjectImpl.hpp
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2025, Benoit BLANCHON
3
// MIT License
4

5
#pragma once
6

7
#include <ArduinoJson/Variant/VariantCompare.hpp>
8
#include <ArduinoJson/Variant/VariantImpl.hpp>
9

10
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
11

12
template <typename TAdaptedString>
13
inline VariantData* VariantImpl::getMember(TAdaptedString key,
4,690✔
14
                                           VariantData* data,
15
                                           ResourceManager* resources) {
16
  auto it = findKey(key, data, resources);
4,690✔
17
  if (it.done())
4,690✔
18
    return nullptr;
3,427✔
19
  it.next(resources);
1,263✔
20
  return it.data();
1,263✔
21
}
22

23
template <typename TAdaptedString>
24
VariantData* VariantImpl::getOrAddMember(TAdaptedString key, VariantData* data,
947✔
25
                                         ResourceManager* resources) {
26
  ARDUINOJSON_ASSERT(data != nullptr);
27
  ARDUINOJSON_ASSERT(data->isObject());
28
  ARDUINOJSON_ASSERT(resources != nullptr);
29

30
  auto member = getMember(key, data, resources);
947✔
31
  if (member)
947✔
32
    return member;
34✔
33
  return addMember(key, data, resources);
913✔
34
}
35

36
template <typename TAdaptedString>
37
inline VariantImpl::iterator VariantImpl::findKey(TAdaptedString key,
4,718✔
38
                                                  VariantData* data,
39
                                                  ResourceManager* resources) {
40
  ARDUINOJSON_ASSERT(data != nullptr);
41
  ARDUINOJSON_ASSERT(data->isObject());
42
  ARDUINOJSON_ASSERT(resources != nullptr);
43

44
  if (key.isNull())
4,718✔
45
    return iterator();
11✔
46
  bool isKey = true;
4,707✔
47
  for (auto it = createIterator(data, resources); !it.done();
25,555✔
48
       it.next(resources)) {
20,848✔
49
    if (isKey && stringEquals(key, adaptString(it->asString())))
22,137✔
50
      return it;
1,289✔
51
    isKey = !isKey;
20,848✔
52
  }
53
  return iterator();
3,418✔
54
}
55

56
template <typename TAdaptedString>
57
inline VariantData* VariantImpl::addMember(TAdaptedString key,
913✔
58
                                           VariantData* data,
59
                                           ResourceManager* resources) {
60
  ARDUINOJSON_ASSERT(data != nullptr);
61
  ARDUINOJSON_ASSERT(data->isObject());
62
  ARDUINOJSON_ASSERT(resources != nullptr);
63

64
  auto keySlot = resources->allocVariant();
913✔
65
  if (!keySlot)
913✔
66
    return nullptr;
2✔
67

68
  auto valueSlot = resources->allocVariant();
911✔
69
  if (!valueSlot)
911✔
70
    return nullptr;
1✔
71

72
  if (!VariantImpl::setString(key, keySlot.ptr(), resources))
910✔
73
    return nullptr;
3✔
74

75
  appendPair(keySlot, valueSlot, data, resources);
907✔
76

77
  return valueSlot.ptr();
907✔
78
}
79

80
inline VariantData* VariantImpl::addPair(VariantData** value, VariantData* data,
1,336✔
81
                                         ResourceManager* resources) {
82
  ARDUINOJSON_ASSERT(value != nullptr);
83
  ARDUINOJSON_ASSERT(data != nullptr);
84
  ARDUINOJSON_ASSERT(data->isObject());
85
  ARDUINOJSON_ASSERT(resources != nullptr);
86

87
  auto keySlot = resources->allocVariant();
1,336✔
88
  if (!keySlot)
1,336✔
89
    return nullptr;
4✔
90

91
  auto valueSlot = resources->allocVariant();
1,332✔
92
  if (!valueSlot)
1,332✔
UNCOV
93
    return nullptr;
×
94
  *value = valueSlot.ptr();
1,332✔
95

96
  appendPair(keySlot, valueSlot, data, resources);
1,332✔
97

98
  return keySlot.ptr();
1,332✔
99
}
100

101
// Returns the size (in bytes) of an object with n members.
102
constexpr size_t sizeofObject(size_t n) {
1,686✔
103
  return 2 * n * sizeof(VariantData);
1,686✔
104
}
105

106
ARDUINOJSON_END_PRIVATE_NAMESPACE
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc