diff options
author | HampusM <hampus@hampusmat.com> | 2022-02-14 10:11:32 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-02-14 10:11:32 +0100 |
commit | 7892ef9d248c189be68ce7faf63230ec0a318b67 (patch) | |
tree | 7c3d07779d5ce96994f81c0cc22e8b667601ee9d /src/utils/memory.tpp | |
parent | a03dfe959fcafd238119bdf7f27c07b92064496e (diff) |
refactor: reorganize & add debugging
Diffstat (limited to 'src/utils/memory.tpp')
-rw-r--r-- | src/utils/memory.tpp | 48 |
1 files changed, 48 insertions, 0 deletions
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 <typename memType> +memType *malloc_s(unsigned int size) +{ + auto *mem = malloc(size); + + if (mem == nullptr) + { + Serial.println("Error: Memory allocation failed"); + while (true) {} + } + + return static_cast<memType *>(mem); +} + +template <class Target> +unique_ptr<Target>::unique_ptr(Target *target) +{ + this->_target = target; +} + +template <class Target> +unique_ptr<Target>::~unique_ptr() +{ + delete this->_target; +} + +template <class Target> +Target unique_ptr<Target>::operator*() const +{ + return *(this->_target); +} + +template <class Target> +Target *unique_ptr<Target>::operator->() const +{ + return this->_target; +} + +template <class Target, typename... Args> +unique_ptr<Target> make_unique(Args... args) +{ + return unique_ptr<Target>(new Target(args...)); +} |