/src/arduinojson/src/ArduinoJson/Object/JsonPair.hpp
Line | Count | Source |
1 | | // ArduinoJson - https://arduinojson.org |
2 | | // Copyright © 2014-2025, Benoit BLANCHON |
3 | | // MIT License |
4 | | |
5 | | #pragma once |
6 | | |
7 | | #include <ArduinoJson/Strings/JsonString.hpp> |
8 | | #include <ArduinoJson/Variant/JsonVariant.hpp> |
9 | | #include <ArduinoJson/Variant/JsonVariantConst.hpp> |
10 | | |
11 | | ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE |
12 | | |
13 | | // A key-value pair. |
14 | | // https://arduinojson.org/v7/api/jsonobject/begin_end/ |
15 | | class JsonPair { |
16 | | public: |
17 | | // INTERNAL USE ONLY |
18 | | JsonPair(detail::VariantImpl::iterator iterator, |
19 | 0 | detail::ResourceManager* resources) { |
20 | 0 | if (!iterator.done()) { |
21 | 0 | key_ = iterator->asString(); |
22 | 0 | iterator.move(resources); |
23 | 0 | value_ = JsonVariant(iterator.data(), resources); |
24 | 0 | } |
25 | 0 | } |
26 | | |
27 | | // Returns the key. |
28 | 0 | JsonString key() const { |
29 | 0 | return key_; |
30 | 0 | } |
31 | | |
32 | | // Returns the value. |
33 | 0 | JsonVariant value() { |
34 | 0 | return value_; |
35 | 0 | } |
36 | | |
37 | | private: |
38 | | JsonString key_; |
39 | | JsonVariant value_; |
40 | | }; |
41 | | |
42 | | // A read-only key-value pair. |
43 | | // https://arduinojson.org/v7/api/jsonobjectconst/begin_end/ |
44 | | class JsonPairConst { |
45 | | public: |
46 | | JsonPairConst(detail::VariantImpl::iterator iterator, |
47 | 0 | detail::ResourceManager* resources) { |
48 | 0 | if (!iterator.done()) { |
49 | 0 | key_ = iterator->asString(); |
50 | 0 | iterator.move(resources); |
51 | 0 | value_ = JsonVariantConst(iterator.data(), resources); |
52 | 0 | } |
53 | 0 | } |
54 | | |
55 | | // Returns the key. |
56 | 0 | JsonString key() const { |
57 | 0 | return key_; |
58 | 0 | } |
59 | | |
60 | | // Returns the value. |
61 | 0 | JsonVariantConst value() const { |
62 | 0 | return value_; |
63 | 0 | } |
64 | | |
65 | | private: |
66 | | JsonString key_; |
67 | | JsonVariantConst value_; |
68 | | }; |
69 | | |
70 | | ARDUINOJSON_END_PUBLIC_NAMESPACE |