From 7892ef9d248c189be68ce7faf63230ec0a318b67 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 14 Feb 2022 10:11:32 +0100 Subject: refactor: reorganize & add debugging --- src/utils/memory.tpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/utils/memory.tpp (limited to 'src/utils/memory.tpp') diff --git a/src/utils/memory.tpp b/src/utils/memory.tpp new file mode 100644 index 0000000..276b0b4 --- /dev/null +++ b/src/utils/memory.tpp @@ -0,0 +1,48 @@ +#include "memory.hpp" + +#include "Arduino.h" +#include "general.hpp" + +template +memType *malloc_s(unsigned int size) +{ + auto *mem = malloc(size); + + if (mem == nullptr) + { + Serial.println("Error: Memory allocation failed"); + while (true) {} + } + + return static_cast(mem); +} + +template +unique_ptr::unique_ptr(Target *target) +{ + this->_target = target; +} + +template +unique_ptr::~unique_ptr() +{ + delete this->_target; +} + +template +Target unique_ptr::operator*() const +{ + return *(this->_target); +} + +template +Target *unique_ptr::operator->() const +{ + return this->_target; +} + +template +unique_ptr make_unique(Args... args) +{ + return unique_ptr(new Target(args...)); +} -- cgit v1.2.3-18-g5258