From bcdce9633dc351d3bc7f347a165348b8fab87cd9 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 15 Feb 2022 12:33:52 +0100 Subject: refactor: reorganize files & improve classes --- src/utils/memory.tpp | 93 ---------------------------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 src/utils/memory.tpp (limited to 'src/utils/memory.tpp') diff --git a/src/utils/memory.tpp b/src/utils/memory.tpp deleted file mode 100644 index 6261c81..0000000 --- a/src/utils/memory.tpp +++ /dev/null @@ -1,93 +0,0 @@ -#pragma once - -#include "general.hpp" - -#include - -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 -UniquePtr::UniquePtr() = default; - -template -UniquePtr::UniquePtr(Target *target) : _target(target) -{ -} - -template -UniquePtr::UniquePtr(const UniquePtr &unique_ptr) - : _target(new Target(*(unique_ptr._target))) -{ -} - -template -UniquePtr::UniquePtr(UniquePtr &&unique_ptr) noexcept - : _target(unique_ptr._target) -{ - unique_ptr._target = nullptr; -} - -template -UniquePtr &UniquePtr::operator=(const UniquePtr &unique_ptr) -{ - if (&unique_ptr != this) - { - delete _target; - _target = nullptr; - _target = new Target(*(unique_ptr._target)); - } - - return *this; -} - -template -UniquePtr &UniquePtr::operator=(UniquePtr &&unique_ptr) noexcept -{ - if (&unique_ptr != this) - { - delete _target; - _target = unique_ptr._target; - unique_ptr._target = nullptr; - } - - return *this; -} - -template -UniquePtr::~UniquePtr() -{ - if (this->_target != nullptr) - { - delete this->_target; - } -} - -template -Target UniquePtr::operator*() const -{ - return *(this->_target); -} - -template -Target *UniquePtr::operator->() const -{ - return this->_target; -} - -template -UniquePtr make_unique(Args... args) -{ - return UniquePtr(new Target(args...)); -} -- cgit v1.2.3-18-g5258