summaryrefslogtreecommitdiff
path: root/src/common/memory
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/memory')
-rw-r--r--src/common/memory/shared_ptr.hpp44
-rw-r--r--src/common/memory/shared_ptr.tpp153
-rw-r--r--src/common/memory/unique_ptr.hpp37
-rw-r--r--src/common/memory/unique_ptr.tpp55
4 files changed, 0 insertions, 289 deletions
diff --git a/src/common/memory/shared_ptr.hpp b/src/common/memory/shared_ptr.hpp
deleted file mode 100644
index 7e8a910..0000000
--- a/src/common/memory/shared_ptr.hpp
+++ /dev/null
@@ -1,44 +0,0 @@
-#pragma once
-
-#include <stddef.h>
-
-namespace common
-{
-template <class Target>
-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 <typename Target, typename... Args>
-SharedPtr<Target> make_shared(Args &&...args) noexcept;
-
-} // namespace common
-
-#include "shared_ptr.tpp"
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
diff --git a/src/common/memory/unique_ptr.hpp b/src/common/memory/unique_ptr.hpp
deleted file mode 100644
index 94c02d0..0000000
--- a/src/common/memory/unique_ptr.hpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#pragma once
-
-namespace common
-{
-template <class Target>
-class UniquePtr
-{
-public:
- explicit UniquePtr() = default;
- explicit UniquePtr(Target *target);
-
- // Move constructor
- UniquePtr(UniquePtr &&unique_ptr) noexcept;
-
- // Move assignment operator
- UniquePtr &operator=(UniquePtr &&unique_ptr) noexcept;
-
- // Disable the copy constructor
- UniquePtr(const UniquePtr &unique_ptr) = delete;
-
- // Disable the copy assignment operator
- UniquePtr &operator=(const UniquePtr &unique_ptr) = delete;
-
- ~UniquePtr();
-
- Target operator*() const;
- Target *operator->() const;
-
-private:
- Target *_target = nullptr;
-};
-
-template <typename Target, typename... Args>
-UniquePtr<Target> make_unique(Args... args);
-} // namespace common
-
-#include "unique_ptr.tpp"
diff --git a/src/common/memory/unique_ptr.tpp b/src/common/memory/unique_ptr.tpp
deleted file mode 100644
index 3cab9ec..0000000
--- a/src/common/memory/unique_ptr.tpp
+++ /dev/null
@@ -1,55 +0,0 @@
-#pragma once
-
-#include "unique_ptr.hpp"
-
-namespace common
-{
-template <class Target>
-UniquePtr<Target>::UniquePtr(Target *target) : _target(target)
-{
-}
-
-template <class Target>
-UniquePtr<Target>::UniquePtr(UniquePtr &&unique_ptr) noexcept
- : _target(unique_ptr._target)
-{
- unique_ptr._target = nullptr;
-}
-
-template <class Target>
-UniquePtr<Target> &UniquePtr<Target>::operator=(UniquePtr &&unique_ptr) noexcept
-{
- if (&unique_ptr != this)
- {
- delete _target;
- _target = unique_ptr._target;
- unique_ptr._target = nullptr;
- }
-
- return *this;
-}
-
-template <class Target>
-UniquePtr<Target>::~UniquePtr()
-{
- delete _target;
-}
-
-template <class Target>
-Target UniquePtr<Target>::operator*() const
-{
- return *(_target);
-}
-
-template <class Target>
-Target *UniquePtr<Target>::operator->() const
-{
- return _target;
-}
-
-template <class Target, typename... Args>
-UniquePtr<Target> make_unique(Args... args)
-{
- return UniquePtr<Target>(new Target(args...));
-}
-} // namespace common