forked from bblanchon/ArduinoJson
ResourceManagerTests pass
This commit is contained in:
@ -274,9 +274,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_DOUBLE
|
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_DOUBLE
|
||||||
# define ARDUINOJSON_USE_8_BYTE_VALUES 1
|
# define ARDUINOJSON_USE_8_BYTE_POOL 1
|
||||||
#else
|
#else
|
||||||
# define ARDUINOJSON_USE_8_BYTE_VALUES 0
|
# define ARDUINOJSON_USE_8_BYTE_POOL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(nullptr)
|
#if defined(nullptr)
|
||||||
|
@ -39,7 +39,7 @@ class ResourceManager {
|
|||||||
swap(a.stringPool_, b.stringPool_);
|
swap(a.stringPool_, b.stringPool_);
|
||||||
swap(a.variantPools_, b.variantPools_);
|
swap(a.variantPools_, b.variantPools_);
|
||||||
swap(a.staticStringsPools_, b.staticStringsPools_);
|
swap(a.staticStringsPools_, b.staticStringsPools_);
|
||||||
swap(a.lgValuePools_, b.lgValuePools_);
|
swap(a.eightBytePools_, b.eightBytePools_);
|
||||||
swap_(a.allocator_, b.allocator_);
|
swap_(a.allocator_, b.allocator_);
|
||||||
swap_(a.overflowed_, b.overflowed_);
|
swap_(a.overflowed_, b.overflowed_);
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ class ResourceManager {
|
|||||||
void freeVariant(Slot<VariantData> slot);
|
void freeVariant(Slot<VariantData> slot);
|
||||||
VariantData* getVariant(SlotId id) const;
|
VariantData* getVariant(SlotId id) const;
|
||||||
|
|
||||||
#if ARDUINOJSON_USE_8_BYTE_VALUES
|
#if ARDUINOJSON_USE_8_BYTE_POOL
|
||||||
Slot<EightByteValue> allocEightByte();
|
Slot<EightByteValue> allocEightByte();
|
||||||
void freeEightByte(SlotId slot);
|
void freeEightByte(SlotId slot);
|
||||||
EightByteValue* getEightByte(SlotId id) const;
|
EightByteValue* getEightByte(SlotId id) const;
|
||||||
@ -132,16 +132,16 @@ class ResourceManager {
|
|||||||
variantPools_.clear(allocator_);
|
variantPools_.clear(allocator_);
|
||||||
stringPool_.clear(allocator_);
|
stringPool_.clear(allocator_);
|
||||||
staticStringsPools_.clear(allocator_);
|
staticStringsPools_.clear(allocator_);
|
||||||
#if ARDUINOJSON_USE_8_BYTE_VALUES
|
#if ARDUINOJSON_USE_8_BYTE_POOL
|
||||||
lgValuePools_.clear(allocator_);
|
eightBytePools_.clear(allocator_);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void shrinkToFit() {
|
void shrinkToFit() {
|
||||||
variantPools_.shrinkToFit(allocator_);
|
variantPools_.shrinkToFit(allocator_);
|
||||||
staticStringsPools_.shrinkToFit(allocator_);
|
staticStringsPools_.shrinkToFit(allocator_);
|
||||||
#if ARDUINOJSON_USE_8_BYTE_VALUES
|
#if ARDUINOJSON_USE_8_BYTE_POOL
|
||||||
lgValuePools_.shrinkToFit(allocator_);
|
eightBytePools_.shrinkToFit(allocator_);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ class ResourceManager {
|
|||||||
StringPool stringPool_;
|
StringPool stringPool_;
|
||||||
MemoryPoolList<SlotData> variantPools_;
|
MemoryPoolList<SlotData> variantPools_;
|
||||||
MemoryPoolList<const char*> staticStringsPools_;
|
MemoryPoolList<const char*> staticStringsPools_;
|
||||||
#if ARDUINOJSON_USE_8_BYTE_VALUES
|
#if ARDUINOJSON_USE_8_BYTE_POOL
|
||||||
MemoryPoolList<EightByteValue> eightBytePools_;
|
MemoryPoolList<EightByteValue> eightBytePools_;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -12,12 +12,13 @@
|
|||||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||||
|
|
||||||
inline Slot<VariantData> ResourceManager::allocVariant() {
|
inline Slot<VariantData> ResourceManager::allocVariant() {
|
||||||
auto p = variantPools_.allocSlot(allocator_);
|
auto slot = variantPools_.allocSlot(allocator_);
|
||||||
if (!p) {
|
if (!slot) {
|
||||||
overflowed_ = true;
|
overflowed_ = true;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return {new (&p->variant) VariantData, p.id()};
|
new (slot.ptr()) VariantData();
|
||||||
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ResourceManager::freeVariant(Slot<VariantData> variant) {
|
inline void ResourceManager::freeVariant(Slot<VariantData> variant) {
|
||||||
@ -29,7 +30,7 @@ inline VariantData* ResourceManager::getVariant(SlotId id) const {
|
|||||||
return reinterpret_cast<VariantData*>(variantPools_.getSlot(id));
|
return reinterpret_cast<VariantData*>(variantPools_.getSlot(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ARDUINOJSON_USE_8_BYTE_VALUES
|
#if ARDUINOJSON_USE_8_BYTE_POOL
|
||||||
inline Slot<EightByteValue> ResourceManager::allocEightByte() {
|
inline Slot<EightByteValue> ResourceManager::allocEightByte() {
|
||||||
auto slot = eightBytePools_.allocSlot(allocator_);
|
auto slot = eightBytePools_.allocSlot(allocator_);
|
||||||
if (!slot) {
|
if (!slot) {
|
||||||
@ -45,7 +46,7 @@ inline void ResourceManager::freeEightByte(SlotId id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline EightByteValue* ResourceManager::getEightByte(SlotId id) const {
|
inline EightByteValue* ResourceManager::getEightByte(SlotId id) const {
|
||||||
return eightBytePools_.getSlot(id).ptr();
|
return eightBytePools_.getSlot(id);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ union VariantContent {
|
|||||||
char asTinyString[tinyStringMaxLength + 1];
|
char asTinyString[tinyStringMaxLength + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
#if ARDUINOJSON_USE_8_BYTE_VALUES
|
#if ARDUINOJSON_USE_8_BYTE_POOL
|
||||||
union EightByteValue {
|
union EightByteValue {
|
||||||
# if ARDUINOJSON_USE_LONG_LONG
|
# if ARDUINOJSON_USE_LONG_LONG
|
||||||
uint64_t asUint64;
|
uint64_t asUint64;
|
||||||
|
@ -53,7 +53,7 @@ class VariantData {
|
|||||||
template <typename TVisitor>
|
template <typename TVisitor>
|
||||||
typename TVisitor::result_type accept(
|
typename TVisitor::result_type accept(
|
||||||
TVisitor& visit, const ResourceManager* resources) const {
|
TVisitor& visit, const ResourceManager* resources) const {
|
||||||
#if ARDUINOJSON_USE_EIGHT_BYTE_VALUES
|
#if ARDUINOJSON_USE_8_BYTE_POOL
|
||||||
auto eightByteValue = getEightByte(resources);
|
auto eightByteValue = getEightByte(resources);
|
||||||
#else
|
#else
|
||||||
(void)resources; // silence warning
|
(void)resources; // silence warning
|
||||||
@ -145,7 +145,7 @@ class VariantData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool asBoolean(const ResourceManager* resources) const {
|
bool asBoolean(const ResourceManager* resources) const {
|
||||||
#if ARDUINOJSON_USE_EIGHT_BYTE_VALUES
|
#if ARDUINOJSON_USE_8_BYTE_POOL
|
||||||
auto eightByteValue = getEightByte(resources);
|
auto eightByteValue = getEightByte(resources);
|
||||||
#else
|
#else
|
||||||
(void)resources; // silence warning
|
(void)resources; // silence warning
|
||||||
@ -193,7 +193,7 @@ class VariantData {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
T asFloat(const ResourceManager* resources) const {
|
T asFloat(const ResourceManager* resources) const {
|
||||||
static_assert(is_floating_point<T>::value, "T must be a floating point");
|
static_assert(is_floating_point<T>::value, "T must be a floating point");
|
||||||
#if ARDUINOJSON_USE_EIGHT_BYTE_VALUES
|
#if ARDUINOJSON_USE_8_BYTE_POOL
|
||||||
auto eightByteValue = getEightByte(resources);
|
auto eightByteValue = getEightByte(resources);
|
||||||
#else
|
#else
|
||||||
(void)resources; // silence warning
|
(void)resources; // silence warning
|
||||||
@ -238,7 +238,7 @@ class VariantData {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
T asIntegral(const ResourceManager* resources) const {
|
T asIntegral(const ResourceManager* resources) const {
|
||||||
static_assert(is_integral<T>::value, "T must be an integral type");
|
static_assert(is_integral<T>::value, "T must be an integral type");
|
||||||
#if ARDUINOJSON_USE_EIGHT_BYTE_VALUES
|
#if ARDUINOJSON_USE_8_BYTE_POOL
|
||||||
auto eightByteValue = getEightByte(resources);
|
auto eightByteValue = getEightByte(resources);
|
||||||
#else
|
#else
|
||||||
(void)resources; // silence warning
|
(void)resources; // silence warning
|
||||||
@ -314,7 +314,7 @@ class VariantData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ARDUINOJSON_USE_8_BYTE_VALUES
|
#if ARDUINOJSON_USE_8_BYTE_POOL
|
||||||
const EightByteValue* getEightByte(const ResourceManager* resources) const;
|
const EightByteValue* getEightByte(const ResourceManager* resources) const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ inline void VariantData::clear(ResourceManager* resources) {
|
|||||||
if (type_ & VariantTypeBits::OwnedStringBit)
|
if (type_ & VariantTypeBits::OwnedStringBit)
|
||||||
resources->dereferenceString(content_.asOwnedString->data);
|
resources->dereferenceString(content_.asOwnedString->data);
|
||||||
|
|
||||||
#if ARDUINOJSON_USE_EIGHT_BYTE_VALUES
|
#if ARDUINOJSON_USE_8_BYTE_POOL
|
||||||
if (type_ & VariantTypeBits::EightByteBit)
|
if (type_ & VariantTypeBits::EightByteBit)
|
||||||
resources->freeEightByte(content_.asSlotId);
|
resources->freeEightByte(content_.asSlotId);
|
||||||
#endif
|
#endif
|
||||||
@ -73,11 +73,11 @@ inline void VariantData::clear(ResourceManager* resources) {
|
|||||||
type_ = VariantType::Null;
|
type_ = VariantType::Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ARDUINOJSON_USE_EIGHT_BYTE_VALUES
|
#if ARDUINOJSON_USE_8_BYTE_POOL
|
||||||
inline const EightByteValue* VariantData::getEightByteValue(
|
inline const EightByteValue* VariantData::getEightByte(
|
||||||
const ResourceManager* resources) const {
|
const ResourceManager* resources) const {
|
||||||
return type_ & VariantTypeBits::EightByteBit
|
return type_ & VariantTypeBits::EightByteBit
|
||||||
? resources->getEightByteValue(content_.asSlotId)
|
? resources->getEightByte(content_.asSlotId)
|
||||||
: 0;
|
: 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user