mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-30 18:57:32 +02:00
ResourceManager: move out-of-class definitions back in the class
This commit is contained in:
@ -3,7 +3,6 @@
|
|||||||
// MIT License
|
// MIT License
|
||||||
|
|
||||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||||
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
|
|
||||||
#include <ArduinoJson/Strings/StringAdapters.hpp>
|
#include <ArduinoJson/Strings/StringAdapters.hpp>
|
||||||
#include <catch.hpp>
|
#include <catch.hpp>
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// MIT License
|
// MIT License
|
||||||
|
|
||||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||||
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
|
|
||||||
#include <catch.hpp>
|
#include <catch.hpp>
|
||||||
|
|
||||||
#include "Allocators.hpp"
|
#include "Allocators.hpp"
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// MIT License
|
// MIT License
|
||||||
|
|
||||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||||
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
|
|
||||||
#include <catch.hpp>
|
#include <catch.hpp>
|
||||||
|
|
||||||
#include "Allocators.hpp"
|
#include "Allocators.hpp"
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#include <ArduinoJson/Memory/Alignment.hpp>
|
#include <ArduinoJson/Memory/Alignment.hpp>
|
||||||
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
||||||
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
|
|
||||||
#include <catch.hpp>
|
#include <catch.hpp>
|
||||||
|
|
||||||
#include "Allocators.hpp"
|
#include "Allocators.hpp"
|
||||||
|
@ -45,7 +45,6 @@
|
|||||||
#include "ArduinoJson/Array/ElementProxy.hpp"
|
#include "ArduinoJson/Array/ElementProxy.hpp"
|
||||||
#include "ArduinoJson/Array/Utilities.hpp"
|
#include "ArduinoJson/Array/Utilities.hpp"
|
||||||
#include "ArduinoJson/Collection/CollectionImpl.hpp"
|
#include "ArduinoJson/Collection/CollectionImpl.hpp"
|
||||||
#include "ArduinoJson/Memory/ResourceManagerImpl.hpp"
|
|
||||||
#include "ArduinoJson/Object/MemberProxy.hpp"
|
#include "ArduinoJson/Object/MemberProxy.hpp"
|
||||||
#include "ArduinoJson/Object/ObjectImpl.hpp"
|
#include "ArduinoJson/Object/ObjectImpl.hpp"
|
||||||
#include "ArduinoJson/Variant/ConverterImpl.hpp"
|
#include "ArduinoJson/Variant/ConverterImpl.hpp"
|
||||||
|
@ -57,14 +57,42 @@ class ResourceManager {
|
|||||||
return overflowed_;
|
return overflowed_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Slot<VariantData> allocVariant();
|
Slot<VariantData> allocVariant() {
|
||||||
void freeVariant(Slot<VariantData> slot);
|
auto slot = variantPools_.allocSlot(allocator_);
|
||||||
VariantData* getVariant(SlotId id) const;
|
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
|
#if ARDUINOJSON_USE_8_BYTE_POOL
|
||||||
Slot<EightByteValue> allocEightByte();
|
Slot<EightByteValue> allocEightByte() {
|
||||||
void freeEightByte(SlotId slot);
|
auto slot = eightBytePools_.allocSlot(allocator_);
|
||||||
EightByteValue* getEightByte(SlotId id) const;
|
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
|
#endif
|
||||||
|
|
||||||
template <typename TAdaptedString>
|
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