(Component) Added clone virtual method
Replaced Component<C>::GetId by GetComponentId<C>() Former-commit-id: 4fae3f73c7fad0a5c36dae16e49b6f12c8bf6ae2
This commit is contained in:
parent
8b77825fb8
commit
9c0c991fe0
|
|
@ -17,6 +17,8 @@ namespace Ndk
|
|||
BaseComponent(nzUInt32 componentId);
|
||||
virtual ~BaseComponent();
|
||||
|
||||
virtual BaseComponent* Clone() const = 0;
|
||||
|
||||
nzUInt32 GetComponentId() const;
|
||||
|
||||
static nzUInt32 GetNextId();
|
||||
|
|
|
|||
|
|
@ -19,8 +19,11 @@ namespace Ndk
|
|||
Component();
|
||||
virtual ~Component();
|
||||
|
||||
static nzUInt32 GetId();
|
||||
virtual BaseComponent* Clone() const override;
|
||||
};
|
||||
|
||||
template<typename ComponentType>
|
||||
constexpr nzUInt32 GetComponentId();
|
||||
}
|
||||
|
||||
#include <NDK/Component.inl>
|
||||
|
|
|
|||
|
|
@ -2,11 +2,13 @@
|
|||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
template<typename ComponentType>
|
||||
Component<ComponentType>::Component() :
|
||||
BaseComponent(GetId())
|
||||
BaseComponent(GetComponentId<ComponentType>())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -14,7 +16,15 @@ namespace Ndk
|
|||
Component<ComponentType>::~Component() = default;
|
||||
|
||||
template<typename ComponentType>
|
||||
nzUInt32 Component<ComponentType>::GetId()
|
||||
virtual BaseComponent* Component<ComponentType>::Clone() const
|
||||
{
|
||||
static_assert<std::is_trivially_copy_constructible<ComponentType>::value, "ComponentType should be copy-constructible">
|
||||
|
||||
return new ComponentType(static_cast<ComponentType&>(*this));
|
||||
}
|
||||
|
||||
template<typename ComponentType>
|
||||
constexpr nzUInt32 GetComponentId()
|
||||
{
|
||||
return ComponentType::ComponentId;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue