Fix documentation for module: Core

Former-commit-id: 5f47321109e66e3961a09c4a2394335c4868453f
This commit is contained in:
Gawaboumga 2016-05-30 14:09:51 +02:00
parent 406bebe717
commit 7721fd2284
11 changed files with 421 additions and 25 deletions

View File

@ -12,7 +12,7 @@
#include <type_traits> #include <type_traits>
#define NazaraCheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err) #define NazaraCheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err)
// We fore the value of MANAGE_MEMORY in debug // We force the value of MANAGE_MEMORY in debug
#if defined(NAZARA_DEBUG) && !NAZARA_CORE_MANAGE_MEMORY #if defined(NAZARA_DEBUG) && !NAZARA_CORE_MANAGE_MEMORY
#undef NAZARA_CORE_MANAGE_MEMORY #undef NAZARA_CORE_MANAGE_MEMORY
#define NAZARA_CORE_MANAGE_MEMORY 0 #define NAZARA_CORE_MANAGE_MEMORY 0

View File

@ -10,6 +10,17 @@
namespace Nz namespace Nz
{ {
/*!
* \ingroup core
* \class Nz::HandledObject<T>
* \brief Core class that represents a handled object
*/
/*!
* \brief Constructs a HandledObject object by assignation
*
* \param object HandledObject to assign into this
*/
template<typename T> template<typename T>
HandledObject<T>::HandledObject(const HandledObject& object) HandledObject<T>::HandledObject(const HandledObject& object)
{ {
@ -17,6 +28,11 @@ namespace Nz
// Don't copy anything, we're a copy of the object, we have no handle right now // Don't copy anything, we're a copy of the object, we have no handle right now
} }
/*!
* \brief Constructs a HandledObject object by move semantic
*
* \param object HandledObject to move into this
*/
template<typename T> template<typename T>
HandledObject<T>::HandledObject(HandledObject&& object) : HandledObject<T>::HandledObject(HandledObject&& object) :
m_handles(std::move(object.m_handles)) m_handles(std::move(object.m_handles))
@ -25,18 +41,33 @@ namespace Nz
handle->OnObjectMoved(static_cast<T*>(this)); handle->OnObjectMoved(static_cast<T*>(this));
} }
/*!
* \brief Destructs the object and calls UnregisterAllHandles
*
* \see UnregisterAllHandles
*/
template<typename T> template<typename T>
HandledObject<T>::~HandledObject() HandledObject<T>::~HandledObject()
{ {
UnregisterAllHandles(); UnregisterAllHandles();
} }
/*!
* \brief Creates a ObjectHandle for this
* \return ObjectHandle to this
*/
template<typename T> template<typename T>
ObjectHandle<T> HandledObject<T>::CreateHandle() ObjectHandle<T> HandledObject<T>::CreateHandle()
{ {
return ObjectHandle<T>(static_cast<T*>(this)); return ObjectHandle<T>(static_cast<T*>(this));
} }
/*!
* \brief Sets the reference of the HandledObject with the handle from another
* \return A reference to this
*
* \param object The other HandledObject
*/
template<typename T> template<typename T>
HandledObject<T>& HandledObject<T>::operator=(const HandledObject& object) HandledObject<T>& HandledObject<T>::operator=(const HandledObject& object)
{ {
@ -44,6 +75,12 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Moves the HandledObject into this
* \return A reference to this
*
* \param object HandledObject to move in this
*/
template<typename T> template<typename T>
HandledObject<T>& HandledObject<T>::operator=(HandledObject&& object) HandledObject<T>& HandledObject<T>::operator=(HandledObject&& object)
{ {
@ -54,13 +91,22 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Registers a handle
*
* \param handle Handle to register
*
* \remark One handle can only be registered once, errors can occur if it's more than once
*/
template<typename T> template<typename T>
void HandledObject<T>::RegisterHandle(ObjectHandle<T>* handle) void HandledObject<T>::RegisterHandle(ObjectHandle<T>* handle)
{ {
///DOC: Un handle ne doit être enregistré qu'une fois, des erreurs se produisent s'il l'est plus d'une fois
m_handles.push_back(handle); m_handles.push_back(handle);
} }
/*!
* \brief Unregisters all handles
*/
template<typename T> template<typename T>
void HandledObject<T>::UnregisterAllHandles() void HandledObject<T>::UnregisterAllHandles()
{ {
@ -71,10 +117,17 @@ namespace Nz
m_handles.clear(); m_handles.clear();
} }
/*!
* \brief Unregisters a handle
*
* \param handle Handle to unregister
*
* \remark One handle can only be unregistered once, crash can occur if it's more than once
* \remark Produces a NazaraAssert if handle not registered
*/
template<typename T> template<typename T>
void HandledObject<T>::UnregisterHandle(ObjectHandle<T>* handle) noexcept void HandledObject<T>::UnregisterHandle(ObjectHandle<T>* handle) noexcept
{ {
///DOC: Un handle ne doit être libéré qu'une fois, et doit faire partie de la liste, sous peine de crash
auto it = std::find(m_handles.begin(), m_handles.end(), handle); auto it = std::find(m_handles.begin(), m_handles.end(), handle);
NazaraAssert(it != m_handles.end(), "Handle not registered"); NazaraAssert(it != m_handles.end(), "Handle not registered");
@ -83,6 +136,14 @@ namespace Nz
m_handles.pop_back(); m_handles.pop_back();
} }
/*!
* \brief Updates one handle with another
*
* \param oldHandle Old handle to replace
* \param newHandle New handle to take place
*
* \remark Produces a NazaraAssert if handle not registered
*/
template<typename T> template<typename T>
void HandledObject<T>::UpdateHandle(ObjectHandle<T>* oldHandle, ObjectHandle<T>* newHandle) noexcept void HandledObject<T>::UpdateHandle(ObjectHandle<T>* oldHandle, ObjectHandle<T>* newHandle) noexcept
{ {

View File

@ -9,12 +9,26 @@
namespace Nz namespace Nz
{ {
/*!
* \ingroup core
* \class Nz::ObjectHandle
* \brief Core class that represents a object handle
*/
/*!
* \brief Constructs a ObjectHandle object by default
*/
template<typename T> template<typename T>
ObjectHandle<T>::ObjectHandle() : ObjectHandle<T>::ObjectHandle() :
m_object(nullptr) m_object(nullptr)
{ {
} }
/*!
* \brief Constructs a ObjectHandle object with a pointer to an object
*
* \param object Pointer to handle like an object (can be nullptr)
*/
template<typename T> template<typename T>
ObjectHandle<T>::ObjectHandle(T* object) : ObjectHandle<T>::ObjectHandle(T* object) :
ObjectHandle() ObjectHandle()
@ -22,59 +36,97 @@ namespace Nz
Reset(object); Reset(object);
} }
/*!
* \brief Constructs a ObjectHandle object by assignation
*
* \param handle ObjectHandle to assign into this
*/
template<typename T> template<typename T>
ObjectHandle<T>::ObjectHandle(const ObjectHandle<T>& handle) : ObjectHandle<T>::ObjectHandle(const ObjectHandle& handle) :
ObjectHandle() ObjectHandle()
{ {
Reset(handle); Reset(handle);
} }
/*!
* \brief Constructs a ObjectHandle object by move semantic
*
* \param handle ObjectHandle to move into this
*/
template<typename T> template<typename T>
ObjectHandle<T>::ObjectHandle(ObjectHandle<T>&& handle) noexcept : ObjectHandle<T>::ObjectHandle(ObjectHandle&& handle) noexcept :
ObjectHandle() ObjectHandle()
{ {
Reset(std::move(handle)); Reset(std::move(handle));
} }
/*!
* \brief Destructs the object and calls reset with nullptr
*
* \see Reset
*/
template<typename T> template<typename T>
ObjectHandle<T>::~ObjectHandle() ObjectHandle<T>::~ObjectHandle()
{ {
Reset(nullptr); Reset(nullptr);
} }
/*!
* \brief Gets the underlying object
* \return Underlying object
*/
template<typename T> template<typename T>
T* ObjectHandle<T>::GetObject() const T* ObjectHandle<T>::GetObject() const
{ {
return m_object; return m_object;
} }
/*!
* \brief Checks whether the object is valid
* \return true if object is not nullptr
*/
template<typename T> template<typename T>
bool ObjectHandle<T>::IsValid() const bool ObjectHandle<T>::IsValid() const
{ {
return m_object != nullptr; return m_object != nullptr;
} }
/*!
* \brief Resets the content of the ObjectHandle with another object
*
* \param object Object to handle
*/
template<typename T> template<typename T>
void ObjectHandle<T>::Reset(T* object) void ObjectHandle<T>::Reset(T* object)
{ {
// Si nous avions déjà une entité, nous devons l'informer que nous ne pointons plus sur elle // If we already have an entity, we must alert it that we are not pointing to it anymore
if (m_object) if (m_object)
m_object->UnregisterHandle(this); m_object->UnregisterHandle(this);
m_object = object; m_object = object;
if (m_object) if (m_object)
// On informe la nouvelle entité que nous pointons sur elle // We alert the new entity that we are pointing to it
m_object->RegisterHandle(this); m_object->RegisterHandle(this);
} }
/*!
* \brief Resets the content of this with another object
*
* \param handle New object to handle
*/
template<typename T> template<typename T>
void ObjectHandle<T>::Reset(const ObjectHandle<T>& handle) void ObjectHandle<T>::Reset(const ObjectHandle& handle)
{ {
Reset(handle.GetObject()); Reset(handle.GetObject());
} }
/*!
* \brief Resets the content of this with another object by move semantic
*
* \param handle New object to handle to move into this
*/
template<typename T> template<typename T>
void ObjectHandle<T>::Reset(ObjectHandle<T>&& handle) noexcept void ObjectHandle<T>::Reset(ObjectHandle&& handle) noexcept
{ {
if (m_object) if (m_object)
m_object->UnregisterHandle(this); m_object->UnregisterHandle(this);
@ -87,12 +139,18 @@ namespace Nz
} }
} }
/*!
* \brief Swaps the content of the two ObjectHandle
* \return A reference to this
*
* \param handle ObjectHandle to swap
*/
template<typename T> template<typename T>
ObjectHandle<T>& ObjectHandle<T>::Swap(ObjectHandle<T>& handle) ObjectHandle<T>& ObjectHandle<T>::Swap(ObjectHandle& handle)
{ {
// Comme nous inversons les handles, nous devons prévenir les entités // As we swap the two handles, we must alert the entities
// La version par défaut de swap (à base de move) aurait fonctionné, // The default version with swap (move) would be working,
// mais en enregistrant les handles une fois de plus que nécessaire (à cause de la copie temporaire). // but will register handles one more time (due to temporary copy).
if (m_object) if (m_object)
{ {
m_object->UnregisterHandle(this); m_object->UnregisterHandle(this);
@ -105,11 +163,15 @@ namespace Nz
handle.m_object->RegisterHandle(this); handle.m_object->RegisterHandle(this);
} }
// On effectue l'échange // We do the swap
std::swap(m_object, handle.m_object); std::swap(m_object, handle.m_object);
return *this; return *this;
} }
/*!
* \brief Gives a string representation
* \return A string representation of the object "ObjectHandle(object representation) or Null"
*/
template<typename T> template<typename T>
Nz::String ObjectHandle<T>::ToString() const Nz::String ObjectHandle<T>::ToString() const
{ {
@ -125,24 +187,44 @@ namespace Nz
return ss; return ss;
} }
/*!
* \brief Converts the ObjectHandle to bool
* \return true if reference is not nullptr
*
* \see IsValid
*/
template<typename T> template<typename T>
ObjectHandle<T>::operator bool() const ObjectHandle<T>::operator bool() const
{ {
return IsValid(); return IsValid();
} }
/*!
* \brief Dereferences the ObjectHandle
* \return Underlying pointer
*/
template<typename T> template<typename T>
ObjectHandle<T>::operator T*() const ObjectHandle<T>::operator T*() const
{ {
return m_object; return m_object;
} }
/*!
* \brief Dereferences the ObjectHandle
* \return Underlying pointer
*/
template<typename T> template<typename T>
T* ObjectHandle<T>::operator->() const T* ObjectHandle<T>::operator->() const
{ {
return m_object; return m_object;
} }
/*!
* \brief Assigns the entity into this
* \return A reference to this
*
* \param entity Pointer to handle like an object (can be nullptr)
*/
template<typename T> template<typename T>
ObjectHandle<T>& ObjectHandle<T>::operator=(T* entity) ObjectHandle<T>& ObjectHandle<T>::operator=(T* entity)
{ {
@ -151,22 +233,37 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Sets the handle of the ObjectHandle with the handle from another
* \return A reference to this
*
* \param handle The other ObjectHandle
*/
template<typename T> template<typename T>
ObjectHandle<T>& ObjectHandle<T>::operator=(const ObjectHandle<T>& handle) ObjectHandle<T>& ObjectHandle<T>::operator=(const ObjectHandle& handle)
{ {
Reset(handle); Reset(handle);
return *this; return *this;
} }
/*!
* \brief Moves the ObjectHandle into this
* \return A reference to this
*
* \param handle ObjectHandle to move in this
*/
template<typename T> template<typename T>
ObjectHandle<T>& ObjectHandle<T>::operator=(ObjectHandle<T>&& handle) noexcept ObjectHandle<T>& ObjectHandle<T>::operator=(ObjectHandle&& handle) noexcept
{ {
Reset(std::move(handle)); Reset(std::move(handle));
return *this; return *this;
} }
/*!
* \brief Action to do on object destruction
*/
template<typename T> template<typename T>
void ObjectHandle<T>::OnObjectDestroyed() void ObjectHandle<T>::OnObjectDestroyed()
{ {
@ -174,6 +271,9 @@ namespace Nz
m_object = nullptr; m_object = nullptr;
} }
/*!
* \brief Action to do on object move
*/
template<typename T> template<typename T>
void ObjectHandle<T>::OnObjectMoved(T* newObject) void ObjectHandle<T>::OnObjectMoved(T* newObject)
{ {
@ -181,114 +281,247 @@ namespace Nz
m_object = newObject; m_object = newObject;
} }
/*!
* \brief Output operator
* \return The stream
*
* \param out The stream
* \param handle The ObjectHandle to output
*/
template<typename T> template<typename T>
std::ostream& operator<<(std::ostream& out, const ObjectHandle<T>& handle) std::ostream& operator<<(std::ostream& out, const ObjectHandle<T>& handle)
{ {
return handle.ToString(); return handle.ToString();
} }
/*!
* \brief Checks whether the first object handle is equal to the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator==(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs) bool operator==(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs)
{ {
return lhs.GetObject() == rhs.GetObject(); return lhs.GetObject() == rhs.GetObject();
} }
/*!
* \brief Checks whether the object is equal to the second object handle
* \return true if it is the case
*
* \param first Object to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator==(const T& lhs, const ObjectHandle<T>& rhs) bool operator==(const T& lhs, const ObjectHandle<T>& rhs)
{ {
return &lhs == rhs.GetObject(); return &lhs == rhs.GetObject();
} }
/*!
* \brief Checks whether the object handle is equal to the second object
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second Object to compare in right hand side
*/
template<typename T> template<typename T>
bool operator==(const ObjectHandle<T>& lhs, const T& rhs) bool operator==(const ObjectHandle<T>& lhs, const T& rhs)
{ {
return lhs.GetObject() == &rhs; return lhs.GetObject() == &rhs;
} }
/*!
* \brief Checks whether the first object handle is equal to the second object handle
* \return false if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator!=(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs) bool operator!=(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
/*!
* \brief Checks whether the object is equal to the second object handle
* \return false if it is the case
*
* \param first Object to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator!=(const T& lhs, const ObjectHandle<T>& rhs) bool operator!=(const T& lhs, const ObjectHandle<T>& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
/*!
* \brief Checks whether the object handle is equal to the second object
* \return false if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second Object to compare in right hand side
*/
template<typename T> template<typename T>
bool operator!=(const ObjectHandle<T>& lhs, const T& rhs) bool operator!=(const ObjectHandle<T>& lhs, const T& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
/*!
* \brief Checks whether the first object handle is less than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator<(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs) bool operator<(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs)
{ {
return lhs.m_object < rhs.m_object; return lhs.m_object < rhs.m_object;
} }
/*!
* \brief Checks whether the first object handle is less than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator<(const T& lhs, const ObjectHandle<T>& rhs) bool operator<(const T& lhs, const ObjectHandle<T>& rhs)
{ {
return &lhs < rhs.m_object; return &lhs < rhs.m_object;
} }
/*!
* \brief Checks whether the first object handle is less than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator<(const ObjectHandle<T>& lhs, const T& rhs) bool operator<(const ObjectHandle<T>& lhs, const T& rhs)
{ {
return lhs.m_object < &rhs; return lhs.m_object < &rhs;
} }
/*!
* \brief Checks whether the first object handle is less or equal than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator<=(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs) bool operator<=(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs)
{ {
return !(lhs > rhs); return !(lhs > rhs);
} }
/*!
* \brief Checks whether the first object handle is less or equal than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator<=(const T& lhs, const ObjectHandle<T>& rhs) bool operator<=(const T& lhs, const ObjectHandle<T>& rhs)
{ {
return !(lhs > rhs); return !(lhs > rhs);
} }
/*!
* \brief Checks whether the first object handle is less or equal than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator<=(const ObjectHandle<T>& lhs, const T& rhs) bool operator<=(const ObjectHandle<T>& lhs, const T& rhs)
{ {
return !(lhs > rhs); return !(lhs > rhs);
} }
/*!
* \brief Checks whether the first object handle is greather than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator>(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs) bool operator>(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs)
{ {
return rhs < lhs; return rhs < lhs;
} }
/*!
* \brief Checks whether the first object handle is greather than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator>(const T& lhs, const ObjectHandle<T>& rhs) bool operator>(const T& lhs, const ObjectHandle<T>& rhs)
{ {
return rhs < lhs; return rhs < lhs;
} }
/*!
* \brief Checks whether the first object handle is greather than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator>(const ObjectHandle<T>& lhs, const T& rhs) bool operator>(const ObjectHandle<T>& lhs, const T& rhs)
{ {
return rhs < lhs; return rhs < lhs;
} }
/*!
* \brief Checks whether the first object handle is greather or equal than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator>=(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs) bool operator>=(const ObjectHandle<T>& lhs, const ObjectHandle<T>& rhs)
{ {
return !(lhs < rhs); return !(lhs < rhs);
} }
/*!
* \brief Checks whether the first object handle is greather or equal than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator>=(const T& lhs, const ObjectHandle<T>& rhs) bool operator>=(const T& lhs, const ObjectHandle<T>& rhs)
{ {
return !(lhs < rhs); return !(lhs < rhs);
} }
/*!
* \brief Checks whether the first object handle is greather or equal than the second object handle
* \return true if it is the case
*
* \param first ObjectHandle to compare in left hand side
* \param second ObjectHandle to compare in right hand side
*/
template<typename T> template<typename T>
bool operator>=(const ObjectHandle<T>& lhs, const T& rhs) bool operator>=(const ObjectHandle<T>& lhs, const T& rhs)
{ {
@ -301,6 +534,12 @@ namespace Nz
namespace std namespace std
{ {
/*!
* \brief Swaps two ObjectHandle, specialisation of std
*
* \param lhs First object handle
* \param rhs Second object handle
*/
template<typename T> template<typename T>
void swap(Nz::ObjectHandle<T>& lhs, Nz::ObjectHandle<T>& rhs) void swap(Nz::ObjectHandle<T>& lhs, Nz::ObjectHandle<T>& rhs)
{ {

View File

@ -50,6 +50,8 @@ namespace Nz
void SetParameter(const String& name, void* value); void SetParameter(const String& name, void* value);
void SetParameter(const String& name, void* value, Destructor destructor); void SetParameter(const String& name, void* value, Destructor destructor);
String ToString() const;
ParameterList& operator=(const ParameterList& list); ParameterList& operator=(const ParameterList& list);
ParameterList& operator=(ParameterList&&) = default; ParameterList& operator=(ParameterList&&) = default;
@ -73,7 +75,7 @@ namespace Nz
ParameterType type; ParameterType type;
union Value union Value
{ {
// On définit un constructeur/destructeur vide, permettant de mettre des classes dans l'union // We define an empty constructor/destructor, to be able to put classes in the union
Value() {} Value() {}
Value(const Value&) {} // Placeholder Value(const Value&) {} // Placeholder
~Value() {} ~Value() {}
@ -98,4 +100,6 @@ namespace Nz
}; };
} }
std::ostream& operator<<(std::ostream& out, const Nz::ParameterList& parameterList);
#endif // NAZARA_PARAMETERLIST_HPP #endif // NAZARA_PARAMETERLIST_HPP

View File

@ -66,7 +66,7 @@ namespace Nz
return false; return false;
} }
File file(path); // Ouvert seulement en cas de besoin File file(path); // Open only if needed
bool found = false; bool found = false;
for (Loader& loader : Type::s_loaders) for (Loader& loader : Type::s_loaders)

View File

@ -28,7 +28,7 @@ namespace Nz
bool Core::Initialize() bool Core::Initialize()
{ {
if (s_moduleReferenceCounter > 0) if (IsInitialized())
{ {
s_moduleReferenceCounter++; s_moduleReferenceCounter++;
return true; // Already initialized return true; // Already initialized

View File

@ -906,5 +906,5 @@ namespace Nz
} }
return true; return true;
} };
} }

View File

@ -607,6 +607,54 @@ namespace Nz
parameter.value.ptrVal = value; parameter.value.ptrVal = value;
} }
/*!
* \brief Gives a string representation
* \return A string representation of the object: "ParameterList(Name: Type(value), ...)"
*/
String ParameterList::ToString() const
{
StringStream ss;
ss << "ParameterList(";
for (auto it = m_parameters.cbegin(); it != m_parameters.cend();)
{
ss << it->first << ": ";
switch (it->second.type)
{
case ParameterType_Boolean:
ss << "Boolean(" << String::Boolean(it->second.value.boolVal) << ")";
break;
case ParameterType_Color:
ss << "Color(" << it->second.value.colorVal.ToString() << ")";
break;
case ParameterType_Float:
ss << "Float(" << it->second.value.floatVal << ")";
break;
case ParameterType_Integer:
ss << "Integer(" << it->second.value.intVal << ")";
break;
case ParameterType_String:
ss << "String(" << it->second.value.stringVal << ")";
break;
case ParameterType_Pointer:
ss << "Pointer(" << String::Pointer(it->second.value.ptrVal) << ")";
break;
case ParameterType_Userdata:
ss << "Userdata(" << String::Pointer(it->second.value.userdataVal->ptr) << ")";
break;
case ParameterType_None:
ss << "None";
break;
}
if (++it != m_parameters.cend())
ss << ", ";
}
ss << ")";
return ss;
}
/*! /*!
* \brief Sets a userdata parameter named `name` * \brief Sets a userdata parameter named `name`
* *
@ -724,3 +772,17 @@ namespace Nz
} }
} }
} }
/*!
* \brief Output operator
* \return The stream
*
* \param out The stream
* \param parameterList The ParameterList to output
*/
std::ostream& operator<<(std::ostream& out, const Nz::ParameterList& parameterList)
{
out << parameterList.ToString();
return out;
}

View File

@ -213,4 +213,24 @@ SCENARIO("ByteArray", "[CORE][BYTEARRAY]")
} }
} }
} }
GIVEN("A default byte array")
{
Nz::ByteArray defaultByteArray;
WHEN("We resize")
{
Nz::UInt64 oldSize = defaultByteArray.GetSize();
REQUIRE(oldSize == 0);
defaultByteArray.Resize(10);
THEN("Capacity has increased")
{
REQUIRE(defaultByteArray[oldSize] == 0);
REQUIRE(defaultByteArray.GetCapacity() >= 10);
REQUIRE(defaultByteArray.GetSize() == 10);
}
}
}
} }

View File

@ -32,12 +32,22 @@ SCENARIO("File", "[CORE][FILE]")
REQUIRE(Nz::String(message) == "Test String"); REQUIRE(Nz::String(message) == "Test String");
} }
AND_THEN("We can get its size")
{
REQUIRE(file.GetSize() == 33U);
}
AND_THEN("We close it") AND_THEN("We close it")
{ {
file.Close(); file.Close();
REQUIRE(file.GetSize() == 33U);
CHECK(!file.IsOpen()); CHECK(!file.IsOpen());
} }
AND_THEN("Change its size")
{
file.SetSize(50U);
REQUIRE(file.GetSize() == 50U);
}
} }
WHEN("We delete this file") WHEN("We delete this file")