Add generic handlers
Former-commit-id: 8fc343d3a056de8031cf453748b8801d50d3710e
This commit is contained in:
93
include/Nazara/Core/ObjectHandle.hpp
Normal file
93
include/Nazara/Core/ObjectHandle.hpp
Normal file
@@ -0,0 +1,93 @@
|
||||
// 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 <Nazara/Core/Algorithm.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename T> class HandledObject;
|
||||
|
||||
template<typename T>
|
||||
class ObjectHandle
|
||||
{
|
||||
friend HandledObject<T>;
|
||||
|
||||
public:
|
||||
ObjectHandle();
|
||||
explicit ObjectHandle(T* object);
|
||||
ObjectHandle(const ObjectHandle& handle);
|
||||
~ObjectHandle();
|
||||
|
||||
T* GetObject() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
void Reset(T* object = nullptr);
|
||||
void Reset(const ObjectHandle& handle);
|
||||
|
||||
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);
|
||||
|
||||
static const ObjectHandle InvalidHandle;
|
||||
|
||||
protected:
|
||||
void OnObjectDestroyed();
|
||||
void OnObjectMoved(T* newObject);
|
||||
|
||||
T* m_object;
|
||||
};
|
||||
|
||||
template<typename T> std::ostream& operator<<(std::ostream& out, const ObjectHandle<T>& handle);
|
||||
|
||||
template<typename T> bool operator==(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator==(const T& lhs, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator==(const ObjectHandle<T>& lhs, const T& rhs);
|
||||
|
||||
template<typename T> bool operator!=(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator!=(const T& lhs, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator!=(const ObjectHandle<T>& lhs, const T& rhs);
|
||||
|
||||
template<typename T> bool operator<(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator<(const T& lhs, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator<(const ObjectHandle<T>& lhs, const T& rhs);
|
||||
|
||||
template<typename T> bool operator<=(const ObjectHandle<T>, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator<=(const T& lhs, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator<=(const ObjectHandle<T>& lhs, const T& rhs);
|
||||
|
||||
template<typename T> bool operator>(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator>(const T& lhs, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator>(const ObjectHandle<T>& lhs, const T& rhs);
|
||||
|
||||
template<typename T> bool operator>=(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator>=(const T& lhs, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator>=(const ObjectHandle<T>& lhs, const T& rhs);
|
||||
|
||||
template<typename T> struct PointedType<ObjectHandle<T>> { typedef T type; };
|
||||
template<typename T> struct PointedType<const ObjectHandle<T>> { typedef T type; };
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<typename T>
|
||||
void swap(Nz::ObjectHandle<T>& lhs, Nz::ObjectHandle<T>& rhs);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/ObjectHandle.inl>
|
||||
|
||||
#endif // NAZARA_OBJECTHANDLE_HPP
|
||||
Reference in New Issue
Block a user