ResourceManager: move out-of-class definitions back in the class

This commit is contained in:
Benoit Blanchon
2025-07-15 18:32:38 +02:00
parent 59573ac1f9
commit 43548db37d
7 changed files with 34 additions and 61 deletions

View File

@ -3,7 +3,6 @@
// MIT License
#include <ArduinoJson/Memory/ResourceManager.hpp>
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
#include <ArduinoJson/Strings/StringAdapters.hpp>
#include <catch.hpp>

View File

@ -3,7 +3,6 @@
// MIT License
#include <ArduinoJson/Memory/ResourceManager.hpp>
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
#include <catch.hpp>
#include "Allocators.hpp"

View File

@ -3,7 +3,6 @@
// MIT License
#include <ArduinoJson/Memory/ResourceManager.hpp>
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
#include <catch.hpp>
#include "Allocators.hpp"

View File

@ -4,7 +4,6 @@
#include <ArduinoJson/Memory/Alignment.hpp>
#include <ArduinoJson/Memory/ResourceManager.hpp>
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
#include <catch.hpp>
#include "Allocators.hpp"

View File

@ -45,7 +45,6 @@
#include "ArduinoJson/Array/ElementProxy.hpp"
#include "ArduinoJson/Array/Utilities.hpp"
#include "ArduinoJson/Collection/CollectionImpl.hpp"
#include "ArduinoJson/Memory/ResourceManagerImpl.hpp"
#include "ArduinoJson/Object/MemberProxy.hpp"
#include "ArduinoJson/Object/ObjectImpl.hpp"
#include "ArduinoJson/Variant/ConverterImpl.hpp"

View File

@ -57,14 +57,42 @@ class ResourceManager {
return overflowed_;
}
Slot<VariantData> allocVariant();
void freeVariant(Slot<VariantData> slot);
VariantData* getVariant(SlotId id) const;
Slot<VariantData> allocVariant() {
auto slot = variantPools_.allocSlot(allocator_);
if (!slot) {
overflowed_ = true;
return {};
}
new (slot.ptr()) VariantData();
return slot;
}
void freeVariant(Slot<VariantData> slot) {
variantPools_.freeSlot(slot);
}
VariantData* getVariant(SlotId id) const {
return variantPools_.getSlot(id);
}
#if ARDUINOJSON_USE_8_BYTE_POOL
Slot<EightByteValue> allocEightByte();
void freeEightByte(SlotId slot);
EightByteValue* getEightByte(SlotId id) const;
Slot<EightByteValue> allocEightByte() {
auto slot = eightBytePools_.allocSlot(allocator_);
if (!slot) {
overflowed_ = true;
return {};
}
return slot;
}
void freeEightByte(SlotId id) {
auto p = getEightByte(id);
eightBytePools_.freeSlot({p, id});
}
EightByteValue* getEightByte(SlotId id) const {
return eightBytePools_.getSlot(id);
}
#endif
template <typename TAdaptedString>

View File

@ -1,50 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2025, Benoit BLANCHON
// MIT License
#pragma once
#include <ArduinoJson/Memory/ResourceManager.hpp>
#include <ArduinoJson/Polyfills/alias_cast.hpp>
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
inline Slot<VariantData> ResourceManager::allocVariant() {
auto slot = variantPools_.allocSlot(allocator_);
if (!slot) {
overflowed_ = true;
return {};
}
new (slot.ptr()) VariantData();
return slot;
}
inline void ResourceManager::freeVariant(Slot<VariantData> slot) {
variantPools_.freeSlot(slot);
}
inline VariantData* ResourceManager::getVariant(SlotId id) const {
return reinterpret_cast<VariantData*>(variantPools_.getSlot(id));
}
#if ARDUINOJSON_USE_8_BYTE_POOL
inline Slot<EightByteValue> ResourceManager::allocEightByte() {
auto slot = eightBytePools_.allocSlot(allocator_);
if (!slot) {
overflowed_ = true;
return {};
}
return slot;
}
inline void ResourceManager::freeEightByte(SlotId id) {
auto p = getEightByte(id);
eightBytePools_.freeSlot({p, id});
}
inline EightByteValue* ResourceManager::getEightByte(SlotId id) const {
return eightBytePools_.getSlot(id);
}
#endif
ARDUINOJSON_END_PRIVATE_NAMESPACE