Improved code

Fixed Directory being copyable
Fixed ByteArray and String self-assignation
Made it clear Clock is copyable


Former-commit-id: 36702d8a389abe6d3faa1e283d9a20f0326041a6
This commit is contained in:
Lynix 2014-07-23 11:57:04 +02:00
parent 221e2583ac
commit 8b34e21e2f
4 changed files with 20 additions and 29 deletions

View File

@ -19,6 +19,7 @@ class NAZARA_API NzClock
{
public:
NzClock(nzUInt64 startingValue = 0, bool paused = false);
NzClock(const NzClock& clock) = default;
float GetSeconds() const;
nzUInt64 GetMicroseconds() const;
@ -30,6 +31,8 @@ class NAZARA_API NzClock
void Restart();
void Unpause();
NzClock& operator=(const NzClock& clock) = default;
private:
NazaraMutexAttrib(m_mutex, mutable)

View File

@ -8,6 +8,7 @@
#define NAZARA_DIRECTORY_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/String.hpp>
#if defined(NAZARA_PLATFORM_WINDOWS)
@ -27,7 +28,7 @@
class NzDirectoryImpl;
class NAZARA_API NzDirectory
class NAZARA_API NzDirectory : NzNonCopyable
{
public:
NzDirectory();

View File

@ -403,12 +403,15 @@ nzUInt8 NzByteArray::operator[](unsigned int pos) const
}
NzByteArray& NzByteArray::operator=(const NzByteArray& array)
{
if (this != &array)
{
ReleaseArray();
m_sharedArray = array.m_sharedArray;
if (m_sharedArray != &emptyArray)
m_sharedArray->refCount++;
}
return *this;
}

View File

@ -2785,35 +2785,19 @@ NzString& NzString::Set(const char* string, unsigned int length)
NzString& NzString::Set(const std::string& string)
{
if (string.size() > 0)
{
if (m_sharedString->capacity >= string.size())
EnsureOwnership(true);
else
{
ReleaseString();
m_sharedString = new SharedString;
m_sharedString->capacity = string.size();
m_sharedString->string = new char[string.size()+1];
}
m_sharedString->size = string.size();
std::memcpy(m_sharedString->string, string.c_str(), string.size()+1);
}
else
ReleaseString();
return *this;
return Set(string.data(), string.size());
}
NzString& NzString::Set(const NzString& string)
{
if (this != &string)
{
ReleaseString();
m_sharedString = string.m_sharedString;
if (m_sharedString != &emptyString)
m_sharedString->refCount++;
}
return *this;
}