2021-03-29 17:14:01 +02:00
|
|
|
// ArduinoJson - https://arduinojson.org
|
2022-01-01 10:00:54 +01:00
|
|
|
// Copyright © 2014-2022, Benoit BLANCHON
|
2018-11-30 17:53:54 +01:00
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-08-26 11:57:57 +02:00
|
|
|
#include <ArduinoJson/Strings/String.hpp>
|
|
|
|
#include <ArduinoJson/Variant/VariantRef.hpp>
|
2018-11-30 17:53:54 +01:00
|
|
|
|
|
|
|
namespace ARDUINOJSON_NAMESPACE {
|
2018-12-07 09:16:58 +01:00
|
|
|
// A key value pair for CollectionData.
|
2018-11-30 17:53:54 +01:00
|
|
|
class Pair {
|
|
|
|
public:
|
2018-12-07 12:08:30 +01:00
|
|
|
Pair(MemoryPool* pool, VariantSlot* slot) {
|
2018-11-30 17:53:54 +01:00
|
|
|
if (slot) {
|
2022-02-17 10:47:42 +01:00
|
|
|
_key = String(slot->key(),
|
|
|
|
slot->ownsKey() ? String::Copied : String::Linked);
|
2018-12-07 09:16:58 +01:00
|
|
|
_value = VariantRef(pool, slot->data());
|
2018-11-30 17:53:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-07 12:08:30 +01:00
|
|
|
String key() const {
|
2018-11-30 17:53:54 +01:00
|
|
|
return _key;
|
|
|
|
}
|
|
|
|
|
|
|
|
VariantRef value() const {
|
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-12-07 12:08:30 +01:00
|
|
|
String _key;
|
2018-11-30 17:53:54 +01:00
|
|
|
VariantRef _value;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PairConst {
|
|
|
|
public:
|
2018-12-07 12:08:30 +01:00
|
|
|
PairConst(const VariantSlot* slot) {
|
2018-11-30 17:53:54 +01:00
|
|
|
if (slot) {
|
2022-02-17 10:47:42 +01:00
|
|
|
_key = String(slot->key(),
|
|
|
|
slot->ownsKey() ? String::Copied : String::Linked);
|
2018-12-07 09:16:58 +01:00
|
|
|
_value = VariantConstRef(slot->data());
|
2018-11-30 17:53:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-07 12:08:30 +01:00
|
|
|
String key() const {
|
2018-11-30 17:53:54 +01:00
|
|
|
return _key;
|
|
|
|
}
|
|
|
|
|
|
|
|
VariantConstRef value() const {
|
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-12-07 12:08:30 +01:00
|
|
|
String _key;
|
2018-11-30 17:53:54 +01:00
|
|
|
VariantConstRef _value;
|
|
|
|
};
|
|
|
|
} // namespace ARDUINOJSON_NAMESPACE
|