// Copyright (C) 2015 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 namespace Nz { template class HandledObject; template class ObjectHandle { friend HandledObject; public: ObjectHandle(); explicit ObjectHandle(T* object); ObjectHandle(const ObjectHandle& handle); 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); Nz::String ToString() const; operator bool() const; operator T*() const; T* operator->() const; ObjectHandle& operator=(T* object); ObjectHandle& operator=(const ObjectHandle& handle); ObjectHandle& operator=(ObjectHandle&& handle) noexcept; static const ObjectHandle InvalidHandle; protected: void OnObjectDestroyed(); void OnObjectMoved(T* newObject); T* m_object; }; 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 struct PointedType> { typedef T type; }; template struct PointedType> { typedef T type; }; } namespace std { template void swap(Nz::ObjectHandle& lhs, Nz::ObjectHandle& rhs); } #include #endif // NAZARA_OBJECTHANDLE_HPP