Core: Add MovablePtr class

This commit is contained in:
Lynix
2017-09-30 13:57:25 +02:00
parent f95fc332f1
commit 2cd9fa2b7a
29 changed files with 157 additions and 259 deletions

View File

@@ -102,18 +102,4 @@ namespace Nz
NazaraAssert(mutex != nullptr, "Mutex must be valid");
return m_impl->Wait(mutex->m_impl, timeout);
}
/*!
* \brief Moves a condition to another ConditionVariable object
* \return A reference to the object
*/
ConditionVariable& ConditionVariable::operator=(ConditionVariable&& condition) noexcept
{
delete m_impl;
m_impl = condition.m_impl;
condition.m_impl = nullptr;
return *this;
}
}

View File

@@ -40,19 +40,6 @@ namespace Nz
{
}
/*!
* \brief Constructs a DynLib object by move semantic
*
* \param lib DynLib to move into this
*/
DynLib::DynLib(DynLib&& lib) :
m_lastError(std::move(lib.m_lastError)),
m_impl(lib.m_impl)
{
lib.m_impl = nullptr;
}
/*!
* \brief Destructs the object and calls Unload
*
@@ -150,23 +137,4 @@ namespace Nz
m_impl = nullptr;
}
}
/*!
* \brief Moves the other lib into this
* \return A reference to this
*
* \param lib DynLib to move in this
*/
DynLib& DynLib::operator=(DynLib&& lib)
{
Unload();
m_impl = lib.m_impl;
m_lastError = std::move(lib.m_lastError);
lib.m_impl = nullptr;
return *this;
}
}

View File

@@ -70,20 +70,6 @@ namespace Nz
Open(filePath, openMode);
}
/*!
* \brief Constructs a File object by move semantic
*
* \param file File to move into this
*/
File::File(File&& file) noexcept :
Stream(std::move(file)),
m_filePath(std::move(file.m_filePath)),
m_impl(file.m_impl)
{
file.m_impl = nullptr;
}
/*!
* \brief Destructs the object and calls Close
*
@@ -487,23 +473,6 @@ namespace Nz
return *this;
}
/*!
* \brief Moves the other file into this
* \return A reference to this
*
* \param file File to move in this
*/
File& File::operator=(File&& file) noexcept
{
NazaraLock(m_mutex)
std::swap(m_filePath, file.m_filePath);
std::swap(m_impl, file.m_impl);
return *this;
}
/*!
* \brief Gets the absolute path of the file
* \return Absolute path of the file

View File

@@ -77,18 +77,4 @@ namespace Nz
NazaraAssert(m_impl, "Cannot unlock a moved mutex");
m_impl->Unlock();
}
/*!
* \brief Moves a mutex to another mutex object
* \return A reference to the object
*/
Mutex& Mutex::operator=(Mutex&& mutex) noexcept
{
delete m_impl;
m_impl = mutex.m_impl;
mutex.m_impl = nullptr;
return *this;
}
}

View File

@@ -6,6 +6,7 @@
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/HardwareInfo.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <ostream>
#include <stdexcept>
@@ -36,18 +37,6 @@ namespace Nz
{
}
/*!
* \brief Constructs a Thread<T> object by move semantic
*
* \param other Thread to move into this
*/
Thread::Thread(Thread&& other) noexcept :
m_impl(other.m_impl)
{
other.m_impl = nullptr;
}
/*!
* \brief Waits that the thread ends and then destroys this
*/
@@ -136,30 +125,6 @@ namespace Nz
m_impl->SetName(name);
}
/*!
* \brief Moves the other thread into this
* \return A reference to this
*
* \param thread Thread to move in this
*
* \remark Produce a NazaraError if no functor was assigned and NAZARA_CORE_SAFE is defined
* \remark And call std::terminate if no functor was assigned and NAZARA_CORE_SAFE is defined
*/
Thread& Thread::operator=(Thread&& thread)
{
#if NAZARA_CORE_SAFE
if (m_impl)
{
NazaraError("This thread cannot be joined");
std::terminate();
}
#endif
std::swap(m_impl, thread.m_impl);
return *this;
}
/*!
* \brief Gets the number of simulatenous threads that can run on the same cpu
* \return The number of simulatenous threads

View File

@@ -50,7 +50,7 @@ namespace Nz
}
}
bool ContextImpl::Activate()
bool ContextImpl::Activate() const
{
return glXMakeCurrent(m_display, m_window, m_context) == true;
}

View File

@@ -19,7 +19,7 @@ namespace Nz
ContextImpl();
~ContextImpl();
bool Activate();
bool Activate() const;
bool Create(ContextParameters& parameters);

View File

@@ -20,7 +20,7 @@ namespace Nz
{
}
bool ContextImpl::Activate()
bool ContextImpl::Activate() const
{
return wglMakeCurrent(m_deviceContext, m_context) == TRUE;
}

View File

@@ -18,7 +18,7 @@ namespace Nz
public:
ContextImpl();
bool Activate();
bool Activate() const;
bool Create(ContextParameters& parameters);

View File

@@ -88,8 +88,8 @@ namespace Nz
{
Joint* joint = targetSkeleton->GetJoint(i);
SequenceJoint& sequenceJointA = m_impl->sequenceJoints[frameA*m_impl->jointCount + i];
SequenceJoint& sequenceJointB = m_impl->sequenceJoints[frameB*m_impl->jointCount + i];
const SequenceJoint& sequenceJointA = m_impl->sequenceJoints[frameA*m_impl->jointCount + i];
const SequenceJoint& sequenceJointB = m_impl->sequenceJoints[frameB*m_impl->jointCount + i];
joint->SetPosition(Vector3f::Lerp(sequenceJointA.position, sequenceJointB.position, interpolation));
joint->SetRotation(Quaternionf::Slerp(sequenceJointA.rotation, sequenceJointB.rotation, interpolation));