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

bblanchon / ArduinoJson / 9401199389

06 Jun 2024 12:50PM CUT coverage: 99.563% (+0.2%) from 99.362%
9401199389

push

github

bblanchon
Rewrite fromJson

15 of 15 new or added lines in 1 file covered. (100.0%)

3876 of 3893 relevant lines covered (99.56%)

10740.81 hits per line

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

97.14
/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::getOrAddElement(size_t index,
148✔
23
                                               ResourceManager* resources) {
24
  auto it = createIterator(resources);
148✔
25
  while (!it.done() && index > 0) {
173✔
26
    it.next(resources);
25✔
27
    index--;
25✔
28
  }
29
  if (it.done())
148✔
30
    index++;
111✔
31
  VariantData* element = it.data();
148✔
32
  while (index > 0) {
271✔
33
    element = addElement(resources);
123✔
34
    if (!element)
123✔
35
      return nullptr;
×
36
    index--;
123✔
37
  }
38
  return element;
148✔
39
}
40

41
inline VariantData* ArrayData::getElement(
440✔
42
    size_t index, const ResourceManager* resources) const {
43
  return at(index, resources).data();
440✔
44
}
45

46
inline void ArrayData::removeElement(size_t index, ResourceManager* resources) {
14✔
47
  remove(at(index, resources), resources);
14✔
48
}
14✔
49

50
template <typename T>
51
inline bool ArrayData::addValue(T&& value, ResourceManager* resources) {
66,286✔
52
  ARDUINOJSON_ASSERT(resources != nullptr);
53
  auto slot = resources->allocSlot();
66,286✔
54
  if (!slot)
66,286✔
55
    return false;
7✔
56
  JsonVariant variant(slot->data(), resources);
66,279✔
57
  if (!variant.set(detail::forward<T>(value))) {
66,279✔
58
    resources->freeSlot(slot);
4✔
59
    return false;
4✔
60
  }
61
  addSlot(slot, resources);
66,275✔
62
  return true;
66,275✔
63
}
64

65
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