Ndk: Add EntityOwner class

Former-commit-id: ef7486e39124642cb1d1b8c24c4c726dc592486b
This commit is contained in:
Lynix
2015-12-18 13:27:09 +01:00
parent 39f2c4eb07
commit 26e7fa1686
4 changed files with 115 additions and 2 deletions

View File

@@ -0,0 +1,78 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <Nazara/Core/StringStream.hpp>
#include <functional>
#include <limits>
namespace Ndk
{
inline EntityOwner::EntityOwner(Entity* entity) :
EntityOwner()
{
Reset(entity);
}
inline EntityOwner::EntityOwner(const EntityOwner& handle) :
EntityHandle(handle)
{
}
inline EntityOwner::EntityOwner(EntityOwner&& handle) :
EntityHandle(std::move(handle))
{
}
inline EntityOwner::~EntityOwner()
{
Reset(nullptr);
}
inline void EntityOwner::Reset(Entity* entity)
{
if (m_entity)
m_entity->Kill();
EntityHandle::Reset(entity);
}
inline void EntityOwner::Reset(const EntityOwner& handle)
{
Reset(handle.GetEntity());
}
inline void EntityOwner::Reset(EntityOwner&& handle)
{
Reset(handle.GetEntity());
}
inline EntityOwner& EntityOwner::operator=(Entity* entity)
{
Reset(entity);
return *this;
}
inline EntityOwner& EntityOwner::operator=(const EntityOwner& handle)
{
Reset(handle);
return *this;
}
inline EntityOwner& EntityOwner::operator=(EntityOwner&& handle)
{
Reset(std::move(handle));
return *this;
}
}
namespace std
{
template<>
struct hash<Ndk::EntityOwner> : public hash<Ndk::EntityHandle>
{
};
}