(NDK) Minor changes

Added some asserts and comments,


Former-commit-id: 805246f0276aac157c66cbf346c392ab57934e84
This commit is contained in:
Lynix
2015-03-30 04:36:56 +02:00
parent 6d1ac4fe18
commit 1903cbda8d
3 changed files with 21 additions and 12 deletions

View File

@@ -2,6 +2,7 @@
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <Nazara/Core/Error.hpp>
#include <Ndk/Algorithm.hpp>
#include <type_traits>
@@ -20,9 +21,13 @@ namespace Ndk
template<typename ComponentType, unsigned int N>
ComponentIndex BaseComponent::Register(const char (&name)[N])
{
// Il faut que notre composant possède un constructeur par défaut (pour la factory)
static_assert(std::is_default_constructible<ComponentType>::value, "ComponentType should be default-constructible");
// On récupère la chaîne de caractère sous la forme d'un nombre qui servira d'identifiant unique
ComponentId id = BuildComponentId(name);
// On utilise les lambda pour créer une fonction factory
auto factory = []() -> BaseComponent*
{
return new ComponentType;
@@ -33,13 +38,18 @@ namespace Ndk
inline ComponentIndex BaseComponent::Register(ComponentId id, Factory factoryFunc)
{
// Nous allons rajouter notre composant à la fin
ComponentIndex index = s_entries.size();
s_entries.resize(index + 1);
// On récupère et on affecte
ComponentEntry& entry = s_entries.back();
entry.factory = factoryFunc;
entry.id = id;
// Une petite assertion pour s'assurer que l'identifiant n'est pas déjà utilisé
NazaraAssert(s_idToInsert.find(id) == s_idToInsert.end(), "This id is already in use");
s_idToIndex[id] = index;
return index;