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

bblanchon / ArduinoJson / 16241432057

11 Jul 2025 04:36PM UTC coverage: 99.266% (-0.001%) from 99.267%
16241432057

push

github

bblanchon
CollectionIterator: remove friendship with `VariantImpl`

6 of 6 new or added lines in 2 files covered. (100.0%)

2 existing lines in 2 files now uncovered.

3924 of 3953 relevant lines covered (99.27%)

11114.7 hits per line

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

98.15
/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) const {
4,761✔
14
  auto it = findKey(key);
4,761✔
15
  if (it.done())
4,761✔
16
    return nullptr;
3,499✔
17
  it.next();
1,262✔
18
  return it->data();
1,262✔
19
}
20

21
template <typename TAdaptedString>
22
VariantData* VariantImpl::getOrAddMember(TAdaptedString key) {
962✔
23
  auto data = getMember(key);
962✔
24
  if (data)
962✔
25
    return data;
34✔
26
  return addMember(key);
928✔
27
}
28

29
template <typename TAdaptedString>
30
inline VariantImpl::iterator VariantImpl::findKey(TAdaptedString key) const {
4,792✔
31
  if (!isObject())
4,792✔
32
    return iterator();
63✔
33
  if (key.isNull())
4,729✔
34
    return iterator();
11✔
35
  bool isKey = true;
4,718✔
36
  for (auto it = createIterator(); !it.done(); it.next()) {
25,560✔
37
    if (isKey && stringEquals(key, adaptString(it->asString())))
22,130✔
38
      return it;
1,288✔
39
    isKey = !isKey;
20,842✔
40
  }
41
  return iterator();
3,430✔
42
}
43

44
template <typename TAdaptedString>
45
inline void VariantImpl::removeMember(TAdaptedString key) {
31✔
46
  removeMember(findKey(key));
31✔
47
}
31✔
48

49
inline void VariantImpl::removeMember(iterator it) {
35✔
50
  removePair(it);
35✔
51
}
35✔
52

53
template <typename TAdaptedString>
54
inline VariantData* VariantImpl::addMember(TAdaptedString key) {
928✔
55
  if (!isObject())
928✔
56
    return nullptr;
3✔
57

58
  auto keySlot = allocVariant();
925✔
59
  if (!keySlot)
925✔
60
    return nullptr;
2✔
61

62
  auto valueSlot = allocVariant();
923✔
63
  if (!valueSlot)
923✔
64
    return nullptr;
1✔
65

66
  VariantImpl keyImpl(keySlot.ptr(), resources_);
922✔
67
  if (!keyImpl.setString(key))
922✔
68
    return nullptr;
3✔
69

70
  VariantImpl::appendPair(keySlot, valueSlot);
919✔
71

72
  return valueSlot.ptr();
919✔
73
}
74

75
inline VariantData* VariantImpl::addPair(VariantData** value) {
1,336✔
76
  ARDUINOJSON_ASSERT(isObject());
77

78
  auto keySlot = allocVariant();
1,336✔
79
  if (!keySlot)
1,336✔
80
    return nullptr;
4✔
81

82
  auto valueSlot = allocVariant();
1,332✔
83
  if (!valueSlot)
1,332✔
UNCOV
84
    return nullptr;
×
85
  *value = valueSlot.ptr();
1,332✔
86

87
  VariantImpl::appendPair(keySlot, valueSlot);
1,332✔
88

89
  return keySlot.ptr();
1,332✔
90
}
91

92
// Returns the size (in bytes) of an object with n members.
93
constexpr size_t sizeofObject(size_t n) {
1,688✔
94
  return 2 * n * sizeof(VariantData);
1,688✔
95
}
96

97
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