mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-29 10:17:39 +02:00
ResourceManager: move out-of-class definitions back in the class
This commit is contained in:
@ -3,7 +3,6 @@
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapters.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
|
@ -3,7 +3,6 @@
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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>
|
||||
|
@ -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
|
Reference in New Issue
Block a user