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

bblanchon / ArduinoJson / 6770901880

06 Nov 2023 12:24PM CUT coverage: 99.545%. Remained the same
6770901880

push

github

bblanchon
CI: always use libc++ with clang

3497 of 3513 relevant lines covered (99.54%)

10637.15 hits per line

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

96.97
/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/v7/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) {}
6✔
23

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

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

33
  // Returns true if the reference is unbound.
34
  // https://arduinojson.org/v7/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/v7/api/jsonobjectconst/isnull/
41
  FORCE_INLINE operator bool() const {
42
    return data_ != 0;
518✔
43
  }
44

45
  // Returns the depth (nesting level) of the object.
46
  // https://arduinojson.org/v7/api/jsonobjectconst/nesting/
47
  FORCE_INLINE size_t nesting() const {
48
    return detail::VariantData::nesting(collectionToVariant(data_), resources_);
49
  }
50

51
  // Returns the number of members in the object.
52
  // https://arduinojson.org/v7/api/jsonobjectconst/size/
53
  FORCE_INLINE size_t size() const {
54
    return data_ ? data_->size(resources_) : 0;
196✔
55
  }
56

57
  // Returns an iterator to the first key-value pair of the object.
58
  // https://arduinojson.org/v7/api/jsonobjectconst/begin/
59
  FORCE_INLINE iterator begin() const {
60
    if (!data_)
224✔
61
      return iterator();
1✔
62
    return iterator(data_->createIterator(resources_), resources_);
285✔
63
  }
64

65
  // Returns an iterator following the last key-value pair of the object.
66
  // https://arduinojson.org/v7/api/jsonobjectconst/end/
67
  FORCE_INLINE iterator end() const {
68
    return iterator();
290✔
69
  }
70

71
  // Returns true if the object contains the specified key.
72
  // https://arduinojson.org/v7/api/jsonobjectconst/containskey/
73
  template <typename TString>
74
  FORCE_INLINE bool containsKey(const TString& key) const {
75
    return detail::ObjectData::getMember(data_, detail::adaptString(key),
76
                                         resources_) != 0;
77
  }
78

79
  // Returns true if the object contains the specified key.
80
  // https://arduinojson.org/v7/api/jsonobjectconst/containskey/
81
  template <typename TChar>
82
  FORCE_INLINE bool containsKey(TChar* key) const {
83
    return detail::ObjectData::getMember(data_, detail::adaptString(key),
2✔
84
                                         resources_) != 0;
4✔
85
  }
86

87
  // Gets the member with specified key.
88
  // https://arduinojson.org/v7/api/jsonobjectconst/subscript/
89
  template <typename TString>
90
  FORCE_INLINE typename detail::enable_if<detail::IsString<TString>::value,
91
                                          JsonVariantConst>::type
92
  operator[](const TString& key) const {
93
    return JsonVariantConst(detail::ObjectData::getMember(
1,272✔
94
                                data_, detail::adaptString(key), resources_),
424✔
95
                            resources_);
848✔
96
  }
97

98
  // Gets the member with specified key.
99
  // https://arduinojson.org/v7/api/jsonobjectconst/subscript/
100
  template <typename TChar>
101
  FORCE_INLINE typename detail::enable_if<detail::IsString<TChar*>::value,
102
                                          JsonVariantConst>::type
103
  operator[](TChar* key) const {
104
    return JsonVariantConst(
105
        detail::ObjectData::getMember(data_, detail::adaptString(key)));
106
  }
107

108
  // DEPRECATED: always returns zero
109
  ARDUINOJSON_DEPRECATED("always returns zero")
110
  size_t memoryUsage() const {
1✔
111
    return 0;
1✔
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) {
258✔
124
  if (!lhs && !rhs)  // both are null
259✔
125
    return true;
×
126

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

130
  size_t count = 0;
256✔
131
  for (auto kvp : lhs) {
876✔
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();
196✔
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