|
|
@@ -4,8 +4,8 @@
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
-#include "Data/ObjectFunctions.hpp"
|
|
|
-#include "JsonObjectIterator.hpp"
|
|
|
+#include "ObjectFunctions.hpp"
|
|
|
+#include "ObjectIterator.hpp"
|
|
|
|
|
|
// Returns the size (in bytes) of an object with n elements.
|
|
|
// Can be very handy to determine the size of a StaticMemoryPool.
|
|
|
@@ -15,7 +15,7 @@
|
|
|
namespace ARDUINOJSON_NAMESPACE {
|
|
|
|
|
|
template <typename TData>
|
|
|
-class JsonObjectProxy {
|
|
|
+class ObjectRefBase {
|
|
|
public:
|
|
|
// Tells weither the specified key is present and associated with a value.
|
|
|
//
|
|
|
@@ -42,20 +42,20 @@ class JsonObjectProxy {
|
|
|
}
|
|
|
|
|
|
protected:
|
|
|
- JsonObjectProxy(TData* data) : _data(data) {}
|
|
|
+ ObjectRefBase(TData* data) : _data(data) {}
|
|
|
TData* _data;
|
|
|
};
|
|
|
|
|
|
-class JsonObjectConst : public JsonObjectProxy<const JsonObjectData>,
|
|
|
- public Visitable {
|
|
|
- friend class JsonObject;
|
|
|
- typedef JsonObjectProxy<const JsonObjectData> proxy_type;
|
|
|
+class ObjectConstRef : public ObjectRefBase<const ObjectData>,
|
|
|
+ public Visitable {
|
|
|
+ friend class ObjectRef;
|
|
|
+ typedef ObjectRefBase<const ObjectData> base_type;
|
|
|
|
|
|
public:
|
|
|
- typedef JsonObjectConstIterator iterator;
|
|
|
+ typedef ObjectConstIterator iterator;
|
|
|
|
|
|
- JsonObjectConst() : proxy_type(0) {}
|
|
|
- JsonObjectConst(const JsonObjectData* data) : proxy_type(data) {}
|
|
|
+ ObjectConstRef() : base_type(0) {}
|
|
|
+ ObjectConstRef(const ObjectData* data) : base_type(data) {}
|
|
|
|
|
|
template <typename Visitor>
|
|
|
FORCE_INLINE void accept(Visitor& visitor) const {
|
|
|
@@ -79,66 +79,65 @@ class JsonObjectConst : public JsonObjectProxy<const JsonObjectData>,
|
|
|
// TValue get<TValue>(TKey) const;
|
|
|
// TKey = const std::string&, const String&
|
|
|
// TValue = bool, char, long, int, short, float, double,
|
|
|
- // std::string, String, JsonArrayConst, JsonObjectConst
|
|
|
+ // std::string, String, ArrayConstRef, ObjectConstRef
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE JsonVariantConst get(const TKey& key) const {
|
|
|
+ FORCE_INLINE VariantConstRef get(const TKey& key) const {
|
|
|
return get_impl(makeString(key));
|
|
|
}
|
|
|
//
|
|
|
// TValue get<TValue>(TKey) const;
|
|
|
// TKey = char*, const char*, const FlashStringHelper*
|
|
|
// TValue = bool, char, long, int, short, float, double,
|
|
|
- // std::string, String, JsonArrayConst, JsonObjectConst
|
|
|
+ // std::string, String, ArrayConstRef, ObjectConstRef
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE JsonVariantConst get(TKey* key) const {
|
|
|
+ FORCE_INLINE VariantConstRef get(TKey* key) const {
|
|
|
return get_impl(makeString(key));
|
|
|
}
|
|
|
|
|
|
//
|
|
|
- // JsonVariantConst operator[](TKey) const;
|
|
|
+ // VariantConstRef operator[](TKey) const;
|
|
|
// TKey = const std::string&, const String&
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE typename enable_if<IsString<TKey>::value, JsonVariantConst>::type
|
|
|
+ FORCE_INLINE typename enable_if<IsString<TKey>::value, VariantConstRef>::type
|
|
|
operator[](const TKey& key) const {
|
|
|
return get_impl(makeString(key));
|
|
|
}
|
|
|
//
|
|
|
- // JsonVariantConst operator[](TKey) const;
|
|
|
+ // VariantConstRef operator[](TKey) const;
|
|
|
// TKey = const char*, const char[N], const FlashStringHelper*
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE
|
|
|
- typename enable_if<IsString<TKey*>::value, JsonVariantConst>::type
|
|
|
- operator[](TKey* key) const {
|
|
|
+ FORCE_INLINE typename enable_if<IsString<TKey*>::value, VariantConstRef>::type
|
|
|
+ operator[](TKey* key) const {
|
|
|
return get_impl(makeString(key));
|
|
|
}
|
|
|
|
|
|
- FORCE_INLINE bool operator==(JsonObjectConst rhs) const {
|
|
|
+ FORCE_INLINE bool operator==(ObjectConstRef rhs) const {
|
|
|
return objectEquals(_data, rhs._data);
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE JsonVariantConst get_impl(TKey key) const {
|
|
|
- return JsonVariantConst(objectGet(_data, key));
|
|
|
+ FORCE_INLINE VariantConstRef get_impl(TKey key) const {
|
|
|
+ return VariantConstRef(objectGet(_data, key));
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-class JsonObject : public JsonObjectProxy<JsonObjectData>, public Visitable {
|
|
|
- typedef JsonObjectProxy<JsonObjectData> proxy_type;
|
|
|
+class ObjectRef : public ObjectRefBase<ObjectData>, public Visitable {
|
|
|
+ typedef ObjectRefBase<ObjectData> base_type;
|
|
|
|
|
|
public:
|
|
|
- typedef JsonObjectIterator iterator;
|
|
|
+ typedef ObjectIterator iterator;
|
|
|
|
|
|
- FORCE_INLINE JsonObject() : proxy_type(0), _memoryPool(0) {}
|
|
|
- FORCE_INLINE JsonObject(MemoryPool* buf, JsonObjectData* data)
|
|
|
- : proxy_type(data), _memoryPool(buf) {}
|
|
|
+ FORCE_INLINE ObjectRef() : base_type(0), _memoryPool(0) {}
|
|
|
+ FORCE_INLINE ObjectRef(MemoryPool* buf, ObjectData* data)
|
|
|
+ : base_type(data), _memoryPool(buf) {}
|
|
|
|
|
|
- operator JsonVariant() const {
|
|
|
- return JsonVariant(_memoryPool, getVariantData(_data));
|
|
|
+ operator VariantRef() const {
|
|
|
+ return VariantRef(_memoryPool, getVariantData(_data));
|
|
|
}
|
|
|
|
|
|
- operator JsonObjectConst() const {
|
|
|
- return JsonObjectConst(_data);
|
|
|
+ operator ObjectConstRef() const {
|
|
|
+ return ObjectConstRef(_data);
|
|
|
}
|
|
|
|
|
|
FORCE_INLINE iterator begin() const {
|
|
|
@@ -154,35 +153,35 @@ class JsonObject : public JsonObjectProxy<JsonObjectData>, public Visitable {
|
|
|
objectClear(_data);
|
|
|
}
|
|
|
|
|
|
- FORCE_INLINE bool copyFrom(JsonObjectConst src) {
|
|
|
+ FORCE_INLINE bool copyFrom(ObjectConstRef src) {
|
|
|
return objectCopy(_data, src._data, _memoryPool);
|
|
|
}
|
|
|
|
|
|
- // Creates and adds a JsonArray.
|
|
|
+ // Creates and adds a ArrayRef.
|
|
|
//
|
|
|
- // JsonArray createNestedArray(TKey);
|
|
|
+ // ArrayRef createNestedArray(TKey);
|
|
|
// TKey = const std::string&, const String&
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE JsonArray createNestedArray(const TKey& key) const;
|
|
|
- // JsonArray createNestedArray(TKey);
|
|
|
+ FORCE_INLINE ArrayRef createNestedArray(const TKey& key) const;
|
|
|
+ // ArrayRef createNestedArray(TKey);
|
|
|
// TKey = char*, const char*, char[], const char[], const FlashStringHelper*
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE JsonArray createNestedArray(TKey* key) const;
|
|
|
+ FORCE_INLINE ArrayRef createNestedArray(TKey* key) const;
|
|
|
|
|
|
- // Creates and adds a JsonObject.
|
|
|
+ // Creates and adds a ObjectRef.
|
|
|
//
|
|
|
- // JsonObject createNestedObject(TKey);
|
|
|
+ // ObjectRef createNestedObject(TKey);
|
|
|
// TKey = const std::string&, const String&
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE JsonObject createNestedObject(const TKey& key) const {
|
|
|
- return set(key).template to<JsonObject>();
|
|
|
+ FORCE_INLINE ObjectRef createNestedObject(const TKey& key) const {
|
|
|
+ return set(key).template to<ObjectRef>();
|
|
|
}
|
|
|
//
|
|
|
- // JsonObject createNestedObject(TKey);
|
|
|
+ // ObjectRef createNestedObject(TKey);
|
|
|
// TKey = char*, const char*, char[], const char[], const FlashStringHelper*
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE JsonObject createNestedObject(TKey* key) const {
|
|
|
- return set(key).template to<JsonObject>();
|
|
|
+ FORCE_INLINE ObjectRef createNestedObject(TKey* key) const {
|
|
|
+ return set(key).template to<ObjectRef>();
|
|
|
}
|
|
|
|
|
|
// Gets the value associated with the specified key.
|
|
|
@@ -190,39 +189,38 @@ class JsonObject : public JsonObjectProxy<JsonObjectData>, public Visitable {
|
|
|
// TValue get<TValue>(TKey) const;
|
|
|
// TKey = const std::string&, const String&
|
|
|
// TValue = bool, char, long, int, short, float, double,
|
|
|
- // std::string, String, JsonArray, JsonObject
|
|
|
+ // std::string, String, ArrayRef, ObjectRef
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE JsonVariant get(const TKey& key) const {
|
|
|
+ FORCE_INLINE VariantRef get(const TKey& key) const {
|
|
|
return get_impl(makeString(key));
|
|
|
}
|
|
|
//
|
|
|
// TValue get<TValue>(TKey) const;
|
|
|
// TKey = char*, const char*, const FlashStringHelper*
|
|
|
// TValue = bool, char, long, int, short, float, double,
|
|
|
- // std::string, String, JsonArray, JsonObject
|
|
|
+ // std::string, String, ArrayRef, ObjectRef
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE JsonVariant get(TKey* key) const {
|
|
|
+ FORCE_INLINE VariantRef get(TKey* key) const {
|
|
|
return get_impl(makeString(key));
|
|
|
}
|
|
|
|
|
|
// Gets or sets the value associated with the specified key.
|
|
|
//
|
|
|
- // JsonObjectSubscript operator[](TKey)
|
|
|
+ // ObjectSubscript operator[](TKey)
|
|
|
// TKey = const std::string&, const String&
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE JsonObjectSubscript<const TKey&> operator[](
|
|
|
- const TKey& key) const {
|
|
|
- return JsonObjectSubscript<const TKey&>(*this, key);
|
|
|
+ FORCE_INLINE ObjectSubscript<const TKey&> operator[](const TKey& key) const {
|
|
|
+ return ObjectSubscript<const TKey&>(*this, key);
|
|
|
}
|
|
|
//
|
|
|
- // JsonObjectSubscript operator[](TKey)
|
|
|
+ // ObjectSubscript operator[](TKey)
|
|
|
// TKey = char*, const char*, char[], const char[N], const FlashStringHelper*
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE JsonObjectSubscript<TKey*> operator[](TKey* key) const {
|
|
|
- return JsonObjectSubscript<TKey*>(*this, key);
|
|
|
+ FORCE_INLINE ObjectSubscript<TKey*> operator[](TKey* key) const {
|
|
|
+ return ObjectSubscript<TKey*>(*this, key);
|
|
|
}
|
|
|
|
|
|
- FORCE_INLINE bool operator==(JsonObject rhs) const {
|
|
|
+ FORCE_INLINE bool operator==(ObjectRef rhs) const {
|
|
|
return objectEquals(_data, rhs._data);
|
|
|
}
|
|
|
|
|
|
@@ -247,37 +245,37 @@ class JsonObject : public JsonObjectProxy<JsonObjectData>, public Visitable {
|
|
|
}
|
|
|
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE JsonVariant set(TKey* key) const {
|
|
|
+ FORCE_INLINE VariantRef set(TKey* key) const {
|
|
|
return set_impl(makeString(key));
|
|
|
}
|
|
|
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE JsonVariant set(const TKey& key) const {
|
|
|
+ FORCE_INLINE VariantRef set(const TKey& key) const {
|
|
|
return set_impl(makeString(key));
|
|
|
}
|
|
|
|
|
|
- FORCE_INLINE JsonVariant set(StringInMemoryPool key) const {
|
|
|
+ FORCE_INLINE VariantRef set(StringInMemoryPool key) const {
|
|
|
return set_impl(key);
|
|
|
}
|
|
|
|
|
|
- FORCE_INLINE JsonVariant set(ZeroTerminatedRamStringConst key) const {
|
|
|
+ FORCE_INLINE VariantRef set(ZeroTerminatedRamStringConst key) const {
|
|
|
return set_impl(key);
|
|
|
}
|
|
|
|
|
|
template <typename Visitor>
|
|
|
FORCE_INLINE void accept(Visitor& visitor) const {
|
|
|
- JsonObjectConst(_data).accept(visitor);
|
|
|
+ ObjectConstRef(_data).accept(visitor);
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
template <typename TStringRef>
|
|
|
- FORCE_INLINE JsonVariant get_impl(TStringRef key) const {
|
|
|
- return JsonVariant(_memoryPool, objectGet(_data, key));
|
|
|
+ FORCE_INLINE VariantRef get_impl(TStringRef key) const {
|
|
|
+ return VariantRef(_memoryPool, objectGet(_data, key));
|
|
|
}
|
|
|
|
|
|
template <typename TKey>
|
|
|
- FORCE_INLINE JsonVariant set_impl(TKey key) const {
|
|
|
- return JsonVariant(_memoryPool, objectSet(_data, key, _memoryPool));
|
|
|
+ FORCE_INLINE VariantRef set_impl(TKey key) const {
|
|
|
+ return VariantRef(_memoryPool, objectSet(_data, key, _memoryPool));
|
|
|
}
|
|
|
|
|
|
template <typename TStringRef>
|