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

bblanchon / ArduinoJson / 10700044544

04 Sep 2024 10:40AM CUT coverage: 99.301%. First build
10700044544

push

github

bblanchon
Approx

3975 of 4003 relevant lines covered (99.3%)

10563.62 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
#include <ArduinoJson/Variant/VariantData.hpp>
10

11
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
12

13
inline ArrayData::iterator ArrayData::at(
456✔
14
    size_t index, const ResourceManager* resources) const {
15
  auto it = createIterator(resources);
456✔
16
  while (!it.done() && index) {
777✔
17
    it.next(resources);
321✔
18
    --index;
321✔
19
  }
20
  return it;
456✔
21
}
22

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

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

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

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

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

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

79
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