/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* shared_ptr.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 #include #include namespace unstd { template class SharedPtr { template 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 _refs; T* _ptr; bits::RefCount* _ref; }; } #include #endif