Skip to content

Commit 693791c

Browse files
committed
ResourceManager: move out-of-class definitions back in the class
1 parent f7d444d commit 693791c

File tree

7 files changed

+34
-61
lines changed

7 files changed

+34
-61
lines changed

extras/tests/ResourceManager/clear.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// MIT License
44

55
#include <ArduinoJson/Memory/ResourceManager.hpp>
6-
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
76
#include <ArduinoJson/Strings/StringAdapters.hpp>
87
#include <catch.hpp>
98

extras/tests/ResourceManager/shrinkToFit.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// MIT License
44

55
#include <ArduinoJson/Memory/ResourceManager.hpp>
6-
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
76
#include <catch.hpp>
87

98
#include "Allocators.hpp"

extras/tests/ResourceManager/size.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// MIT License
44

55
#include <ArduinoJson/Memory/ResourceManager.hpp>
6-
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
76
#include <catch.hpp>
87

98
#include "Allocators.hpp"

extras/tests/ResourceManager/swap.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <ArduinoJson/Memory/Alignment.hpp>
66
#include <ArduinoJson/Memory/ResourceManager.hpp>
7-
#include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
87
#include <catch.hpp>
98

109
#include "Allocators.hpp"

src/ArduinoJson.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include "ArduinoJson/Array/ElementProxy.hpp"
4646
#include "ArduinoJson/Array/Utilities.hpp"
4747
#include "ArduinoJson/Collection/CollectionImpl.hpp"
48-
#include "ArduinoJson/Memory/ResourceManagerImpl.hpp"
4948
#include "ArduinoJson/Object/MemberProxy.hpp"
5049
#include "ArduinoJson/Object/ObjectImpl.hpp"
5150
#include "ArduinoJson/Variant/ConverterImpl.hpp"

src/ArduinoJson/Memory/ResourceManager.hpp

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,42 @@ class ResourceManager {
5555
return overflowed_;
5656
}
5757

58-
Slot<VariantData> allocVariant();
59-
void freeVariant(Slot<VariantData> slot);
60-
VariantData* getVariant(SlotId id) const;
58+
Slot<VariantData> allocVariant() {
59+
auto slot = variantPools_.allocSlot(allocator_);
60+
if (!slot) {
61+
overflowed_ = true;
62+
return {};
63+
}
64+
new (slot.ptr()) VariantData();
65+
return slot;
66+
}
67+
68+
void freeVariant(Slot<VariantData> slot) {
69+
variantPools_.freeSlot(slot);
70+
}
71+
72+
VariantData* getVariant(SlotId id) const {
73+
return variantPools_.getSlot(id);
74+
}
6175

6276
#if ARDUINOJSON_USE_8_BYTE_POOL
63-
Slot<EightByteValue> allocEightByte();
64-
void freeEightByte(SlotId slot);
65-
EightByteValue* getEightByte(SlotId id) const;
77+
Slot<EightByteValue> allocEightByte() {
78+
auto slot = eightBytePools_.allocSlot(allocator_);
79+
if (!slot) {
80+
overflowed_ = true;
81+
return {};
82+
}
83+
return slot;
84+
}
85+
86+
void freeEightByte(SlotId id) {
87+
auto p = getEightByte(id);
88+
eightBytePools_.freeSlot({p, id});
89+
}
90+
91+
EightByteValue* getEightByte(SlotId id) const {
92+
return eightBytePools_.getSlot(id);
93+
}
6694
#endif
6795

6896
template <typename TAdaptedString>

src/ArduinoJson/Memory/ResourceManagerImpl.hpp

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)