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

bblanchon / ArduinoJson / 4469075312

pending completion
4469075312

push

github

Benoit Blanchon
`MemoryPool` calls the `Allocator` directly

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

3283 of 3299 relevant lines covered (99.52%)

6203.28 hits per line

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

100.0
/src/ArduinoJson/Collection/CollectionData.hpp
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2023, Benoit BLANCHON
3
// MIT License
4

5
#pragma once
6

7
#include <ArduinoJson/Namespace.hpp>
8
#include <ArduinoJson/Polyfills/assert.hpp>
9

10
#include <stddef.h>  // size_t
11

12
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
13

14
class MemoryPool;
15
class VariantData;
16
class VariantSlot;
17

18
class CollectionData {
19
  VariantSlot* _head;
20
  VariantSlot* _tail;
21

22
 public:
23
  // Must be a POD!
24
  // - no constructor
25
  // - no destructor
26
  // - no virtual
27
  // - no inheritance
28

29
  // Array only
30

31
  VariantData* addElement(MemoryPool* pool);
32

33
  VariantData* getElement(size_t index) const;
34

35
  VariantData* getOrAddElement(size_t index, MemoryPool* pool);
36

37
  void removeElement(size_t index);
38

39
  // Object only
40

41
  template <typename TAdaptedString>
42
  VariantData* addMember(TAdaptedString key, MemoryPool* pool);
43

44
  template <typename TAdaptedString>
45
  VariantData* getMember(TAdaptedString key) const;
46

47
  template <typename TAdaptedString>
48
  VariantData* getOrAddMember(TAdaptedString key, MemoryPool* pool);
49

50
  template <typename TAdaptedString>
51
  void removeMember(TAdaptedString key) {
25✔
52
    removeSlot(getSlot(key));
25✔
53
  }
25✔
54

55
  template <typename TAdaptedString>
56
  bool containsKey(const TAdaptedString& key) const;
57

58
  // Generic
59

60
  void clear();
61
  size_t memoryUsage() const;
62
  size_t size() const;
63

64
  VariantSlot* addSlot(MemoryPool*);
65
  void removeSlot(VariantSlot* slot);
66

67
  bool copyFrom(const CollectionData& src, MemoryPool* pool);
68

69
  VariantSlot* head() const {
1,496✔
70
    return _head;
1,496✔
71
  }
72

73
  void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance);
74

75
 private:
76
  VariantSlot* getSlot(size_t index) const;
77

78
  template <typename TAdaptedString>
79
  VariantSlot* getSlot(TAdaptedString key) const;
80

81
  VariantSlot* getPreviousSlot(VariantSlot*) const;
82
};
83

84
inline const VariantData* collectionToVariant(
270✔
85
    const CollectionData* collection) {
86
  const void* data = collection;  // prevent warning cast-align
270✔
87
  return reinterpret_cast<const VariantData*>(data);
270✔
88
}
89

90
inline VariantData* collectionToVariant(CollectionData* collection) {
1,206✔
91
  void* data = collection;  // prevent warning cast-align
1,206✔
92
  return reinterpret_cast<VariantData*>(data);
1,206✔
93
}
94

95
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