Added Image
Added pixel format support Added MemoryStream Added Rect Added ResourceLoader Added generic loader (bmp, gif, hdr, jpg, jpeg, pic, png, psd, tga) Added PCX loader Added utility module initializer Fixed Config.hpp include Prerequesites.hpp now overwrites _WIN32_WINNT when defined version is less than requiered version Renderer's initialisation will implicitly initialize utility module Removed RENDERER_SINGLETON option Shaders are now resources
This commit is contained in:
@@ -3,6 +3,29 @@
|
||||
#include <cstring>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
inline unsigned int nzPow2(unsigned int n)
|
||||
{
|
||||
unsigned int x = 1;
|
||||
|
||||
while(x <= n)
|
||||
x <<= 1;
|
||||
|
||||
return x;
|
||||
}
|
||||
// Cet algorithme est inspiré de la documentation de Qt
|
||||
inline unsigned int nzGetNewSize(unsigned int newSize)
|
||||
{
|
||||
if (newSize < 20)
|
||||
return newSize+4;
|
||||
else
|
||||
{
|
||||
if (newSize < (1 << 12)-12)
|
||||
return nzPow2(newSize << 1)-12;
|
||||
else
|
||||
return newSize + (1 << 11);
|
||||
}
|
||||
}
|
||||
|
||||
NzByteArray::NzByteArray() :
|
||||
m_sharedArray(&emptyArray)
|
||||
{
|
||||
@@ -13,10 +36,10 @@ NzByteArray::NzByteArray(const nzUInt8* buffer, unsigned int bufferLength)
|
||||
if (bufferLength > 0)
|
||||
{
|
||||
m_sharedArray = new SharedArray;
|
||||
m_sharedArray->allocatedSize = bufferLength;
|
||||
m_sharedArray->buffer = new nzUInt8[bufferLength];
|
||||
m_sharedArray->capacity = bufferLength;
|
||||
m_sharedArray->size = bufferLength;
|
||||
std::memcpy(m_sharedArray->buffer, buffer, bufferLength*sizeof(nzUInt8));
|
||||
std::memcpy(m_sharedArray->buffer, buffer, bufferLength);
|
||||
}
|
||||
else
|
||||
m_sharedArray = &emptyArray;
|
||||
@@ -49,9 +72,38 @@ NzByteArray::~NzByteArray()
|
||||
ReleaseArray();
|
||||
}
|
||||
|
||||
unsigned int NzByteArray::Capacity() const
|
||||
NzByteArray& NzByteArray::Append(const NzByteArray& byteArray)
|
||||
{
|
||||
return m_sharedArray->allocatedSize;
|
||||
if (byteArray.m_sharedArray->size == 0)
|
||||
return *this;
|
||||
|
||||
if (m_sharedArray->size == 0 && m_sharedArray->capacity < byteArray.m_sharedArray->size)
|
||||
return operator=(byteArray);
|
||||
|
||||
if (m_sharedArray->capacity >= m_sharedArray->size + byteArray.m_sharedArray->size)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
std::memcpy(&m_sharedArray->buffer[m_sharedArray->size], byteArray.m_sharedArray->buffer, byteArray.m_sharedArray->size);
|
||||
m_sharedArray->size += byteArray.m_sharedArray->size;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int newSize = m_sharedArray->size + byteArray.m_sharedArray->size;
|
||||
unsigned int bufferSize = nzGetNewSize(newSize);
|
||||
|
||||
nzUInt8* buffer = new nzUInt8[bufferSize+1];
|
||||
std::memcpy(buffer, m_sharedArray->buffer, m_sharedArray->size);
|
||||
std::memcpy(&buffer[m_sharedArray->size], byteArray.m_sharedArray->buffer, byteArray.m_sharedArray->size);
|
||||
|
||||
ReleaseArray();
|
||||
m_sharedArray = new SharedArray;
|
||||
m_sharedArray->buffer = buffer;
|
||||
m_sharedArray->capacity = bufferSize;
|
||||
m_sharedArray->size = newSize;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void NzByteArray::Clear()
|
||||
@@ -59,7 +111,19 @@ void NzByteArray::Clear()
|
||||
ReleaseArray();
|
||||
}
|
||||
|
||||
const nzUInt8* NzByteArray::GetBuffer() const
|
||||
nzUInt8* NzByteArray::GetBuffer()
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
return m_sharedArray->buffer;
|
||||
}
|
||||
|
||||
unsigned int NzByteArray::GetCapacity() const
|
||||
{
|
||||
return m_sharedArray->capacity;
|
||||
}
|
||||
|
||||
const nzUInt8* NzByteArray::GetConstBuffer() const
|
||||
{
|
||||
return m_sharedArray->buffer;
|
||||
}
|
||||
@@ -83,12 +147,12 @@ NzByteArray& NzByteArray::Insert(int pos, const nzUInt8* buffer, unsigned int bu
|
||||
unsigned int start = std::min(static_cast<unsigned int>(pos), m_sharedArray->size);
|
||||
|
||||
// Si le buffer est déjà suffisamment grand
|
||||
if (m_sharedArray->allocatedSize >= m_sharedArray->size + bufferLength)
|
||||
if (m_sharedArray->capacity >= m_sharedArray->size + bufferLength)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
std::memmove(&m_sharedArray->buffer[start+bufferLength], &m_sharedArray->buffer[start], m_sharedArray->size*sizeof(nzUInt8));
|
||||
std::memcpy(&m_sharedArray->buffer[start], buffer, bufferLength*sizeof(nzUInt8));
|
||||
std::memmove(&m_sharedArray->buffer[start+bufferLength], &m_sharedArray->buffer[start], m_sharedArray->size);
|
||||
std::memcpy(&m_sharedArray->buffer[start], buffer, bufferLength);
|
||||
|
||||
m_sharedArray->size += bufferLength;
|
||||
}
|
||||
@@ -118,7 +182,55 @@ NzByteArray& NzByteArray::Insert(int pos, const nzUInt8* buffer, unsigned int bu
|
||||
return *this;
|
||||
}
|
||||
|
||||
NzByteArray& NzByteArray::Insert(int pos, const NzByteArray& byteArray);
|
||||
NzByteArray& NzByteArray::Insert(int pos, const NzByteArray& byteArray)
|
||||
{
|
||||
if (string.m_sharedArray->size == 0)
|
||||
return *this;
|
||||
|
||||
if (m_sharedArray->size == 0 && m_sharedArray->capacity < string.m_sharedArray->size)
|
||||
return operator=(string);
|
||||
|
||||
if (pos < 0)
|
||||
pos = std::max(static_cast<int>(m_sharedArray->size + pos), 0);
|
||||
|
||||
unsigned int start = std::min(static_cast<unsigned int>(pos), m_sharedArray->size);
|
||||
|
||||
// Si le buffer est déjà suffisamment grand
|
||||
if (m_sharedArray->capacity >= m_sharedArray->size + string.m_sharedArray->size)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
std::memmove(&m_sharedArray->string[start+string.m_sharedArray->size], &m_sharedArray->string[start], m_sharedArray->size*sizeof(char));
|
||||
std::memcpy(&m_sharedArray->string[start], string.m_sharedArray->string, string.m_sharedArray->size*sizeof(char));
|
||||
|
||||
m_sharedArray->size += string.m_sharedArray->size;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int newSize = m_sharedArray->size+string.m_sharedArray->size;
|
||||
char* newString = new char[newSize+1];
|
||||
|
||||
char* ptr = newString;
|
||||
const char* s = m_sharedArray->string;
|
||||
|
||||
while (ptr != &newString[start])
|
||||
*ptr++ = *s++;
|
||||
|
||||
const char* p = string.m_sharedArray->string;
|
||||
while (ptr != &newString[start+string.m_sharedArray->size])
|
||||
*ptr++ = *p++;
|
||||
|
||||
std::strcpy(ptr, s);
|
||||
|
||||
ReleaseString();
|
||||
m_sharedArray = new SharedString;
|
||||
m_sharedArray->capacity = newSize;
|
||||
m_sharedArray->size = newSize;
|
||||
m_sharedArray->string = newString;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool NzByteArray::IsEmpty() const
|
||||
{
|
||||
@@ -130,9 +242,9 @@ void NzByteArray::Reserve(unsigned int bufferSize)
|
||||
if (m_sharedArray->allocatedSize >= bufferSize)
|
||||
return;
|
||||
|
||||
char* ptr = new char[bufferSize+1];
|
||||
nzUInt8* ptr = new nzUInt8[bufferSize+1];
|
||||
if (m_sharedArray->size > 0)
|
||||
std::strcpy(ptr, m_sharedArray->buffer);
|
||||
std::memcpy(ptr, m_sharedArray->buffer, m_sharedArray->size);
|
||||
|
||||
unsigned int size = m_sharedArray->size;
|
||||
|
||||
@@ -143,45 +255,6 @@ void NzByteArray::Reserve(unsigned int bufferSize)
|
||||
m_sharedArray->size = size;
|
||||
}
|
||||
|
||||
NzByteArray& NzByteArray::Resize(int size, nzUInt8 byte = '\0');
|
||||
NzByteArray NzByteArray::Resized(int size, nzUInt8 byte = '\0') const;
|
||||
|
||||
NzByteArray SubArray(int startPos, int endPos = -1) const;
|
||||
|
||||
void Swap(NzByteArray& byteArray);
|
||||
|
||||
NzByteArray& Trim(nzUInt8 byte = '\0');
|
||||
NzByteArray Trimmed(nzUInt8 byte = '\0') const;
|
||||
|
||||
// Méthodes compatibles STD
|
||||
nzUInt8* begin();
|
||||
const nzUInt8* begin() const;
|
||||
nzUInt8* end();
|
||||
const nzUInt8* end() const;
|
||||
void push_front(nzUInt8 c);
|
||||
void push_back(nzUInt8 c);
|
||||
|
||||
typedef const nzUInt8& const_reference;
|
||||
typedef nzUInt8* iterator;
|
||||
//typedef nzUInt8* reverse_iterator;
|
||||
typedef nzUInt8 value_type;
|
||||
// Méthodes compatibles STD
|
||||
|
||||
nzUInt8& operator[](unsigned int pos);
|
||||
nzUInt8 operator[](unsigned int pos) const;
|
||||
|
||||
NzByteArray& operator=(const NzByteArray& byteArray);
|
||||
NzByteArray& operator=(NzByteArray&& byteArray);
|
||||
|
||||
NzByteArray operator+(const NzByteArray& byteArray) const;
|
||||
NzByteArray& operator+=(const NzByteArray& byteArray);
|
||||
|
||||
static int Compare(const NzByteArray& first, const NzByteArray& second);
|
||||
|
||||
static SharedArray emptyArray;
|
||||
|
||||
private:
|
||||
void EnsureOwnership();
|
||||
bool FillHash(NzHashImpl* hash) const;
|
||||
void ReleaseArray();
|
||||
NzByteArray::SharedString NzByteArray::emptyArray(0, 0, 0, nullptr);
|
||||
unsigned int NzByteArray::npos(static_cast<unsigned int>(-1));
|
||||
*/
|
||||
|
||||
50
src/Nazara/Core/MemoryStream.cpp
Normal file
50
src/Nazara/Core/MemoryStream.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/MemoryStream.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzMemoryStream::NzMemoryStream(const void* ptr, nzUInt64 size) :
|
||||
m_ptr(static_cast<const nzUInt8*>(ptr)),
|
||||
m_pos(0),
|
||||
m_size(size)
|
||||
{
|
||||
}
|
||||
|
||||
NzMemoryStream::~NzMemoryStream()
|
||||
{
|
||||
}
|
||||
|
||||
bool NzMemoryStream::EndOfStream() const
|
||||
{
|
||||
return m_pos == m_size;
|
||||
}
|
||||
|
||||
nzUInt64 NzMemoryStream::GetCursorPos() const
|
||||
{
|
||||
return m_pos;
|
||||
}
|
||||
|
||||
nzUInt64 NzMemoryStream::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
std::size_t NzMemoryStream::Read(void* buffer, std::size_t size)
|
||||
{
|
||||
unsigned int readSize = std::min(static_cast<nzUInt64>(size), m_size-m_pos);
|
||||
std::memcpy(buffer, &m_ptr[m_pos], readSize);
|
||||
m_pos += readSize;
|
||||
|
||||
return readSize;
|
||||
}
|
||||
|
||||
bool NzMemoryStream::SetCursorPos(nzUInt64 offset)
|
||||
{
|
||||
m_pos = std::min(offset, m_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -91,7 +91,7 @@ NzString::NzString(char character)
|
||||
else
|
||||
{
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = 1;
|
||||
m_sharedString->capacity = 1;
|
||||
m_sharedString->size = 1;
|
||||
m_sharedString->string = new char[2];
|
||||
m_sharedString->string[0] = character;
|
||||
@@ -107,7 +107,7 @@ NzString::NzString(const char* string)
|
||||
if (size > 0)
|
||||
{
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = size;
|
||||
m_sharedString->capacity = size;
|
||||
m_sharedString->size = size;
|
||||
m_sharedString->string = new char[size+1];
|
||||
std::strcpy(m_sharedString->string, string);
|
||||
@@ -124,7 +124,7 @@ NzString::NzString(const std::string& string)
|
||||
if (string.size() > 0)
|
||||
{
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = string.capacity();
|
||||
m_sharedString->capacity = string.capacity();
|
||||
m_sharedString->size = string.size();
|
||||
m_sharedString->string = new char[string.capacity()+1];
|
||||
std::strcpy(m_sharedString->string, string.c_str());
|
||||
@@ -165,10 +165,10 @@ NzString& NzString::Append(char character)
|
||||
if (character == '\0')
|
||||
return *this;
|
||||
|
||||
if (m_sharedString->size == 0 && m_sharedString->allocatedSize == 0)
|
||||
if (m_sharedString->size == 0 && m_sharedString->capacity == 0)
|
||||
return operator=(character);
|
||||
|
||||
if (m_sharedString->allocatedSize > m_sharedString->size)
|
||||
if (m_sharedString->capacity > m_sharedString->size)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
@@ -188,7 +188,7 @@ NzString& NzString::Append(char character)
|
||||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = str;
|
||||
}
|
||||
@@ -205,7 +205,7 @@ NzString& NzString::Append(const char* string)
|
||||
if (length == 0)
|
||||
return *this;
|
||||
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size + length)
|
||||
if (m_sharedString->capacity >= m_sharedString->size + length)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
@@ -223,7 +223,7 @@ NzString& NzString::Append(const char* string)
|
||||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = str;
|
||||
}
|
||||
@@ -236,10 +236,10 @@ NzString& NzString::Append(const NzString& string)
|
||||
if (string.m_sharedString->size == 0)
|
||||
return *this;
|
||||
|
||||
if (m_sharedString->size == 0 && m_sharedString->allocatedSize < string.m_sharedString->size)
|
||||
if (m_sharedString->size == 0 && m_sharedString->capacity < string.m_sharedString->size)
|
||||
return operator=(string);
|
||||
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size + string.m_sharedString->size)
|
||||
if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
@@ -257,7 +257,7 @@ NzString& NzString::Append(const NzString& string)
|
||||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = str;
|
||||
}
|
||||
@@ -2231,7 +2231,7 @@ char* NzString::GetBuffer()
|
||||
|
||||
unsigned int NzString::GetCapacity() const
|
||||
{
|
||||
return m_sharedString->allocatedSize;
|
||||
return m_sharedString->capacity;
|
||||
}
|
||||
|
||||
const char* NzString::GetConstBuffer() const
|
||||
@@ -2464,7 +2464,7 @@ NzString& NzString::Insert(int pos, char character)
|
||||
if (character == '\0')
|
||||
return *this;
|
||||
|
||||
if (m_sharedString->size == 0 && m_sharedString->allocatedSize == 0)
|
||||
if (m_sharedString->size == 0 && m_sharedString->capacity == 0)
|
||||
return operator=(character);
|
||||
|
||||
if (pos < 0)
|
||||
@@ -2473,7 +2473,7 @@ NzString& NzString::Insert(int pos, char character)
|
||||
unsigned int start = std::min(static_cast<unsigned int>(pos), m_sharedString->size);
|
||||
|
||||
// Si le buffer est déjà suffisamment grand
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size+1)
|
||||
if (m_sharedString->capacity >= m_sharedString->size+1)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
@@ -2499,7 +2499,7 @@ NzString& NzString::Insert(int pos, char character)
|
||||
ReleaseString();
|
||||
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = newSize;
|
||||
m_sharedString->capacity = newSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = newString;
|
||||
}
|
||||
@@ -2519,7 +2519,7 @@ NzString& NzString::Insert(int pos, const char* string)
|
||||
|
||||
// Si le buffer est déjà suffisamment grand
|
||||
unsigned int len = std::strlen(string);
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size+len)
|
||||
if (m_sharedString->capacity >= m_sharedString->size+len)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
@@ -2547,7 +2547,7 @@ NzString& NzString::Insert(int pos, const char* string)
|
||||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = newSize;
|
||||
m_sharedString->capacity = newSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = newString;
|
||||
}
|
||||
@@ -2560,7 +2560,7 @@ NzString& NzString::Insert(int pos, const NzString& string)
|
||||
if (string.m_sharedString->size == 0)
|
||||
return *this;
|
||||
|
||||
if (m_sharedString->size == 0 && m_sharedString->allocatedSize < string.m_sharedString->size)
|
||||
if (m_sharedString->size == 0 && m_sharedString->capacity < string.m_sharedString->size)
|
||||
return operator=(string);
|
||||
|
||||
if (pos < 0)
|
||||
@@ -2569,7 +2569,7 @@ NzString& NzString::Insert(int pos, const NzString& string)
|
||||
unsigned int start = std::min(static_cast<unsigned int>(pos), m_sharedString->size);
|
||||
|
||||
// Si le buffer est déjà suffisamment grand
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size + string.m_sharedString->size)
|
||||
if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
@@ -2597,7 +2597,7 @@ NzString& NzString::Insert(int pos, const NzString& string)
|
||||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = newSize;
|
||||
m_sharedString->capacity = newSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = newString;
|
||||
}
|
||||
@@ -2870,7 +2870,7 @@ unsigned int NzString::Replace(const char* oldString, const char* replaceString,
|
||||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = newSize;
|
||||
m_sharedString->capacity = newSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = newString;
|
||||
}
|
||||
@@ -2940,7 +2940,7 @@ unsigned int NzString::Replace(const NzString& oldString, const NzString& replac
|
||||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = newSize;
|
||||
m_sharedString->capacity = newSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = newString;
|
||||
}
|
||||
@@ -3180,7 +3180,7 @@ unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharact
|
||||
*/
|
||||
void NzString::Reserve(unsigned int bufferSize)
|
||||
{
|
||||
if (m_sharedString->allocatedSize >= bufferSize)
|
||||
if (m_sharedString->capacity >= bufferSize)
|
||||
return;
|
||||
|
||||
char* ptr = new char[bufferSize+1];
|
||||
@@ -3191,7 +3191,7 @@ void NzString::Reserve(unsigned int bufferSize)
|
||||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = size;
|
||||
m_sharedString->string = ptr;
|
||||
}
|
||||
@@ -3203,7 +3203,7 @@ NzString& NzString::Resize(int size, char character)
|
||||
|
||||
unsigned int newSize = static_cast<unsigned int>(size);
|
||||
|
||||
if (m_sharedString->allocatedSize >= newSize)
|
||||
if (m_sharedString->capacity >= newSize)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
@@ -3232,7 +3232,7 @@ NzString& NzString::Resize(int size, char character)
|
||||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = newSize;
|
||||
m_sharedString->capacity = newSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = newString;
|
||||
}
|
||||
@@ -4103,13 +4103,13 @@ NzString& NzString::operator=(char character)
|
||||
{
|
||||
if (character != '\0')
|
||||
{
|
||||
if (m_sharedString->allocatedSize >= 1)
|
||||
if (m_sharedString->capacity >= 1)
|
||||
EnsureOwnership();
|
||||
else
|
||||
{
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = 1;
|
||||
m_sharedString->capacity = 1;
|
||||
m_sharedString->string = new char[2];
|
||||
}
|
||||
|
||||
@@ -4128,14 +4128,14 @@ NzString& NzString::operator=(const char* string)
|
||||
if (string && string[0] != '\0')
|
||||
{
|
||||
unsigned int size = std::strlen(string);
|
||||
if (m_sharedString->allocatedSize >= size)
|
||||
if (m_sharedString->capacity >= size)
|
||||
EnsureOwnership();
|
||||
else
|
||||
{
|
||||
ReleaseString();
|
||||
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = size;
|
||||
m_sharedString->capacity = size;
|
||||
m_sharedString->string = new char[size+1];
|
||||
}
|
||||
|
||||
@@ -4152,14 +4152,14 @@ NzString& NzString::operator=(const std::string& string)
|
||||
{
|
||||
if (string.size() > 0)
|
||||
{
|
||||
if (m_sharedString->allocatedSize >= string.size())
|
||||
if (m_sharedString->capacity >= string.size())
|
||||
EnsureOwnership();
|
||||
else
|
||||
{
|
||||
ReleaseString();
|
||||
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = string.size();
|
||||
m_sharedString->capacity = string.size();
|
||||
m_sharedString->string = new char[string.size()+1];
|
||||
}
|
||||
|
||||
@@ -4269,7 +4269,7 @@ NzString& NzString::operator+=(char character)
|
||||
if (m_sharedString->size == 0)
|
||||
return operator=(character);
|
||||
|
||||
if (m_sharedString->allocatedSize > m_sharedString->size)
|
||||
if (m_sharedString->capacity > m_sharedString->size)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
@@ -4289,7 +4289,7 @@ NzString& NzString::operator+=(char character)
|
||||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = str;
|
||||
}
|
||||
@@ -4309,7 +4309,7 @@ NzString& NzString::operator+=(const char* string)
|
||||
if (length == 0)
|
||||
return *this;
|
||||
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size + length)
|
||||
if (m_sharedString->capacity >= m_sharedString->size + length)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
@@ -4327,7 +4327,7 @@ NzString& NzString::operator+=(const char* string)
|
||||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = str;
|
||||
}
|
||||
@@ -4343,7 +4343,7 @@ NzString& NzString::operator+=(const std::string& string)
|
||||
if (m_sharedString->size == 0)
|
||||
return operator=(string);
|
||||
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size + string.size())
|
||||
if (m_sharedString->capacity >= m_sharedString->size + string.size())
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
@@ -4361,7 +4361,7 @@ NzString& NzString::operator+=(const std::string& string)
|
||||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = str;
|
||||
}
|
||||
@@ -4377,7 +4377,7 @@ NzString& NzString::operator+=(const NzString& string)
|
||||
if (m_sharedString->size == 0)
|
||||
return operator=(string);
|
||||
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size + string.m_sharedString->size)
|
||||
if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
@@ -4395,7 +4395,7 @@ NzString& NzString::operator+=(const NzString& string)
|
||||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = str;
|
||||
}
|
||||
@@ -5037,10 +5037,10 @@ void NzString::EnsureOwnership()
|
||||
{
|
||||
m_sharedString->refCount--;
|
||||
|
||||
char* string = new char[m_sharedString->allocatedSize+1];
|
||||
char* string = new char[m_sharedString->capacity+1];
|
||||
std::strcpy(string, m_sharedString->string);
|
||||
|
||||
m_sharedString = new SharedString(1, m_sharedString->allocatedSize, m_sharedString->size, string);
|
||||
m_sharedString = new SharedString(1, m_sharedString->capacity, m_sharedString->size, string);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <Nazara/Core/Win32/Time.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
///TODO: Faire en sorte que le EOF corresponde aux autres EOF de Nazara
|
||||
|
||||
NzFileImpl::NzFileImpl(const NzFile* parent) :
|
||||
m_endOfFile(false)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user