Minh Nguyen / ArduinoJson
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ObjectFunctions.hpp Source File

ObjectFunctions.hpp

00001 // ArduinoJson - arduinojson.org
00002 // Copyright Benoit Blanchon 2014-2021
00003 // MIT License
00004 
00005 #pragma once
00006 
00007 #include <ArduinoJson/Collection/CollectionData.hpp>
00008 
00009 namespace ARDUINOJSON_NAMESPACE {
00010 
00011 template <typename TVisitor>
00012 typename TVisitor::result_type objectAccept(const CollectionData *obj,
00013                                             TVisitor &visitor) {
00014   if (obj)
00015     return visitor.visitObject(*obj);
00016   else
00017     return visitor.visitNull();
00018 }
00019 
00020 inline bool objectEquals(const CollectionData *lhs, const CollectionData *rhs) {
00021   if (lhs == rhs)
00022     return true;
00023   if (!lhs || !rhs)
00024     return false;
00025   return lhs->equalsObject(*rhs);
00026 }
00027 
00028 template <typename TAdaptedString>
00029 inline VariantData *objectGetMember(const CollectionData *obj,
00030                                     TAdaptedString key) {
00031   if (!obj)
00032     return 0;
00033   return obj->getMember(key);
00034 }
00035 
00036 template <typename TAdaptedString>
00037 void objectRemove(CollectionData *obj, TAdaptedString key) {
00038   if (!obj)
00039     return;
00040   obj->removeMember(key);
00041 }
00042 
00043 template <typename TAdaptedString>
00044 inline VariantData *objectGetOrAddMember(CollectionData *obj,
00045                                          TAdaptedString key, MemoryPool *pool) {
00046   if (!obj)
00047     return 0;
00048 
00049   return obj->getOrAddMember(key, pool);
00050 }
00051 }  // namespace ARDUINOJSON_NAMESPACE