mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 08:48:30 +01:00
Extracted VariantData and CollectionData classes
This commit is contained in:
@@ -12,10 +12,10 @@ class ArduinoString {
|
||||
public:
|
||||
ArduinoString(const ::String& str) : _str(&str) {}
|
||||
|
||||
char* save(MemoryPool* memoryPool) const {
|
||||
char* save(MemoryPool* pool) const {
|
||||
if (isNull()) return NULL;
|
||||
size_t n = _str->length() + 1;
|
||||
char* dup = memoryPool->allocFrozenString(n);
|
||||
char* dup = pool->allocFrozenString(n);
|
||||
if (dup) memcpy(dup, _str->c_str(), n);
|
||||
return dup;
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ class FixedSizeFlashString {
|
||||
return !_str;
|
||||
}
|
||||
|
||||
char* save(MemoryPool* memoryPool) const {
|
||||
char* save(MemoryPool* pool) const {
|
||||
if (!_str) return NULL;
|
||||
char* dup = memoryPool->allocFrozenString(_size);
|
||||
char* dup = pool->allocFrozenString(_size);
|
||||
if (!dup) memcpy_P(dup, (const char*)_str, _size);
|
||||
return dup;
|
||||
}
|
||||
|
||||
@@ -22,10 +22,9 @@ class FixedSizeRamString {
|
||||
return !_str;
|
||||
}
|
||||
|
||||
template <typename TMemoryPool>
|
||||
char* save(TMemoryPool* memoryPool) const {
|
||||
char* save(MemoryPool* pool) const {
|
||||
if (!_str) return NULL;
|
||||
char* dup = memoryPool->allocFrozenString(_size);
|
||||
char* dup = pool->allocFrozenString(_size);
|
||||
if (dup) memcpy(dup, _str, _size);
|
||||
return dup;
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ class StlString {
|
||||
public:
|
||||
StlString(const std::string& str) : _str(&str) {}
|
||||
|
||||
char* save(MemoryPool* memoryPool) const {
|
||||
char* save(MemoryPool* pool) const {
|
||||
size_t n = _str->length() + 1;
|
||||
char* dup = memoryPool->allocFrozenString(n);
|
||||
char* dup = pool->allocFrozenString(n);
|
||||
if (dup) memcpy(dup, _str->c_str(), n);
|
||||
return dup;
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string.h>
|
||||
#include "../Memory/MemoryPool.hpp"
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class StringInMemoryPool {
|
||||
public:
|
||||
StringInMemoryPool(char* s = 0) : _value(s) {}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
if (!_value) return expected == 0;
|
||||
const char* actual = _value;
|
||||
if (actual == expected) return true;
|
||||
return strcmp(actual, expected) == 0;
|
||||
}
|
||||
|
||||
char* save(void*) {
|
||||
return _value;
|
||||
}
|
||||
|
||||
bool isNull() const {
|
||||
return !_value;
|
||||
}
|
||||
|
||||
const char* c_str() const {
|
||||
return _value;
|
||||
}
|
||||
|
||||
protected:
|
||||
char* _value;
|
||||
};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Memory/MemoryPool.hpp"
|
||||
#include "../Polyfills/type_traits.hpp"
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
@@ -18,7 +19,6 @@ struct IsString<T&> : IsString<T> {};
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
||||
#include "FixedSizeRamString.hpp"
|
||||
#include "StringInMemoryPool.hpp"
|
||||
#include "ZeroTerminatedRamString.hpp"
|
||||
#include "ZeroTerminatedRamStringConst.hpp"
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ class ZeroTerminatedFlashString {
|
||||
return !_str;
|
||||
}
|
||||
|
||||
char* save(MemoryPool* memoryPool) const {
|
||||
char* save(MemoryPool* pool) const {
|
||||
if (!_str) return NULL;
|
||||
size_t n = size() + 1; // copy the terminator
|
||||
char* dup = memoryPool->allocFrozenString(n);
|
||||
char* dup = pool->allocFrozenString(n);
|
||||
if (dup) memcpy_P(dup, reinterpret_cast<const char*>(_str), n);
|
||||
return dup;
|
||||
}
|
||||
|
||||
@@ -13,11 +13,10 @@ class ZeroTerminatedRamString : public ZeroTerminatedRamStringConst {
|
||||
ZeroTerminatedRamString(const char* str)
|
||||
: ZeroTerminatedRamStringConst(str) {}
|
||||
|
||||
template <typename TMemoryPool>
|
||||
char* save(TMemoryPool* memoryPool) const {
|
||||
char* save(MemoryPool* pool) const {
|
||||
if (!_str) return NULL;
|
||||
size_t n = size() + 1;
|
||||
char* dup = memoryPool->allocFrozenString(n);
|
||||
char* dup = pool->allocFrozenString(n);
|
||||
if (dup) memcpy(dup, _str, n);
|
||||
return dup;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user