Files
42_irc/includes/unstd/shared_ptr.h
2024-01-20 13:17:11 +01:00

55 lines
1.6 KiB
C++

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* shared_ptr.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/20 10:09:02 by maldavid #+# #+# */
/* Updated: 2024/01/20 13:08:04 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __UNSTD_SHARED_PTR__
#define __UNSTD_SHARED_PTR__
#include <unstd/bits/ref_counter.h>
#include <cstddef>
#include <map>
namespace unstd
{
template <typename T>
class SharedPtr
{
template <typename WT>
friend class WeakPtr;
public:
explicit SharedPtr(T* ptr = NULL);
SharedPtr(const SharedPtr& rhs);
SharedPtr& operator=(const SharedPtr& rhs);
operator bool() const;
bool operator==(const SharedPtr& rhs);
bool operator==(T* ptr);
T& operator*();
T* operator->();
T* get();
void swap(SharedPtr& rhs);
void reset(T* ptr = NULL);
~SharedPtr();
private:
void safeRelease();
private:
static std::map<void*, bits::RefCount*> _refs;
T* _ptr;
bits::RefCount* _ref;
};
}
#include <unstd/shared_ptr.ipp>
#endif