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

bblanchon / ArduinoJson / 5377130425

pending completion
5377130425

push

github

bblanchon
Convert "variant functions" to static member functions

126 of 126 new or added lines in 16 files covered. (100.0%)

3385 of 3408 relevant lines covered (99.33%)

6305.9 hits per line

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

95.92
/src/ArduinoJson/Array/ArrayImpl.hpp
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2023, Benoit BLANCHON
3
// MIT License
4

5
#pragma once
6

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

10
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
11

12
inline VariantData* ArrayData::addElement(ResourceManager* resources) {
68,510✔
13
  auto slot = resources->allocVariant();
68,510✔
14
  if (!slot)
68,510✔
15
    return nullptr;
19✔
16
  addSlot(slot);
68,491✔
17
  return slot->data();
68,491✔
18
}
19

20
inline bool ArrayData::copyFrom(const ArrayData& src,
12✔
21
                                ResourceManager* resources) {
22
  clear(resources);
12✔
23

24
  for (VariantSlot* s = src.head(); s; s = s->next()) {
17✔
25
    auto var = addElement(resources);
6✔
26
    if (!var)
6✔
27
      return false;
1✔
28
    if (!var->copyFrom(s->data(), resources))
5✔
29
      return false;
×
30
  }
31
  return true;
11✔
32
}
33

34
inline bool ArrayData::equals(const ArrayData& other) const {
249✔
35
  auto a = head();
249✔
36
  auto b = other.head();
249✔
37

38
  for (;;) {
39
    if (!a && !b)  // both ended
665✔
40
      return true;
189✔
41
    if (!a || !b)  // one ended
476✔
42
      return false;
4✔
43
    if (compare(a->data(), b->data()) != COMPARE_RESULT_EQUAL)
472✔
44
      return false;
56✔
45
    a = a->next();
416✔
46
    b = b->next();
416✔
47
  }
48
}
49

50
inline VariantData* ArrayData::getOrAddElement(size_t index,
135✔
51
                                               ResourceManager* resources) {
52
  VariantSlot* slot = head();
135✔
53
  while (slot && index > 0) {
145✔
54
    slot = slot->next();
10✔
55
    index--;
10✔
56
  }
57
  if (!slot)
135✔
58
    index++;
101✔
59
  while (index > 0) {
249✔
60
    slot = resources->allocVariant();
114✔
61
    if (!slot)
114✔
62
      return nullptr;
×
63
    addSlot(slot);
114✔
64
    index--;
114✔
65
  }
66
  return slot->data();
135✔
67
}
68

69
inline VariantData* ArrayData::getElement(size_t index) const {
412✔
70
  return slotData(getSlot(index));
412✔
71
}
72

73
inline VariantSlot* ArrayData::getSlot(size_t index) const {
422✔
74
  if (!head())
422✔
75
    return 0;
1✔
76
  return head()->next(index);
421✔
77
}
78

79
inline void ArrayData::removeElement(size_t index, ResourceManager* resources) {
10✔
80
  removeSlot(getSlot(index), resources);
10✔
81
}
10✔
82

83
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