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

bblanchon / ArduinoJson / 13696030297

06 Mar 2025 10:00AM CUT coverage: 99.309%. Remained the same
13696030297

push

github

bblanchon
Fix CLang Tidy error

4023 of 4051 relevant lines covered (99.31%)

10751.08 hits per line

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

97.83
/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/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(
4,700✔
15
    TAdaptedString key, const ResourceManager* resources) const {
16
  auto it = findKey(key, resources);
4,700✔
17
  if (it.done())
4,700✔
18
    return nullptr;
3,436✔
19
  it.next(resources);
1,264✔
20
  return it.data();
1,264✔
21
}
22

23
template <typename TAdaptedString>
24
VariantData* ObjectData::getOrAddMember(TAdaptedString key,
957✔
25
                                        ResourceManager* resources) {
26
  auto data = getMember(key, resources);
957✔
27
  if (data)
957✔
28
    return data;
34✔
29
  return addMember(key, resources);
923✔
30
}
31

32
template <typename TAdaptedString>
33
inline ObjectData::iterator ObjectData::findKey(
4,728✔
34
    TAdaptedString key, const ResourceManager* resources) const {
35
  if (key.isNull())
4,728✔
36
    return iterator();
10✔
37
  bool isKey = true;
4,718✔
38
  for (auto it = createIterator(resources); !it.done(); it.next(resources)) {
25,566✔
39
    if (isKey && stringEquals(key, adaptString(it->asString())))
22,138✔
40
      return it;
1,290✔
41
    isKey = !isKey;
20,848✔
42
  }
43
  return iterator();
3,428✔
44
}
45

46
template <typename TAdaptedString>
47
inline void ObjectData::removeMember(TAdaptedString key,
28✔
48
                                     ResourceManager* resources) {
49
  remove(findKey(key, resources), resources);
28✔
50
}
28✔
51

52
template <typename TAdaptedString>
53
inline VariantData* ObjectData::addMember(TAdaptedString key,
923✔
54
                                          ResourceManager* resources) {
55
  auto keySlot = resources->allocVariant();
923✔
56
  if (!keySlot)
923✔
57
    return nullptr;
2✔
58

59
  auto valueSlot = resources->allocVariant();
921✔
60
  if (!valueSlot)
921✔
61
    return nullptr;
1✔
62

63
  if (!keySlot->setString(key, resources))
920✔
64
    return nullptr;
2✔
65

66
  CollectionData::appendPair(keySlot, valueSlot, resources);
918✔
67

68
  return valueSlot.ptr();
918✔
69
}
70

71
inline VariantData* ObjectData::addPair(VariantData** value,
1,335✔
72
                                        ResourceManager* resources) {
73
  auto keySlot = resources->allocVariant();
1,335✔
74
  if (!keySlot)
1,335✔
75
    return nullptr;
4✔
76

77
  auto valueSlot = resources->allocVariant();
1,331✔
78
  if (!valueSlot)
1,331✔
79
    return nullptr;
×
80
  *value = valueSlot.ptr();
1,331✔
81

82
  CollectionData::appendPair(keySlot, valueSlot, resources);
1,331✔
83

84
  return keySlot.ptr();
1,331✔
85
}
86

87
// Returns the size (in bytes) of an object with n members.
88
constexpr size_t sizeofObject(size_t n) {
1,688✔
89
  return 2 * n * ResourceManager::slotSize;
1,688✔
90
}
91

92
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