// Copyright (C) 2020 Jérôme Leclercq // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_OBJECTHANDLE_HPP #define NAZARA_OBJECTHANDLE_HPP #include #include #include #include #include namespace Nz { template class ObjectHandle { friend HandledObject; public: ObjectHandle(); explicit ObjectHandle(T* object); template ObjectHandle(const ObjectHandle& ref); template ObjectHandle(ObjectHandle&& ref); ObjectHandle(const ObjectHandle& handle) = default; ObjectHandle(ObjectHandle&& handle) noexcept; ~ObjectHandle(); T* GetObject() const; bool IsValid() const; void Reset(T* object = nullptr); void Reset(const ObjectHandle& handle); void Reset(ObjectHandle&& handle) noexcept; ObjectHandle& Swap(ObjectHandle& handle); std::string ToString() const; explicit operator bool() const; operator T*() const; T* operator->() const; ObjectHandle& operator=(T* object); ObjectHandle& operator=(const ObjectHandle& handle) = default; ObjectHandle& operator=(ObjectHandle&& handle) noexcept; static const ObjectHandle InvalidHandle; protected: std::shared_ptr m_handleData; }; template std::ostream& operator<<(std::ostream& out, const ObjectHandle& handle); template bool operator==(const ObjectHandle& lhs, const ObjectHandle& rhs); template bool operator==(const T& lhs, const ObjectHandle& rhs); template bool operator==(const ObjectHandle& lhs, const T& rhs); template bool operator!=(const ObjectHandle& lhs, const ObjectHandle& rhs); template bool operator!=(const T& lhs, const ObjectHandle& rhs); template bool operator!=(const ObjectHandle& lhs, const T& rhs); template bool operator<(const ObjectHandle& lhs, const ObjectHandle& rhs); template bool operator<(const T& lhs, const ObjectHandle& rhs); template bool operator<(const ObjectHandle& lhs, const T& rhs); template bool operator<=(const ObjectHandle&, const ObjectHandle& rhs); template bool operator<=(const T& lhs, const ObjectHandle& rhs); template bool operator<=(const ObjectHandle& lhs, const T& rhs); template bool operator>(const ObjectHandle& lhs, const ObjectHandle& rhs); template bool operator>(const T& lhs, const ObjectHandle& rhs); template bool operator>(const ObjectHandle& lhs, const T& rhs); template bool operator>=(const ObjectHandle& lhs, const ObjectHandle& rhs); template bool operator>=(const T& lhs, const ObjectHandle& rhs); template bool operator>=(const ObjectHandle& lhs, const T& rhs); template ObjectHandle ConstRefCast(const ObjectHandle& ref); template ObjectHandle DynamicRefCast(const ObjectHandle& ref); template ObjectHandle ReinterpretRefCast(const ObjectHandle& ref); template ObjectHandle StaticRefCast(const ObjectHandle& ref); template struct PointedType> { using type = T; }; template struct PointedType> { using type = T; }; } namespace std { template void swap(Nz::ObjectHandle& lhs, Nz::ObjectHandle& rhs); } #include #endif // NAZARA_OBJECTHANDLE_HPP