forked from bblanchon/ArduinoJson
Rename SlotWithId
to Slot
This commit is contained in:
@ -97,17 +97,15 @@ class CollectionData {
|
||||
}
|
||||
|
||||
protected:
|
||||
void appendOne(SlotWithId<VariantData> slot,
|
||||
const ResourceManager* resources);
|
||||
void appendPair(SlotWithId<VariantData> key, SlotWithId<VariantData> value,
|
||||
void appendOne(Slot<VariantData> slot, const ResourceManager* resources);
|
||||
void appendPair(Slot<VariantData> key, Slot<VariantData> value,
|
||||
const ResourceManager* resources);
|
||||
|
||||
void removeOne(iterator it, ResourceManager* resources);
|
||||
void removePair(iterator it, ResourceManager* resources);
|
||||
|
||||
private:
|
||||
SlotWithId<VariantData> getPreviousSlot(VariantData*,
|
||||
const ResourceManager*) const;
|
||||
Slot<VariantData> getPreviousSlot(VariantData*, const ResourceManager*) const;
|
||||
};
|
||||
|
||||
inline const VariantData* collectionToVariant(
|
||||
|
@ -30,7 +30,7 @@ inline CollectionData::iterator CollectionData::createIterator(
|
||||
return iterator(resources->getVariant(head_), head_);
|
||||
}
|
||||
|
||||
inline void CollectionData::appendOne(SlotWithId<VariantData> slot,
|
||||
inline void CollectionData::appendOne(Slot<VariantData> slot,
|
||||
const ResourceManager* resources) {
|
||||
if (tail_ != NULL_SLOT) {
|
||||
auto tail = resources->getVariant(tail_);
|
||||
@ -42,8 +42,8 @@ inline void CollectionData::appendOne(SlotWithId<VariantData> slot,
|
||||
}
|
||||
}
|
||||
|
||||
inline void CollectionData::appendPair(SlotWithId<VariantData> key,
|
||||
SlotWithId<VariantData> value,
|
||||
inline void CollectionData::appendPair(Slot<VariantData> key,
|
||||
Slot<VariantData> value,
|
||||
const ResourceManager* resources) {
|
||||
key->setNext(value.id());
|
||||
|
||||
@ -63,22 +63,22 @@ inline void CollectionData::clear(ResourceManager* resources) {
|
||||
auto currId = next;
|
||||
auto slot = resources->getVariant(next);
|
||||
next = slot->next();
|
||||
resources->freeVariant(SlotWithId<VariantData>(slot, currId));
|
||||
resources->freeVariant({slot, currId});
|
||||
}
|
||||
|
||||
head_ = NULL_SLOT;
|
||||
tail_ = NULL_SLOT;
|
||||
}
|
||||
|
||||
inline SlotWithId<VariantData> CollectionData::getPreviousSlot(
|
||||
inline Slot<VariantData> CollectionData::getPreviousSlot(
|
||||
VariantData* target, const ResourceManager* resources) const {
|
||||
auto prev = SlotWithId<VariantData>();
|
||||
auto prev = Slot<VariantData>();
|
||||
auto currentId = head_;
|
||||
while (currentId != NULL_SLOT) {
|
||||
auto currentSlot = resources->getVariant(currentId);
|
||||
if (currentSlot == target)
|
||||
break;
|
||||
prev = SlotWithId<VariantData>(currentSlot, currentId);
|
||||
prev = Slot<VariantData>(currentSlot, currentId);
|
||||
currentId = currentSlot->next();
|
||||
}
|
||||
return prev;
|
||||
|
@ -15,15 +15,15 @@ using SlotCount = SlotId;
|
||||
const SlotId NULL_SLOT = SlotId(-1);
|
||||
|
||||
template <typename T>
|
||||
class SlotWithId {
|
||||
class Slot {
|
||||
public:
|
||||
SlotWithId() : slot_(nullptr), id_(NULL_SLOT) {}
|
||||
SlotWithId(T* slot, SlotId id) : slot_(slot), id_(id) {
|
||||
ARDUINOJSON_ASSERT((slot == nullptr) == (id == NULL_SLOT));
|
||||
Slot() : ptr_(nullptr), id_(NULL_SLOT) {}
|
||||
Slot(T* p, SlotId id) : ptr_(p), id_(id) {
|
||||
ARDUINOJSON_ASSERT((p == nullptr) == (id == NULL_SLOT));
|
||||
}
|
||||
|
||||
explicit operator bool() const {
|
||||
return slot_ != nullptr;
|
||||
return ptr_ != nullptr;
|
||||
}
|
||||
|
||||
SlotId id() const {
|
||||
@ -31,16 +31,16 @@ class SlotWithId {
|
||||
}
|
||||
|
||||
T* ptr() const {
|
||||
return slot_;
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
T* operator->() const {
|
||||
ARDUINOJSON_ASSERT(slot_ != nullptr);
|
||||
return slot_;
|
||||
ARDUINOJSON_ASSERT(ptr_ != nullptr);
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
private:
|
||||
T* slot_;
|
||||
T* ptr_;
|
||||
SlotId id_;
|
||||
};
|
||||
|
||||
@ -62,7 +62,7 @@ class MemoryPool {
|
||||
usage_ = 0;
|
||||
}
|
||||
|
||||
SlotWithId<T> allocSlot() {
|
||||
Slot<T> allocSlot() {
|
||||
if (!slots_)
|
||||
return {};
|
||||
if (usage_ >= capacity_)
|
||||
|
@ -79,7 +79,7 @@ class MemoryPoolList {
|
||||
return *this;
|
||||
}
|
||||
|
||||
SlotWithId<T> allocSlot(Allocator* allocator) {
|
||||
Slot<T> allocSlot(Allocator* allocator) {
|
||||
// try to allocate from free list
|
||||
if (freeList_ != NULL_SLOT) {
|
||||
return allocFromFreeList();
|
||||
@ -100,7 +100,7 @@ class MemoryPoolList {
|
||||
return allocFromLastPool();
|
||||
}
|
||||
|
||||
void freeSlot(SlotWithId<T> slot) {
|
||||
void freeSlot(Slot<T> slot) {
|
||||
reinterpret_cast<FreeSlot*>(slot.ptr())->next = freeList_;
|
||||
freeList_ = slot.id();
|
||||
}
|
||||
@ -149,7 +149,7 @@ class MemoryPoolList {
|
||||
}
|
||||
|
||||
private:
|
||||
SlotWithId<T> allocFromFreeList() {
|
||||
Slot<T> allocFromFreeList() {
|
||||
ARDUINOJSON_ASSERT(freeList_ != NULL_SLOT);
|
||||
auto id = freeList_;
|
||||
auto slot = getSlot(freeList_);
|
||||
@ -157,7 +157,7 @@ class MemoryPoolList {
|
||||
return {slot, id};
|
||||
}
|
||||
|
||||
SlotWithId<T> allocFromLastPool() {
|
||||
Slot<T> allocFromLastPool() {
|
||||
ARDUINOJSON_ASSERT(count_ > 0);
|
||||
auto poolIndex = SlotId(count_ - 1);
|
||||
auto slot = pools_[poolIndex].allocSlot();
|
||||
|
@ -49,9 +49,9 @@ class ResourceManager {
|
||||
return overflowed_;
|
||||
}
|
||||
|
||||
SlotWithId<VariantData> allocVariant();
|
||||
Slot<VariantData> allocVariant();
|
||||
|
||||
void freeVariant(SlotWithId<VariantData> slot);
|
||||
void freeVariant(Slot<VariantData> slot);
|
||||
|
||||
VariantData* getVariant(SlotId id) const;
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
inline SlotWithId<VariantData> ResourceManager::allocVariant() {
|
||||
inline Slot<VariantData> ResourceManager::allocVariant() {
|
||||
auto p = variantPools_.allocSlot(allocator_);
|
||||
if (!p) {
|
||||
overflowed_ = true;
|
||||
@ -19,7 +19,7 @@ inline SlotWithId<VariantData> ResourceManager::allocVariant() {
|
||||
return {new (p.ptr()) VariantData, p.id()};
|
||||
}
|
||||
|
||||
inline void ResourceManager::freeVariant(SlotWithId<VariantData> variant) {
|
||||
inline void ResourceManager::freeVariant(Slot<VariantData> variant) {
|
||||
variant->setNull(this);
|
||||
variantPools_.freeSlot(variant);
|
||||
}
|
||||
|
Reference in New Issue
Block a user