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

bblanchon / ArduinoJson / 10547870473

25 Aug 2024 02:46PM CUT coverage: 99.514% (+0.004%) from 99.51%
10547870473

push

github

bblanchon
Decouple `parseNumber()` from `VariantData`

52 of 52 new or added lines in 3 files covered. (100.0%)

3892 of 3911 relevant lines covered (99.51%)

10766.65 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(
454✔
14
    size_t index, const ResourceManager* resources) const {
15
  auto it = createIterator(resources);
454✔
16
  while (!it.done() && index) {
774✔
17
    it.next(resources);
320✔
18
    --index;
320✔
19
  }
20
  return it;
454✔
21
}
22

23
inline VariantData* ArrayData::addElement(ResourceManager* resources) {
2,889✔
24
  auto slot = resources->allocVariant();
2,889✔
25
  if (!slot)
2,889✔
26
    return nullptr;
11✔
27
  CollectionData::appendOne(slot, resources);
2,878✔
28
  return slot.ptr();
2,878✔
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) {
397✔
42
    element = addElement(resources);
248✔
43
    if (!element)
248✔
44
      return nullptr;
×
45
    index--;
248✔
46
  }
47
  return element;
149✔
48
}
49

50
inline VariantData* ArrayData::getElement(
440✔
51
    size_t index, const ResourceManager* resources) const {
52
  return at(index, resources).data();
440✔
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,289✔
61
  ARDUINOJSON_ASSERT(resources != nullptr);
62
  auto slot = resources->allocVariant();
66,289✔
63
  if (!slot)
66,289✔
64
    return false;
7✔
65
  JsonVariant variant(slot.ptr(), resources);
66,282✔
66
  if (!variant.set(detail::forward<T>(value))) {
66,282✔
67
    resources->freeVariant(slot);
4✔
68
    return false;
4✔
69
  }
70
  CollectionData::appendOne(slot, resources);
66,278✔
71
  return true;
66,278✔
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