From de8983a382e56b61ac09cc64a457de148998eda9 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sat, 3 Nov 2018 16:49:51 +0100 Subject: [PATCH] - remove kexStr --- CMakeLists.txt | 2 - src/lightmap/common.h | 1 - src/lightmap/kexlib/binfile.cpp | 8 +- src/lightmap/kexlib/binfile.h | 5 +- src/lightmap/kexlib/kstring.cpp | 612 ---------------------------- src/lightmap/kexlib/kstring.h | 127 ------ src/lightmap/kexlib/math/mathlib.h | 4 +- src/lightmap/kexlib/math/vector.cpp | 6 +- 8 files changed, 13 insertions(+), 752 deletions(-) delete mode 100644 src/lightmap/kexlib/kstring.cpp delete mode 100644 src/lightmap/kexlib/kstring.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f26a3e1..599cdd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,7 +153,6 @@ set( SOURCES src/lightmap/collision.cpp src/lightmap/halffloat.cpp src/lightmap/kexlib/binfile.cpp - src/lightmap/kexlib/kstring.cpp src/lightmap/kexlib/memheap.cpp src/lightmap/kexlib/math/angle.cpp src/lightmap/kexlib/math/bounds.cpp @@ -195,7 +194,6 @@ set( HEADERS src/lightmap/collision.h src/lightmap/halffloat.h src/lightmap/kexlib/binfile.h - src/lightmap/kexlib/kstring.h src/lightmap/kexlib/memheap.h src/lightmap/kexlib/math/mathlib.h ) diff --git a/src/lightmap/common.h b/src/lightmap/common.h index d4ca17b..682d58a 100644 --- a/src/lightmap/common.h +++ b/src/lightmap/common.h @@ -154,7 +154,6 @@ typedef union #endif #include "kexlib/memheap.h" -#include "kexlib/kstring.h" #include "kexlib/math/mathlib.h" void Error(const char *error, ...); diff --git a/src/lightmap/kexlib/binfile.cpp b/src/lightmap/kexlib/binfile.cpp index 962679d..5de8f24 100644 --- a/src/lightmap/kexlib/binfile.cpp +++ b/src/lightmap/kexlib/binfile.cpp @@ -219,9 +219,9 @@ kexVec3 kexBinFile::ReadVector() return vec; } -kexStr kexBinFile::ReadString() +std::string kexBinFile::ReadString() { - kexStr str; + std::string str; char c = 0; while (1) @@ -278,11 +278,11 @@ void kexBinFile::WriteVector(const kexVec3 &val) WriteFloat(val.z); } -void kexBinFile::WriteString(const kexStr &val) +void kexBinFile::WriteString(const std::string &val) { const char *c = val.c_str(); - for (int i = 0; i < val.Length(); i++) + for (size_t i = 0; i < val.size(); i++) { Write8(c[i]); } diff --git a/src/lightmap/kexlib/binfile.h b/src/lightmap/kexlib/binfile.h index c1e8403..71226f5 100644 --- a/src/lightmap/kexlib/binfile.h +++ b/src/lightmap/kexlib/binfile.h @@ -28,6 +28,7 @@ #pragma once #include "lightmap/kexlib/math/mathlib.h" +#include class kexBinFile { @@ -47,14 +48,14 @@ public: int Read32(); float ReadFloat(); kexVec3 ReadVector(); - kexStr ReadString(); + std::string ReadString(); void Write8(const byte val); void Write16(const short val); void Write32(const int val); void WriteFloat(const float val); void WriteVector(const kexVec3 &val); - void WriteString(const kexStr &val); + void WriteString(const std::string &val); int GetOffsetValue(int id); byte *GetOffset(int id, byte *subdata = NULL, int *count = NULL); diff --git a/src/lightmap/kexlib/kstring.cpp b/src/lightmap/kexlib/kstring.cpp deleted file mode 100644 index eaea3f4..0000000 --- a/src/lightmap/kexlib/kstring.cpp +++ /dev/null @@ -1,612 +0,0 @@ -//----------------------------------------------------------------------------- -// Note: this is a modified version of dlight. It is not the original software. -//----------------------------------------------------------------------------- -// -// Copyright (c) 2013-2014 Samuel Villarreal -// svkaiser@gmail.com -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source -// distribution. -// -//----------------------------------------------------------------------------- -// -// DESCRIPTION: String Class -// -//----------------------------------------------------------------------------- - -#include -#include "kstring.h" - -void kexStr::Init() -{ - length = 0; - bufferLength = STRING_DEFAULT_SIZE; - charPtr = defaultBuffer; - charPtr[0] = '\0'; -} - -void kexStr::CheckSize(int size, bool bKeepString) -{ - if (size <= bufferLength) - { - return; - } - - Resize(size, bKeepString); -} - -void kexStr::CopyNew(const char *string, int len) -{ - CheckSize(len + 1, false); - strcpy(charPtr, string); - length = len; -} - -kexStr::kexStr() -{ - Init(); -} - -kexStr::kexStr(const char *string) -{ - Init(); - - if (string == NULL) - { - return; - } - - CopyNew(string, strlen(string)); -} - -kexStr::kexStr(const char *string, const int length) -{ - Init(); - - if (string == NULL) - { - return; - } - - CopyNew(string, length); -} - -kexStr::kexStr(const kexStr &string) -{ - Init(); - - if (string.charPtr == NULL) - { - return; - } - - CopyNew(string.charPtr, string.Length()); -} - -kexStr::~kexStr() -{ - if (charPtr != defaultBuffer) - { - delete[] charPtr; - charPtr = defaultBuffer; - } - - charPtr[0] = '\0'; - length = 0; -} - -kexStr &kexStr::Concat(const char *string) -{ - return Concat(string, strlen(string)); -} - -kexStr &kexStr::Concat(const char c) -{ - CheckSize((length + 1) + 1, true); - charPtr[length++] = c; - charPtr[length] = '\0'; - return *this; -} - -kexStr &kexStr::Concat(const char *string, int len) -{ - CheckSize((length + len) + 1, true); - - for (int i = 0; i < len; i++) - { - charPtr[length + i] = string[i]; - } - - length += len; - charPtr[length] = '\0'; - - return *this; -} - -kexStr &kexStr::Copy(const kexStr &src, int len) -{ - int i = 0; - const char *p = src; - CheckSize((length + len) + 1, true); - - while ((len--) >= 0) - { - charPtr[i] = p[i]; - i++; - } - - return *this; -} - -kexStr &kexStr::Copy(const kexStr &src) -{ - return Copy(src, src.Length()); -} - -kexStr &kexStr::operator=(const kexStr &str) -{ - int len = str.Length(); - - CheckSize(len + 1, false); - strncpy(charPtr, str.charPtr, len); - length = len; - charPtr[length] = '\0'; - - return *this; -} - -kexStr &kexStr::operator=(const char *str) -{ - int len = strlen(str); - - CheckSize(len + 1, false); - strncpy(charPtr, str, len); - length = len; - charPtr[length] = '\0'; - - return *this; -} - -kexStr &kexStr::operator=(const bool b) -{ - const char *str = b ? "true" : "false"; - int len = strlen(str); - - CheckSize(len + 1, false); - strncpy(charPtr, str, len); - length = len; - charPtr[length] = '\0'; - - return *this; -} - -kexStr kexStr::operator+(const kexStr &str) -{ - kexStr out(*this); - - return out.Concat(str.c_str()); -} - -kexStr kexStr::operator+(const char *str) -{ - kexStr out(*this); - - return out.Concat(str); -} - -kexStr kexStr::operator+(const bool b) -{ - kexStr out(*this); - - return out.Concat(b ? "true" : "false"); -} - -kexStr kexStr::operator+(const int i) -{ - kexStr out(*this); - - char tmp[64]; - sprintf(tmp, "%i", i); - - return out.Concat(tmp); -} - -kexStr kexStr::operator+(const float f) -{ - kexStr out(*this); - - char tmp[64]; - sprintf(tmp, "%f", f); - - return out.Concat(tmp); -} - -kexStr &kexStr::operator+=(const kexStr &str) -{ - return Concat(str.c_str()); -} - -kexStr &kexStr::operator+=(const char *str) -{ - return Concat(str); -} - -kexStr &kexStr::operator+=(const char c) -{ - return Concat(c); -} - -kexStr &kexStr::operator+=(const bool b) -{ - return Concat(b ? "true" : "false"); -} - -const char kexStr::operator[](int index) const -{ - assert(index >= 0 && index < length); - return charPtr[index]; -} - -void kexStr::Resize(int size, bool bKeepString) -{ - - if (size <= 0) - { - return; - } - - int newsize = size + ((32 - (size & 31)) & 31); - char *newbuffer = new char[newsize]; - - if (bKeepString) - { - strncpy(newbuffer, charPtr, length); - } - - if (charPtr != defaultBuffer) - { - delete[] charPtr; - } - - charPtr = newbuffer; - bufferLength = newsize; -} - -int kexStr::IndexOf(const char *pattern) const -{ - int patlen = strlen(pattern); - int i = 0; - int j = 0; - - while (i + j < Length()) - { - if (charPtr[i + j] == pattern[j]) - { - if (++j == patlen) - { - return i; - } - } - else - { - i++; - j = 0; - } - } - - return -1; -} - -int kexStr::IndexOf(const char *string, const char *pattern) -{ - int patlen = strlen(pattern); - int i = 0; - int j = 0; - - while (i + j < (int)strlen(string)) - { - if (string[i + j] == pattern[j]) - { - if (++j == patlen) - { - return i; - } - } - else - { - i++; - j = 0; - } - } - - return -1; -} - -int kexStr::IndexOf(const kexStr &pattern) const -{ - return IndexOf(pattern.c_str()); -} - -kexStr &kexStr::NormalizeSlashes() -{ - for (int i = 0; i < length; i++) - { - if ((charPtr[i] == '/' || charPtr[i] == '\\') && charPtr[i] != DIR_SEPARATOR) - { - charPtr[i] = DIR_SEPARATOR; - } - } - - return *this; -} - -kexStr &kexStr::StripPath() -{ - int pos = 0; - int i = 0; - - pos = length; - - for (i = length - 1; charPtr[i] != '\\' && charPtr[i] != '/'; i--, pos--) - { - if (pos <= 0) - { - return *this; - } - } - length = length - pos; - for (i = 0; i < length; i++) - { - charPtr[i] = charPtr[pos + i]; - } - - CheckSize(length, true); - charPtr[length] = '\0'; - return *this; -} - -kexStr &kexStr::StripExtension() -{ - int pos = IndexOf("."); - - if (pos == -1) - { - return *this; - } - - length = pos; - CheckSize(length, true); - charPtr[length] = '\0'; - - return *this; -} - -kexStr &kexStr::StripFile() -{ - int pos = 0; - int i = 0; - - if (IndexOf(".") == -1) - { - return *this; - } - - pos = length; - - for (i = length - 1; charPtr[i] != '\\' && charPtr[i] != '/'; i--, pos--) - { - if (pos <= 0) - { - return *this; - } - } - - length = pos; - CheckSize(length, true); - charPtr[length] = '\0'; - - return *this; -} - -int kexStr::Hash() -{ - unsigned int hash = 0; - char *str = (char*)charPtr; - char c; - - while ((c = *str++)) - { - hash = c + (hash << 6) + (hash << 16) - hash; - } - - return hash & (MAX_HASH - 1); -} - -int kexStr::Hash(const char *s) -{ - unsigned int hash = 0; - char *str = (char*)s; - char c; - - while ((c = *str++)) - { - hash = c + (hash << 6) + (hash << 16) - hash; - } - - return hash & (MAX_HASH - 1); -} - -char *kexStr::Format(const char *str, ...) -{ - va_list v; - static char vastr[1024]; - - va_start(v, str); - vsprintf(vastr, str, v); - va_end(v); - - return vastr; -} - -kexStr kexStr::Substr(int start, int len) const -{ - kexStr str; - int l = Length(); - - if (l <= 0 || start >= l) - { - return str; - } - - if (start + len >= l) - { - len = l - start; - } - - return str.Concat((const char*)&charPtr[start], len); -} -/* -void kexStr::Split(kexStrList &list, const char seperator) -{ - int splitLen = 0; - int startOffs = 0; - for (int i = 0; i < length; i++) - { - if (charPtr[i] == seperator) - { - if (splitLen == 0) - { - continue; - } - - list.Push(kexStr(&charPtr[startOffs], splitLen)); - startOffs += (splitLen + 1); - splitLen = 0; - continue; - } - - splitLen++; - } - - if (splitLen != 0 && startOffs != 0) - { - list.Push(kexStr(&charPtr[startOffs], splitLen)); - } -} -*/ -int kexStr::Atoi() -{ - return atoi(charPtr); -} - -float kexStr::Atof() -{ - return (float)atof(charPtr); -} - -void kexStr::WriteToFile(const char *file) -{ - if (length <= 0) - { - return; - } - - FILE *f = fopen(file, "w"); - fprintf(f, "%s", charPtr); - fclose(f); -} - -kexStr &kexStr::ToUpper() -{ - char c; - for (int i = 0; i < length; i++) - { - c = charPtr[i]; - if (c >= 'a' && c <= 'z') - { - c -= 'a' - 'A'; - } - charPtr[i] = c; - } - - return *this; -} - -kexStr &kexStr::ToLower() -{ - char c; - for (int i = 0; i < length; i++) - { - c = charPtr[i]; - if (c >= 'A' && c <= 'Z') - { - c += 32; - } - charPtr[i] = c; - } - - return *this; -} - -bool kexStr::CompareCase(const char *s1, const char *s2) -{ - while (*s1 && *s2) - { - if (*s1 != *s2) - { - return (*s2 - *s1) != 0; - } - s1++; - s2++; - } - if (*s1 != *s2) - { - return (*s2 - *s1) != 0; - } - - return false; -} - -bool kexStr::CompareCase(const kexStr &a, const kexStr &b) -{ - return CompareCase(a.c_str(), b.c_str()); -} - -bool kexStr::Compare(const char *s1, const char *s2) -{ - const byte *us1 = (const byte*)s1; - const byte *us2 = (const byte*)s2; - - while (tolower(*us1) == tolower(*us2)) - { - if (*us1++ == '\0') - { - return false; - } - - us2++; - } - - return (tolower(*us1) - tolower(*us2)) != 0; -} - -bool kexStr::Compare(const kexStr &a, const kexStr &b) -{ - return Compare(a.c_str(), b.c_str()); -} diff --git a/src/lightmap/kexlib/kstring.h b/src/lightmap/kexlib/kstring.h deleted file mode 100644 index d7f3e97..0000000 --- a/src/lightmap/kexlib/kstring.h +++ /dev/null @@ -1,127 +0,0 @@ -//----------------------------------------------------------------------------- -// Note: this is a modified version of dlight. It is not the original software. -//----------------------------------------------------------------------------- -// -// Copyright (c) 2013-2014 Samuel Villarreal -// svkaiser@gmail.com -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source -// distribution. -// - -#pragma once - -#include -#include "lightmap/common.h" - -class kexStr; - -//typedef kexArray kexStrList; - -class kexStr -{ -public: - kexStr(); - kexStr(const char *string); - kexStr(const char *string, const int length); - kexStr(const kexStr &string); - ~kexStr(); - - void CheckSize(int size, bool bKeepString); - int IndexOf(const char *pattern) const; - int IndexOf(const kexStr &pattern) const; - kexStr &Concat(const char *string); - kexStr &Concat(const char *string, int len); - kexStr &Concat(const char c); - kexStr &NormalizeSlashes(); - kexStr &StripPath(); - kexStr &StripExtension(); - kexStr &StripFile(); - kexStr &Copy(const kexStr &src, int len); - kexStr &Copy(const kexStr &src); - kexStr &ToUpper(); - kexStr &ToLower(); - int Hash(); - kexStr Substr(int start, int len) const; - //void Split(kexStrList &list, const char seperator); - int Atoi(); - float Atof(); - void WriteToFile(const char *file); - - int Length() const { return length; } - const char *c_str() const { return charPtr; } - - kexStr &operator=(const kexStr &str); - kexStr &operator=(const char *str); - kexStr &operator=(const bool b); - kexStr operator+(const kexStr &str); - kexStr operator+(const char *str); - kexStr operator+(const bool b); - kexStr operator+(const int i); - kexStr operator+(const float f); - kexStr &operator+=(const kexStr &str); - kexStr &operator+=(const char *str); - kexStr &operator+=(const char c); - kexStr &operator+=(const bool b); - const char operator[](int index) const; - - friend bool operator==(const kexStr &a, const kexStr &b); - friend bool operator==(const char *a, const kexStr &b); - friend bool operator==(const kexStr &a, const char *b); - - operator const char *() const { return c_str(); } - operator const char *() { return c_str(); } - - static bool CompareCase(const char *s1, const char *s2); - static bool CompareCase(const kexStr &a, const kexStr &b); - static bool Compare(const char *s1, const char *s2); - static bool Compare(const kexStr &a, const kexStr &b); - static int IndexOf(const char *string, const char *pattern); - static int Hash(const char *s); - static char *Format(const char *str, ...); - -private: - void Resize(int size, bool bKeepString); - void CopyNew(const char *string, int len); - -protected: - void Init(); - - static const int STRING_DEFAULT_SIZE = 32; - - char *charPtr; - char defaultBuffer[STRING_DEFAULT_SIZE]; - int length; - int bufferLength; -}; - -d_inline bool operator==(const kexStr &a, const kexStr &b) -{ - return (!strcmp(a.charPtr, b.charPtr)); -} - -d_inline bool operator==(const char *a, const kexStr &b) -{ - return (!strcmp(a, b.charPtr)); -} - -d_inline bool operator==(const kexStr &a, const char *b) -{ - return (!strcmp(a.charPtr, b)); -} diff --git a/src/lightmap/kexlib/math/mathlib.h b/src/lightmap/kexlib/math/mathlib.h index aae91a7..6c65235 100644 --- a/src/lightmap/kexlib/math/mathlib.h +++ b/src/lightmap/kexlib/math/mathlib.h @@ -162,7 +162,7 @@ public: kexVec2 Lerp(const kexVec2 &next, float movement) const; kexVec2 &Lerp(const kexVec2 &next, const float movement); kexVec2 &Lerp(const kexVec2 &start, const kexVec2 &next, float movement); - kexStr ToString() const; + //kexStr ToString() const; float ToYaw() const; float *ToFloatPtr(); kexVec3 ToVec3(); @@ -230,7 +230,7 @@ public: kexQuat ToQuat(); float ToYaw() const; float ToPitch() const; - kexStr ToString() const; + //kexStr ToString() const; float *ToFloatPtr(); kexVec2 ToVec2(); kexVec2 ToVec2() const; diff --git a/src/lightmap/kexlib/math/vector.cpp b/src/lightmap/kexlib/math/vector.cpp index be12ee7..634ddbe 100644 --- a/src/lightmap/kexlib/math/vector.cpp +++ b/src/lightmap/kexlib/math/vector.cpp @@ -268,13 +268,14 @@ float kexVec2::ToYaw() const // // kexVec2::ToString // - +/* kexStr kexVec2::ToString() const { kexStr str; str = str + x + " " + y; return str; } +*/ // // kexVec2::ToFloatPtr @@ -774,13 +775,14 @@ float kexVec3::ToPitch() const // // kexVec3::ToString // - +/* kexStr kexVec3::ToString() const { kexStr str; str = str + x + " " + y + " " + z; return str; } +*/ // // kexVec3::ToFloatPtr