diff options
author | HampusM <hampus@hampusmat.com> | 2022-03-21 13:00:36 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-03-21 13:00:36 +0100 |
commit | 757a29d0137b974fff6ddcc945d76e69ae120ecb (patch) | |
tree | 1fff46951e30eeae0402e99070e60901bd104eea /src/common/memory/shared_ptr.tpp | |
parent | 12e3713e7705e4353d306ae2ec03abfe8fcd5f55 (diff) |
Diffstat (limited to 'src/common/memory/shared_ptr.tpp')
-rw-r--r-- | src/common/memory/shared_ptr.tpp | 153 |
1 files changed, 0 insertions, 153 deletions
diff --git a/src/common/memory/shared_ptr.tpp b/src/common/memory/shared_ptr.tpp deleted file mode 100644 index d9b57c3..0000000 --- a/src/common/memory/shared_ptr.tpp +++ /dev/null @@ -1,153 +0,0 @@ -#pragma once
-
-#include "shared_ptr.hpp"
-
-#include "common/memory.hpp"
-
-#include <stdlib.h>
-
-namespace common
-{
-
-template <class Target>
-SharedPtr<Target>::SharedPtr() noexcept
- : _reference_cnt(malloc_s<unsigned int>(sizeof(unsigned int)))
-{
- (*_reference_cnt) = 0;
-}
-
-template <class Target>
-SharedPtr<Target>::SharedPtr(nullptr_t) noexcept
- : _reference_cnt(malloc_s<unsigned int>(sizeof(unsigned int)))
-{
- (*_reference_cnt) = 0;
-}
-
-template <class Target>
-SharedPtr<Target>::SharedPtr(Target *target) noexcept
- : _target(target), _reference_cnt(malloc_s<unsigned int>(sizeof(unsigned int)))
-{
- (*_reference_cnt) = 0;
-}
-
-/**
- * Copy constructor
- */
-template <class Target>
-SharedPtr<Target>::SharedPtr(const SharedPtr &shared_ptr) noexcept
- : _target(shared_ptr._target), _reference_cnt(shared_ptr._reference_cnt)
-{
- (*_reference_cnt)++;
-}
-
-/**
- * Move constructor
- */
-template <class Target>
-SharedPtr<Target>::SharedPtr(SharedPtr &&shared_ptr) noexcept
- : _target(shared_ptr._target), _reference_cnt(shared_ptr._reference_cnt)
-{
- shared_ptr._target = nullptr;
-}
-
-template <class Target>
-SharedPtr<Target>::~SharedPtr() noexcept
-{
- if ((*_reference_cnt) != 0U)
- {
- (*_reference_cnt)--;
- }
-
- if ((*_reference_cnt) == 0U)
- {
- delete _target;
- free(_reference_cnt);
- _reference_cnt = nullptr;
- }
-}
-
-template <class Target>
-unsigned int SharedPtr<Target>::reference_cnt() const noexcept
-{
- if (_reference_cnt == nullptr)
- {
- return 0;
- }
-
- return *_reference_cnt;
-}
-
-template <class Target>
-bool SharedPtr<Target>::is_disposable() const noexcept
-{
- return _reference_cnt == nullptr || (*_reference_cnt) == 0U;
-}
-
-/**
- * Copy assignment operator
- */
-template <class Target>
-SharedPtr<Target> &SharedPtr<Target>::operator=(const SharedPtr &rhs) noexcept
-{
- if (&rhs != this)
- {
- if (is_disposable())
- {
- delete _target;
- free(_reference_cnt);
- }
-
- _target = nullptr;
- _target = rhs._target;
-
- _reference_cnt = nullptr;
- _reference_cnt = rhs._reference_cnt;
- (*_reference_cnt)++;
- }
-
- return *this;
-}
-
-/**
- * Move assignment operator
- */
-template <class Target>
-SharedPtr<Target> &SharedPtr<Target>::operator=(SharedPtr &&rhs) noexcept
-{
- if (&rhs != this)
- {
- if (is_disposable())
- {
- delete _target;
- free(_reference_cnt);
- }
-
- _target = rhs._target;
- rhs._target = nullptr;
-
- _reference_cnt = rhs._reference_cnt;
- rhs._reference_cnt = nullptr;
- }
-
- return *this;
-}
-
-template <class Target>
-Target &SharedPtr<Target>::operator*() const noexcept
-{
- return *(_target);
-}
-
-template <class Target>
-Target *SharedPtr<Target>::operator->() const noexcept
-{
- return _target;
-}
-
-template <class Target, typename... Args>
-SharedPtr<Target> make_shared(Args &&...args) noexcept
-{
- return SharedPtr<Target>(new Target(args...));
-}
-
-} // namespace common
|