Minh Nguyen / ArduinoJson
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Pair.hpp Source File

Pair.hpp

00001 // ArduinoJson - arduinojson.org
00002 // Copyright Benoit Blanchon 2014-2021
00003 // MIT License
00004 
00005 #pragma once
00006 
00007 #include <ArduinoJson/Strings/String.hpp>
00008 #include <ArduinoJson/Variant/VariantRef.hpp>
00009 
00010 namespace ARDUINOJSON_NAMESPACE {
00011 // A key value pair for CollectionData.
00012 class Pair {
00013  public:
00014   Pair(MemoryPool* pool, VariantSlot* slot) {
00015     if (slot) {
00016       _key = String(slot->key(), !slot->ownsKey());
00017       _value = VariantRef(pool, slot->data());
00018     }
00019   }
00020 
00021   String key() const {
00022     return _key;
00023   }
00024 
00025   VariantRef value() const {
00026     return _value;
00027   }
00028 
00029  private:
00030   String _key;
00031   VariantRef _value;
00032 };
00033 
00034 class PairConst {
00035  public:
00036   PairConst(const VariantSlot* slot) {
00037     if (slot) {
00038       _key = String(slot->key(), !slot->ownsKey());
00039       _value = VariantConstRef(slot->data());
00040     }
00041   }
00042 
00043   String key() const {
00044     return _key;
00045   }
00046 
00047   VariantConstRef value() const {
00048     return _value;
00049   }
00050 
00051  private:
00052   String _key;
00053   VariantConstRef _value;
00054 };
00055 }  // namespace ARDUINOJSON_NAMESPACE