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

bblanchon / ArduinoJson / 5641653306

pending completion
5641653306

push

github

bblanchon
friend member

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

3444 of 3458 relevant lines covered (99.6%)

8764.75 hits per line

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

96.77
/src/ArduinoJson/Object/JsonObjectConst.hpp
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2023, Benoit BLANCHON
3
// MIT License
4

5
#pragma once
6

7
#include <ArduinoJson/Object/JsonObjectIterator.hpp>
8
#include <ArduinoJson/Variant/VariantOperators.hpp>
9

10
ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
11

12
// A read-only reference to an object in a JsonDocument.
13
// https://arduinojson.org/v6/api/jsonobjectconst/
14
class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
15
  friend class JsonObject;
16
  friend class detail::VariantAttorney;
17

18
 public:
19
  typedef JsonObjectConstIterator iterator;
20

21
  // Creates an unbound reference.
22
  JsonObjectConst() : data_(0) {}
5✔
23

24
  // INTERNAL USE ONLY
25
  JsonObjectConst(const detail::ObjectData* data,
2,077✔
26
                  const detail::ResourceManager* resources)
27
      : data_(data), resources_(resources) {}
2,077✔
28

29
  operator JsonVariantConst() const {
143✔
30
    return JsonVariantConst(collectionToVariant(data_), resources_);
143✔
31
  }
32

33
  // Returns true if the reference is unbound.
34
  // https://arduinojson.org/v6/api/jsonobjectconst/isnull/
35
  FORCE_INLINE bool isNull() const {
36
    return data_ == 0;
3✔
37
  }
38

39
  // Returns true if the reference is bound.
40
  // https://arduinojson.org/v6/api/jsonobjectconst/isnull/
41
  FORCE_INLINE operator bool() const {
42
    return data_ != 0;
520✔
43
  }
44

45
  // Returns the number of bytes occupied by the object.
46
  // https://arduinojson.org/v6/api/jsonobjectconst/memoryusage/
47
  FORCE_INLINE size_t memoryUsage() const {
48
    return data_ ? data_->memoryUsage(resources_) : 0;
49
  }
50

51
  // Returns the depth (nesting level) of the object.
52
  // https://arduinojson.org/v6/api/jsonobjectconst/nesting/
53
  FORCE_INLINE size_t nesting() const {
54
    return detail::VariantData::nesting(collectionToVariant(data_), resources_);
55
  }
56

57
  // Returns the number of members in the object.
58
  // https://arduinojson.org/v6/api/jsonobjectconst/size/
59
  FORCE_INLINE size_t size() const {
60
    return data_ ? data_->size(resources_) : 0;
197✔
61
  }
62

63
  // Returns an iterator to the first key-value pair of the object.
64
  // https://arduinojson.org/v6/api/jsonobjectconst/begin/
65
  FORCE_INLINE iterator begin() const {
66
    if (!data_)
221✔
67
      return iterator();
1✔
68
    return iterator(data_->createIterator(resources_), resources_);
283✔
69
  }
70

71
  // Returns an iterator following the last key-value pair of the object.
72
  // https://arduinojson.org/v6/api/jsonobjectconst/end/
73
  FORCE_INLINE iterator end() const {
74
    return iterator();
288✔
75
  }
76

77
  // Returns true if the object contains the specified key.
78
  // https://arduinojson.org/v6/api/jsonobjectconst/containskey/
79
  template <typename TString>
80
  FORCE_INLINE bool containsKey(const TString& key) const {
81
    return detail::ObjectData::getMember(data_, detail::adaptString(key),
82
                                         resources_) != 0;
83
  }
84

85
  // Returns true if the object contains the specified key.
86
  // https://arduinojson.org/v6/api/jsonobjectconst/containskey/
87
  template <typename TChar>
88
  FORCE_INLINE bool containsKey(TChar* key) const {
89
    return detail::ObjectData::getMember(data_, detail::adaptString(key),
2✔
90
                                         resources_) != 0;
4✔
91
  }
92

93
  // Gets the member with specified key.
94
  // https://arduinojson.org/v6/api/jsonobjectconst/subscript/
95
  template <typename TString>
96
  FORCE_INLINE typename detail::enable_if<detail::IsString<TString>::value,
97
                                          JsonVariantConst>::type
98
  operator[](const TString& key) const {
99
    return JsonVariantConst(detail::ObjectData::getMember(
1,272✔
100
                                data_, detail::adaptString(key), resources_),
424✔
101
                            resources_);
848✔
102
  }
103

104
  // Gets the member with specified key.
105
  // https://arduinojson.org/v6/api/jsonobjectconst/subscript/
106
  template <typename TChar>
107
  FORCE_INLINE typename detail::enable_if<detail::IsString<TChar*>::value,
108
                                          JsonVariantConst>::type
109
  operator[](TChar* key) const {
110
    return JsonVariantConst(
111
        detail::ObjectData::getMember(data_, detail::adaptString(key)));
112
  }
113

114
 private:
115
  const detail::VariantData* getData() const {
116
    return collectionToVariant(data_);
117
  }
118

119
  const detail::ObjectData* data_;
120
  const detail::ResourceManager* resources_;
121
};
122

123
inline bool operator==(JsonObjectConst lhs, JsonObjectConst rhs) {
259✔
124
  if (!lhs && !rhs)  // both are null
260✔
125
    return true;
×
126

127
  if (!lhs || !rhs)  // only one is null
517✔
128
    return false;
2✔
129

130
  size_t count = 0;
257✔
131
  for (auto kvp : lhs) {
878✔
132
    auto rhsValue = rhs[kvp.key()];
848✔
133
    if (rhsValue.isUnbound())
424✔
134
      return false;
60✔
135
    if (kvp.value() != rhsValue)
418✔
136
      return false;
54✔
137
    count++;
364✔
138
  }
139
  return count == rhs.size();
197✔
140
}
141

142
ARDUINOJSON_END_PUBLIC_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