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