Files
ArduinoJson/src/ArduinoJson/Object/Pair.hpp

58 lines
1.1 KiB
C++
Raw Normal View History

// 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
#include <ArduinoJson/Strings/String.hpp>
#include <ArduinoJson/Variant/VariantRef.hpp>
2018-11-30 17:53:54 +01:00
namespace ARDUINOJSON_NAMESPACE {
// 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) {
_key = String(slot->key(),
slot->ownsKey() ? String::Copied : String::Linked);
_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) {
_key = String(slot->key(),
slot->ownsKey() ? String::Copied : String::Linked);
_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