Commit b3951c6f authored by D-AIRY's avatar D-AIRY

Some refactor

parent 332b5eb4
......@@ -25,7 +25,7 @@ template<typename T, int BlockSize=16>
class Array
{
public:
Array():Size(0),AllocSize(0),Data(NULL)
Array():Size(0), AllocSize(0), Data(NULL)
{
Alloc();
}
......@@ -35,13 +35,13 @@ public:
Alloc();
//this->AllocSize = arr.AllocSize;
//this->Size = arr.Size;
for(int i = arr.Size - 1; i >= 0; i--)
{
(*this)[i] = arr[i];
}
for(int i = arr.Size - 1; i >= 0; i--)
{
(*this)[i] = arr[i];
}
}
void swap(Array &arr)
void swap(Array &arr)
{
UINT tmpS = Size;
Size = arr.Size;
......@@ -56,7 +56,7 @@ public:
arr.Data = (T*)tmpD;
}
void resize(UINT NewSize)
void resize(UINT NewSize)
{
if(NewSize == Size)
{
......@@ -64,10 +64,10 @@ public:
}
Realloc(NewSize);
//ConstructInterval(this->Size, key);
if(this->Size < NewSize)
{
ConstructInterval(this->Size, NewSize - 1);
}
if(this->Size < NewSize)
{
ConstructInterval(this->Size, NewSize - 1);
}
this->Size = NewSize;
}
......@@ -88,7 +88,7 @@ public:
this->Size = NewSize;
}
void reserve(UINT size)
void reserve(UINT size)
{
Realloc(size);
}
......@@ -120,12 +120,12 @@ public:
//inline Array & operator=(T* arr)
//{
//this->AllocSize = arr.AllocSize;
//this->Size = arr.Size;
/*for(int i = arr.Size - 1; i >= 0; i--)
{
(*this)[i] = arr[i];
}*/
//this->AllocSize = arr.AllocSize;
//this->Size = arr.Size;
/*for(int i = arr.Size - 1; i >= 0; i--)
{
(*this)[i] = arr[i];
}*/
// return(*this);
//}
......@@ -151,15 +151,15 @@ public:
{
}
if(key >= this->Size)
if(key >= this->Size)
{
if(key >= this->AllocSize)
{
if(key >= this->AllocSize)
{
Realloc(max(this->AllocSize, key) + BlockSize);
}
ConstructInterval(this->Size, key);
this->Size = key + 1;
Realloc(max(this->AllocSize, key) + BlockSize);
}
ConstructInterval(this->Size, key);
this->Size = key + 1;
}
return(Data[key]);
}
......@@ -176,33 +176,33 @@ public:
const T & operator[](UINT key) const
{
if(key >= this->Size)
if(key >= this->Size)
{
/*_asm
{
/*_asm
{
int 3;
};*/
//SkyXEngine::Core::InError("exit in array");
}
int 3;
};*/
//SkyXEngine::Core::InError("exit in array");
}
return(Data[key]);
}
~Array()
{
if(Size)
{
DestructInterval(0, Size - 1);
}
if(Size)
{
DestructInterval(0, Size - 1);
}
free(Data);
}
void clear()
{
if(Size)
{
DestructInterval(0, Size - 1);
}
if(Size)
{
DestructInterval(0, Size - 1);
}
free(Data);
Size = 0;
AllocSize = 0;
......@@ -210,7 +210,7 @@ public:
Alloc();
}
void clearFast()
void clearFast()
{
if(Size)
{
......@@ -228,7 +228,7 @@ public:
void quickSort(const L& CompareFunc)
{
//don't sort 0 or 1 elements
if(size()>1)
if(size() > 1)
{
quickSortInternal(CompareFunc, 0, size() - 1);
}
......@@ -239,7 +239,7 @@ protected:
/*
#ifdef S4G
friend s4g_Stack<T, BlockSize>;
#endif*/
#endif*/
void Alloc()
{
Realloc(BlockSize);
......@@ -253,12 +253,12 @@ protected:
}
T * tmpData = (T*)malloc(sizeof(T) * NewSize);
memcpy(tmpData, this->Data, min(NewSize, this->Size) * sizeof(T));
if(this->Size > NewSize)
{
DestructInterval(NewSize, this->Size - 1);
this->Size = NewSize;
}
if(this->Size > NewSize)
{
DestructInterval(NewSize, this->Size - 1);
this->Size = NewSize;
}
this->AllocSize = NewSize;
T * tmpDel = this->Data;
this->Data = tmpData;
......@@ -268,18 +268,18 @@ protected:
void ConstructInterval(UINT start, UINT end)
{
//this->Data + start = new(this->Data + start) T[end - start + 1];
for(UINT i = start; i <= end; i++)
{
new(&this->Data[i]) T;
}
for(UINT i = start; i <= end; i++)
{
new(&this->Data[i]) T;
}
}
void DestructInterval(UINT start, UINT end)
{
for(UINT i = start; i <= end; i++)
{
(&this->Data[i])->~T();
}
for(UINT i = start; i <= end; i++)
{
(&this->Data[i])->~T();
}
}
......@@ -308,9 +308,9 @@ protected:
while(i <= j);
// recursion
if(lo<j)
if(lo < j)
quickSortInternal(CompareFunc, lo, j);
if(i<hi)
if(i < hi)
quickSortInternal(CompareFunc, i, hi);
}
......
This diff is collapsed.
......@@ -47,9 +47,9 @@ void operator delete[](void* ptr)\
#define SM_PIDIV2 1.570796327f
#define SM_PIDIV4 0.785398163f
#define vlerp(x,y,s) (x + s*(y - x))
#define sign(x) (x >= 0 ? (x>0 ?1 :0) : -1)
#define sign2(x) (x >= 0 ? 1 : -1)
#define vlerp(x,y,s) ((x) + (s)*((y) - (x)))
#define sign(x) ((x) >= 0 ? ((x)>0 ?1 :0) : -1)
#define sign2(x) ((x) >= 0 ? 1 : -1)
#define SMToRadian(degree)((degree)*(SM_PI / 180.0f))
#define SMToAngle(rad)((rad)*(180.0f / SM_PI))
......
......@@ -72,25 +72,26 @@ public:
this->CurrentNode->data = data;
}
T pop()
bool pop(T *pOut)
{
if(SP)
{
StackNode * tmp = this->CurrentNode;
CurrentNode = this->CurrentNode->Parent;
this->SP--;
T data = tmp->data;
//remove tmp
Data.Delete(tmp);
return(data);
}
//return(NULL);
assert(pOut);
if(SP)
{
StackNode * tmp = this->CurrentNode;
CurrentNode = this->CurrentNode->Parent;
this->SP--;
*pOut = tmp->data;
//remove tmp
Data.Delete(tmp);
return(true);
}
return(false);
}
void pop(int countpop)
void popN(int countpop)
{
for (int i = 0; i < countpop; ++i)
for(int i = 0; i < countpop; ++i)
{
if (SP)
if(SP)
{
StackNode * tmp = this->CurrentNode;
CurrentNode = this->CurrentNode->Parent;
......@@ -123,12 +124,12 @@ public:
T get(int id)
{
if (id < 0)
if(id < 0)
{
id += this->SP;
}
--id;
if (id < 0 || id >= this->SP)
if(id < 0 || id >= this->SP)
{
return(NULL);
}
......
......@@ -177,15 +177,6 @@ String String::operator+(const String &str) const
return(newSXStr);
}
String String::operator+(const String *str)
{
char * ns = new char[length() + str->length() + 1];
sprintf(ns, "%s%s", m_szString, str->c_str());
String newSXStr = ns;
SAFE_DELETE_A(ns);
return(newSXStr);
}
String String::operator+(const char * str)
{
char * ns = new char[length() + strlen(str) + 1];
......@@ -263,17 +254,12 @@ String String::operator+(const bool & bf)
String & String::operator=(const String & str)
{
release();
m_szString = new char[str.length() + 1];
memcpy(m_szString, str.c_str(), str.length() + 1);
return(*this);
}
String & String::operator=(const String * str)
{
release();
m_szString = new char[str->length() + 1];
memcpy(m_szString, str->c_str(), str->length() + 1);
if(&str != this)
{
release();
m_szString = new char[str.length() + 1];
memcpy(m_szString, str.c_str(), str.length() + 1);
}
return(*this);
}
......@@ -380,15 +366,6 @@ String & String::operator+=(const String & str)
return(*this);
}
String & String::operator+=(const String * str)
{
char * ns = new char[length() + str->length() + 1];
sprintf(ns, "%s%s", m_szString, str->c_str());
SAFE_DELETE_A(m_szString);
m_szString = ns;
return(*this);
}
String & String::operator+=(const char * str)
{
char * newstring = new char[length() + strlen(str) + 1];
......@@ -470,13 +447,6 @@ String String::operator-(const String & str)
return(newStr);
}
String String::operator-(const String * str)
{
String newStr = this;
newStr.replace(str, "", 0);
return(newStr);
}
String String::operator-(const char * str)
{
String newStr = this;
......@@ -541,12 +511,6 @@ String & String::operator-=(const String & str)
return(*this);
}
String & String::operator-=(const String * str)
{
replace(str, "", 0);
return(*this);
}
String & String::operator-=(const char * str)
{
replace(str, "", 0);
......@@ -604,13 +568,6 @@ String String::operator/(const String & str)
return(newStr);
}
String String::operator/(const String * str)
{
String newStr = this;
newStr.replaceAll(str, "");
return(newStr);
}
String String::operator/(const char * str)
{
String newStr = this;
......@@ -675,12 +632,6 @@ String & String::operator/=(const String & str)
return(*this);
}
String & String::operator/=(const String * str)
{
replaceAll(str, "");
return(*this);
}
String & String::operator/=(const char * str)
{
replaceAll(str, "");
......@@ -733,37 +684,15 @@ String & String::operator/=(const bool & bf)
bool String::operator==(const String & str) const
{
/*if(this->length() == str.length())
{
DWORD len = this->length();
for(DWORD i = 0; i<len; i++)
if(&str == this || !strcmp(m_szString, str.m_szString))
{
if(this->m_szString[i] != str.m_szString[i])
return false;
}
return(true);
}
else
return false;
return true;*/
return(operator==(&str));
}
bool String::operator==(const String * str) const
{
if(length() == str->length())
{
DWORD len = length();
for(DWORD i = 0; i<len; i++)
{
if(m_szString[i] != str->m_szString[i])
return false;
}
}
else
return false;
return(false);
return true;
return(operator==(&str));
}
bool String::operator==(const char * str) const
......@@ -841,11 +770,6 @@ bool String::operator!=(const String & str) const
return !(*this == str);
}
bool String::operator!=(const String * str) const
{
return !(*this == *str);
}
bool String::operator!=(const char * str) const
{
return !(*this == str);
......@@ -968,7 +892,7 @@ DWORD String::replaceAll(const char * str, const char * replace)
while(PosCodeBegin != ~0)
{
PosCodeBegin = find(str, (DWORD)PosCodeOld);
if(PosCodeBegin != ~0)
if(PosCodeBegin != (size_t)((DWORD)~0))
{
CountCodeFMT++;
PosCodeOld = PosCodeBegin + strlen(str);
......@@ -1000,7 +924,7 @@ DWORD String::replaceAll(const char * str, const char * replace)
OldPosEndFmt = PosBeginFmt+StrLen;*/
memcpy(count_str, m_szString + OldPosEndFmt, PosBeginFmt - OldPosEndFmt);
count_str_last_len += PosBeginFmt - OldPosEndFmt;
memcpy(count_str + count_str_last_len, replace, strlen(replace));
strcpy(count_str + count_str_last_len, replace);
count_str_last_len += strlen(replace);
OldPosEndFmt = PosBeginFmt + StrLen;
}
......@@ -1016,7 +940,7 @@ DWORD String::replaceAll(const char * str, const char * replace)
memcpy(count_str + count_str_last_len, m_szString + OldPosEndFmt, PosBeginFmt - OldPosEndFmt);
count_str_last_len += PosBeginFmt - OldPosEndFmt;
memcpy(count_str + count_str_last_len, replace, strlen(replace));
strcpy(count_str + count_str_last_len, replace);
count_str_last_len += strlen(replace);
OldPosEndFmt = PosBeginFmt + StrLen;
......@@ -1341,15 +1265,6 @@ StringW StringW::operator+(const StringW &str) const
return(newSXStr);
}
StringW StringW::operator+(const StringW *str)
{
WCHAR * ns = new WCHAR[length() + str->length() + 1];
swprintf(ns, length() + str->length() + 1, L"%ls%ls", m_szString, str->c_str());
StringW newSXStr = ns;
SAFE_DELETE_A(ns);
return(newSXStr);
}
StringW StringW::operator+(const WCHAR * str)
{
WCHAR * ns = new WCHAR[length() + wcslen(str) + 1];
......@@ -1427,17 +1342,12 @@ StringW StringW::operator+(const bool & bf)
StringW & StringW::operator=(const StringW & str)
{
release();
m_szString = new WCHAR[str.length() + 1];
memcpy(m_szString, str.c_str(), sizeof(WCHAR) * (str.length() + 1));
return(*this);
}
StringW & StringW::operator=(const StringW * str)
{
release();
m_szString = new WCHAR[str->length() + 1];
memcpy(m_szString, str->c_str(), sizeof(WCHAR) * (str->length() + 1));
if(&str != this)
{
release();
m_szString = new WCHAR[str.length() + 1];
memcpy(m_szString, str.c_str(), sizeof(WCHAR) * (str.length() + 1));
}
return(*this);
}
......@@ -1544,15 +1454,6 @@ StringW & StringW::operator+=(const StringW & str)
return(*this);
}
StringW & StringW::operator+=(const StringW * str)
{
WCHAR * ns = new WCHAR[length() + str->length() + 1];
swprintf(ns, length() + str->length() + 1, L"%ls%ls", m_szString, str->c_str());
SAFE_DELETE_A(m_szString);
m_szString = ns;
return(*this);
}
StringW & StringW::operator+=(const WCHAR * str)
{
WCHAR * newstring = new WCHAR[length() + wcslen(str) + 1];
......@@ -1634,13 +1535,6 @@ StringW StringW::operator-(const StringW & str)
return(newStr);
}
StringW StringW::operator-(const StringW * str)
{
StringW newStr = this;
newStr.replace(str, "", 0);
return(newStr);
}
StringW StringW::operator-(const WCHAR * str)
{
StringW newStr = this;
......@@ -1705,12 +1599,6 @@ StringW & StringW::operator-=(const StringW & str)
return(*this);
}
StringW & StringW::operator-=(const StringW * str)
{
replace(str, "", 0);
return(*this);
}
StringW & StringW::operator-=(const WCHAR * str)
{
replace(str, "", 0);
......@@ -1768,13 +1656,6 @@ StringW StringW::operator/(const StringW & str)
return(newStr);
}
StringW StringW::operator/(const StringW * str)
{
StringW newStr = this;
newStr.replaceAll(str, L"");
return(newStr);
}
StringW StringW::operator/(const WCHAR * str)
{
StringW newStr = this;
......@@ -1839,12 +1720,6 @@ StringW & StringW::operator/=(const StringW & str)
return(*this);
}
StringW & StringW::operator/=(const StringW * str)
{
replaceAll(str, L"");
return(*this);
}
StringW & StringW::operator/=(const WCHAR * str)
{
replaceAll(str, L"");
......@@ -1897,37 +1772,12 @@ StringW & StringW::operator/=(const bool & bf)
bool StringW::operator==(const StringW & str) const
{
/*if(this->length() == str.length())
{
DWORD len = this->length();
for(DWORD i = 0; i<len; i++)
{
if(this->m_szString[i] != str.m_szString[i])
return false;
}
}
else
return false;
return true;*/
return(operator==(&str));
}
bool StringW::operator==(const StringW * str) const
{
if(length() == str->length())
if(&str == this || !lstrcmpW(m_szString, str.m_szString))
{
DWORD len = length();
for(DWORD i = 0; i<len; i++)
{
if(m_szString[i] != str->m_szString[i])
return false;
}
return(true);
}
else
return false;
return true;
return(false);
}
bool StringW::operator==(const WCHAR * str) const
......@@ -2005,11 +1855,6 @@ bool StringW::operator!=(const StringW & str) const
return !(*this == str);
}
bool StringW::operator!=(const StringW * str) const
{
return !(*this == *str);
}
bool StringW::operator!=(const WCHAR * str) const
{
return !(*this == str);
......@@ -2292,7 +2137,7 @@ double StringW::toDouble() const
{
//return(atof(m_szString));
double tmp;
swscanf(m_szString, L"%G", &tmp);
swscanf(m_szString, L"%lg", &tmp);
return(tmp);
}
......
......@@ -50,7 +50,6 @@ public:
//который и содержит результат сложения строк
String operator+(const String & str) const;
String operator+(const String * str);
String operator+(const char * str);
String operator+(const char & sym);
......@@ -65,7 +64,6 @@ public:
//операции присваивания
String & operator=(const String & str);
String & operator=(const String * str);
String & operator=(const char * str);
String & operator=(const char & sym);
......@@ -81,7 +79,6 @@ public:
////////////////////////////////////
//операции сложения строк объекта к которому применяется сложение и слагаемого
String & operator+=(const String &str);
String & operator+=(const String *str);
String & operator+=(const char * str);
String & operator+=(const char & sym);
......@@ -96,7 +93,6 @@ public:
//искоючить первое нахождение из строки
//возвращается новый объект String, который содержит результат
String operator-(const String & str);
String operator-(const String * str);
String operator-(const char * str);
String operator-(const char & sym);
......@@ -110,7 +106,6 @@ public:
////////////////////////////////////
//исключает первое нахождение из данного объекта
String & operator-=(const String &str);
String & operator-=(const String *str);
String & operator-=(const char * str);
String & operator-=(const char & sym);
......@@ -125,7 +120,6 @@ public:
//исключить все похожие нахождения
//возвращается новый объект String
String operator / (const String &str);
String operator / (const String *str);
String operator/(const char * str);
String operator/(const char & sym);
......@@ -139,7 +133,6 @@ public:
////////////////////////////////////
//исключить все похожие нахождения
String & operator/=(const String &str);
String & operator/=(const String *str);
String & operator/=(const char * str);
String & operator/=(const char & sym);
......@@ -153,7 +146,6 @@ public:
////////////////////////////////////
bool operator==(const String &str) const;
bool operator==(const String *str) const;
bool operator==(const char * str) const;
bool operator==(const char & sym) const;
......@@ -167,7 +159,6 @@ public:
//////////////////////////////////////
bool operator!= (const String &str) const;
bool operator!= (const String *str) const;
bool operator!=(const char * str) const;
bool operator!=(const char & sym) const;
......@@ -255,7 +246,6 @@ public:
//который и содержит результат сложения строк
StringW operator+(const StringW & str) const;
StringW operator+(const StringW * str);
StringW operator+(const WCHAR * str);
StringW operator+(const WCHAR & sym);
......@@ -270,7 +260,6 @@ public:
//операции присвоения
StringW & operator=(const StringW & str);
StringW & operator=(const StringW * str);
StringW & operator=(const WCHAR * str);
StringW & operator=(const WCHAR & sym);
......@@ -286,7 +275,6 @@ public:
////////////////////////////////////
//операции сложения строк объекта к которому применяется сложение и слагаемого
StringW & operator+=(const StringW &str);
StringW & operator+=(const StringW *str);
StringW & operator+=(const WCHAR * str);
StringW & operator+=(const WCHAR & sym);
......@@ -301,7 +289,6 @@ public:
//искоючить первое нахождение из строки
//возвращается новый объект String, который содержит результат
StringW operator-(const StringW & str);
StringW operator-(const StringW * str);
StringW operator-(const WCHAR * str);
StringW operator-(const WCHAR & sym);
......@@ -315,7 +302,6 @@ public:
////////////////////////////////////
//исключает первое нахождение из данного объекта
StringW & operator-=(const StringW &str);
StringW & operator-=(const StringW *str);
StringW & operator-=(const WCHAR * str);
StringW & operator-=(const WCHAR & sym);
......@@ -330,7 +316,6 @@ public: