From 5b6427dde0bb8e3b466793243bbfc185f4739ac6 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 14 Mar 2022 14:13:54 +0100 Subject: refactor: implement & use shared ptr --- src/common/memory/shared_ptr.hpp | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/common/memory/shared_ptr.hpp (limited to 'src/common/memory/shared_ptr.hpp') diff --git a/src/common/memory/shared_ptr.hpp b/src/common/memory/shared_ptr.hpp new file mode 100644 index 0000000..7e8a910 --- /dev/null +++ b/src/common/memory/shared_ptr.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include + +namespace common +{ +template +class SharedPtr +{ +public: + SharedPtr() noexcept; + SharedPtr(nullptr_t) noexcept; // NOLINT(google-explicit-constructor) + + explicit SharedPtr(Target *target) noexcept; + + SharedPtr(const SharedPtr &shared_ptr) noexcept; + + SharedPtr(SharedPtr &&shared_ptr) noexcept; + + ~SharedPtr() noexcept; + + [[nodiscard]] unsigned int reference_cnt() const noexcept; + + [[nodiscard]] bool is_disposable() const noexcept; + + SharedPtr &operator=(const SharedPtr &rhs) noexcept; + + SharedPtr &operator=(SharedPtr &&rhs) noexcept; + + Target &operator*() const noexcept; + Target *operator->() const noexcept; + +private: + Target *_target = nullptr; + + unsigned int *_reference_cnt; +}; + +template +SharedPtr make_shared(Args &&...args) noexcept; + +} // namespace common + +#include "shared_ptr.tpp" -- cgit v1.2.3-18-g5258