mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Reduced executable size
This commit is contained in:
		| @@ -15,7 +15,7 @@ namespace Internals { | ||||
| // Used by List<T> and its iterators. | ||||
| template <typename T> | ||||
| struct ListNode : public Internals::JsonBufferAllocated { | ||||
|   ListNode() throw() : next(NULL) {} | ||||
|   ListNode() NOEXCEPT : next(NULL) {} | ||||
|  | ||||
|   ListNode<T> *next; | ||||
|   T content; | ||||
|   | ||||
| @@ -21,10 +21,11 @@ class JsonArray { | ||||
|  public: | ||||
|   typedef JsonArrayIterator iterator; | ||||
|  | ||||
|   JsonArray() : _buffer(0), _data(0) {} | ||||
|   explicit JsonArray(Internals::JsonBuffer* buf, Internals::JsonArrayData* arr) | ||||
|   FORCE_INLINE JsonArray() : _buffer(0), _data(0) {} | ||||
|   FORCE_INLINE JsonArray(Internals::JsonBuffer* buf, | ||||
|                          Internals::JsonArrayData* arr) | ||||
|       : _buffer(buf), _data(arr) {} | ||||
|   explicit JsonArray(Internals::JsonBuffer* buf) | ||||
|   FORCE_INLINE explicit JsonArray(Internals::JsonBuffer* buf) | ||||
|       : _buffer(buf), _data(new (buf) Internals::JsonArrayData()) {} | ||||
|  | ||||
|   // Adds the specified value at the end of the array. | ||||
| @@ -33,29 +34,29 @@ class JsonArray { | ||||
|   // TValue = bool, long, int, short, float, double, serialized, JsonVariant, | ||||
|   //          std::string, String, JsonArrayData, JsonObject | ||||
|   template <typename T> | ||||
|   bool add(const T& value) { | ||||
|   FORCE_INLINE bool add(const T& value) { | ||||
|     return add_impl<const T&>(value); | ||||
|   } | ||||
|   // | ||||
|   // bool add(TValue); | ||||
|   // TValue = char*, const char*, const FlashStringHelper* | ||||
|   template <typename T> | ||||
|   bool add(T* value) { | ||||
|   FORCE_INLINE bool add(T* value) { | ||||
|     return add_impl<T*>(value); | ||||
|   } | ||||
|  | ||||
|   iterator begin() const { | ||||
|   FORCE_INLINE iterator begin() const { | ||||
|     if (!_data) return iterator(); | ||||
|     return iterator(_buffer, _data->begin()); | ||||
|   } | ||||
|  | ||||
|   iterator end() const { | ||||
|   FORCE_INLINE iterator end() const { | ||||
|     return iterator(); | ||||
|   } | ||||
|  | ||||
|   // Imports a 1D array | ||||
|   template <typename T, size_t N> | ||||
|   bool copyFrom(T (&array)[N]) { | ||||
|   FORCE_INLINE bool copyFrom(T (&array)[N]) { | ||||
|     return copyFrom(array, N); | ||||
|   } | ||||
|  | ||||
| @@ -84,7 +85,7 @@ class JsonArray { | ||||
|  | ||||
|   // Exports a 1D array | ||||
|   template <typename T, size_t N> | ||||
|   size_t copyTo(T (&array)[N]) const { | ||||
|   FORCE_INLINE size_t copyTo(T (&array)[N]) const { | ||||
|     return copyTo(array, N); | ||||
|   } | ||||
|  | ||||
| @@ -106,39 +107,41 @@ class JsonArray { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   JsonArray createNestedArray(); | ||||
|   JsonObject createNestedObject(); | ||||
|   FORCE_INLINE JsonArray createNestedArray(); | ||||
|   FORCE_INLINE JsonObject createNestedObject(); | ||||
|  | ||||
|   Internals::JsonArraySubscript operator[](size_t index); | ||||
|   FORCE_INLINE Internals::JsonArraySubscript operator[](size_t index); | ||||
|  | ||||
|   const Internals::JsonArraySubscript operator[](size_t index) const; | ||||
|   FORCE_INLINE const Internals::JsonArraySubscript operator[]( | ||||
|       size_t index) const; | ||||
|  | ||||
|   bool operator==(const JsonArray& rhs) const { | ||||
|   FORCE_INLINE bool operator==(const JsonArray& rhs) const { | ||||
|     return _data == rhs._data; | ||||
|   } | ||||
|  | ||||
|   // Gets the value at the specified index. | ||||
|   template <typename T> | ||||
|   typename Internals::JsonVariantAs<T>::type get(size_t index) const { | ||||
|   FORCE_INLINE typename Internals::JsonVariantAs<T>::type get( | ||||
|       size_t index) const { | ||||
|     iterator it = begin() += index; | ||||
|     return it != end() ? it->as<T>() : T(); | ||||
|   } | ||||
|  | ||||
|   // Check the type of the value at specified index. | ||||
|   template <typename T> | ||||
|   bool is(size_t index) const { | ||||
|   FORCE_INLINE bool is(size_t index) const { | ||||
|     iterator it = begin() += index; | ||||
|     return it != end() ? it->is<T>() : false; | ||||
|   } | ||||
|  | ||||
|   // Removes element at specified position. | ||||
|   void remove(iterator it) { | ||||
|   FORCE_INLINE void remove(iterator it) { | ||||
|     if (!_data) return; | ||||
|     _data->remove(it.internal()); | ||||
|   } | ||||
|  | ||||
|   // Removes element at specified index. | ||||
|   void remove(size_t index) { | ||||
|   FORCE_INLINE void remove(size_t index) { | ||||
|     remove(begin() += index); | ||||
|   } | ||||
|  | ||||
| @@ -148,7 +151,7 @@ class JsonArray { | ||||
|   // TValue = bool, long, int, short, float, double, serialized, JsonVariant, | ||||
|   //          std::string, String, JsonArrayData, JsonObject | ||||
|   template <typename T> | ||||
|   bool set(size_t index, const T& value) { | ||||
|   FORCE_INLINE bool set(size_t index, const T& value) { | ||||
|     if (!_data) return false; | ||||
|     return set_impl<const T&>(index, value); | ||||
|   } | ||||
| @@ -156,22 +159,22 @@ class JsonArray { | ||||
|   // bool add(size_t index, TValue); | ||||
|   // TValue = char*, const char*, const FlashStringHelper* | ||||
|   template <typename T> | ||||
|   bool set(size_t index, T* value) { | ||||
|   FORCE_INLINE bool set(size_t index, T* value) { | ||||
|     if (!_data) return false; | ||||
|     return set_impl<T*>(index, value); | ||||
|   } | ||||
|  | ||||
|   size_t size() const { | ||||
|   FORCE_INLINE size_t size() const { | ||||
|     if (!_data) return 0; | ||||
|     return _data->size(); | ||||
|   } | ||||
|  | ||||
|   bool isNull() const { | ||||
|   FORCE_INLINE bool isNull() const { | ||||
|     return _data == 0; | ||||
|   } | ||||
|  | ||||
|   template <typename Visitor> | ||||
|   void visit(Visitor& visitor) const { | ||||
|   FORCE_INLINE void visit(Visitor& visitor) const { | ||||
|     if (_data) | ||||
|       visitor.acceptArray(*_data); | ||||
|     else | ||||
| @@ -180,14 +183,14 @@ class JsonArray { | ||||
|  | ||||
|  private: | ||||
|   template <typename TValueRef> | ||||
|   bool set_impl(size_t index, TValueRef value) { | ||||
|   FORCE_INLINE bool set_impl(size_t index, TValueRef value) { | ||||
|     iterator it = begin() += index; | ||||
|     if (it == end()) return false; | ||||
|     return it->set(value); | ||||
|   } | ||||
|  | ||||
|   template <typename TValueRef> | ||||
|   bool add_impl(TValueRef value) { | ||||
|   FORCE_INLINE bool add_impl(TValueRef value) { | ||||
|     if (!_data) return false; | ||||
|     iterator it = iterator(_buffer, _data->add(_buffer)); | ||||
|     if (it == end()) return false; | ||||
|   | ||||
| @@ -16,14 +16,14 @@ class JsonObject { | ||||
|  public: | ||||
|   typedef JsonObjectIterator iterator; | ||||
|  | ||||
|   JsonObject() : _buffer(0), _data(0) {} | ||||
|   explicit JsonObject(Internals::JsonBuffer* buf, | ||||
|                       Internals::JsonObjectData* object) | ||||
|   FORCE_INLINE JsonObject() : _buffer(0), _data(0) {} | ||||
|   FORCE_INLINE JsonObject(Internals::JsonBuffer* buf, | ||||
|                           Internals::JsonObjectData* object) | ||||
|       : _buffer(buf), _data(object) {} | ||||
|   explicit JsonObject(Internals::JsonBuffer* buf) | ||||
|   FORCE_INLINE explicit JsonObject(Internals::JsonBuffer* buf) | ||||
|       : _buffer(buf), _data(new (buf) Internals::JsonObjectData()) {} | ||||
|  | ||||
|   iterator begin() const { | ||||
|   FORCE_INLINE iterator begin() const { | ||||
|     if (!_data) return iterator(); | ||||
|     return iterator(_buffer, _data->begin()); | ||||
|   } | ||||
| @@ -33,18 +33,18 @@ class JsonObject { | ||||
|   // bool containsKey(TKey); | ||||
|   // TKey = const std::string&, const String& | ||||
|   template <typename TString> | ||||
|   bool containsKey(const TString& key) const { | ||||
|   FORCE_INLINE bool containsKey(const TString& key) const { | ||||
|     return containsKey_impl<const TString&>(key); | ||||
|   } | ||||
|   // | ||||
|   // bool containsKey(TKey); | ||||
|   // TKey = char*, const char*, char[], const char[], const FlashStringHelper* | ||||
|   template <typename TString> | ||||
|   bool containsKey(TString* key) const { | ||||
|   FORCE_INLINE bool containsKey(TString* key) const { | ||||
|     return containsKey_impl<TString*>(key); | ||||
|   } | ||||
|  | ||||
|   iterator end() const { | ||||
|   FORCE_INLINE iterator end() const { | ||||
|     return iterator(); | ||||
|   } | ||||
|  | ||||
| @@ -53,18 +53,18 @@ class JsonObject { | ||||
|   // JsonArray createNestedArray(TKey); | ||||
|   // TKey = const std::string&, const String& | ||||
|   template <typename TString> | ||||
|   JsonArray createNestedArray(const TString& key); | ||||
|   FORCE_INLINE JsonArray createNestedArray(const TString& key); | ||||
|   // JsonArray createNestedArray(TKey); | ||||
|   // TKey = char*, const char*, char[], const char[], const FlashStringHelper* | ||||
|   template <typename TString> | ||||
|   JsonArray createNestedArray(TString* key); | ||||
|   FORCE_INLINE JsonArray createNestedArray(TString* key); | ||||
|  | ||||
|   // Creates and adds a JsonObject. | ||||
|   // | ||||
|   // JsonObject createNestedObject(TKey); | ||||
|   // TKey = const std::string&, const String& | ||||
|   template <typename TString> | ||||
|   JsonObject createNestedObject(const TString& key) { | ||||
|   FORCE_INLINE JsonObject createNestedObject(const TString& key) { | ||||
|     if (!_data) return JsonObject(); | ||||
|     return createNestedObject_impl<const TString&>(key); | ||||
|   } | ||||
| @@ -72,7 +72,7 @@ class JsonObject { | ||||
|   // JsonObject createNestedObject(TKey); | ||||
|   // TKey = char*, const char*, char[], const char[], const FlashStringHelper* | ||||
|   template <typename TString> | ||||
|   JsonObject createNestedObject(TString* key) { | ||||
|   FORCE_INLINE JsonObject createNestedObject(TString* key) { | ||||
|     return createNestedObject_impl<TString*>(key); | ||||
|   } | ||||
|  | ||||
| @@ -83,7 +83,7 @@ class JsonObject { | ||||
|   // TValue = bool, char, long, int, short, float, double, | ||||
|   //          std::string, String, JsonArray, JsonObject | ||||
|   template <typename TValue, typename TString> | ||||
|   typename Internals::JsonVariantAs<TValue>::type get( | ||||
|   FORCE_INLINE typename Internals::JsonVariantAs<TValue>::type get( | ||||
|       const TString& key) const { | ||||
|     return get_impl<const TString&, TValue>(key); | ||||
|   } | ||||
| @@ -93,7 +93,8 @@ class JsonObject { | ||||
|   // TValue = bool, char, long, int, short, float, double, | ||||
|   //          std::string, String, JsonArray, JsonObject | ||||
|   template <typename TValue, typename TString> | ||||
|   typename Internals::JsonVariantAs<TValue>::type get(TString* key) const { | ||||
|   FORCE_INLINE typename Internals::JsonVariantAs<TValue>::type get( | ||||
|       TString* key) const { | ||||
|     return get_impl<TString*, TValue>(key); | ||||
|   } | ||||
|  | ||||
| @@ -105,7 +106,7 @@ class JsonObject { | ||||
|   // TValue = bool, char, long, int, short, float, double, | ||||
|   //          std::string, String, JsonArray, JsonObject | ||||
|   template <typename TValue, typename TString> | ||||
|   bool is(const TString& key) const { | ||||
|   FORCE_INLINE bool is(const TString& key) const { | ||||
|     return is_impl<const TString&, TValue>(key); | ||||
|   } | ||||
|   // | ||||
| @@ -114,7 +115,7 @@ class JsonObject { | ||||
|   // TValue = bool, char, long, int, short, float, double, | ||||
|   //          std::string, String, JsonArray, JsonObject | ||||
|   template <typename TValue, typename TString> | ||||
|   bool is(TString* key) const { | ||||
|   FORCE_INLINE bool is(TString* key) const { | ||||
|     return is_impl<TString*, TValue>(key); | ||||
|   } | ||||
|  | ||||
| @@ -123,7 +124,7 @@ class JsonObject { | ||||
|   // JsonObjectSubscript operator[](TKey) | ||||
|   // TKey = const std::string&, const String& | ||||
|   template <typename TString> | ||||
|   Internals::JsonObjectSubscript<const TString&> operator[]( | ||||
|   FORCE_INLINE Internals::JsonObjectSubscript<const TString&> operator[]( | ||||
|       const TString& key) { | ||||
|     return Internals::JsonObjectSubscript<const TString&>(*this, key); | ||||
|   } | ||||
| @@ -131,7 +132,8 @@ class JsonObject { | ||||
|   // JsonObjectSubscript operator[](TKey) | ||||
|   // TKey = char*, const char*, char[], const char[N], const FlashStringHelper* | ||||
|   template <typename TString> | ||||
|   Internals::JsonObjectSubscript<TString*> operator[](TString* key) { | ||||
|   FORCE_INLINE Internals::JsonObjectSubscript<TString*> operator[]( | ||||
|       TString* key) { | ||||
|     return Internals::JsonObjectSubscript<TString*>(*this, key); | ||||
|   } | ||||
|  | ||||
| @@ -140,7 +142,7 @@ class JsonObject { | ||||
|   // const JsonObjectSubscript operator[](TKey) const; | ||||
|   // TKey = const std::string&, const String& | ||||
|   template <typename TString> | ||||
|   const Internals::JsonObjectSubscript<const TString&> operator[]( | ||||
|   FORCE_INLINE const Internals::JsonObjectSubscript<const TString&> operator[]( | ||||
|       const TString& key) const { | ||||
|     return Internals::JsonObjectSubscript<const TString&>(*this, key); | ||||
|   } | ||||
| @@ -148,16 +150,16 @@ class JsonObject { | ||||
|   // const JsonObjectSubscript operator[](TKey) const; | ||||
|   // TKey = const char*, const char[N], const FlashStringHelper* | ||||
|   template <typename TString> | ||||
|   const Internals::JsonObjectSubscript<TString*> operator[]( | ||||
|   FORCE_INLINE const Internals::JsonObjectSubscript<TString*> operator[]( | ||||
|       TString* key) const { | ||||
|     return Internals::JsonObjectSubscript<TString*>(*this, key); | ||||
|   } | ||||
|  | ||||
|   bool operator==(const JsonObject& rhs) const { | ||||
|   FORCE_INLINE bool operator==(const JsonObject& rhs) const { | ||||
|     return _data == rhs._data; | ||||
|   } | ||||
|  | ||||
|   void remove(iterator it) { | ||||
|   FORCE_INLINE void remove(iterator it) { | ||||
|     if (!_data) return; | ||||
|     _data->remove(it.internal()); | ||||
|   } | ||||
| @@ -167,14 +169,14 @@ class JsonObject { | ||||
|   // void remove(TKey); | ||||
|   // TKey = const std::string&, const String& | ||||
|   template <typename TString> | ||||
|   void remove(const TString& key) { | ||||
|   FORCE_INLINE void remove(const TString& key) { | ||||
|     remove_impl<const TString&>(key); | ||||
|   } | ||||
|   // | ||||
|   // void remove(TKey); | ||||
|   // TKey = char*, const char*, char[], const char[], const FlashStringHelper* | ||||
|   template <typename TString> | ||||
|   void remove(TString* key) { | ||||
|   FORCE_INLINE void remove(TString* key) { | ||||
|     remove_impl<TString*>(key); | ||||
|   } | ||||
|  | ||||
| @@ -185,7 +187,7 @@ class JsonObject { | ||||
|   // TValue = bool, long, int, short, float, double, serialized, JsonVariant, | ||||
|   //          std::string, String, JsonArray, JsonObject | ||||
|   template <typename TValue, typename TString> | ||||
|   bool set(const TString& key, const TValue& value) { | ||||
|   FORCE_INLINE bool set(const TString& key, const TValue& value) { | ||||
|     return set_impl<const TString&, const TValue&>(key, value); | ||||
|   } | ||||
|   // | ||||
| @@ -193,7 +195,7 @@ class JsonObject { | ||||
|   // TKey = const std::string&, const String& | ||||
|   // TValue = char*, const char*, const FlashStringHelper* | ||||
|   template <typename TValue, typename TString> | ||||
|   bool set(const TString& key, TValue* value) { | ||||
|   FORCE_INLINE bool set(const TString& key, TValue* value) { | ||||
|     return set_impl<const TString&, TValue*>(key, value); | ||||
|   } | ||||
|   // | ||||
| @@ -202,7 +204,7 @@ class JsonObject { | ||||
|   // TValue = bool, long, int, short, float, double, serialized, JsonVariant, | ||||
|   //          std::string, String, JsonArray, JsonObject | ||||
|   template <typename TValue, typename TString> | ||||
|   bool set(TString* key, const TValue& value) { | ||||
|   FORCE_INLINE bool set(TString* key, const TValue& value) { | ||||
|     return set_impl<TString*, const TValue&>(key, value); | ||||
|   } | ||||
|   // | ||||
| @@ -210,21 +212,21 @@ class JsonObject { | ||||
|   // TKey = char*, const char*, const FlashStringHelper* | ||||
|   // TValue = char*, const char*, const FlashStringHelper* | ||||
|   template <typename TValue, typename TString> | ||||
|   bool set(TString* key, TValue* value) { | ||||
|   FORCE_INLINE bool set(TString* key, TValue* value) { | ||||
|     return set_impl<TString*, TValue*>(key, value); | ||||
|   } | ||||
|  | ||||
|   size_t size() const { | ||||
|   FORCE_INLINE size_t size() const { | ||||
|     if (!_data) return 0; | ||||
|     return _data->size(); | ||||
|   } | ||||
|  | ||||
|   bool isNull() const { | ||||
|   FORCE_INLINE bool isNull() const { | ||||
|     return _data == 0; | ||||
|   } | ||||
|  | ||||
|   template <typename Visitor> | ||||
|   void visit(Visitor& visitor) const { | ||||
|   FORCE_INLINE void visit(Visitor& visitor) const { | ||||
|     if (_data) | ||||
|       visitor.acceptObject(*_data); | ||||
|     else | ||||
| @@ -233,15 +235,15 @@ class JsonObject { | ||||
|  | ||||
|  private: | ||||
|   template <typename TStringRef> | ||||
|   bool containsKey_impl(TStringRef key) const { | ||||
|   FORCE_INLINE bool containsKey_impl(TStringRef key) const { | ||||
|     return findKey<TStringRef>(key) != _data->end(); | ||||
|   } | ||||
|  | ||||
|   template <typename TStringRef> | ||||
|   JsonArray createNestedArray_impl(TStringRef key); | ||||
|   FORCE_INLINE JsonArray createNestedArray_impl(TStringRef key); | ||||
|  | ||||
|   template <typename TStringRef> | ||||
|   JsonObject createNestedObject_impl(TStringRef key); | ||||
|   FORCE_INLINE JsonObject createNestedObject_impl(TStringRef key); | ||||
|  | ||||
|   // Returns the list node that matches the specified key. | ||||
|   template <typename TStringRef> | ||||
| @@ -254,12 +256,12 @@ class JsonObject { | ||||
|     return it; | ||||
|   } | ||||
|   template <typename TStringRef> | ||||
|   internal_iterator findKey(TStringRef key) const { | ||||
|   FORCE_INLINE internal_iterator findKey(TStringRef key) const { | ||||
|     return const_cast<JsonObject*>(this)->findKey<TStringRef>(key); | ||||
|   } | ||||
|  | ||||
|   template <typename TStringRef, typename TValue> | ||||
|   typename Internals::JsonVariantAs<TValue>::type get_impl( | ||||
|   FORCE_INLINE typename Internals::JsonVariantAs<TValue>::type get_impl( | ||||
|       TStringRef key) const { | ||||
|     internal_iterator it = findKey<TStringRef>(key); | ||||
|     return it != _data->end() ? JsonVariant(_buffer, &it->value).as<TValue>() | ||||
| @@ -267,20 +269,20 @@ class JsonObject { | ||||
|   } | ||||
|  | ||||
|   template <typename TStringRef, typename TValue> | ||||
|   bool is_impl(TStringRef key) const { | ||||
|   FORCE_INLINE bool is_impl(TStringRef key) const { | ||||
|     internal_iterator it = findKey<TStringRef>(key); | ||||
|     return it != _data->end() ? JsonVariant(_buffer, &it->value).is<TValue>() | ||||
|                               : false; | ||||
|   } | ||||
|  | ||||
|   template <typename TStringRef> | ||||
|   void remove_impl(TStringRef key) { | ||||
|   FORCE_INLINE void remove_impl(TStringRef key) { | ||||
|     if (!_data) return; | ||||
|     _data->remove(findKey<TStringRef>(key)); | ||||
|   } | ||||
|  | ||||
|   template <typename TStringRef, typename TValueRef> | ||||
|   bool set_impl(TStringRef key, TValueRef value) { | ||||
|   FORCE_INLINE bool set_impl(TStringRef key, TValueRef value) { | ||||
|     if (!_data) return false; | ||||
|  | ||||
|     // ignore null key | ||||
| @@ -300,13 +302,13 @@ class JsonObject { | ||||
|     return JsonVariant(_buffer, &it->value).set(value); | ||||
|   } | ||||
|  | ||||
|   bool set_key(internal_iterator& it, const char* key) { | ||||
|   FORCE_INLINE bool set_key(internal_iterator& it, const char* key) { | ||||
|     it->key = key; | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
|   template <typename T> | ||||
|   bool set_key(internal_iterator& it, const T& key) { | ||||
|   FORCE_INLINE bool set_key(internal_iterator& it, const T& key) { | ||||
|     const char* dup = Internals::makeString(key).save(_buffer); | ||||
|     if (!dup) return false; | ||||
|     it->key = dup; | ||||
|   | ||||
| @@ -31,15 +31,15 @@ class JsonObject; | ||||
| class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|  public: | ||||
|   // Intenal use only | ||||
|   explicit JsonVariant(Internals::JsonBuffer *buffer, | ||||
|                        Internals::JsonVariantData *data) | ||||
|   FORCE_INLINE JsonVariant(Internals::JsonBuffer *buffer, | ||||
|                            Internals::JsonVariantData *data) | ||||
|       : _buffer(buffer), _data(data) {} | ||||
|  | ||||
|   // Creates an uninitialized JsonVariant | ||||
|   JsonVariant() : _buffer(0), _data(0) {} | ||||
|   FORCE_INLINE JsonVariant() : _buffer(0), _data(0) {} | ||||
|  | ||||
|   // set(bool value) | ||||
|   bool set(bool value) { | ||||
|   FORCE_INLINE bool set(bool value) { | ||||
|     if (!_data) return false; | ||||
|     _data->setBoolean(value); | ||||
|     return true; | ||||
| @@ -48,8 +48,9 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // set(double value); | ||||
|   // set(float value); | ||||
|   template <typename T> | ||||
|   bool set(T value, typename Internals::enable_if< | ||||
|                         Internals::is_floating_point<T>::value>::type * = 0) { | ||||
|   FORCE_INLINE bool set( | ||||
|       T value, typename Internals::enable_if< | ||||
|                    Internals::is_floating_point<T>::value>::type * = 0) { | ||||
|     if (!_data) return false; | ||||
|     _data->setFloat(static_cast<Internals::JsonFloat>(value)); | ||||
|     return true; | ||||
| @@ -61,10 +62,11 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // set(signed long) | ||||
|   // set(signed char) | ||||
|   template <typename T> | ||||
|   bool set(T value, | ||||
|            typename Internals::enable_if<Internals::is_integral<T>::value && | ||||
|                                          Internals::is_signed<T>::value>::type | ||||
|                * = 0) { | ||||
|   FORCE_INLINE bool set( | ||||
|       T value, | ||||
|       typename Internals::enable_if<Internals::is_integral<T>::value && | ||||
|                                     Internals::is_signed<T>::value>::type * = | ||||
|           0) { | ||||
|     if (!_data) return false; | ||||
|     if (value >= 0) | ||||
|       _data->setPostiveInteger(static_cast<Internals::JsonUInt>(value)); | ||||
| @@ -77,17 +79,18 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // set(unsigned int) | ||||
|   // set(unsigned long) | ||||
|   template <typename T> | ||||
|   bool set(T value, | ||||
|            typename Internals::enable_if<Internals::is_integral<T>::value && | ||||
|                                          Internals::is_unsigned<T>::value>::type | ||||
|                * = 0) { | ||||
|   FORCE_INLINE bool set( | ||||
|       T value, | ||||
|       typename Internals::enable_if<Internals::is_integral<T>::value && | ||||
|                                     Internals::is_unsigned<T>::value>::type * = | ||||
|           0) { | ||||
|     if (!_data) return false; | ||||
|     _data->setPostiveInteger(static_cast<Internals::JsonUInt>(value)); | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
|   // set(SerializedValue<const char *>) | ||||
|   bool set(Internals::SerializedValue<const char *> value) { | ||||
|   FORCE_INLINE bool set(Internals::SerializedValue<const char *> value) { | ||||
|     if (!_data) return false; | ||||
|     _data->setRaw(value.data(), value.size()); | ||||
|     return true; | ||||
| @@ -97,9 +100,10 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // set(SerializedValue<String>) | ||||
|   // set(SerializedValue<const __FlashStringHelper*>) | ||||
|   template <typename T> | ||||
|   bool set(Internals::SerializedValue<T> value, | ||||
|            typename Internals::enable_if< | ||||
|                !Internals::is_same<const char *, T>::value>::type * = 0) { | ||||
|   FORCE_INLINE bool set( | ||||
|       Internals::SerializedValue<T> value, | ||||
|       typename Internals::enable_if< | ||||
|           !Internals::is_same<const char *, T>::value>::type * = 0) { | ||||
|     if (!_data) return false; | ||||
|     const char *dup = | ||||
|         Internals::makeString(value.data(), value.size()).save(_buffer); | ||||
| @@ -113,9 +117,10 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // set(const std::string&) | ||||
|   // set(const String&) | ||||
|   template <typename T> | ||||
|   bool set(const T &value, | ||||
|            typename Internals::enable_if<Internals::IsString<T>::value>::type | ||||
|                * = 0) { | ||||
|   FORCE_INLINE bool set( | ||||
|       const T &value, | ||||
|       typename Internals::enable_if<Internals::IsString<T>::value>::type * = | ||||
|           0) { | ||||
|     if (!_data) return false; | ||||
|     const char *dup = Internals::makeString(value).save(_buffer); | ||||
|     if (dup) { | ||||
| @@ -129,9 +134,10 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|  | ||||
|   // set(char*) | ||||
|   template <typename T> | ||||
|   bool set(T *value, | ||||
|            typename Internals::enable_if<Internals::IsString<T *>::value>::type | ||||
|                * = 0) { | ||||
|   FORCE_INLINE bool set( | ||||
|       T *value, | ||||
|       typename Internals::enable_if<Internals::IsString<T *>::value>::type * = | ||||
|           0) { | ||||
|     if (!_data) return false; | ||||
|     const char *dup = Internals::makeString(value).save(_buffer); | ||||
|     if (dup) { | ||||
| @@ -144,13 +150,13 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   } | ||||
|  | ||||
|   // set(const char*); | ||||
|   bool set(const char *value) { | ||||
|   FORCE_INLINE bool set(const char *value) { | ||||
|     if (!_data) return false; | ||||
|     _data->setString(value); | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
|   bool set(const JsonVariant &value) { | ||||
|   FORCE_INLINE bool set(const JsonVariant &value) { | ||||
|     if (!_data) return false; | ||||
|     if (value._data) | ||||
|       *_data = *value._data; | ||||
| @@ -159,11 +165,11 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
|   bool set(const JsonArray &array); | ||||
|   bool set(const Internals::JsonArraySubscript &); | ||||
|   bool set(const JsonObject &object); | ||||
|   FORCE_INLINE bool set(const JsonArray &array); | ||||
|   FORCE_INLINE bool set(const Internals::JsonArraySubscript &); | ||||
|   FORCE_INLINE bool set(const JsonObject &object); | ||||
|   template <typename TString> | ||||
|   bool set(const Internals::JsonObjectSubscript<TString> &); | ||||
|   FORCE_INLINE bool set(const Internals::JsonObjectSubscript<TString> &); | ||||
|  | ||||
|   // Get the variant as the specified type. | ||||
|   // | ||||
| @@ -177,14 +183,15 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // unsigned int as<unsigned int>() const; | ||||
|   // unsigned long as<unsigned long>() const; | ||||
|   template <typename T> | ||||
|   const typename Internals::enable_if<Internals::is_integral<T>::value, T>::type | ||||
|   FORCE_INLINE const typename Internals::enable_if< | ||||
|       Internals::is_integral<T>::value, T>::type | ||||
|   as() const { | ||||
|     return _data ? _data->asInteger<T>() : T(); | ||||
|   } | ||||
|   // bool as<bool>() const | ||||
|   template <typename T> | ||||
|   const typename Internals::enable_if<Internals::is_same<T, bool>::value, | ||||
|                                       T>::type | ||||
|   FORCE_INLINE const typename Internals::enable_if< | ||||
|       Internals::is_same<T, bool>::value, T>::type | ||||
|   as() const { | ||||
|     return _data && _data->asInteger<int>() != 0; | ||||
|   } | ||||
| @@ -192,8 +199,8 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // double as<double>() const; | ||||
|   // float as<float>() const; | ||||
|   template <typename T> | ||||
|   const typename Internals::enable_if<Internals::is_floating_point<T>::value, | ||||
|                                       T>::type | ||||
|   FORCE_INLINE const typename Internals::enable_if< | ||||
|       Internals::is_floating_point<T>::value, T>::type | ||||
|   as() const { | ||||
|     return _data ? _data->asFloat<T>() : 0; | ||||
|   } | ||||
| @@ -201,9 +208,10 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // const char* as<const char*>() const; | ||||
|   // const char* as<char*>() const; | ||||
|   template <typename T> | ||||
|   typename Internals::enable_if<Internals::is_same<T, const char *>::value || | ||||
|                                     Internals::is_same<T, char *>::value, | ||||
|                                 const char *>::type | ||||
|   FORCE_INLINE typename Internals::enable_if< | ||||
|       Internals::is_same<T, const char *>::value || | ||||
|           Internals::is_same<T, char *>::value, | ||||
|       const char *>::type | ||||
|   as() const { | ||||
|     return _data ? _data->asString() : 0; | ||||
|   } | ||||
| @@ -211,8 +219,10 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // std::string as<std::string>() const; | ||||
|   // String as<String>() const; | ||||
|   template <typename T> | ||||
|   typename Internals::enable_if<Internals::IsWriteableString<T>::value, T>::type | ||||
|   as() const { | ||||
|   FORCE_INLINE | ||||
|       typename Internals::enable_if<Internals::IsWriteableString<T>::value, | ||||
|                                     T>::type | ||||
|       as() const { | ||||
|     const char *cstr = _data ? _data->asString() : 0; | ||||
|     if (cstr) return T(cstr); | ||||
|     T s; | ||||
| @@ -223,7 +233,7 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // JsonArray as<JsonArray>() const; | ||||
|   // const JsonArray as<const JsonArray>() const; | ||||
|   template <typename T> | ||||
|   typename Internals::enable_if< | ||||
|   FORCE_INLINE typename Internals::enable_if< | ||||
|       Internals::is_same<typename Internals::remove_const<T>::type, | ||||
|                          JsonArray>::value, | ||||
|       JsonArray>::type | ||||
| @@ -232,7 +242,7 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // JsonObject as<JsonObject>() const; | ||||
|   // const JsonObject as<const JsonObject>() const; | ||||
|   template <typename T> | ||||
|   typename Internals::enable_if< | ||||
|   FORCE_INLINE typename Internals::enable_if< | ||||
|       Internals::is_same<typename Internals::remove_const<T>::type, | ||||
|                          JsonObject>::value, | ||||
|       T>::type | ||||
| @@ -240,9 +250,10 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // | ||||
|   // JsonVariant as<JsonVariant> const; | ||||
|   template <typename T> | ||||
|   typename Internals::enable_if<Internals::is_same<T, JsonVariant>::value, | ||||
|                                 T>::type | ||||
|   as() const { | ||||
|   FORCE_INLINE | ||||
|       typename Internals::enable_if<Internals::is_same<T, JsonVariant>::value, | ||||
|                                     T>::type | ||||
|       as() const { | ||||
|     return *this; | ||||
|   } | ||||
|  | ||||
| @@ -259,7 +270,8 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // bool is<unsigned int>() const; | ||||
|   // bool is<unsigned long>() const; | ||||
|   template <typename T> | ||||
|   typename Internals::enable_if<Internals::is_integral<T>::value, bool>::type | ||||
|   FORCE_INLINE typename Internals::enable_if<Internals::is_integral<T>::value, | ||||
|                                              bool>::type | ||||
|   is() const { | ||||
|     return _data && _data->isInteger(); | ||||
|   } | ||||
| @@ -267,15 +279,17 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // bool is<double>() const; | ||||
|   // bool is<float>() const; | ||||
|   template <typename T> | ||||
|   typename Internals::enable_if<Internals::is_floating_point<T>::value, | ||||
|                                 bool>::type | ||||
|   is() const { | ||||
|   FORCE_INLINE | ||||
|       typename Internals::enable_if<Internals::is_floating_point<T>::value, | ||||
|                                     bool>::type | ||||
|       is() const { | ||||
|     return _data && _data->isFloat(); | ||||
|   } | ||||
|   // | ||||
|   // bool is<bool>() const | ||||
|   template <typename T> | ||||
|   typename Internals::enable_if<Internals::is_same<T, bool>::value, bool>::type | ||||
|   FORCE_INLINE typename Internals::enable_if<Internals::is_same<T, bool>::value, | ||||
|                                              bool>::type | ||||
|   is() const { | ||||
|     return _data && _data->isBoolean(); | ||||
|   } | ||||
| @@ -283,9 +297,10 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // bool is<const char*>() const; | ||||
|   // bool is<char*>() const; | ||||
|   template <typename T> | ||||
|   typename Internals::enable_if<Internals::is_same<T, const char *>::value || | ||||
|                                     Internals::is_same<T, char *>::value, | ||||
|                                 bool>::type | ||||
|   FORCE_INLINE typename Internals::enable_if< | ||||
|       Internals::is_same<T, const char *>::value || | ||||
|           Internals::is_same<T, char *>::value, | ||||
|       bool>::type | ||||
|   is() const { | ||||
|     return _data && _data->isString(); | ||||
|   } | ||||
| @@ -293,7 +308,7 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // bool is<JsonArray> const; | ||||
|   // bool is<const JsonArray> const; | ||||
|   template <typename T> | ||||
|   typename Internals::enable_if< | ||||
|   FORCE_INLINE typename Internals::enable_if< | ||||
|       Internals::is_same<typename Internals::remove_const<T>::type, | ||||
|                          JsonArray>::value, | ||||
|       bool>::type | ||||
| @@ -304,7 +319,7 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   // bool is<JsonObject> const; | ||||
|   // bool is<const JsonObject> const; | ||||
|   template <typename T> | ||||
|   typename Internals::enable_if< | ||||
|   FORCE_INLINE typename Internals::enable_if< | ||||
|       Internals::is_same<typename Internals::remove_const<T>::type, | ||||
|                          JsonObject>::value, | ||||
|       bool>::type | ||||
| @@ -313,12 +328,12 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> { | ||||
|   } | ||||
|  | ||||
|   // Returns true if the variant has a value | ||||
|   bool isNull() const { | ||||
|   FORCE_INLINE bool isNull() const { | ||||
|     return _data == 0 || _data->isNull(); | ||||
|   } | ||||
|  | ||||
|   template <typename Visitor> | ||||
|   void visit(Visitor &visitor) const { | ||||
|   FORCE_INLINE void visit(Visitor &visitor) const { | ||||
|     if (_data) | ||||
|       _data->visit(visitor); | ||||
|     else | ||||
|   | ||||
| @@ -11,12 +11,12 @@ namespace Internals { | ||||
|  | ||||
| class JsonBufferAllocated { | ||||
|  public: | ||||
|   void *operator new(size_t n, JsonBuffer *jsonBuffer) throw() { | ||||
|   void *operator new(size_t n, JsonBuffer *jsonBuffer) NOEXCEPT { | ||||
|     if (!jsonBuffer) return NULL; | ||||
|     return jsonBuffer->alloc(n); | ||||
|   } | ||||
|  | ||||
|   void operator delete(void *, JsonBuffer *)throw() {} | ||||
|   void operator delete(void *, JsonBuffer *)NOEXCEPT {} | ||||
| }; | ||||
| }  // namespace Internals | ||||
| }  // namespace ArduinoJson | ||||
|   | ||||
| @@ -27,3 +27,9 @@ | ||||
| #define DEPRECATED(msg) | ||||
|  | ||||
| #endif | ||||
|  | ||||
| #if __cplusplus >= 201103L | ||||
| #define NOEXCEPT noexcept | ||||
| #else | ||||
| #define NOEXCEPT throw() | ||||
| #endif | ||||
|   | ||||
		Reference in New Issue
	
	Block a user