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

bblanchon / ArduinoJson / 10546949766

25 Aug 2024 12:30PM UTC coverage: 99.51%. First build
10546949766

push

github

bblanchon
Remove VariantSlot

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

3862 of 3881 relevant lines covered (99.51%)

10845.49 hits per line

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

97.67
/src/ArduinoJson/Array/ArrayImpl.hpp
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2024, 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 ArrayData::iterator ArrayData::at(
454✔
13
    size_t index, const ResourceManager* resources) const {
14
  auto it = createIterator(resources);
454✔
15
  while (!it.done() && index) {
774✔
16
    it.next(resources);
320✔
17
    --index;
320✔
18
  }
19
  return it;
454✔
20
}
21

22
inline VariantData* ArrayData::addElement(ResourceManager* resources) {
2,889✔
23
  auto slot = resources->allocVariant();
2,889✔
24
  if (!slot)
2,889✔
25
    return nullptr;
11✔
26
  CollectionData::appendOne(slot, resources);
2,878✔
27
  return slot.ptr();
2,878✔
28
}
29

30
inline VariantData* ArrayData::getOrAddElement(size_t index,
149✔
31
                                               ResourceManager* resources) {
32
  auto it = createIterator(resources);
149✔
33
  while (!it.done() && index > 0) {
174✔
34
    it.next(resources);
25✔
35
    index--;
25✔
36
  }
37
  if (it.done())
149✔
38
    index++;
112✔
39
  VariantData* element = it.data();
149✔
40
  while (index > 0) {
397✔
41
    element = addElement(resources);
248✔
42
    if (!element)
248✔
43
      return nullptr;
×
44
    index--;
248✔
45
  }
46
  return element;
149✔
47
}
48

49
inline VariantData* ArrayData::getElement(
440✔
50
    size_t index, const ResourceManager* resources) const {
51
  return at(index, resources).data();
440✔
52
}
53

54
inline void ArrayData::removeElement(size_t index, ResourceManager* resources) {
14✔
55
  remove(at(index, resources), resources);
14✔
56
}
14✔
57

58
template <typename T>
59
inline bool ArrayData::addValue(T&& value, ResourceManager* resources) {
66,289✔
60
  ARDUINOJSON_ASSERT(resources != nullptr);
61
  auto slot = resources->allocVariant();
66,289✔
62
  if (!slot)
66,289✔
63
    return false;
7✔
64
  JsonVariant variant(slot.ptr(), resources);
66,282✔
65
  if (!variant.set(detail::forward<T>(value))) {
66,282✔
66
    resources->freeVariant(slot);
4✔
67
    return false;
4✔
68
  }
69
  CollectionData::appendOne(slot, resources);
66,278✔
70
  return true;
66,278✔
71
}
72

73
// Returns the size (in bytes) of an array with n elements.
74
constexpr size_t sizeofArray(size_t n) {
83✔
75
  return n * sizeof(VariantData);
83✔
76
}
77

78
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