removed unnecesary includes

This commit is contained in:
2024-02-06 11:54:39 +01:00
parent 24462adbd5
commit 9f17fc58d6
4 changed files with 0 additions and 318 deletions

View File

@@ -1,55 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* unique_ptr.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/20 09:40:56 by maldavid #+# #+# */
/* Updated: 2024/01/20 19:12:51 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __UNSTD_UNIQUE_PTR__
#define __UNSTD_UNIQUE_PTR__
#include <cstddef>
namespace unstd
{
template <typename T>
class UniquePtr
{
public:
UniquePtr();
UniquePtr(UniquePtr& ptr);
explicit UniquePtr(T* ptr);
inline T* get();
inline void swap(const UniquePtr<T>& ptr);
inline void reset(T* ptr = NULL);
inline T* release();
inline operator bool() const;
inline UniquePtr& operator=(T* ptr);
inline T* operator->() const;
inline T& operator*() const;
~UniquePtr();
private:
UniquePtr(const UniquePtr& ptr);
inline UniquePtr& operator=(const UniquePtr& ptr);
private:
T* _ptr;
};
}
#include <unstd/unique_ptr.ipp>
#endif

View File

@@ -1,103 +0,0 @@
/* **************************************************************************** */
/* */
/* ::: :::::::: */
/* unique_ptr.tpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/20 09:53:45 by maldavid #+# #+# */
/* Updated: 2024/01/20 09:53:45 by maldavid ### ########.fr */
/* */
/* **************************************************************************** */
#include <cassert>
namespace unstd
{
template <typename T>
UniquePtr<T>::UniquePtr() : _ptr(NULL) {}
template <typename T>
UniquePtr<T>::UniquePtr(T* ptr) : _ptr(ptr) {}
template <typename T>
UniquePtr<T>::UniquePtr(UniquePtr<T>& rhs) : _ptr(rhs._ptr)
{
rhs._ptr = NULL;
}
template <typename T>
T* UniquePtr<T>::get()
{
return _ptr;
}
template <typename T>
void UniquePtr<T>::swap(const UniquePtr<T>& ptr)
{
T* temp = _ptr;
_ptr = ptr._ptr;
ptr._ptr = temp;
}
template <typename T>
void UniquePtr<T>::reset(T* ptr)
{
if(_ptr != NULL)
delete _ptr;
_ptr = ptr;
}
template <typename T>
T* UniquePtr<T>::release()
{
T* temp = _ptr;
_ptr = NULL;
return temp;
}
template <typename T>
UniquePtr<T>::operator bool() const
{
return _ptr != NULL;
}
template <typename T>
UniquePtr<T>& UniquePtr<T>::operator=(T* ptr)
{
assert(_ptr == NULL && "UniquePtr assertion failed : `operator=`, unique ptr already holds a pointer");
reset(ptr);
}
template <typename T>
T* UniquePtr<T>::operator->() const
{
return _ptr;
}
template <typename T>
T& UniquePtr<T>::operator*() const
{
return *_ptr;
}
template <typename T>
UniquePtr<T>::~UniquePtr()
{
if(_ptr != NULL)
delete _ptr;
}
template <typename T>
UniquePtr<T>::UniquePtr(const UniquePtr<T>& ptr)
{
(void)ptr;
}
template <typename T>
UniquePtr<T>& UniquePtr<T>::operator=(const UniquePtr& ptr)
{
(void)ptr;
return *this;
}
}

View File

@@ -1,51 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* weak_ptr.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/20 11:17:07 by maldavid #+# #+# */
/* Updated: 2024/01/20 19:13:13 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __UNSTD_WEAK_PTR__
#define __UNSTD_WEAK_PTR__
#include <unstd/bits/ref_counter.hpp>
#include <unstd/shared_ptr.hpp>
namespace unstd
{
template <typename T>
class WeakPtr
{
public:
WeakPtr();
WeakPtr(const WeakPtr& rhs);
WeakPtr(const SharedPtr<T>& shared);
WeakPtr& operator=(const WeakPtr& rhs);
WeakPtr& operator=(const SharedPtr<T>& shared);
void reset();
void swap(WeakPtr& rhs);
bool expired() const;
SharedPtr<T> lock() const;
~WeakPtr();
private:
void safeRelease();
private:
bits::RefCount* _ref;
T* _ptr;
};
}
#include <unstd/weak_ptr.ipp>
#endif

View File

@@ -1,109 +0,0 @@
/* **************************************************************************** */
/* */
/* ::: :::::::: */
/* weak_ptr.ipp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/20 12:58:44 by maldavid #+# #+# */
/* Updated: 2024/01/20 12:58:44 by maldavid ### ########.fr */
/* */
/* **************************************************************************** */
namespace unstd
{
template <typename T>
WeakPtr<T>::WeakPtr() : _ref(NULL), _ptr(NULL) {}
template <typename T>
WeakPtr<T>::WeakPtr(const WeakPtr<T>& rhs) : _ref(rhs._ref), _ptr(rhs._ptr)
{
if(_ptr && _ref)
_ref->weak++;
}
template <typename T>
WeakPtr<T>::WeakPtr(const SharedPtr<T>& shared) : _ref(shared._ref), _ptr(shared._ptr)
{
if(_ptr && _ref)
_ref->weak++;
}
template <typename T>
WeakPtr<T>& WeakPtr<T>::operator=(const WeakPtr<T>& rhs)
{
if(_ptr == rhs._ptr)
return *this;
safeRelease();
_ptr = rhs._ptr;
_ref = rhs._ref;
return *this;
}
template <typename T>
WeakPtr<T>& WeakPtr<T>::operator=(const SharedPtr<T>& shared)
{
if(_ptr == shared._ptr)
return *this;
safeRelease();
_ptr = shared._ptr;
_ref = shared._ref;
_ref->weak++;
return *this;
}
template <typename T>
void WeakPtr<T>::reset()
{
safeRelease();
_ptr = NULL;
_ref = NULL;
}
template <typename T>
void WeakPtr<T>::swap(WeakPtr<T>& rhs)
{
T* tmptr = _ptr;
bits::RefCount* tmpref = _ref;
_ptr = rhs._ptr;
_ref = rhs._ref;
rhs._ptr = tmptr;
rhs._ref = tmpref;
}
template <typename T>
bool WeakPtr<T>::expired() const
{
return (_ptr && _ref && _ref->shared > 0);
}
template <typename T>
SharedPtr<T> WeakPtr<T>::lock() const
{
return (expired() ? SharedPtr<T>() : SharedPtr<T>(_ptr));
}
template <typename T>
void WeakPtr<T>::safeRelease()
{
if(_ref == NULL)
return;
_ref->weak--;
if(_ref && _ref->shared <= 0)
{
delete _ptr;
_ptr = NULL;
delete _ref;
_ref = NULL;
}
}
template <typename T>
WeakPtr<T>::~WeakPtr()
{
if(_ptr && _ref && _ref->shared > 0)
safeRelease();
}
}