diff --git a/Common/CFourCC.cpp b/Common/CFourCC.cpp index 0d4c61d6..684297da 100644 --- a/Common/CFourCC.cpp +++ b/Common/CFourCC.cpp @@ -11,7 +11,7 @@ CFourCC::CFourCC(const char *src) *this = src; } -CFourCC::CFourCC(const std::string& src) +CFourCC::CFourCC(const TString& src) { *this = src; } @@ -37,9 +37,9 @@ u32 CFourCC::ToLong() const return mFourCC[0] << 24 | mFourCC[1] << 16 | mFourCC[2] << 8 | mFourCC[3]; } -std::string CFourCC::ToString() const +TString CFourCC::ToString() const { - return std::string(mFourCC, 4); + return TString(mFourCC, 4); } CFourCC CFourCC::ToUpper() const @@ -64,9 +64,9 @@ CFourCC& CFourCC::operator=(const char *src) return *this; } -CFourCC& CFourCC::operator=(const std::string& src) +CFourCC& CFourCC::operator=(const TString& src) { - memcpy(&mFourCC[0], src.c_str(), 4); + memcpy(&mFourCC[0], src.CString(), 4); return *this; } diff --git a/Common/CFourCC.h b/Common/CFourCC.h index 9bd6eb5e..7e822ad1 100644 --- a/Common/CFourCC.h +++ b/Common/CFourCC.h @@ -2,9 +2,9 @@ #define CFOURCC_H #include "types.h" +#include "TString.h" #include #include -#include class CFourCC { @@ -13,19 +13,19 @@ public: // Constructors CFourCC(); CFourCC(const char *src); - CFourCC(const std::string& src); + CFourCC(const TString& src); CFourCC(u32 src); CFourCC(CInputStream& src); // Functionality void Write(COutputStream& Output); u32 ToLong() const; - std::string ToString() const; + TString ToString() const; CFourCC ToUpper() const; // Operators CFourCC& operator=(const char *src); - CFourCC& operator=(const std::string& src); + CFourCC& operator=(const TString& src); CFourCC& operator=(u32 src); bool operator==(const CFourCC& other) const; bool operator!=(const CFourCC& other) const; diff --git a/Common/CHashFNV1A.cpp b/Common/CHashFNV1A.cpp index 9bb9e729..c325e813 100644 --- a/Common/CHashFNV1A.cpp +++ b/Common/CHashFNV1A.cpp @@ -66,7 +66,7 @@ void CHashFNV1A::HashFloat(const float& v) HashData(&v, 4); } -void CHashFNV1A::HashString(const std::string& v) +void CHashFNV1A::HashString(const TString& v) { - HashData(v.data(), v.size()); + HashData(v.Data(), v.Size()); } diff --git a/Common/CHashFNV1A.h b/Common/CHashFNV1A.h index 0b76e0cc..84b6c764 100644 --- a/Common/CHashFNV1A.h +++ b/Common/CHashFNV1A.h @@ -2,7 +2,7 @@ #define CHASHFNV1A_H #include "types.h" -#include +#include "TString.h" class CHashFNV1A { @@ -30,7 +30,7 @@ public: void HashShort(const u16& v); void HashLong(const u32& v); void HashFloat(const float& v); - void HashString(const std::string& v); + void HashString(const TString& v); }; #endif // CHASHFNV1A_H diff --git a/Common/CUniqueID.cpp b/Common/CUniqueID.cpp index 1aafc29a..7e7e87db 100644 --- a/Common/CUniqueID.cpp +++ b/Common/CUniqueID.cpp @@ -1,5 +1,5 @@ #include "CUniqueID.h" -#include +#include #include #include @@ -81,26 +81,28 @@ u64 CUniqueID::ToLongLong() const return *((u64*) &mID[8]); } -std::string CUniqueID::ToString() const +TString CUniqueID::ToString() const { - std::stringstream Ret; - Ret << std::hex << std::setfill('0'); - switch (mLength) { case e32Bit: - Ret << std::setw(8) << ToLong(); - break; + return TString::FromInt32(ToLong(), 8); + case e64Bit: - Ret << std::setw(16) << ToLongLong(); - break; + return TString::FromInt64(ToLongLong(), 16); + case e128Bit: + // todo: TString should have a "FromInt128" function + std::stringstream Ret; + Ret << std::hex << std::setfill('0'); + for (u32 i = 0; i < 16; i++) Ret << std::setw(2) << (u32) mID[i]; - break; + + return Ret.str(); } - return Ret.str(); + return "INVALID ID LENGTH"; } void CUniqueID::Reverse() @@ -223,21 +225,20 @@ bool CUniqueID::operator!=(u64 Other) const } // ************ STATIC ************ -CUniqueID CUniqueID::FromString(std::string String) +CUniqueID CUniqueID::FromString(const TString& String) { // If the input is a hex ID in string form, then preserve it... otherwise, generate an ID by hashing the string - std::string Name = StringUtil::GetFileName(String); - if (Name.back() == '\0') Name.pop_back(); - u32 NameLength = Name.length(); + TString Name = String.GetFileName(false); + u32 NameLength = Name.Length(); - if (StringUtil::IsHexString(Name)) + if (Name.IsHexString()) { if (NameLength == 8) { CUniqueID ID; ID.mLength = e32Bit; - u32 LongID = StringUtil::ToInt32(Name); + u32 LongID = Name.ToInt32(); if (SystemEndianness == LittleEndian) memcpy(ID.mID, &LongID, 4); @@ -252,7 +253,7 @@ CUniqueID CUniqueID::FromString(std::string String) CUniqueID ID; ID.mLength = e64Bit; - u64 LongID = StringUtil::ToInt64(Name); + u64 LongID = Name.ToInt64(); if (SystemEndianness == LittleEndian) memcpy(ID.mID, &LongID, 8); @@ -266,12 +267,12 @@ CUniqueID CUniqueID::FromString(std::string String) { CUniqueID ID; ID.mLength = e128Bit; - StringUtil::ToInt128(Name, (char*) ID.mID); + Name.ToInt128((char*) ID.mID); return ID; } } - return CUniqueID( (u64) StringUtil::Hash64(String) ); + return CUniqueID(String.Hash64()); } CUniqueID CUniqueID::FromData(void *pData, EUIDLength Length) diff --git a/Common/CUniqueID.h b/Common/CUniqueID.h index 61e6c6c5..27703ecc 100644 --- a/Common/CUniqueID.h +++ b/Common/CUniqueID.h @@ -2,6 +2,7 @@ #define CUNIQUEID_H #include "types.h" +#include "TString.h" #include enum EUIDLength @@ -25,7 +26,7 @@ public: CUniqueID(CInputStream& Input, EUIDLength Length); u32 ToLong() const; u64 ToLongLong() const; - std::string ToString() const; + TString ToString() const; void Reverse(); EUIDLength Length() const; void SetLength(EUIDLength Length); @@ -44,7 +45,7 @@ public: bool operator!=(u64 Other) const; // Static - static CUniqueID FromString(std::string String); + static CUniqueID FromString(const TString& String); static CUniqueID FromData(void *pData, EUIDLength Length); static CUniqueID RandomID(); diff --git a/Common/StringUtil.cpp b/Common/StringUtil.cpp deleted file mode 100644 index 1f978ccf..00000000 --- a/Common/StringUtil.cpp +++ /dev/null @@ -1,312 +0,0 @@ -#include -#include -#include -#include -#include "StringUtil.h" - -#include // For SwapBytes - -namespace StringUtil -{ - std::string GetFileDirectory(std::string path) - { - size_t endpath = path.find_last_of("\\/"); - return path.substr(0, endpath + 1); - } - - std::string GetFileName(std::string path) - { - size_t endpath = path.find_last_of("\\/") + 1; - size_t endname = path.find_last_of("."); - return path.substr(endpath, endname - endpath); - } - - std::string GetFileNameWithExtension(std::string path) - { - size_t endpath = path.find_last_of("\\/"); - return path.substr(endpath + 1, path.size() - endpath); - } - - std::string GetPathWithoutExtension(std::string path) - { - size_t endname = path.find_last_of("."); - return path.substr(0, endname); - } - - std::string GetExtension(std::string path) - { - size_t endname = path.find_last_of("."); - return path.substr(endname + 1, path.size() - endname); - } - - std::string ToUpper(std::string str) - { - for (unsigned int i = 0; i < str.length(); i++) - { - if ((str[i] >= 0x61) && (str[i] <= 0x7A)) - str[i] -= 0x20; - } - - return str; - } - - std::string ToLower(std::string str) - { - for (unsigned int i = 0; i < str.length(); i++) - { - if ((str[i] >= 0x41) && (str[i] <= 0x5A)) - str[i] += 0x20; - } - - return str; - } - - std::string ToHexString(unsigned char num, bool addPrefix, bool uppercase, int width) - { - return ToHexString((unsigned long) num, addPrefix, uppercase, width); - } - - std::string ToHexString(unsigned short num, bool addPrefix, bool uppercase, int width) - { - return ToHexString((unsigned long) num, addPrefix, uppercase, width); - } - - std::string ToHexString(unsigned long num, bool addPrefix, bool uppercase, int width) - { - std::stringstream stream; - stream << std::hex << std::setw(width) << std::setfill('0') << num; - - std::string str = stream.str(); - if (uppercase) str = ToUpper(str); - if (addPrefix) str = std::string("0x") + str; - return str; - } - - long Hash32(std::string str) - { - unsigned long hash = 0; - - for (unsigned int c = 0; c < str.size(); c++) { - hash += str[c]; - hash *= 101; - } - - return hash; - } - - long long Hash64(std::string str) - { - unsigned long long hash = 0; - - for (unsigned int c = 0; c < str.size(); c++) { - hash += str[c]; - hash *= 101; - } - - return hash; - } - - long ToInt32(std::string str) { - return std::stoul(str, nullptr, 16); - } - - long long ToInt64(std::string str) { - return std::stoull(str, nullptr, 16); - } - - void ToInt128(std::string str, char *out) { - long long Part1 = std::stoull(str.substr(0, 16), nullptr, 16); - long long Part2 = std::stoull(str.substr(16, 16), nullptr, 16); - - if (IOUtil::SystemEndianness == IOUtil::LittleEndian) - { - IOUtil::SwapBytes(Part1); - IOUtil::SwapBytes(Part2); - } - - memcpy(out, &Part1, 8); - memcpy(out + 8, &Part2, 8); - } - - std::string ToString(unsigned long v) - { - std::stringstream sstream; - sstream << std::hex << std::setw(8) << std::setfill('0') << v << std::dec; - return sstream.str(); - } - - std::string ToString(unsigned long long v) - { - std::stringstream sstream; - sstream << std::hex << std::setw(16) << std::setfill('0') << v << std::dec; - return sstream.str(); - } - - bool IsHexString(std::string str, bool requirePrefix, long width) - { - str = GetFileName(str); - - if (requirePrefix && (str.substr(0, 2) != "0x")) - return false; - - if ((width == -1) && (str.substr(0, 2) == "0x")) - str = str.substr(2, str.size() - 2); - - if (width == -1) - width = str.size(); - - if ((str.size() == width + 2) && (str.substr(0, 2) == "0x")) - str = str.substr(2, width); - - if (str.size() != width) return false; - - for (int c = 0; c < width; c++) - { - char chr = str[c]; - if (!((chr >= '0') && (chr <= '9')) && - !((chr >= 'a') && (chr <= 'f')) && - !((chr >= 'A') && (chr <= 'F'))) - return false; - } - return true; - } - - std::string AppendSlash(std::string str) - { - char a = str.back(); - char b = str[str.length() - 1]; - - if (a == 0) - { - if ((b != '/') && (b != '\\')) - { - str.back() = '/'; - str.push_back(0); - } - } - - else if ((a != '/') && (b != '\\')) - str.push_back('/'); - - return str; - } - - std::wstring UTF8to16(std::string str) - { - const char *cstr = str.c_str(); - std::vector CodePoints; - - // Step 1: decode UTF-8 code points - while (cstr[0]) - { - int CodePoint; - - // One byte - if ((cstr[0] & 0x80) == 0) - { - CodePoint = cstr[0] & 0x7FFFFFFF; - cstr++; - } - - // Two bytes - else if ((cstr[0] & 0xE0) == 0xC0) - { - CodePoint = (((cstr[0] & 0x1F) << 6) | - (cstr[1] & 0x3F)); - cstr += 2; - } - - // Three bytes - else if ((cstr[0] & 0xF0) == 0xE0) - { - CodePoint = (((cstr[0] & 0xF) << 12) | - ((cstr[1] & 0x3F) << 6) | - (cstr[2] & 0x3F)); - cstr += 3; - } - - // Four bytes - else if ((cstr[0] & 0xF8) == 0xF0) - { - CodePoint = (((cstr[0] & 0x7) << 18) | - ((cstr[1] & 0x3F) << 12) | - ((cstr[2] & 0x3F) << 6) | - (cstr[3] & 0x3F)); - cstr += 4; - } - - // Five bytes - else if ((cstr[0] & 0xFC) == 0xF8) - { - CodePoint = (((cstr[0] & 0x3) << 24) | - ((cstr[1] & 0x3F) << 18) | - ((cstr[2] & 0x3F) << 12) | - ((cstr[3] & 0x3F) << 6) | - (cstr[4] & 0x3F)); - cstr += 5; - } - - // Six bytes - else if ((cstr[0] & 0xFE) == 0xFC) - { - CodePoint = (((cstr[0] & 0x1) << 30) | - ((cstr[1] & 0x3F) << 24) | - ((cstr[2] & 0x3F) << 18) | - ((cstr[3] & 0x3F) << 12) | - ((cstr[4] & 0x3F) << 6) | - (cstr[5] & 0x3F)); - cstr += 6; - } - - CodePoints.push_back(CodePoint); - } - - // Step 2: encode as UTF-16 - std::wstring out; - out.reserve(CodePoints.size()); - - for (int c = 0; c < CodePoints.size(); c++) - { - // todo: support all code points - if (((CodePoints[c] >= 0) && (CodePoints[c] <= 0xD7FF)) || - ((CodePoints[c] >= 0xE000) && (CodePoints[c] <= 0xFFFF))) - { - out.push_back(CodePoints[c] & 0xFFFF); - } - } - - return out; - } - - CStringList Tokenize(const std::string& str, const char *pTokens) - { - CStringList out; - int lastSplit = 0; - - // Iterate over all characters in the input string - for (int iChr = 0; iChr < str.length(); iChr++) - { - // Check whether this character is one of the user-provided tokens - for (int iTok = 0; true; iTok++) - { - if (!pTokens[iTok]) break; - - if (str[iChr] == pTokens[iTok]) - { - // Token found - split string - if (iChr > lastSplit) - out.push_back(str.substr(lastSplit, iChr - lastSplit)); - - lastSplit = iChr + 1; - break; - } - } - } - - // Add final string - if (lastSplit != str.length()) - out.push_back(str.substr(lastSplit, str.length() - lastSplit)); - - return out; - } -} diff --git a/Common/StringUtil.h b/Common/StringUtil.h deleted file mode 100644 index b3ea46d1..00000000 --- a/Common/StringUtil.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef STRINGUTIL_H -#define STRINGUTIL_H - -#include -#include -typedef std::list CStringList; - -namespace StringUtil -{ - std::string GetFileDirectory(std::string path); - std::string GetFileName(std::string path); - std::string GetFileNameWithExtension(std::string path); - std::string GetPathWithoutExtension(std::string path); - std::string GetExtension(std::string path); - std::string ToUpper(std::string str); - std::string ToLower(std::string str); - std::string ToHexString(unsigned char num, bool addPrefix = true, bool uppercase = false, int width = 0); - std::string ToHexString(unsigned short num, bool addPrefix = true, bool uppercase = false, int width = 0); - std::string ToHexString(unsigned long num, bool addPrefix = true, bool uppercase = false, int width = 0); - long Hash32(std::string str); - long long Hash64(std::string str); - long ToInt32(std::string str); - long long ToInt64(std::string str); - void ToInt128(std::string str, char *out); - std::string ToString(unsigned long ID); - std::string ToString(unsigned long long ID); - bool IsHexString(std::string str, bool requirePrefix = false, long width = -1); - std::string AppendSlash(std::string str); - CStringList Tokenize(const std::string& str, const char *pTokens); - - std::wstring UTF8to16(std::string str); -} - -#endif // STRINGUTIL_H diff --git a/Common/TString.cpp b/Common/TString.cpp index 4632920b..5d7a22f7 100644 --- a/Common/TString.cpp +++ b/Common/TString.cpp @@ -7,6 +7,11 @@ TString::TString(const wchar_t* pkText) *this = TWideString(pkText).ToUTF8(); } +TString::TString(const std::wstring& rkText) +{ + *this = TWideString(rkText).ToUTF8(); +} + TString::TString(const TWideString& rkText) { *this = rkText.ToUTF8(); @@ -94,6 +99,11 @@ TWideString::TWideString(const char* pkText) *this = TString(pkText).ToUTF16(); } +TWideString::TWideString(const std::string& rkText) +{ + *this = TString(rkText).ToUTF16(); +} + TWideString::TWideString(const TString& rkText) { *this = rkText.ToUTF16(); diff --git a/Common/TString.h b/Common/TString.h index a34f8ecd..cbd61d48 100644 --- a/Common/TString.h +++ b/Common/TString.h @@ -34,10 +34,11 @@ template class TBasicString { typedef TBasicString _TString; + typedef std::basic_string _TStdString; typedef std::list<_TString> _TStringList; protected: - std::basic_string mInternalString; + _TStdString mInternalString; public: // Constructors @@ -61,17 +62,32 @@ public: { } - TBasicString(const std::basic_string& rkText) + TBasicString(const CharType* pkText, u32 length) + : mInternalString(pkText, length) + { + } + + TBasicString(const _TStdString& rkText) : mInternalString(rkText) { } + // Forward declares of some static functions that are handy for internal use + //static bool CompareCStrings(const CharType*, const CharType*); + //static u32 CStringLength(const CharType*); + //static bool IsWhitespace(CharType); + // Data Accessors inline const CharType* CString() const { return mInternalString.c_str(); } + inline const CharType* Data() const + { + return mInternalString.data(); + } + inline CharType At(u32 pos) const { #if _DEBUG @@ -103,12 +119,22 @@ public: inline u32 IndexOf(const CharType* pkCharacters) const { - return (u32) mInternalString.find_first_of(pkCharacters); + size_t pos = mInternalString.find_first_of(pkCharacters); + + if (pos == _TStdString::npos) + return -1; + else + return (u32) pos; } inline u32 LastIndexOf(const CharType* pkCharacters) const { - return (u32) mInternalString.find_last_of(pkCharacters); + size_t pos = mInternalString.find_last_of(pkCharacters); + + if (pos == _TStdString::npos) + return -1; + else + return (u32) pos; } // Modify String @@ -206,7 +232,6 @@ public: _TString Trimmed() const { - static bool _TString::IsWhitespace(CharType); int start, end; for (u32 iChar = 0; iChar < Size(); iChar++) @@ -271,12 +296,12 @@ public: return hash; } - inline u32 ToInt32(int base = 10) const + inline u32 ToInt32(int base = 16) const { return std::stoul(mInternalString, nullptr, base); } - inline u64 ToInt64(int base = 10) const + inline u64 ToInt64(int base = 16) const { return std::stoull(mInternalString, nullptr, base); } @@ -297,6 +322,11 @@ public: memcpy(pOut + 8, &part2, 8); } + inline _TStdString ToStdString() const + { + return mInternalString; + } + _TStringList Split(const CharType* pkTokens) const { _TStringList out; @@ -342,6 +372,11 @@ public: } // Check String + bool IsEmpty() const + { + return (Size() == 0); + } + bool StartsWith(const _TString& str) const { if (Size() < str.Size()) @@ -484,9 +519,24 @@ public: return *this; } + inline CharType& operator[](int pos) + { + return mInternalString[pos]; + } + + inline const CharType& operator[](int pos) const + { + return mInternalString[pos]; + } + + inline const CharType* operator*() const + { + return CString(); + } + _TString operator+(const CharType* pkOther) const { - size_t len = strlen(pkOther); + u32 len = CStringLength(pkOther); _TString out(len + Size()); memcpy(&out[0], mInternalString.data(), Size() * sizeof(CharType)); @@ -511,7 +561,7 @@ public: inline friend _TString operator+(const CharType* pkLeft, const _TString& rkRight) { - size_t len = strlen(pkLeft); + u32 len = CStringLength(pkLeft); _TString out(len + rkRight.Size()); memcpy(&out[0], pkLeft, len * sizeof(CharType)); @@ -519,19 +569,32 @@ public: return out; } - inline CharType& operator[](int pos) + inline friend _TString operator+(const _TStdString& rkLeft, const _TString& rkRight) { - return mInternalString[pos]; - } - - inline const CharType& operator[](int pos) const - { - return mInternalString[pos]; + _TString out(rkLeft.size() + rkRight.Size()); + memcpy(&out[0], rkLeft.data(), rkLeft.size() * sizeof(CharType)); + memcpy(&out[rkLeft.size()], rkRight.Data(), rkRight.Size() * sizeof(CharType)); + return out; } inline bool operator==(const CharType *pkText) const { - return strcmp(pkText, mInternalString.data()) == 0; + return CompareCStrings(pkText, CString()); + } + + inline bool operator==(const _TString& rkOther) const + { + return (mInternalString == rkOther.mInternalString); + } + + inline friend bool operator==(const CharType *pkText, const _TString& rkString) + { + return (rkString == pkText); + } + + inline friend bool operator==(const _TStdString& rkStringA, const _TString& rkStringB) + { + return (rkStringB == rkStringA); } inline bool operator!=(const CharType *pkText) const @@ -539,50 +602,125 @@ public: return (!(*this == pkText)); } - inline bool operator==(const _TString& rkOther) const - { - return (strcmp(mInternalString.data(), rkOther.mInternalString.data()) == 0); - } - inline bool operator!=(const _TString& rkOther) const { return (!(*this == rkOther)); } - inline friend bool operator==(const CharType *pText, const _TString& rkString) + inline friend bool operator!=(const CharType *pkText, const _TString& rkString) { - return (rkString == pText); + return (rkString != pkText); } - inline friend bool operator!=(const CharType *pText, const _TString& rkString) + inline friend bool operator!=(const _TStdString& rkStringA, const _TString& rkStringB) { - return (rkString != pText); + return (rkStringB != rkStringA); } - inline friend std::ostream& operator<<(std::ostream& rLeft, const _TString& rkRight) + inline bool operator<(const CharType* pkText) const { - rLeft << rkRight.mInternalString; - return rLeft; + return (mInternalString < pkText); } - inline friend std::istream& operator>>(std::istream& rLeft, const _TString& rkRight) + inline bool operator<(const _TString& rkOther) const { - rLeft >> rkRight.mInternalString; - return rLeft; + return (mInternalString < rkOther.mInternalString); + } + + inline friend bool operator<(const CharType* pkText, const _TString& rkString) + { + return (rkString > pkText); + } + + inline friend bool operator<(const _TStdString& rkStringA, const _TString& rkStringB) + { + return (rkStringB > rkStringA); + } + + inline bool operator<=(const CharType* pkText) const + { + return (mInternalString <= pkText); + } + + inline bool operator<=(const _TString& rkOther) const + { + return (mInternalString <= rkOther.mInternalString); + } + + inline friend bool operator<=(const CharType* pkText, const _TString& rkString) + { + return (rkString >= pkText); + } + + inline friend bool operator<=(const _TStdString& rkStringA, const _TString& rkStringB) + { + return (rkStringB >= rkStringA); + } + + inline bool operator>(const CharType* pkText) const + { + return (mInternalString > pkText); + } + + inline bool operator>(const _TString& rkOther) const + { + return (mInternalString > rkOther.mInternalString); + } + + inline friend bool operator>(const CharType* pkText, const _TString& rkString) + { + return (rkString < pkText); + } + + inline friend bool operator>(const _TStdString& rkStringA, const _TString& rkStringB) + { + return (rkStringB < rkStringA); + } + + inline bool operator>=(const CharType* pkText) const + { + return (mInternalString >= pkText); + } + + inline bool operator>=(const _TString& rkOther) const + { + return (mInternalString >= rkOther.mInternalString); + } + + inline friend bool operator>=(const CharType* pkText, const _TString& rkString) + { + return (rkString <= pkText); + } + + inline friend bool operator>=(const _TStdString& rkStringA, const _TString& rkStringB) + { + return (rkStringB <= rkStringA); + } + + inline friend std::ostream& operator<<(std::ostream& rStream, const _TString& rkString) + { + rStream << rkString.mInternalString; + return rStream; + } + + inline friend std::istream& operator>>(std::istream& rStream, const _TString& rkString) + { + rStream >> rkString.mInternalString; + return rStream; } // Static - static TBasicString FromInt32(u32 value, int base = 10) + static TBasicString FromInt32(u32 value, int width = 0, int base = 16) { std::basic_stringstream sstream; - sstream << std::setbase(base) << value; + sstream << std::setbase(base) << std::setw(width) << std::setfill('0') << value; return sstream.str(); } - static TBasicString FromInt64(u64 value, int base = 10) + static TBasicString FromInt64(u64 value, int width = 0, int base = 16) { std::basic_stringstream sstream; - sstream << std::setbase(base) << value; + sstream << std::setbase(base) << std::setw(width) << std::setfill('0') << value; return sstream.str(); } @@ -607,6 +745,31 @@ public: return str; } + static bool CompareCStrings(const CharType* pkA, const CharType* pkB) + { + // Replacement for strcmp so we can compare any CharType + while (true) + { + if (*pkA != *pkB) return false; + if ((*pkA == 0) || (*pkB == 0)) return true; + pkA++; + pkB++; + } + } + + static u32 CStringLength(const CharType* pkStr) + { + // Replacement for strlen so we can measure any CharType + u32 out = 0; + + while (true) + { + if (*pkStr == 0) return out; + out++; + pkStr++; + } + } + static bool IsWhitespace(CharType c) { return ( (c == '\t') || @@ -626,16 +789,13 @@ public: TString(size_t size) : TBasicString(size) {} TString(size_t size, char fill) : TBasicString(size, fill) {} TString(const char* pkText) : TBasicString(pkText) {} + TString(const char* pkText, u32 length) : TBasicString(pkText, length) {} TString(const std::string& rkText) : TBasicString(rkText) {} TString(const TBasicString& rkStr) : TBasicString(rkStr) {} TString(const wchar_t* pkText); + TString(const std::wstring& rkText); TString(const class TWideString& rkText); - inline std::string ToStdString() - { - return mInternalString; - } - class TWideString ToUTF16() const; }; @@ -647,16 +807,13 @@ public: TWideString(u32 size) : TBasicString(size) {} TWideString(u32 size, wchar_t fill) : TBasicString(size, fill) {} TWideString(const wchar_t* pkText) : TBasicString(pkText) {} + TWideString(const wchar_t* pkText, u32 length) : TBasicString(pkText, length) {} TWideString(const std::wstring& rkText) : TBasicString(rkText) {} TWideString(const TBasicString& rkStr) : TBasicString(rkStr) {} TWideString(const char* pkText); + TWideString(const std::string& rkText); TWideString(const TString& rkText); - inline std::wstring ToStdWString() - { - return mInternalString; - } - class TString ToUTF8() const; }; diff --git a/Core/CResCache.cpp b/Core/CResCache.cpp index cc9024af..a00a7815 100644 --- a/Core/CResCache.cpp +++ b/Core/CResCache.cpp @@ -1,6 +1,6 @@ #include "CResCache.h" #include "Log.h" -#include +#include #include #include #include @@ -54,17 +54,17 @@ void CResCache::Clean() Log::Write(std::to_string(mResourceCache.size()) + " resources loaded"); } -void CResCache::SetFolder(std::string path) +void CResCache::SetFolder(TString path) { - StringUtil::AppendSlash(path); + path.EnsureEndsWith("/"); mResSource.Path = path; mResSource.Source = SResSource::Folder; Log::Write("Set resource folder: " + path); } -void CResCache::SetPak(std::string path) +void CResCache::SetPak(const TString& path) { - CFileInStream *pakfile = new CFileInStream(path, IOUtil::BigEndian); + CFileInStream *pakfile = new CFileInStream(path.ToStdString(), IOUtil::BigEndian); if (!pakfile->IsValid()) { Log::Error("Couldn't load pak file: " + path); @@ -89,7 +89,7 @@ SResSource CResCache::GetResSource() return mResSource; } -std::string CResCache::GetSourcePath() +TString CResCache::GetSourcePath() { return mResSource.Path; } @@ -104,7 +104,7 @@ CResource* CResCache::GetResource(CUniqueID ResID, CFourCC type) return got->second; std::vector *pBuffer = nullptr; - std::string Source; + TString Source; // Load from pak if (mResSource.Source == SResSource::PakFile) @@ -116,17 +116,12 @@ CResource* CResCache::GetResource(CUniqueID ResID, CFourCC type) // Load from folder else { - Source = mResSource.Path + StringUtil::ToString(ResID.ToLong()) + "." + type.ToString(); - CFileInStream file(Source, IOUtil::BigEndian); + Source = mResSource.Path + ResID.ToString() + "." + type.ToString(); + CFileInStream file(Source.ToStdString(), IOUtil::BigEndian); if (!file.IsValid()) { - Source = mResSource.Path + StringUtil::ToString(ResID.ToLongLong()) + "." + type.ToString(); - file.Open(Source, IOUtil::BigEndian); - if (!file.IsValid()) - { - Log::Error("Couldn't open resource: " + ResID.ToString() + "." + type.ToString()); - return nullptr; - } + Log::Error("Couldn't open resource: " + ResID.ToString() + "." + type.ToString()); + return nullptr; } pBuffer = new std::vector; @@ -137,7 +132,7 @@ CResource* CResCache::GetResource(CUniqueID ResID, CFourCC type) // Load resource CMemoryInStream mem(pBuffer->data(), pBuffer->size(), IOUtil::BigEndian); - mem.SetSourceString(StringUtil::GetFileNameWithExtension(Source)); + mem.SetSourceString(*Source.GetFileName()); CResource *Res = nullptr; bool SupportedFormat = true; @@ -167,17 +162,17 @@ CResource* CResCache::GetResource(CUniqueID ResID, CFourCC type) return Res; } -CResource* CResCache::GetResource(std::string ResPath) +CResource* CResCache::GetResource(const TString& ResPath) { // Since this function takes a string argument it always loads directly from a file - no pak - CUniqueID ResID = StringUtil::Hash64(ResPath); + CUniqueID ResID = ResPath.Hash64(); auto got = mResourceCache.find(ResID.ToLongLong()); if (got != mResourceCache.end()) return got->second; - CFileInStream file(ResPath, IOUtil::BigEndian); + CFileInStream file(ResPath.ToStdString(), IOUtil::BigEndian); if (!file.IsValid()) { Log::Error("Couldn't open resource: " + ResPath); @@ -187,11 +182,11 @@ CResource* CResCache::GetResource(std::string ResPath) // Save old ResSource to restore later const SResSource OldSource = mResSource; mResSource.Source = SResSource::Folder; - mResSource.Path = StringUtil::GetFileDirectory(ResPath); + mResSource.Path = ResPath.GetFileDirectory(); // Load resource CResource *Res = nullptr; - CFourCC type = StringUtil::ToUpper( StringUtil::GetExtension(ResPath) ).c_str(); + CFourCC type = ResPath.GetFileExtension().ToUpper(); bool SupportedFormat = true; if (type == "CMDL") Res = CModelLoader::LoadCMDL(file); @@ -208,7 +203,7 @@ CResource* CResCache::GetResource(std::string ResPath) if (!Res) Res = new CResource(); // Default for unsupported formats // Add to cache and cleanup - Res->mID = ResPath.c_str(); + Res->mID = *ResPath; Res->mResSource = ResPath; mResourceCache[ResID.ToLongLong()] = Res; mResSource = OldSource; diff --git a/Core/CResCache.h b/Core/CResCache.h index cc86f7be..fde23ef4 100644 --- a/Core/CResCache.h +++ b/Core/CResCache.h @@ -2,13 +2,14 @@ #define CRESCACHE_H #include +#include #include #include #include struct SResSource { - std::string Path; + TString Path; enum { Folder, PakFile } Source; @@ -24,13 +25,13 @@ public: CResCache(); ~CResCache(); void Clean(); - void SetFolder(std::string path); - void SetPak(std::string path); + void SetFolder(TString path); + void SetPak(const TString& path); void SetResSource(SResSource& ResSource); SResSource GetResSource(); - std::string GetSourcePath(); + TString GetSourcePath(); CResource* GetResource(CUniqueID ResID, CFourCC type); - CResource* GetResource(std::string res); + CResource* GetResource(const TString& ResPath); void CacheResource(CResource *pRes); void DeleteResource(CUniqueID ResID); }; diff --git a/Core/CSceneManager.cpp b/Core/CSceneManager.cpp index 83d34ffe..3807b693 100644 --- a/Core/CSceneManager.cpp +++ b/Core/CSceneManager.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include #include diff --git a/Core/IRenderable.h b/Core/IRenderable.h index 9b26ffa7..5e2c69cf 100644 --- a/Core/IRenderable.h +++ b/Core/IRenderable.h @@ -13,9 +13,9 @@ class IRenderable public: IRenderable() {} virtual ~IRenderable() {} - virtual void AddToRenderer(CRenderer *pRenderer, const CFrustumPlanes& frustum) = 0; - virtual void Draw(ERenderOptions options) {} - virtual void DrawAsset(ERenderOptions options, u32 asset) {} + virtual void AddToRenderer(CRenderer* pRenderer, const CFrustumPlanes& frustum) = 0; + virtual void Draw(ERenderOptions /*options*/) {} + virtual void DrawAsset(ERenderOptions /*options*/, u32 /*asset*/) {} virtual void DrawSelection() {} }; diff --git a/Core/Log.cpp b/Core/Log.cpp index 1ae823ea..ffaa515a 100644 --- a/Core/Log.cpp +++ b/Core/Log.cpp @@ -1,18 +1,16 @@ #include #include -#include +#include #include -#include namespace Log { -static const std::string gskLogFilename = "primeworldeditor.log"; -FILE *gpLogFile = fopen(gskLogFilename.c_str(), "w"); +static const TString gskLogFilename = "primeworldeditor.log"; +FILE *gpLogFile = fopen(*gskLogFilename, "w"); -void Write(const std::string& message) +void Write(const TString& message) { - if (gpLogFile) { time_t RawTime; @@ -22,12 +20,12 @@ void Write(const std::string& message) char Buffer[80]; strftime(Buffer, 80, "[%H:%M:%S]", pTimeInfo); - fprintf(gpLogFile, "%s %s\n", Buffer, message.c_str()); + fprintf(gpLogFile, "%s %s\n", Buffer, *message); fflush(gpLogFile); } } -void Error(const std::string& message) +void Error(const TString& message) { Write("ERROR: " + message); @@ -36,7 +34,7 @@ void Error(const std::string& message) #endif } -void Warning(const std::string& message) +void Warning(const TString& message) { Write("Warning: " + message); @@ -45,34 +43,34 @@ void Warning(const std::string& message) #endif } -void FileWrite(const std::string& filename, const std::string& message) +void FileWrite(const TString& filename, const TString& message) { Write(filename + " : " + message); } -void FileWrite(const std::string& filename, unsigned long offset, const std::string& message) +void FileWrite(const TString& filename, unsigned long offset, const TString& message) { - Write(filename + " : " + StringUtil::ToHexString(offset) + " - " + message); + Write(filename + " : " + TString::HexString(offset) + " - " + message); } -void FileError(const std::string& filename, const std::string& message) +void FileError(const TString& filename, const TString& message) { Error(filename + " : " + message); } -void FileError(const std::string &filename, unsigned long offset, const std::string &message) +void FileError(const TString& filename, unsigned long offset, const TString& message) { - Error(filename + " : " + StringUtil::ToHexString(offset) + " - " + message); + Error(filename + " : " + TString::HexString(offset) + " - " + message); } -void FileWarning(const std::string& filename, const std::string& message) +void FileWarning(const TString& filename, const TString& message) { Warning(filename + " : " + message); } -void FileWarning(const std::string& filename, unsigned long offset, const std::string& message) +void FileWarning(const TString& filename, unsigned long offset, const TString& message) { - Warning(filename + " : " + StringUtil::ToHexString(offset) + " - " + message); + Warning(filename + " : " + TString::HexString(offset) + " - " + message); } } diff --git a/Core/Log.h b/Core/Log.h index 35e34c75..94ff940c 100644 --- a/Core/Log.h +++ b/Core/Log.h @@ -1,20 +1,20 @@ #ifndef INFO #define INFO -#include +#include namespace Log { -void Write(const std::string& message); -void Error(const std::string& message); -void Warning(const std::string& message); -void FileWrite(const std::string& filename, const std::string& message); -void FileWrite(const std::string& filename, unsigned long offset, const std::string& message); -void FileError(const std::string& filename, const std::string& message); -void FileError(const std::string& filename, unsigned long offset, const std::string& message); -void FileWarning(const std::string& filename, const std::string& message); -void FileWarning(const std::string& filename, unsigned long offset, const std::string& message); +void Write(const TString& message); +void Error(const TString& message); +void Warning(const TString& message); +void FileWrite(const TString& filename, const TString& message); +void FileWrite(const TString& filename, unsigned long offset, const TString& message); +void FileError(const TString& filename, const TString& message); +void FileError(const TString& filename, unsigned long offset, const TString& message); +void FileWarning(const TString& filename, const TString& message); +void FileWarning(const TString& filename, unsigned long offset, const TString& message); } diff --git a/OpenGL/CShader.cpp b/OpenGL/CShader.cpp index 13fcf786..c9ef3d07 100644 --- a/OpenGL/CShader.cpp +++ b/OpenGL/CShader.cpp @@ -53,7 +53,7 @@ bool CShader::CompileVertexSource(const char* kpSource) if (CompileStatus == GL_FALSE) { - std::string Out = "dump/BadVS_" + std::to_string(gFailedCompileCount) + ".txt"; + TString Out = "dump/BadVS_" + std::to_string(gFailedCompileCount) + ".txt"; std::cout << "ERROR: Unable to compile vertex shader; dumped to " << Out << "\n"; DumpShaderSource(mVertexShader, Out); @@ -65,7 +65,7 @@ bool CShader::CompileVertexSource(const char* kpSource) // Debug dump else if (gDebugDumpShaders == true) { - std::string Out = "dump/VS_" + std::to_string(gSuccessfulCompileCount) + ".txt"; + TString Out = "dump/VS_" + TString::FromInt64(gSuccessfulCompileCount, 8, 10) + ".txt"; std::cout << "Debug shader dumping enabled; dumped to " << Out << "\n"; DumpShaderSource(mVertexShader, Out); @@ -88,7 +88,7 @@ bool CShader::CompilePixelSource(const char* kpSource) if (CompileStatus == GL_FALSE) { - std::string Out = "dump/BadPS_" + std::to_string(gFailedCompileCount) + ".txt"; + TString Out = "dump/BadPS_" + TString::FromInt64(gFailedCompileCount, 8, 10) + ".txt"; std::cout << "ERROR: Unable to compile pixel shader; dumped to " << Out << "\n"; DumpShaderSource(mPixelShader, Out); @@ -100,7 +100,7 @@ bool CShader::CompilePixelSource(const char* kpSource) // Debug dump else if (gDebugDumpShaders == true) { - std::string Out = "dump/PS_" + std::to_string(gSuccessfulCompileCount) + ".txt"; + TString Out = "dump/PS_" + TString::FromInt64(gSuccessfulCompileCount, 8, 10) + ".txt"; std::cout << "Debug shader dumping enabled; dumped to " << Out << "\n"; DumpShaderSource(mPixelShader, Out); @@ -131,7 +131,7 @@ bool CShader::LinkShaders() if (LinkStatus == GL_FALSE) { - std::string Out = "dump/BadLink_" + std::to_string(gFailedCompileCount) + ".txt"; + TString Out = "dump/BadLink_" + TString::FromInt64(gFailedCompileCount, 8, 10) + ".txt"; std::cout << "ERROR: Unable to link shaders. Dumped error log to " << Out << "\n"; GLint LogLen; @@ -140,7 +140,7 @@ bool CShader::LinkShaders() glGetProgramInfoLog(mProgram, LogLen, NULL, InfoLog); std::ofstream LinkOut; - LinkOut.open(Out.c_str()); + LinkOut.open(*Out); if (LogLen > 0) LinkOut << InfoLog; @@ -197,12 +197,12 @@ void CShader::SetCurrent() } // ************ STATIC ************ -CShader* CShader::FromResourceFile(std::string ShaderName) +CShader* CShader::FromResourceFile(const TString& ShaderName) { - std::string VertexShaderFilename = "../resources/shaders/" + ShaderName + ".vs"; - std::string PixelShaderFilename = "../resources/shaders/" + ShaderName + ".ps"; - CTextInStream VertexShaderFile(VertexShaderFilename); - CTextInStream PixelShaderFile(PixelShaderFilename); + TString VertexShaderFilename = "../resources/shaders/" + ShaderName + ".vs"; + TString PixelShaderFilename = "../resources/shaders/" + ShaderName + ".ps"; + CTextInStream VertexShaderFile(VertexShaderFilename.ToStdString()); + CTextInStream PixelShaderFile(PixelShaderFilename.ToStdString()); if (!VertexShaderFile.IsValid()) std::cout << "Error: Couldn't load vertex shader file for " << ShaderName << "\n"; @@ -236,7 +236,7 @@ void CShader::KillCachedShader() } // ************ PRIVATE ************ -void CShader::DumpShaderSource(GLuint Shader, std::string Out) +void CShader::DumpShaderSource(GLuint Shader, const TString& Out) { GLint SourceLen; glGetShaderiv(Shader, GL_SHADER_SOURCE_LENGTH, &SourceLen); @@ -249,7 +249,7 @@ void CShader::DumpShaderSource(GLuint Shader, std::string Out) glGetShaderInfoLog(Shader, LogLen, NULL, InfoLog); std::ofstream ShaderOut; - ShaderOut.open(Out.c_str()); + ShaderOut.open(*Out); if (SourceLen > 0) ShaderOut << Source; diff --git a/OpenGL/CShader.h b/OpenGL/CShader.h index 0825af13..d60a0028 100644 --- a/OpenGL/CShader.h +++ b/OpenGL/CShader.h @@ -2,7 +2,7 @@ #define CSHADER_H #include -#include +#include class CShader { @@ -29,17 +29,17 @@ public: bool LinkShaders(); bool IsValidProgram(); GLuint GetProgramID(); - GLuint GetUniformLocation(const char* Uniform); - GLuint GetUniformBlockIndex(const char* UniformBlock); + GLuint GetUniformLocation(const char* kpUniform); + GLuint GetUniformBlockIndex(const char* kpUniformBlock); void SetCurrent(); // Static - static CShader* FromResourceFile(std::string ShaderName); + static CShader* FromResourceFile(const TString& ShaderName); static CShader* CurrentShader(); static void KillCachedShader(); private: - void DumpShaderSource(GLuint Shader, std::string Out); + void DumpShaderSource(GLuint Shader, const TString& Out); }; #endif // CSHADER_H diff --git a/OpenGL/CShaderGenerator.cpp b/OpenGL/CShaderGenerator.cpp index aa066ab0..8716058d 100644 --- a/OpenGL/CShaderGenerator.cpp +++ b/OpenGL/CShaderGenerator.cpp @@ -4,7 +4,7 @@ #include #include "CShaderGenerator.h" -const std::string gkCoordSrc[] = { +const TString gkCoordSrc[] = { "RawPosition.xyz", "RawNormal.xyz", "0.0, 0.0, 0.0", @@ -19,7 +19,7 @@ const std::string gkCoordSrc[] = { "RawTex7.xy, 1.0" }; -const std::string gkRasSel[] = { +const TString gkRasSel[] = { "vec4(COLOR0A0.rgb, 1.0)", "vec4(COLOR1A1.rgb, 1.0)", "vec4(0.0, 0.0, 0.0, COLOR0A0.a)", @@ -29,7 +29,7 @@ const std::string gkRasSel[] = { "vec4(0.0, 0.0, 0.0, 0.0)" }; -const std::string gkKonstColor[] = { +const TString gkKonstColor[] = { "1.0, 1.0, 1.0", "0.875, 0.875, 0.875", "0.75, 0.75, 0.75", @@ -64,7 +64,7 @@ const std::string gkKonstColor[] = { "KonstColors[3].aaa" }; -const std::string gkKonstAlpha[] = { +const TString gkKonstAlpha[] = { "1.0", "0.875", "0.75", @@ -99,7 +99,7 @@ const std::string gkKonstAlpha[] = { "KonstColors[3].a" }; -const std::string gkTevColor[] = { +const TString gkTevColor[] = { "Prev.rgb", "Prev.aaa", "C0.rgb", @@ -118,7 +118,7 @@ const std::string gkTevColor[] = { "0.0, 0.0, 0.0" }; -const std::string gkTevAlpha[] = { +const TString gkTevAlpha[] = { "Prev.a", "C0.a", "C1.a", @@ -129,7 +129,7 @@ const std::string gkTevAlpha[] = { "0.0" }; -const std::string gkTevRigid[] = { +const TString gkTevRigid[] = { "Prev", "C0", "C1", diff --git a/PrimeWorldEditor.pro b/PrimeWorldEditor.pro index 009d78cc..c36234b0 100644 --- a/PrimeWorldEditor.pro +++ b/PrimeWorldEditor.pro @@ -26,7 +26,7 @@ SOURCES += \ Common/CVector2f.cpp \ Common/CVector3f.cpp \ Common/CVector4f.cpp \ - Common/StringUtil.cpp \ + Common/TString.cpp \ Core/main.cpp \ Core/CSceneManager.cpp \ Core/CRenderer.cpp \ @@ -168,7 +168,7 @@ HEADERS += \ Common/CVector2f.h \ Common/CVector3f.h \ Common/CVector4f.h \ - Common/StringUtil.h \ + Common/TString.h \ Common/types.h \ Core/CCamera.h \ Core/CRenderer.h \ diff --git a/Resource/CAnimSet.cpp b/Resource/CAnimSet.cpp index 2d3cb79b..856dde85 100644 --- a/Resource/CAnimSet.cpp +++ b/Resource/CAnimSet.cpp @@ -19,7 +19,7 @@ u32 CAnimSet::getNodeCount() return nodes.size(); } -std::string CAnimSet::getNodeName(u32 node) +TString CAnimSet::getNodeName(u32 node) { if (node >= nodes.size()) return nodes[0].name; diff --git a/Resource/CAnimSet.h b/Resource/CAnimSet.h index 5244ccb4..01831b30 100644 --- a/Resource/CAnimSet.h +++ b/Resource/CAnimSet.h @@ -14,7 +14,7 @@ class CAnimSet : public CResource struct SNode { - std::string name; + TString name; CModel *model; u32 skinID; u32 skelID; @@ -30,7 +30,7 @@ public: EResType Type(); u32 getNodeCount(); - std::string getNodeName(u32 node); + TString getNodeName(u32 node); CModel* getNodeModel(u32 node); }; diff --git a/Resource/CAnimationParameters.cpp b/Resource/CAnimationParameters.cpp index 3738d421..6382692c 100644 --- a/Resource/CAnimationParameters.cpp +++ b/Resource/CAnimationParameters.cpp @@ -68,7 +68,7 @@ CAnimationParameters::CAnimationParameters(CInputStream& SCLY, EGame game) else if (mUnknown1 != 0x80) { Log::FileError(SCLY.GetSourceString(), offset, - "Unexpected AnimationParameters byte: " + StringUtil::ToHexString(mUnknown1, true, true, 2) + " (property " + StringUtil::ToHexString(propID, true, true, 8) + ")"); + "Unexpected AnimationParameters byte: " + TString::HexString(mUnknown1, true, true, 2) + " (property " + TString::HexString(propID, true, true, 8) + ")"); } } } diff --git a/Resource/CFont.cpp b/Resource/CFont.cpp index 2d4f2802..1957debf 100644 --- a/Resource/CFont.cpp +++ b/Resource/CFont.cpp @@ -28,7 +28,7 @@ inline float PtsToFloat(s32 pt) return 0.00208333f * pt; } -CVector2f CFont::RenderString(std::string String, CRenderer *pRenderer, float, +CVector2f CFont::RenderString(const TString& String, CRenderer *pRenderer, float, CVector2f, CColor FillColor, CColor StrokeColor, u32 FontSize) { // Not using parameter 3 (float - AspectRatio) @@ -58,7 +58,7 @@ CVector2f CFont::RenderString(std::string String, CRenderer *pRenderer, float, if (FontSize == CFONT_DEFAULT_SIZE) Scale = 1.f; else Scale = (float) FontSize / (mDefaultSize != 0 ? mDefaultSize : 18); - for (u32 iChar = 0; iChar < String.length(); iChar++) + for (u32 iChar = 0; iChar < String.Length(); iChar++) { // Get character, check for newline char Char = String[iChar]; diff --git a/Resource/CFont.h b/Resource/CFont.h index 308fe3a9..d771a4fc 100644 --- a/Resource/CFont.h +++ b/Resource/CFont.h @@ -28,7 +28,7 @@ class CFont : public CResource u32 mLineMargin; // Gap between lines, in points - this is added to the line height u32 mVerticalOffset; // In points. This is used to reposition glyphs after the per-glyph vertical offset is applied u32 mDefaultSize; // In points. - std::string mFontName; // Self-explanatory + TString mFontName; // Self-explanatory CTexture *mpFontTexture; // The texture used by this font CToken mTextureToken; // Token for the font u32 mTextureFormat; // Indicates which layers on the texture are for what - multiple glyph layers or fill/stroke @@ -62,7 +62,7 @@ public: ~CFont(); EResType Type(); CResource* MakeCopy(CResCache *pCopyCache); - CVector2f RenderString(std::string String, CRenderer *pRenderer, float AspectRatio, + CVector2f RenderString(const TString& String, CRenderer *pRenderer, float AspectRatio, CVector2f Position = CVector2f(0,0), CColor FillColor = CColor::skWhite, CColor StrokeColor = CColor::skBlack, u32 FontSize = CFONT_DEFAULT_SIZE); diff --git a/Resource/CMaterial.cpp b/Resource/CMaterial.cpp index c6a09103..a0b5870d 100644 --- a/Resource/CMaterial.cpp +++ b/Resource/CMaterial.cpp @@ -217,7 +217,7 @@ void CMaterial::Update() } // ************ GETTERS ************ -std::string CMaterial::Name() const +TString CMaterial::Name() const { return mName; } @@ -283,7 +283,7 @@ CMaterialPass* CMaterial::Pass(u32 PassIndex) const // ************ SETTERS ************ -void CMaterial::SetName(const std::string& name) +void CMaterial::SetName(const TString& name) { mName = name; } diff --git a/Resource/CMaterial.h b/Resource/CMaterial.h index b01b3018..04cf80ad 100644 --- a/Resource/CMaterial.h +++ b/Resource/CMaterial.h @@ -50,7 +50,7 @@ private: static CColor sCurrentTint; // The tint for the currently bound material // Members - std::string mName; // Name of the material + TString mName; // Name of the material CShader *mpShader; // This material's generated shader. Created with GenerateShader(). EShaderStatus mShaderStatus; // A status variable so that PWE won't crash if a shader fails to compile. u64 mParametersHash; // A hash of all the parameters that can identify this TEV setup. @@ -82,7 +82,7 @@ public: void Update(); // Getters - std::string Name() const; + TString Name() const; EGame Version() const; EMaterialOptions Options() const; EVertexDescription VtxDesc() const; @@ -97,7 +97,7 @@ public: CMaterialPass* Pass(u32 PassIndex) const; // Setters - void SetName(const std::string& name); + void SetName(const TString& name); void SetOptions(EMaterialOptions Options); void SetVertexDescription(EVertexDescription desc); void SetBlendMode(GLenum SrcFac, GLenum DstFac); diff --git a/Resource/CMaterialPass.cpp b/Resource/CMaterialPass.cpp index bbebdebe..ca748a3e 100644 --- a/Resource/CMaterialPass.cpp +++ b/Resource/CMaterialPass.cpp @@ -300,7 +300,7 @@ void CMaterialPass::SetEnabled(bool Enabled) } // ************ STATIC ************ -std::string CMaterialPass::PassTypeName(CFourCC Type) +TString CMaterialPass::PassTypeName(CFourCC Type) { if (Type == "CUST") return "Custom"; if (Type == "DIFF") return "Light"; diff --git a/Resource/CMaterialPass.h b/Resource/CMaterialPass.h index d0413bda..3d69ae78 100644 --- a/Resource/CMaterialPass.h +++ b/Resource/CMaterialPass.h @@ -69,7 +69,7 @@ public: return mPassType; } - inline std::string NamedType() const { + inline TString NamedType() const { return PassTypeName(mPassType); } @@ -122,7 +122,7 @@ public: } // Static - static std::string PassTypeName(CFourCC Type); + static TString PassTypeName(CFourCC Type); }; #endif // CMATERIALPASS_H diff --git a/Resource/CMaterialSet.cpp b/Resource/CMaterialSet.cpp index f9c21dcf..3372569c 100644 --- a/Resource/CMaterialSet.cpp +++ b/Resource/CMaterialSet.cpp @@ -34,14 +34,14 @@ CMaterial* CMaterialSet::MaterialByIndex(u32 index) return mMaterials[index]; } -CMaterial* CMaterialSet::MaterialByName(const std::string &name) +CMaterial* CMaterialSet::MaterialByName(const TString& name) { for (auto it = mMaterials.begin(); it != mMaterials.end(); it++) if ((*it)->Name() == name) return *it; return nullptr; } -u32 CMaterialSet::MaterialIndexByName(const std::string& name) +u32 CMaterialSet::MaterialIndexByName(const TString& name) { for (u32 iMat = 0; iMat < mMaterials.size(); iMat++) if (mMaterials[iMat]->Name() == name) return iMat; diff --git a/Resource/CMaterialSet.h b/Resource/CMaterialSet.h index 1a3f59af..aba62e2c 100644 --- a/Resource/CMaterialSet.h +++ b/Resource/CMaterialSet.h @@ -19,8 +19,8 @@ public: CMaterialSet* Clone(); u32 NumMaterials(); CMaterial* MaterialByIndex(u32 index); - CMaterial* MaterialByName(const std::string& name); - u32 MaterialIndexByName(const std::string& name); + CMaterial* MaterialByName(const TString& name); + u32 MaterialIndexByName(const TString& name); }; #endif // CMATERIALSET_H diff --git a/Resource/CResource.cpp b/Resource/CResource.cpp index e2a965d3..66033858 100644 --- a/Resource/CResource.cpp +++ b/Resource/CResource.cpp @@ -16,12 +16,12 @@ EResType CResource::Type() return eResource; } -std::string CResource::Source() +TString CResource::Source() { - return StringUtil::GetFileNameWithExtension(mResSource); + return mResSource.GetFileName(); } -std::string CResource::FullSource() +TString CResource::FullSource() { return mResSource; } diff --git a/Resource/CResource.h b/Resource/CResource.h index bdc15886..e7f3fd3d 100644 --- a/Resource/CResource.h +++ b/Resource/CResource.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include class CResCache; @@ -13,7 +13,7 @@ class CResource { friend class CResCache; - std::string mResSource; + TString mResSource; CUniqueID mID; int mRefCount; @@ -21,8 +21,8 @@ public: CResource(); virtual ~CResource(); virtual EResType Type(); - std::string Source(); - std::string FullSource(); + TString Source(); + TString FullSource(); CUniqueID ResID(); void Lock(); void Release(); diff --git a/Resource/CStringTable.cpp b/Resource/CStringTable.cpp index dbdbc8d8..506bc764 100644 --- a/Resource/CStringTable.cpp +++ b/Resource/CStringTable.cpp @@ -35,7 +35,7 @@ CFourCC CStringTable::GetLangTag(u32 Index) return mLangTables[Index].Language; } -std::wstring CStringTable::GetString(CFourCC Lang, u32 StringIndex) +TWideString CStringTable::GetString(CFourCC Lang, u32 StringIndex) { for (u32 iLang = 0; iLang < GetLangCount(); iLang++) { @@ -46,12 +46,12 @@ std::wstring CStringTable::GetString(CFourCC Lang, u32 StringIndex) return std::wstring(); } -std::wstring CStringTable::GetString(u32 LangIndex, u32 StringIndex) +TWideString CStringTable::GetString(u32 LangIndex, u32 StringIndex) { return mLangTables[LangIndex].Strings[StringIndex]; } -std::string CStringTable::GetStringName(u32 StringIndex) +TString CStringTable::GetStringName(u32 StringIndex) { return mStringNames[StringIndex]; } diff --git a/Resource/CStringTable.h b/Resource/CStringTable.h index c9d5d26b..4c1147a1 100644 --- a/Resource/CStringTable.h +++ b/Resource/CStringTable.h @@ -11,13 +11,13 @@ class CStringTable : public CResource { friend class CStringLoader; - std::vector mStringNames; + std::vector mStringNames; u32 mNumStrings; struct SLangTable { CFourCC Language; - std::vector Strings; + std::vector Strings; }; std::vector mLangTables; @@ -31,9 +31,9 @@ public: u32 GetStringCount(); u32 GetLangCount(); CFourCC GetLangTag(u32 Index); - std::wstring GetString(CFourCC Lang, u32 StringIndex); - std::wstring GetString(u32 LangIndex, u32 StringIndex); - std::string GetStringName(u32 StringIndex); + TWideString GetString(CFourCC Lang, u32 StringIndex); + TWideString GetString(u32 LangIndex, u32 StringIndex); + TString GetStringName(u32 StringIndex); }; #endif // CSTRINGTABLE_H diff --git a/Resource/CWorld.cpp b/Resource/CWorld.cpp index 2a92ae5e..4d2f3d8d 100644 --- a/Resource/CWorld.cpp +++ b/Resource/CWorld.cpp @@ -90,7 +90,7 @@ u32 CWorld::GetAreaAttachedID(u32 AreaIndex, u32 AttachedIndex) return (u32) mAreas[AreaIndex].AttachedAreaIDs[AttachedIndex]; } -std::string CWorld::GetAreaInternalName(u32 AreaIndex) +TString CWorld::GetAreaInternalName(u32 AreaIndex) { return mAreas[AreaIndex].InternalName; } diff --git a/Resource/CWorld.h b/Resource/CWorld.h index d04fc639..15f22691 100644 --- a/Resource/CWorld.h +++ b/Resource/CWorld.h @@ -43,7 +43,7 @@ class CWorld : public CResource struct SArea { - std::string InternalName; + TString InternalName; CStringTable *pAreaName; CTransform4f Transform; CAABox AetherBox; @@ -53,7 +53,7 @@ class CWorld : public CResource std::vector AttachedAreaIDs; std::vector Dependencies; - std::vector RelFilenames; + std::vector RelFilenames; std::vector RelOffsets; u32 CommonDependenciesStart; @@ -71,7 +71,7 @@ class CWorld : public CResource struct SLayer { - std::string LayerName; + TString LayerName; bool EnabledByDefault; u8 LayerID[16]; u32 LayerDependenciesStart; // Offset into Dependencies vector @@ -100,7 +100,7 @@ public: u64 GetAreaResourceID(u32 AreaIndex); u32 GetAreaAttachedCount(u32 AreaIndex); u32 GetAreaAttachedID(u32 AreaIndex, u32 AttachedIndex); - std::string GetAreaInternalName(u32 AreaIndex); + TString GetAreaInternalName(u32 AreaIndex); CStringTable* GetAreaName(u32 AreaIndex); }; diff --git a/Resource/SNamedResource.h b/Resource/SNamedResource.h index e675d399..7a9faa0a 100644 --- a/Resource/SNamedResource.h +++ b/Resource/SNamedResource.h @@ -7,7 +7,7 @@ struct SNamedResource { CFourCC resType; - std::string resName; + TString resName; u64 resID; }; diff --git a/Resource/cooker/CTemplateWriter.cpp b/Resource/cooker/CTemplateWriter.cpp index 7cc49e28..63cc053f 100644 --- a/Resource/cooker/CTemplateWriter.cpp +++ b/Resource/cooker/CTemplateWriter.cpp @@ -13,8 +13,8 @@ void CTemplateWriter::SaveAllTemplates() { // Create directory std::list masterList = CMasterTemplate::GetMasterList(); - std::string out = "../templates/"; - boost::filesystem::create_directory(out); + TString out = "../templates/"; + boost::filesystem::create_directory(out.ToStdString()); // Resave master templates for (auto it = masterList.begin(); it != masterList.end(); it++) @@ -37,14 +37,14 @@ void CTemplateWriter::SaveAllTemplates() XMLElement *pGame = gameList.NewElement("game"); XMLElement *pGameName = gameList.NewElement("name"); - pGameName->SetText(pMaster->mGameName.c_str()); + pGameName->SetText(*pMaster->mGameName); XMLElement *pWorldVersion = gameList.NewElement("mlvl"); u32 versionNumber = CWorldCooker::GetMLVLVersion(pMaster->GetGame()); - pWorldVersion->SetText(StringUtil::ToHexString(versionNumber, true, true, 2).c_str()); + pWorldVersion->SetText(*TString::HexString(versionNumber, true, true, 2)); XMLElement *pTempPath = gameList.NewElement("master"); - pTempPath->SetText(pMaster->mSourceFile.c_str()); + pTempPath->SetText(*pMaster->mSourceFile); pGame->LinkEndChild(pGameName); pGame->LinkEndChild(pWorldVersion); @@ -52,15 +52,15 @@ void CTemplateWriter::SaveAllTemplates() pBase->LinkEndChild(pGame); } - gameList.SaveFile((out + "GameList.xml").c_str()); + gameList.SaveFile(*(out + "GameList.xml")); } -void CTemplateWriter::SaveGameTemplates(CMasterTemplate *pMaster, const std::string& dir) +void CTemplateWriter::SaveGameTemplates(CMasterTemplate *pMaster, const TString& dir) { // Create directory - std::string outFile = dir + pMaster->mSourceFile; - std::string outDir = StringUtil::GetFileDirectory(outFile); - boost::filesystem::create_directory(outDir); + TString outFile = dir + pMaster->mSourceFile; + TString outDir = outFile.GetFileDirectory(); + boost::filesystem::create_directory(outDir.ToStdString()); // Resave script templates for (auto it = pMaster->mTemplates.begin(); it != pMaster->mTemplates.end(); it++) @@ -92,44 +92,44 @@ void CTemplateWriter::SaveGameTemplates(CMasterTemplate *pMaster, const std::str for (auto it = pMaster->mTemplates.begin(); it != pMaster->mTemplates.end(); it++) { - std::string objID; + TString objID; u32 intID = (it->second)->ObjectID(); - if (intID <= 0xFF) objID = StringUtil::ToHexString(intID, true, true, 2); + if (intID <= 0xFF) objID = TString::HexString(intID, true, true, 2); else objID = CFourCC(intID).ToString(); XMLElement *pObj = master.NewElement("object"); - pObj->SetAttribute("ID", objID.c_str()); - pObj->SetAttribute("template", (it->second)->mSourceFile.c_str()); + pObj->SetAttribute("ID", *objID); + pObj->SetAttribute("template", *(it->second)->mSourceFile); pObjects->LinkEndChild(pObj); } // Write script states/messages - std::map *pMaps[2] = { &pMaster->mStates, &pMaster->mMessages }; - std::string types[2] = { "state", "message" }; + std::map *pMaps[2] = { &pMaster->mStates, &pMaster->mMessages }; + TString types[2] = { "state", "message" }; for (u32 iScr = 0; iScr < 2; iScr++) { - XMLElement *pElem = master.NewElement((types[iScr] + "s").c_str()); + XMLElement *pElem = master.NewElement(*(types[iScr] + "s")); pBase->LinkEndChild(pElem); for (auto it = pMaps[iScr]->begin(); it != pMaps[iScr]->end(); it++) { - std::string ID; - if (it->first <= 0xFF) ID = StringUtil::ToHexString(it->first, true, true, 2); + TString ID; + if (it->first <= 0xFF) ID = TString::HexString(it->first, true, true, 2); else ID = CFourCC(it->first).ToString(); - XMLElement *pSubElem = master.NewElement(types[iScr].c_str()); - pSubElem->SetAttribute("ID", ID.c_str()); - pSubElem->SetAttribute("name", (it->second).c_str()); + XMLElement *pSubElem = master.NewElement(*types[iScr]); + pSubElem->SetAttribute("ID", *ID); + pSubElem->SetAttribute("name", *(it->second)); pElem->LinkEndChild(pSubElem); } } // Save file - master.SaveFile(outFile.c_str()); + master.SaveFile(*outFile); } -void CTemplateWriter::SavePropertyList(CMasterTemplate *pMaster, const std::string& dir) +void CTemplateWriter::SavePropertyList(CMasterTemplate *pMaster, const TString& dir) { // Create XML XMLDocument list; @@ -151,13 +151,13 @@ void CTemplateWriter::SavePropertyList(CMasterTemplate *pMaster, const std::stri CStructTemplate *pStructTemp = static_cast(pTemp); XMLElement *pElem = list.NewElement("struct"); - pElem->SetAttribute("ID", StringUtil::ToHexString(pTemp->PropertyID(), true, true, 8).c_str()); - pElem->SetAttribute("name", pTemp->Name().c_str()); + pElem->SetAttribute("ID", *TString::HexString(pTemp->PropertyID(), true, true, 8)); + pElem->SetAttribute("name", *pTemp->Name()); - if (!pStructTemp->mSourceFile.empty()) + if (!pStructTemp->mSourceFile.IsEmpty()) { SaveStructTemplate(pStructTemp, pMaster, dir); - pElem->SetAttribute("template", pStructTemp->mSourceFile.c_str()); + pElem->SetAttribute("template", *pStructTemp->mSourceFile); } pBase->LinkEndChild(pElem); @@ -166,17 +166,17 @@ void CTemplateWriter::SavePropertyList(CMasterTemplate *pMaster, const std::stri else { XMLElement *pElem = list.NewElement("property"); - pElem->SetAttribute("ID", StringUtil::ToHexString(pTemp->PropertyID(), true, true, 8).c_str()); - pElem->SetAttribute("name", pTemp->Name().c_str()); - pElem->SetAttribute("type", PropEnumToPropString(pTemp->Type()).c_str()); + pElem->SetAttribute("ID", *TString::HexString(pTemp->PropertyID(), true, true, 8)); + pElem->SetAttribute("name", *pTemp->Name()); + pElem->SetAttribute("type", *PropEnumToPropString(pTemp->Type())); if (pTemp->Type() == eFileProperty) { // Construct extension list string CFileTemplate *pFileProp = static_cast(pTemp); - const CStringList& extensions = pFileProp->Extensions(); + const TStringList& extensions = pFileProp->Extensions(); - std::string strList = ""; + TString strList = ""; for (auto it = extensions.begin(); it != extensions.end();) { @@ -185,22 +185,22 @@ void CTemplateWriter::SavePropertyList(CMasterTemplate *pMaster, const std::stri if (it != extensions.end()) strList += ","; } - pElem->SetAttribute("ext", strList.c_str()); + pElem->SetAttribute("ext", *strList); } pBase->LinkEndChild(pElem); } } - list.SaveFile((dir + "Properties.xml").c_str()); + list.SaveFile(*(dir + "Properties.xml")); } -void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const std::string& dir) +void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const TString& dir) { // Create directory - std::string outFile = dir + pTemp->mSourceFile; - std::string outDir = StringUtil::GetFileDirectory(outFile); - boost::filesystem::create_directory(outDir); + TString outFile = dir + pTemp->mSourceFile; + TString outDir = outFile.GetFileDirectory(); + boost::filesystem::create_directory(*outDir); // Create new document XMLDocument scriptXML; @@ -215,14 +215,14 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const std::stri // Write object name XMLElement *pName = scriptXML.NewElement("name"); - pName->SetText(pTemp->TemplateName().c_str()); + pName->SetText(*pTemp->TemplateName()); pBase->LinkEndChild(pName); // Write properties for (auto it = pTemp->mPropertySets.begin(); it != pTemp->mPropertySets.end(); it++) { XMLElement *pProperties = scriptXML.NewElement("properties"); - pProperties->SetAttribute("version", it->SetName.c_str()); + pProperties->SetAttribute("version", *it->SetName); SaveProperties(&scriptXML, pProperties, it->pBaseStruct, pTemp->MasterTemplate(), dir); pBase->LinkEndChild(pProperties); } @@ -235,7 +235,7 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const std::stri XMLElement *pEditorProperties = scriptXML.NewElement("properties"); pEditor->LinkEndChild(pEditorProperties); - std::string propNames[6] = { + TString propNames[6] = { "InstanceName", "Position", "Rotation", "Scale", "Active", "LightParameters" }; @@ -247,11 +247,11 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const std::stri for (u32 iProp = 0; iProp < 6; iProp++) { - if (!pPropStrings[iProp]->empty()) + if (!pPropStrings[iProp]->IsEmpty()) { XMLElement *pProperty = scriptXML.NewElement("property"); - pProperty->SetAttribute("name", propNames[iProp].c_str()); - pProperty->SetAttribute("ID", pPropStrings[iProp]->c_str()); + pProperty->SetAttribute("name", *propNames[iProp]); + pProperty->SetAttribute("ID", **pPropStrings[iProp]); pEditorProperties->LinkEndChild(pProperty); } } @@ -262,8 +262,8 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const std::stri for (auto it = pTemp->mAssets.begin(); it != pTemp->mAssets.end(); it++) { - std::string source = (it->AssetSource == CScriptTemplate::SEditorAsset::eFile ? "file" : "property"); - std::string type; + TString source = (it->AssetSource == CScriptTemplate::SEditorAsset::eFile ? "file" : "property"); + TString type; switch (it->AssetType) { @@ -275,10 +275,10 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const std::stri s32 force = -1; if (it->AssetSource == CScriptTemplate::SEditorAsset::eAnimParams) force = it->ForceNodeIndex; - XMLElement *pAsset = scriptXML.NewElement(type.c_str()); - pAsset->SetAttribute("source", source.c_str()); + XMLElement *pAsset = scriptXML.NewElement(*type); + pAsset->SetAttribute("source", *source); if (force >= 0) pAsset->SetAttribute("force", std::to_string(force).c_str()); - pAsset->SetText(it->AssetLocation.c_str()); + pAsset->SetText(*it->AssetLocation); pAssets->LinkEndChild(pAsset); } @@ -302,7 +302,7 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const std::stri pEditor->LinkEndChild(pVolume); // Enum -> String conversion lambda to avoid redundant code - auto GetVolumeString = [](EVolumeShape shape) -> std::string + auto GetVolumeString = [](EVolumeShape shape) -> TString { switch (shape) { @@ -316,11 +316,11 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const std::stri } }; - pVolume->SetAttribute("shape", GetVolumeString(pTemp->mVolumeShape).c_str()); + pVolume->SetAttribute("shape", *GetVolumeString(pTemp->mVolumeShape)); if (pTemp->mVolumeShape == eConditionalShape) { - pVolume->SetAttribute("propertyID", pTemp->mVolumeConditionIDString.c_str()); + pVolume->SetAttribute("propertyID", *pTemp->mVolumeConditionIDString); // Find conditional test property CPropertyTemplate *pProp; @@ -335,32 +335,32 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const std::stri for (auto it = pTemp->mVolumeConditions.begin(); it != pTemp->mVolumeConditions.end(); it++) { // Value should be an integer, or a boolean condition? - std::string strVal; + TString strVal; if (pProp->Type() == eBoolProperty) strVal = (it->Value == 1 ? "true" : "false"); else - strVal = StringUtil::ToHexString((u32) it->Value, true, true, (it->Value > 0xFF ? 8 : 2)); + strVal = TString::HexString((u32) it->Value, true, true, (it->Value > 0xFF ? 8 : 2)); XMLElement *pCondition = scriptXML.NewElement("condition"); - pCondition->SetAttribute("value", strVal.c_str()); - pCondition->SetAttribute("shape", GetVolumeString(it->Shape).c_str()); + pCondition->SetAttribute("value", *strVal); + pCondition->SetAttribute("shape", *GetVolumeString(it->Shape)); pVolume->LinkEndChild(pCondition); } } } // Write to file - scriptXML.SaveFile(outFile.c_str()); + scriptXML.SaveFile(*outFile); } -void CTemplateWriter::SaveStructTemplate(CStructTemplate *pTemp, CMasterTemplate *pMaster, const std::string& dir) +void CTemplateWriter::SaveStructTemplate(CStructTemplate *pTemp, CMasterTemplate *pMaster, const TString& dir) { // Create directory - std::string outFile = dir + pTemp->mSourceFile; - std::string outDir = StringUtil::GetFileDirectory(outFile); - std::string name = StringUtil::GetFileName(pTemp->mSourceFile); - boost::filesystem::create_directory(outDir); + TString outFile = dir + pTemp->mSourceFile; + TString outDir = outFile.GetFileDirectory(); + TString name = pTemp->mSourceFile.GetFileName(); + boost::filesystem::create_directory(outDir.ToStdString()); // Create new document and write struct properties to it XMLDocument structXML; @@ -369,21 +369,21 @@ void CTemplateWriter::SaveStructTemplate(CStructTemplate *pTemp, CMasterTemplate structXML.LinkEndChild(pDecl); XMLElement *pBase = structXML.NewElement("struct"); - pBase->SetAttribute("name", name.c_str()); + pBase->SetAttribute("name", *name); pBase->SetAttribute("type", (pTemp->IsSingleProperty() ? "single" : "multi")); SaveProperties(&structXML, pBase, pTemp, pMaster, dir); structXML.LinkEndChild(pBase); - structXML.SaveFile(outFile.c_str()); + structXML.SaveFile(*outFile); } -void CTemplateWriter::SaveEnumTemplate(CEnumTemplate *pTemp, const std::string& dir) +void CTemplateWriter::SaveEnumTemplate(CEnumTemplate *pTemp, const TString& dir) { // Create directory - std::string outFile = dir + pTemp->mSourceFile; - std::string outDir = StringUtil::GetFileDirectory(outFile); - std::string name = StringUtil::GetFileName(pTemp->mSourceFile); - boost::filesystem::create_directory(outDir); + TString outFile = dir + pTemp->mSourceFile; + TString outDir = outFile.GetFileDirectory(); + TString name = pTemp->mSourceFile.GetFileName(false); + boost::filesystem::create_directory(*outDir); // Create new document and write enumerators to it XMLDocument enumXML; @@ -392,20 +392,20 @@ void CTemplateWriter::SaveEnumTemplate(CEnumTemplate *pTemp, const std::string& enumXML.LinkEndChild(pDecl); XMLElement *pBase = enumXML.NewElement("enum"); - pBase->SetName("name", name.c_str()); + pBase->SetName("name", *name); SaveEnumerators(&enumXML, pBase, pTemp); enumXML.LinkEndChild(pBase); - enumXML.SaveFile(outFile.c_str()); + enumXML.SaveFile(*outFile); } -void CTemplateWriter::SaveBitfieldTemplate(CBitfieldTemplate *pTemp, const std::string& dir) +void CTemplateWriter::SaveBitfieldTemplate(CBitfieldTemplate *pTemp, const TString& dir) { // Create directory - std::string outFile = dir + pTemp->mSourceFile; - std::string outDir = StringUtil::GetFileDirectory(outFile); - std::string name = StringUtil::GetFileName(pTemp->mSourceFile); - boost::filesystem::create_directory(outDir); + TString outFile = dir + pTemp->mSourceFile; + TString outDir = outFile.GetFileDirectory(); + TString name = pTemp->mSourceFile.GetFileName(); + boost::filesystem::create_directory(*outDir); // Create new document and write enumerators to it XMLDocument bitfieldXML; @@ -414,47 +414,47 @@ void CTemplateWriter::SaveBitfieldTemplate(CBitfieldTemplate *pTemp, const std:: bitfieldXML.LinkEndChild(pDecl); XMLElement *pBase = bitfieldXML.NewElement("bitfield"); - pBase->SetName("name", name.c_str()); + pBase->SetName("name", *name); SaveBitFlags(&bitfieldXML, pBase, pTemp); bitfieldXML.LinkEndChild(pBase); - bitfieldXML.SaveFile(outFile.c_str()); + bitfieldXML.SaveFile(*outFile); } -void CTemplateWriter::SaveProperties(XMLDocument *pDoc, XMLElement *pParent, CStructTemplate *pTemp, CMasterTemplate *pMaster, const std::string& dir) +void CTemplateWriter::SaveProperties(XMLDocument *pDoc, XMLElement *pParent, CStructTemplate *pTemp, CMasterTemplate *pMaster, const TString& dir) { for (u32 iProp = 0; iProp < pTemp->Count(); iProp++) { CPropertyTemplate *pProp = pTemp->PropertyByIndex(iProp); u32 propID = (pProp->PropertyID() == 0xFFFFFFFF ? iProp : pProp->PropertyID()); - std::string strID = StringUtil::ToHexString(propID, true, true, (propID > 0xFF ? 8 : 2)); + TString strID = TString::HexString(propID, true, true, (propID > 0xFF ? 8 : 2)); if (pProp->Type() == eStructProperty) { CStructTemplate *pStructTemp = static_cast(pProp); - bool isExternal = (!pStructTemp->mSourceFile.empty()); + bool isExternal = (!pStructTemp->mSourceFile.IsEmpty()); XMLElement *pElem = pDoc->NewElement("struct"); - pElem->SetAttribute("ID", strID.c_str()); + pElem->SetAttribute("ID", *strID); if ((!pMaster->HasPropertyList()) || (pProp->PropertyID() == -1) || pTemp->IsSingleProperty()) { - pElem->SetAttribute("name", pProp->Name().c_str()); + pElem->SetAttribute("name", *pProp->Name()); } if (!isExternal) { - std::string type = pStructTemp->IsSingleProperty() ? "single" : "multi"; - pElem->SetAttribute("type", type.c_str()); + TString type = pStructTemp->IsSingleProperty() ? "single" : "multi"; + pElem->SetAttribute("type", *type); } // Only save properties if this is a multi struct, or if there is no master property list if (!pMaster->HasPropertyList() || !pStructTemp->IsSingleProperty()) { // Embed struct or save to external XML? - if (!pStructTemp->mSourceFile.empty()) + if (!pStructTemp->mSourceFile.IsEmpty()) { SaveStructTemplate(pStructTemp, pMaster, dir); - pElem->SetAttribute("template", pStructTemp->mSourceFile.c_str()); + pElem->SetAttribute("template", *pStructTemp->mSourceFile); } else @@ -469,18 +469,18 @@ void CTemplateWriter::SaveProperties(XMLDocument *pDoc, XMLElement *pParent, CSt else if (pProp->Type() == eEnumProperty) { CEnumTemplate *pEnumTemp = static_cast(pProp); - bool isExternal = (!pEnumTemp->mSourceFile.empty()); + bool isExternal = (!pEnumTemp->mSourceFile.IsEmpty()); XMLElement *pElem = pDoc->NewElement("enum"); - pElem->SetAttribute("ID", strID.c_str()); + pElem->SetAttribute("ID", *strID); if ((!pMaster->HasPropertyList()) || (pProp->PropertyID() == -1)) - pElem->SetAttribute("name", pProp->Name().c_str()); + pElem->SetAttribute("name", *pProp->Name()); if (isExternal) { SaveEnumTemplate(pEnumTemp, dir); - pElem->SetAttribute("template", pEnumTemp->mSourceFile.c_str()); + pElem->SetAttribute("template", *pEnumTemp->mSourceFile); } else @@ -493,18 +493,18 @@ void CTemplateWriter::SaveProperties(XMLDocument *pDoc, XMLElement *pParent, CSt else if (pProp->Type() == eBitfieldProperty) { CBitfieldTemplate *pBitfieldTemp = static_cast(pProp); - bool isExternal = (!pBitfieldTemp->mSourceFile.empty()); + bool isExternal = (!pBitfieldTemp->mSourceFile.IsEmpty()); XMLElement *pElem = pDoc->NewElement("bitfield"); - pElem->SetAttribute("ID", strID.c_str()); + pElem->SetAttribute("ID", *strID); if ((!pMaster->HasPropertyList()) || (pProp->PropertyID() == -1)) - pElem->SetAttribute("name", pProp->Name().c_str()); + pElem->SetAttribute("name", *pProp->Name()); if (isExternal) { SaveBitfieldTemplate(pBitfieldTemp, dir); - pElem->SetAttribute("template", pBitfieldTemp->mSourceFile.c_str()); + pElem->SetAttribute("template", *pBitfieldTemp->mSourceFile); } else @@ -517,20 +517,20 @@ void CTemplateWriter::SaveProperties(XMLDocument *pDoc, XMLElement *pParent, CSt else { XMLElement *pElem = pDoc->NewElement("property"); - pElem->SetAttribute("ID", strID.c_str()); + pElem->SetAttribute("ID", *strID); if ((!pMaster->HasPropertyList()) || (pProp->PropertyID() == -1) || pTemp->IsSingleProperty()) { - pElem->SetAttribute("name", pProp->Name().c_str()); - pElem->SetAttribute("type", PropEnumToPropString(pProp->Type()).c_str()); + pElem->SetAttribute("name", *pProp->Name()); + pElem->SetAttribute("type", *PropEnumToPropString(pProp->Type())); if (pProp->Type() == eFileProperty) { // Construct extension list string CFileTemplate *pFileProp = static_cast(pProp); - const CStringList& extensions = pFileProp->Extensions(); + const TStringList& extensions = pFileProp->Extensions(); - std::string strList = ""; + TString strList = ""; for (auto it = extensions.begin(); it != extensions.end();) { @@ -539,7 +539,7 @@ void CTemplateWriter::SaveProperties(XMLDocument *pDoc, XMLElement *pParent, CSt if (it != extensions.end()) strList += ","; } - pElem->SetAttribute("ext", strList.c_str()); + pElem->SetAttribute("ext", *strList); } } @@ -553,8 +553,8 @@ void CTemplateWriter::SaveEnumerators(XMLDocument *pDoc, XMLElement *pParent, CE for (u32 iEnum = 0; iEnum < pTemp->NumEnumerators(); iEnum++) { XMLElement *pElem = pDoc->NewElement("enumerator"); - pElem->SetAttribute("ID", StringUtil::ToHexString(pTemp->EnumeratorID(iEnum), true, true, 8).c_str()); - pElem->SetAttribute("name", pTemp->EnumeratorName(iEnum).c_str()); + pElem->SetAttribute("ID", *TString::HexString(pTemp->EnumeratorID(iEnum), true, true, 8)); + pElem->SetAttribute("name", *pTemp->EnumeratorName(iEnum)); pParent->LinkEndChild(pElem); } } @@ -564,8 +564,8 @@ void CTemplateWriter::SaveBitFlags(tinyxml2::XMLDocument *pDoc, tinyxml2::XMLEle for (u32 iFlag = 0; iFlag < pTemp->NumFlags(); iFlag++) { XMLElement *pElem = pDoc->NewElement("bitflag"); - pElem->SetAttribute("mask", StringUtil::ToHexString(pTemp->FlagMask(iFlag), true, true, 8).c_str()); - pElem->SetAttribute("name", pTemp->FlagName(iFlag).c_str()); + pElem->SetAttribute("mask", *TString::HexString(pTemp->FlagMask(iFlag), true, true, 8)); + pElem->SetAttribute("name", *pTemp->FlagName(iFlag)); pParent->LinkEndChild(pElem); } } diff --git a/Resource/cooker/CTemplateWriter.h b/Resource/cooker/CTemplateWriter.h index 500673bc..ed6c1b40 100644 --- a/Resource/cooker/CTemplateWriter.h +++ b/Resource/cooker/CTemplateWriter.h @@ -10,13 +10,13 @@ class CTemplateWriter public: static void SaveAllTemplates(); - static void SaveGameTemplates(CMasterTemplate *pMaster, const std::string& dir); - static void SavePropertyList(CMasterTemplate *pMaster, const std::string& dir); - static void SaveScriptTemplate(CScriptTemplate *pTemp, const std::string& dir); - static void SaveStructTemplate(CStructTemplate *pTemp, CMasterTemplate *pMaster, const std::string& dir); - static void SaveEnumTemplate(CEnumTemplate *pTemp, const std::string& dir); - static void SaveBitfieldTemplate(CBitfieldTemplate *pTemp, const std::string& dir); - static void SaveProperties(tinyxml2::XMLDocument *pDoc, tinyxml2::XMLElement *pParent, CStructTemplate *pTemp, CMasterTemplate *pMaster, const std::string& dir); + static void SaveGameTemplates(CMasterTemplate *pMaster, const TString& dir); + static void SavePropertyList(CMasterTemplate *pMaster, const TString& dir); + static void SaveScriptTemplate(CScriptTemplate *pTemp, const TString& dir); + static void SaveStructTemplate(CStructTemplate *pTemp, CMasterTemplate *pMaster, const TString& dir); + static void SaveEnumTemplate(CEnumTemplate *pTemp, const TString& dir); + static void SaveBitfieldTemplate(CBitfieldTemplate *pTemp, const TString& dir); + static void SaveProperties(tinyxml2::XMLDocument *pDoc, tinyxml2::XMLElement *pParent, CStructTemplate *pTemp, CMasterTemplate *pMaster, const TString& dir); static void SaveEnumerators(tinyxml2::XMLDocument *pDoc, tinyxml2::XMLElement *pParent, CEnumTemplate *pTemp); static void SaveBitFlags(tinyxml2::XMLDocument *pDoc, tinyxml2::XMLElement *pParent, CBitfieldTemplate *pTemp); }; diff --git a/Resource/factory/CAnimSetLoader.cpp b/Resource/factory/CAnimSetLoader.cpp index d8684cae..993e6880 100644 --- a/Resource/factory/CAnimSetLoader.cpp +++ b/Resource/factory/CAnimSetLoader.cpp @@ -82,7 +82,7 @@ CAnimSet* CAnimSetLoader::LoadANCS(CInputStream& ANCS) u32 magic = ANCS.ReadLong(); if (magic != 0x00010001) { - Log::FileError(ANCS.GetSourceString(), "Invalid ANCS magic: " + StringUtil::ToHexString(magic)); + Log::FileError(ANCS.GetSourceString(), "Invalid ANCS magic: " + TString::HexString(magic)); return nullptr; } @@ -194,6 +194,6 @@ CAnimSet* CAnimSetLoader::LoadCHAR(CInputStream &CHAR) return loader.LoadReturnsCHAR(CHAR); } - Log::FileError(CHAR.GetSourceString(), "CHAR has invalid first byte: " + StringUtil::ToHexString(check)); + Log::FileError(CHAR.GetSourceString(), "CHAR has invalid first byte: " + TString::HexString(check)); return nullptr; } diff --git a/Resource/factory/CAreaLoader.cpp b/Resource/factory/CAreaLoader.cpp index 3dae1ef5..091d3b21 100644 --- a/Resource/factory/CAreaLoader.cpp +++ b/Resource/factory/CAreaLoader.cpp @@ -475,9 +475,9 @@ void CAreaLoader::Decompress() } } - std::string Source = mpMREA->GetSourceString(); + TString Source = mpMREA->GetSourceString(); mpMREA = new CMemoryInStream(mDecmpBuffer, mTotalDecmpSize, IOUtil::BigEndian); - mpMREA->SetSourceString(Source); + mpMREA->SetSourceString(Source.ToStdString()); mBlockMgr->SetInputStream(mpMREA); mHasDecompressedBuffer = true; } @@ -549,7 +549,7 @@ CGameArea* CAreaLoader::LoadMREA(CInputStream& MREA) u32 deadbeef = MREA.ReadLong(); if (deadbeef != 0xdeadbeef) { - Log::FileError(MREA.GetSourceString(), "Invalid MREA magic: " + StringUtil::ToHexString(deadbeef)); + Log::FileError(MREA.GetSourceString(), "Invalid MREA magic: " + TString::HexString(deadbeef)); return nullptr; } @@ -592,7 +592,7 @@ CGameArea* CAreaLoader::LoadMREA(CInputStream& MREA) if (Loader.mVersion == eCorruption) Loader.ReadLightsCorruption(); break; default: - Log::FileError(MREA.GetSourceString(), "Unsupported MREA version: " + StringUtil::ToHexString(version)); + Log::FileError(MREA.GetSourceString(), "Unsupported MREA version: " + TString::HexString(version)); delete Loader.mpArea; return nullptr; } diff --git a/Resource/factory/CCollisionLoader.cpp b/Resource/factory/CCollisionLoader.cpp index 8abbee44..fc02684d 100644 --- a/Resource/factory/CCollisionLoader.cpp +++ b/Resource/factory/CCollisionLoader.cpp @@ -140,7 +140,7 @@ CCollisionMeshGroup* CCollisionLoader::LoadAreaCollision(CInputStream& MREA) u32 deafbabe = MREA.ReadLong(); if (deafbabe != 0xDEAFBABE) { - Log::FileError(MREA.GetSourceString(), MREA.Tell() - 4, "Invalid collision magic: " + StringUtil::ToHexString(deafbabe)); + Log::FileError(MREA.GetSourceString(), MREA.Tell() - 4, "Invalid collision magic: " + TString::HexString(deafbabe)); return nullptr; } @@ -177,7 +177,7 @@ CCollisionMeshGroup* CCollisionLoader::LoadDCLN(CInputStream &DCLN) if (deafbabe != 0xDEAFBABE) { - Log::FileError(DCLN.GetSourceString(), DCLN.Tell() - 4, "Invalid collision magic: " + StringUtil::ToHexString(deafbabe)); + Log::FileError(DCLN.GetSourceString(), DCLN.Tell() - 4, "Invalid collision magic: " + TString::HexString(deafbabe)); delete loader.mpGroup; return nullptr; } diff --git a/Resource/factory/CFontLoader.cpp b/Resource/factory/CFontLoader.cpp index e337c695..bed27118 100644 --- a/Resource/factory/CFontLoader.cpp +++ b/Resource/factory/CFontLoader.cpp @@ -88,7 +88,7 @@ CFont* CFontLoader::LoadFONT(CInputStream& FONT) CFourCC Magic(FONT); if (Magic != "FONT") { - Log::FileError(FONT.GetSourceString(), "Invalid FONT magic: " + StringUtil::ToHexString((u32) Magic.ToLong())); + Log::FileError(FONT.GetSourceString(), "Invalid FONT magic: " + TString::HexString((u32) Magic.ToLong())); return nullptr; } @@ -96,7 +96,7 @@ CFont* CFontLoader::LoadFONT(CInputStream& FONT) EGame Version = GetFormatVersion(FileVersion); if (Version == eUnknownVersion) { - Log::FileError(FONT.GetSourceString(), "Unsupported FONT version: " + StringUtil::ToHexString(FileVersion)); + Log::FileError(FONT.GetSourceString(), "Unsupported FONT version: " + TString::HexString(FileVersion)); return nullptr; } diff --git a/Resource/factory/CMaterialLoader.cpp b/Resource/factory/CMaterialLoader.cpp index a8a67ac0..cfe1e6a6 100644 --- a/Resource/factory/CMaterialLoader.cpp +++ b/Resource/factory/CMaterialLoader.cpp @@ -39,7 +39,7 @@ void CMaterialLoader::ReadPrimeMatSet() { mpSet->mMaterials[iMat] = ReadPrimeMaterial(); mpSet->mMaterials[iMat]->mVersion = mVersion; - mpSet->mMaterials[iMat]->mName = std::string("Material #") + std::to_string(iMat + 1); + mpSet->mMaterials[iMat]->mName = TString("Material #") + std::to_string(iMat + 1); mpFile->Seek(matsStart + offsets[iMat], SEEK_SET); } } @@ -189,7 +189,7 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial() case 6: // Model Matrix break; default: - Log::FileError(mpFile->GetSourceString(), mpFile->Tell() - 4, "Unsupported animation mode encountered: " + StringUtil::ToHexString((u32) Anims[iAnim].Mode)); + Log::FileError(mpFile->GetSourceString(), mpFile->Tell() - 4, "Unsupported animation mode encountered: " + TString::HexString((u32) Anims[iAnim].Mode)); break; } } @@ -240,7 +240,7 @@ void CMaterialLoader::ReadCorruptionMatSet() u32 Next = mpFile->Tell() + Size; mpSet->mMaterials[iMat] = ReadCorruptionMaterial(); mpSet->mMaterials[iMat]->mVersion = mVersion; - mpSet->mMaterials[iMat]->mName = std::string("Material #") + std::to_string(iMat + 1); + mpSet->mMaterials[iMat]->mName = TString("Material #") + std::to_string(iMat + 1); mpFile->Seek(Next, SEEK_SET); } } @@ -378,7 +378,7 @@ CMaterial* CMaterialLoader::ReadCorruptionMaterial() case 10: // Yet-to-be-named break; default: - Log::FileError(mpFile->GetSourceString(), mpFile->Tell() - 8, "Unsupported animation mode encountered: " + StringUtil::ToHexString((u32) pPass->mAnimMode)); + Log::FileError(mpFile->GetSourceString(), mpFile->Tell() - 8, "Unsupported animation mode encountered: " + TString::HexString((u32) pPass->mAnimMode)); break; } diff --git a/Resource/factory/CModelLoader.cpp b/Resource/factory/CModelLoader.cpp index 19ae0643..31bebac9 100644 --- a/Resource/factory/CModelLoader.cpp +++ b/Resource/factory/CModelLoader.cpp @@ -432,7 +432,7 @@ CModel* CModelLoader::LoadCMDL(CInputStream& CMDL) else { - Log::FileError(CMDL.GetSourceString(), "Invalid CMDL magic: " + StringUtil::ToHexString(Magic)); + Log::FileError(CMDL.GetSourceString(), "Invalid CMDL magic: " + TString::HexString(Magic)); return nullptr; } @@ -441,7 +441,7 @@ CModel* CModelLoader::LoadCMDL(CInputStream& CMDL) if (Loader.mVersion == eUnknownVersion) { - Log::FileError(CMDL.GetSourceString(), "Unsupported CMDL version: " + StringUtil::ToHexString(Magic)); + Log::FileError(CMDL.GetSourceString(), "Unsupported CMDL version: " + TString::HexString(Magic)); return nullptr; } diff --git a/Resource/factory/CScanLoader.cpp b/Resource/factory/CScanLoader.cpp index 074a19ca..9f56e16b 100644 --- a/Resource/factory/CScanLoader.cpp +++ b/Resource/factory/CScanLoader.cpp @@ -48,7 +48,7 @@ CScan* CScanLoader::LoadScanMP2(CInputStream& SCAN) u32 BasePropID = SCAN.ReadLong(); if (BasePropID != 0xFFFFFFFF) { - Log::FileError(SCAN.GetSourceString(), SCAN.Tell() - 4, "Invalid base proprty ID: " + StringUtil::ToHexString(BasePropID)); + Log::FileError(SCAN.GetSourceString(), SCAN.Tell() - 4, "Invalid base proprty ID: " + TString::HexString(BasePropID)); return nullptr; } @@ -65,7 +65,7 @@ CScan* CScanLoader::LoadScanMP2(CInputStream& SCAN) LoadParamsMP3(SCAN); break; default: - Log::FileError(SCAN.GetSourceString(), SCAN.Tell() - 2, "Invalid SNFO property count: " + StringUtil::ToHexString(NumProperties)); + Log::FileError(SCAN.GetSourceString(), SCAN.Tell() - 2, "Invalid SNFO property count: " + TString::HexString(NumProperties)); delete mpScan; return nullptr; } @@ -164,13 +164,13 @@ CScan* CScanLoader::LoadSCAN(CInputStream &SCAN) if (magic != 0x0BADBEEF) { - Log::FileError(SCAN.GetSourceString(), "Invalid SCAN magic: " + StringUtil::ToHexString(magic)); + Log::FileError(SCAN.GetSourceString(), "Invalid SCAN magic: " + TString::HexString(magic)); return nullptr; } if (fileVersion != 5) { - Log::FileError(SCAN.GetSourceString(), "Unsupported SCAN version: " + StringUtil::ToHexString(fileVersion)); + Log::FileError(SCAN.GetSourceString(), "Unsupported SCAN version: " + TString::HexString(fileVersion)); return nullptr; } diff --git a/Resource/factory/CScriptLoader.cpp b/Resource/factory/CScriptLoader.cpp index 7df0d8f2..d27d4c60 100644 --- a/Resource/factory/CScriptLoader.cpp +++ b/Resource/factory/CScriptLoader.cpp @@ -69,7 +69,7 @@ CPropertyStruct* CScriptLoader::LoadStructMP1(CInputStream& SCLY, CStructTemplat mask |= pBitfieldTemp->FlagMask(iMask); u32 check = v & ~mask; - if (check != 0) Log::FileWarning(SCLY.GetSourceString(), SCLY.Tell() - 4, "Bitfield property \"" + pBitfieldTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has flags set that aren't in the template: " + StringUtil::ToHexString(check, true, true, 8)); + if (check != 0) Log::FileWarning(SCLY.GetSourceString(), SCLY.Tell() - 4, "Bitfield property \"" + pBitfieldTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has flags set that aren't in the template: " + TString::HexString(check, true, true, 8)); break; } @@ -77,7 +77,7 @@ CPropertyStruct* CScriptLoader::LoadStructMP1(CInputStream& SCLY, CStructTemplat CEnumTemplate *pEnumTemp = static_cast(pPropTmp); u32 ID = SCLY.ReadLong(); u32 index = pEnumTemp->EnumeratorIndex(ID); - if (index == -1) Log::FileError(SCLY.GetSourceString(), SCLY.Tell() - 4, "Enum property \"" + pEnumTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has invalid enumerator value: " + StringUtil::ToHexString(ID, true, true, 8)); + if (index == -1) Log::FileError(SCLY.GetSourceString(), SCLY.Tell() - 4, "Enum property \"" + pEnumTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has invalid enumerator value: " + TString::HexString(ID, true, true, 8)); pProp = new CEnumProperty(index); break; } @@ -87,7 +87,7 @@ CPropertyStruct* CScriptLoader::LoadStructMP1(CInputStream& SCLY, CStructTemplat break; } case eStringProperty: { - std::string v = SCLY.ReadString(); + TString v = SCLY.ReadString(); pProp = new CStringProperty(v); break; } @@ -104,13 +104,13 @@ CPropertyStruct* CScriptLoader::LoadStructMP1(CInputStream& SCLY, CStructTemplat } case eFileProperty: { u32 ResID = SCLY.ReadLong(); - const CStringList& Extensions = static_cast(pPropTmp)->Extensions(); + const TStringList& Extensions = static_cast(pPropTmp)->Extensions(); CResource *pRes = nullptr; for (auto it = Extensions.begin(); it != Extensions.end(); it++) { - const std::string& ext = *it; + const TString& ext = *it; if ((ext != "MREA") && (ext != "MLVL")) // Let's avoid recursion please pRes = gResCache.GetResource(ResID, ext); @@ -155,7 +155,7 @@ CScriptObject* CScriptLoader::LoadObjectMP1(CInputStream& SCLY) if (!pTemp) { // No valid template for this object; can't load - Log::FileError(SCLY.GetSourceString(), objStart, "Invalid object ID encountered: " + StringUtil::ToHexString(type)); + Log::FileError(SCLY.GetSourceString(), objStart, "Invalid object ID encountered: " + TString::HexString(type)); SCLY.Seek(end, SEEK_SET); return nullptr; } @@ -181,7 +181,7 @@ CScriptObject* CScriptLoader::LoadObjectMP1(CInputStream& SCLY) CStructTemplate *pBase = pTemp->BaseStructByCount(count); if (!pBase) { - Log::Error(pTemp->TemplateName() + " template doesn't match file property count (" + StringUtil::ToString(count) + ")"); + Log::Error(pTemp->TemplateName() + " template doesn't match file property count (" + TString::FromInt32(count) + ")"); pBase = pTemp->BaseStructByIndex(0); } mpObj->mpProperties = LoadStructMP1(SCLY, pBase); @@ -257,7 +257,7 @@ void CScriptLoader::LoadStructMP2(CInputStream& SCLY, CPropertyStruct *pStruct, } if (!pPropTemp) - Log::FileError(SCLY.GetSourceString(), propertyStart, "Can't find template for property " + StringUtil::ToHexString(propertyID) + " - skipping"); + Log::FileError(SCLY.GetSourceString(), propertyStart, "Can't find template for property " + TString::HexString(propertyID) + " - skipping"); else { @@ -299,7 +299,7 @@ void CScriptLoader::LoadStructMP2(CInputStream& SCLY, CPropertyStruct *pStruct, mask |= pBitfieldTemp->FlagMask(iMask); u32 check = pBitfieldCast->Get() & ~mask; - if (check != 0) Log::FileWarning(SCLY.GetSourceString(), SCLY.Tell() - 4, "Bitfield property \"" + pBitfieldTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has flags set that aren't in the template: " + StringUtil::ToHexString(check, true, true, 8)); + if (check != 0) Log::FileWarning(SCLY.GetSourceString(), SCLY.Tell() - 4, "Bitfield property \"" + pBitfieldTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has flags set that aren't in the template: " + TString::HexString(check, true, true, 8)); break; } @@ -309,7 +309,7 @@ void CScriptLoader::LoadStructMP2(CInputStream& SCLY, CPropertyStruct *pStruct, CEnumTemplate *pEnumTemp = static_cast(pPropTemp); u32 ID = SCLY.ReadLong(); u32 index = pEnumTemp->EnumeratorIndex(ID); - if (index == -1) Log::FileError(SCLY.GetSourceString(), SCLY.Tell() - 4, "Enum property \"" + pEnumTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has invalid enumerator value: " + StringUtil::ToHexString(ID, true, true, 8)); + if (index == -1) Log::FileError(SCLY.GetSourceString(), SCLY.Tell() - 4, "Enum property \"" + pEnumTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has invalid enumerator value: " + TString::HexString(ID, true, true, 8)); pEnumCast->Set(index); break; } @@ -343,7 +343,7 @@ void CScriptLoader::LoadStructMP2(CInputStream& SCLY, CPropertyStruct *pStruct, CFileProperty *pFileCast = static_cast(pProp); CUniqueID ResID = (mVersion < eCorruptionProto ? SCLY.ReadLong() : SCLY.ReadLongLong()); - const CStringList& Extensions = static_cast(pPropTemp)->Extensions(); + const TStringList& Extensions = static_cast(pPropTemp)->Extensions(); CResource *pRes = nullptr; @@ -356,7 +356,7 @@ void CScriptLoader::LoadStructMP2(CInputStream& SCLY, CPropertyStruct *pStruct, { for (auto it = Extensions.begin(); it != Extensions.end(); it++) { - const std::string& ext = *it; + const TString& ext = *it; if ((ext != "MREA") && (ext != "MLVL")) { pRes = gResCache.GetResource(ResID, ext); @@ -371,13 +371,13 @@ void CScriptLoader::LoadStructMP2(CInputStream& SCLY, CPropertyStruct *pStruct, // Property may have an incorrect extension listed - print error if ((!pRes) && (CUniqueID(ResID).IsValid()) && (!hasIgnoredExt)) { - std::string ExtList; + TString ExtList; for (auto it = Extensions.begin(); it != Extensions.end(); it++) { if (it != Extensions.begin()) ExtList += "/"; ExtList += *it; } - Log::FileWarning(SCLY.GetSourceString(), "Incorrect resource type? " + ExtList + " " + StringUtil::ToHexString(propertyID)); + Log::FileWarning(SCLY.GetSourceString(), "Incorrect resource type? " + ExtList + " " + TString::HexString(propertyID)); } pFileCast->Set(pRes); @@ -474,7 +474,7 @@ CScriptLayer* CScriptLoader::LoadLayerMP2(CInputStream& SCLY) else if (SCLY_Magic == "SCGN") SCLY.Seek(0x2, SEEK_CUR); else { - Log::FileError(SCLY.GetSourceString(), SCLY.Tell() - 4, "Invalid script layer magic: " + StringUtil::ToHexString((u32) SCLY_Magic.ToLong())); + Log::FileError(SCLY.GetSourceString(), SCLY.Tell() - 4, "Invalid script layer magic: " + TString::HexString((u32) SCLY_Magic.ToLong())); return nullptr; } diff --git a/Resource/factory/CStringLoader.cpp b/Resource/factory/CStringLoader.cpp index eb2ea65d..bc480ff1 100644 --- a/Resource/factory/CStringLoader.cpp +++ b/Resource/factory/CStringLoader.cpp @@ -121,7 +121,7 @@ void CStringLoader::LoadCorruptionSTRG(CInputStream& STRG) STRG.Seek(StringsStart + LangOffsets[iLang][iStr], SEEK_SET); STRG.Seek(0x4, SEEK_CUR); // Skipping string size - pLang->Strings[iStr] = StringUtil::UTF8to16(STRG.ReadString()); + pLang->Strings[iStr] = STRG.ReadString(); } } } @@ -180,7 +180,7 @@ CStringTable* CStringLoader::LoadSTRG(CInputStream& STRG) if (Version != ePrimeDemo) { - Log::FileError(STRG.GetSourceString(), "Invalid STRG magic: " + StringUtil::ToHexString(Magic)); + Log::FileError(STRG.GetSourceString(), "Invalid STRG magic: " + TString::HexString(Magic)); return nullptr; } } @@ -192,7 +192,7 @@ CStringTable* CStringLoader::LoadSTRG(CInputStream& STRG) if (FileVersion == eUnknownVersion) { - Log::FileError(STRG.GetSourceString(), "Unsupported STRG version: " + StringUtil::ToHexString(FileVersion)); + Log::FileError(STRG.GetSourceString(), "Unsupported STRG version: " + TString::HexString(FileVersion)); return nullptr; } } diff --git a/Resource/factory/CTemplateLoader.cpp b/Resource/factory/CTemplateLoader.cpp index 078a98b5..f352e381 100644 --- a/Resource/factory/CTemplateLoader.cpp +++ b/Resource/factory/CTemplateLoader.cpp @@ -2,7 +2,7 @@ #include "CWorldLoader.h" #include -void CTemplateLoader::LoadBitFlags(tinyxml2::XMLElement *pElem, CBitfieldTemplate *pTemp, const std::string& templateName) +void CTemplateLoader::LoadBitFlags(tinyxml2::XMLElement *pElem, CBitfieldTemplate *pTemp, const TString& templateName) { tinyxml2::XMLElement *pChild = pElem->FirstChildElement("bitflag"); @@ -12,11 +12,11 @@ void CTemplateLoader::LoadBitFlags(tinyxml2::XMLElement *pElem, CBitfieldTemplat const char *kpName = pChild->Attribute("name"); if (kpMask && kpName) - pTemp->mBitFlags.push_back(CBitfieldTemplate::SBitFlag(kpName, StringUtil::ToInt32(kpMask))); + pTemp->mBitFlags.push_back(CBitfieldTemplate::SBitFlag(kpName, TString(kpMask).ToInt32())); else { - std::string LogErrorBase = "Couldn't parse bit flag in " + templateName + "; "; + TString LogErrorBase = "Couldn't parse bit flag in " + templateName + "; "; if (!kpMask && kpName) Log::Error(LogErrorBase + "no mask (" + kpName + ")"); else if (kpMask && !kpName) Log::Error(LogErrorBase + "no name (mask " + kpMask + ")"); @@ -27,7 +27,7 @@ void CTemplateLoader::LoadBitFlags(tinyxml2::XMLElement *pElem, CBitfieldTemplat } } -void CTemplateLoader::LoadEnumerators(tinyxml2::XMLElement *pElem, CEnumTemplate *pTemp, const std::string& templateName) +void CTemplateLoader::LoadEnumerators(tinyxml2::XMLElement *pElem, CEnumTemplate *pTemp, const TString& templateName) { tinyxml2::XMLElement *pChild = pElem->FirstChildElement("enumerator"); @@ -37,11 +37,11 @@ void CTemplateLoader::LoadEnumerators(tinyxml2::XMLElement *pElem, CEnumTemplate const char *kpName = pChild->Attribute("name"); if (kpID && kpName) - pTemp->mEnumerators.push_back(CEnumTemplate::SEnumerator(kpName, StringUtil::ToInt32(kpID))); + pTemp->mEnumerators.push_back(CEnumTemplate::SEnumerator(kpName, TString(kpID).ToInt32())); else { - std::string LogErrorBase = "Couldn't parse enumerator in " + templateName + "; "; + TString LogErrorBase = "Couldn't parse enumerator in " + templateName + "; "; if (!kpID && kpName) Log::Error(LogErrorBase + "no valid ID (" + kpName + ")"); else if (kpID && !kpName) Log::Error(LogErrorBase + "no valid name (ID " + kpID + ")"); @@ -52,7 +52,7 @@ void CTemplateLoader::LoadEnumerators(tinyxml2::XMLElement *pElem, CEnumTemplate } } -void CTemplateLoader::LoadStructProperties(tinyxml2::XMLElement *pElem, CStructTemplate *pTemp, const std::string& templateName) +void CTemplateLoader::LoadStructProperties(tinyxml2::XMLElement *pElem, CStructTemplate *pTemp, const TString& templateName) { tinyxml2::XMLElement *pChild = pElem->FirstChildElement(); @@ -67,7 +67,7 @@ void CTemplateLoader::LoadStructProperties(tinyxml2::XMLElement *pElem, CStructT } } -CPropertyTemplate* CTemplateLoader::LoadPropertyTemplate(tinyxml2::XMLElement *pElem, const std::string& templateName) +CPropertyTemplate* CTemplateLoader::LoadPropertyTemplate(tinyxml2::XMLElement *pElem, const TString& templateName) { const char *kpIDStr = pElem->Attribute("ID"); const char *kpNameStr = pElem->Attribute("name"); @@ -76,9 +76,9 @@ CPropertyTemplate* CTemplateLoader::LoadPropertyTemplate(tinyxml2::XMLElement *p const char *kpTemplateStr = pElem->Attribute("template"); // Get ID + name, find source template if it exists - u32 ID = StringUtil::ToInt32(kpIDStr); + u32 ID = TString(kpIDStr).ToInt32(); CPropertyTemplate *pSource = nullptr; - std::string name; + TString name; if (mpMaster->HasPropertyList()) pSource = mpMaster->GetProperty(ID); @@ -88,7 +88,7 @@ CPropertyTemplate* CTemplateLoader::LoadPropertyTemplate(tinyxml2::XMLElement *p else if (pSource) name = pSource->Name(); else - name = StringUtil::ToHexString(ID); + name = TString::HexString(ID); // Load Property if (strcmp(pElem->Name(), "property") == 0) @@ -105,9 +105,9 @@ CPropertyTemplate* CTemplateLoader::LoadPropertyTemplate(tinyxml2::XMLElement *p // File property if (type == eFileProperty) { - CStringList extensions; + TStringList extensions; if (kpExtensionsStr) - extensions = StringUtil::Tokenize(kpExtensionsStr, ","); + extensions = TString(kpExtensionsStr).Split(","); else if (pSource) extensions = static_cast(pSource)->Extensions(); @@ -138,10 +138,10 @@ CPropertyTemplate* CTemplateLoader::LoadPropertyTemplate(tinyxml2::XMLElement *p // Template else if (kpTemplateStr) { - std::string tempPath = mMasterDir + kpTemplateStr; + TString tempPath = mMasterDir + kpTemplateStr; tinyxml2::XMLDocument structXML; - structXML.LoadFile(tempPath.c_str()); + structXML.LoadFile(*tempPath); if (structXML.Error()) Log::Error("Couldn't open struct XML: " + mMasterDir + kpTemplateStr); @@ -179,7 +179,7 @@ CPropertyTemplate* CTemplateLoader::LoadPropertyTemplate(tinyxml2::XMLElement *p pStruct->mIsSingleProperty = static_cast(pSource)->IsSingleProperty(); // Name - if (!name.empty()) + if (!name.IsEmpty()) pStruct->mPropName = name; return pStruct; @@ -200,10 +200,10 @@ CPropertyTemplate* CTemplateLoader::LoadPropertyTemplate(tinyxml2::XMLElement *p // Template else if (kpTemplateStr) { - std::string tempPath = mMasterDir + kpTemplateStr; + TString tempPath = mMasterDir + kpTemplateStr; tinyxml2::XMLDocument enumXML; - enumXML.LoadFile(tempPath.c_str()); + enumXML.LoadFile(*tempPath); if (enumXML.Error()) Log::Error("Couldn't open enum XML: " + mMasterDir + kpTemplateStr); @@ -221,7 +221,7 @@ CPropertyTemplate* CTemplateLoader::LoadPropertyTemplate(tinyxml2::XMLElement *p } // Name - if (!name.empty()) + if (!name.IsEmpty()) pEnum->mPropName = name; return pEnum; @@ -240,10 +240,10 @@ CPropertyTemplate* CTemplateLoader::LoadPropertyTemplate(tinyxml2::XMLElement *p // Template else if (kpTemplateStr) { - std::string tempPath = mMasterDir + kpTemplateStr; + TString tempPath = mMasterDir + kpTemplateStr; tinyxml2::XMLDocument bitfieldXML; - bitfieldXML.LoadFile(tempPath.c_str()); + bitfieldXML.LoadFile(*tempPath); if (bitfieldXML.Error()) Log::Error("Couldn't open bitfield XML: " + mMasterDir + kpTemplateStr); @@ -261,7 +261,7 @@ CPropertyTemplate* CTemplateLoader::LoadPropertyTemplate(tinyxml2::XMLElement *p } // Name - if (!name.empty()) + if (!name.IsEmpty()) pBitfield->mPropName = name; return pBitfield; @@ -270,7 +270,7 @@ CPropertyTemplate* CTemplateLoader::LoadPropertyTemplate(tinyxml2::XMLElement *p } // ************ SCRIPT OBJECT ************ -CScriptTemplate* CTemplateLoader::LoadScriptTemplate(tinyxml2::XMLDocument *pDoc, const std::string& templateName, u32 objectID) +CScriptTemplate* CTemplateLoader::LoadScriptTemplate(tinyxml2::XMLDocument *pDoc, const TString& templateName, u32 objectID) { CScriptTemplate *pScript = new CScriptTemplate(mpMaster); pScript->mObjectID = objectID; @@ -372,7 +372,7 @@ CScriptTemplate* CTemplateLoader::LoadScriptTemplate(tinyxml2::XMLDocument *pDoc const char *kpForce = pAsset->Attribute("force"); if (kpForce) - asset.ForceNodeIndex = StringUtil::ToInt32(kpForce); + asset.ForceNodeIndex = TString(kpForce).ToInt32(); else asset.ForceNodeIndex = -1; @@ -459,7 +459,7 @@ CScriptTemplate* CTemplateLoader::LoadScriptTemplate(tinyxml2::XMLDocument *pDoc else if (strcmp(kpConditionValue, "false") == 0) condition.Value = 0; else - condition.Value = StringUtil::ToInt32(kpConditionValue); + condition.Value = TString(kpConditionValue).ToInt32(); pScript->mVolumeConditions.push_back(condition); } @@ -478,7 +478,7 @@ CScriptTemplate* CTemplateLoader::LoadScriptTemplate(tinyxml2::XMLDocument *pDoc void CTemplateLoader::LoadMasterTemplate(tinyxml2::XMLDocument *pDoc) { tinyxml2::XMLElement *pRoot = pDoc->FirstChildElement("MasterTemplate"); - mpMaster->mVersion = StringUtil::ToInt32(pRoot->Attribute("version")); + mpMaster->mVersion = TString(pRoot->Attribute("version")).ToInt32(); tinyxml2::XMLElement *pElem = pRoot->FirstChildElement(); @@ -487,10 +487,10 @@ void CTemplateLoader::LoadMasterTemplate(tinyxml2::XMLDocument *pDoc) // Properties if (strcmp(pElem->Name(), "properties") == 0) { - std::string propListPath = mMasterDir + pElem->GetText(); + TString propListPath = mMasterDir + pElem->GetText(); tinyxml2::XMLDocument propListXML; - propListXML.LoadFile(propListPath.c_str()); + propListXML.LoadFile(*propListPath); if (propListXML.Error()) Log::Error("Couldn't open property list: " + propListPath); @@ -507,20 +507,20 @@ void CTemplateLoader::LoadMasterTemplate(tinyxml2::XMLDocument *pDoc) while (pObj) { // ID can either be a hex number or an ASCII fourCC - std::string strID = pObj->Attribute("ID"); + TString strID = pObj->Attribute("ID"); u32 ID; - if (StringUtil::IsHexString(strID, true)) - ID = StringUtil::ToInt32(strID); + if (strID.IsHexString(true)) + ID = strID.ToInt32(); else ID = CFourCC(strID).ToLong(); // Load up the object - std::string templateName = pObj->Attribute("template"); - std::string templatePath = mMasterDir + templateName; + TString templateName = pObj->Attribute("template"); + TString templatePath = mMasterDir + templateName; tinyxml2::XMLDocument scriptXML; - scriptXML.LoadFile(templatePath.c_str()); + scriptXML.LoadFile(*templatePath); if (scriptXML.Error()) Log::Error("Couldn't open script template: " + templatePath); @@ -547,15 +547,15 @@ void CTemplateLoader::LoadMasterTemplate(tinyxml2::XMLDocument *pDoc) while (pState) { - std::string strID = pState->Attribute("ID"); + TString strID = pState->Attribute("ID"); u32 stateID; - if (StringUtil::IsHexString(strID, true)) - stateID = StringUtil::ToInt32(strID); + if (strID.IsHexString(true)) + stateID = strID.ToInt32(); else stateID = CFourCC(strID).ToLong(); - std::string stateName = pState->Attribute("name"); + TString stateName = pState->Attribute("name"); mpMaster->mStates[stateID] = stateName; pState = pState->NextSiblingElement("state"); } @@ -568,15 +568,15 @@ void CTemplateLoader::LoadMasterTemplate(tinyxml2::XMLDocument *pDoc) while (pMessage) { - std::string strID = pMessage->Attribute("ID"); + TString strID = pMessage->Attribute("ID"); u32 messageID; - if (StringUtil::IsHexString(strID, true)) - messageID = StringUtil::ToInt32(strID); + if (strID.IsHexString(true)) + messageID = strID.ToInt32(); else messageID = CFourCC(strID).ToLong(); - std::string messageName = pMessage->Attribute("name"); + TString messageName = pMessage->Attribute("name"); mpMaster->mMessages[messageID] = messageName; pMessage = pMessage->NextSiblingElement("message"); } @@ -586,7 +586,7 @@ void CTemplateLoader::LoadMasterTemplate(tinyxml2::XMLDocument *pDoc) } } -void CTemplateLoader::LoadPropertyList(tinyxml2::XMLDocument *pDoc, const std::string& listName) +void CTemplateLoader::LoadPropertyList(tinyxml2::XMLDocument *pDoc, const TString& listName) { tinyxml2::XMLElement *pElem = pDoc->FirstChildElement()->FirstChildElement(); @@ -622,11 +622,11 @@ CMasterTemplate* CTemplateLoader::LoadGame(tinyxml2::XMLNode *pNode) else if (strcmp(pGameElem->Name(), "master") == 0) { - std::string MasterPath = mTemplatesDir + pGameElem->GetText(); - mMasterDir = StringUtil::GetFileDirectory(MasterPath); + TString MasterPath = mTemplatesDir + pGameElem->GetText(); + mMasterDir = MasterPath.GetFileDirectory(); tinyxml2::XMLDocument MasterXML; - MasterXML.LoadFile(MasterPath.c_str()); + MasterXML.LoadFile(*MasterPath); if (MasterXML.Error()) { @@ -649,13 +649,13 @@ CMasterTemplate* CTemplateLoader::LoadGame(tinyxml2::XMLNode *pNode) // ************ PUBLIC ************ void CTemplateLoader::LoadGameList() { - static const std::string skTemplatesDir = "../templates/"; - static const std::string skGameListPath = skTemplatesDir + "GameList.xml"; + static const TString skTemplatesDir = "../templates/"; + static const TString skGameListPath = skTemplatesDir + "GameList.xml"; Log::Write("Loading game list"); // Load Game List XML tinyxml2::XMLDocument GameListXML; - GameListXML.LoadFile(skGameListPath.c_str()); + GameListXML.LoadFile(*skGameListPath); if (GameListXML.Error()) { diff --git a/Resource/factory/CTemplateLoader.h b/Resource/factory/CTemplateLoader.h index 025ee00d..4311e366 100644 --- a/Resource/factory/CTemplateLoader.h +++ b/Resource/factory/CTemplateLoader.h @@ -8,24 +8,24 @@ class CTemplateLoader { CMasterTemplate *mpMaster; - std::string mTemplatesDir; - std::string mMasterDir; + TString mTemplatesDir; + TString mMasterDir; // Constructor - CTemplateLoader(const std::string& templatesDir) : mTemplatesDir(templatesDir) {} + CTemplateLoader(const TString& templatesDir) : mTemplatesDir(templatesDir) {} // Load Property - void LoadBitFlags(tinyxml2::XMLElement *pElem, CBitfieldTemplate *pTemp, const std::string& templateName); - void LoadEnumerators(tinyxml2::XMLElement *pElem, CEnumTemplate *pTemp, const std::string& templateName); - void LoadStructProperties(tinyxml2::XMLElement *pElem, CStructTemplate *pTemp, const std::string& templateName); - CPropertyTemplate* LoadPropertyTemplate(tinyxml2::XMLElement *pElem, const std::string& templateName); + void LoadBitFlags(tinyxml2::XMLElement *pElem, CBitfieldTemplate *pTemp, const TString& templateName); + void LoadEnumerators(tinyxml2::XMLElement *pElem, CEnumTemplate *pTemp, const TString& templateName); + void LoadStructProperties(tinyxml2::XMLElement *pElem, CStructTemplate *pTemp, const TString& templateName); + CPropertyTemplate* LoadPropertyTemplate(tinyxml2::XMLElement *pElem, const TString& templateName); // Load Script Object - CScriptTemplate* LoadScriptTemplate(tinyxml2::XMLDocument *pDoc, const std::string& templateName, u32 objectID); + CScriptTemplate* LoadScriptTemplate(tinyxml2::XMLDocument *pDoc, const TString& templateName, u32 objectID); // Load Master void LoadMasterTemplate(tinyxml2::XMLDocument *pDoc); - void LoadPropertyList(tinyxml2::XMLDocument *pDoc, const std::string& listName); + void LoadPropertyList(tinyxml2::XMLDocument *pDoc, const TString& listName); CMasterTemplate* LoadGame(tinyxml2::XMLNode *pNode); public: diff --git a/Resource/factory/CTextureDecoder.cpp b/Resource/factory/CTextureDecoder.cpp index 9d6ca078..4fa40321 100644 --- a/Resource/factory/CTextureDecoder.cpp +++ b/Resource/factory/CTextureDecoder.cpp @@ -157,7 +157,7 @@ void CTextureDecoder::ReadDDS(CInputStream& DDS) CFourCC Magic(DDS); if (Magic != "DDS ") { - Log::FileError(DDS.GetSourceString(), "Invalid DDS magic: " + StringUtil::ToHexString((u32) Magic.ToLong())); + Log::FileError(DDS.GetSourceString(), "Invalid DDS magic: " + TString::HexString((u32) Magic.ToLong())); return; } diff --git a/Resource/factory/CWorldLoader.cpp b/Resource/factory/CWorldLoader.cpp index 09485559..3ef6acae 100644 --- a/Resource/factory/CWorldLoader.cpp +++ b/Resource/factory/CWorldLoader.cpp @@ -300,7 +300,7 @@ CWorld* CWorldLoader::LoadMLVL(CInputStream& MLVL) u32 Magic = MLVL.ReadLong(); if (Magic != 0xDEAFBABE) { - Log::FileError(MLVL.GetSourceString(), "Invalid MLVL magic: " + StringUtil::ToHexString(Magic)); + Log::FileError(MLVL.GetSourceString(), "Invalid MLVL magic: " + TString::HexString(Magic)); return nullptr; } @@ -308,7 +308,7 @@ CWorld* CWorldLoader::LoadMLVL(CInputStream& MLVL) EGame Version = GetFormatVersion(FileVersion); if (Version == eUnknownVersion) { - Log::FileError(MLVL.GetSourceString(), "Unsupported MLVL version: " + StringUtil::ToHexString(FileVersion)); + Log::FileError(MLVL.GetSourceString(), "Unsupported MLVL version: " + TString::HexString(FileVersion)); return nullptr; } diff --git a/Resource/script/CMasterTemplate.cpp b/Resource/script/CMasterTemplate.cpp index a9df268f..13141eea 100644 --- a/Resource/script/CMasterTemplate.cpp +++ b/Resource/script/CMasterTemplate.cpp @@ -41,7 +41,7 @@ CScriptTemplate* CMasterTemplate::TemplateByIndex(u32 Index) return (std::next(it, Index))->second; } -std::string CMasterTemplate::StateByID(u32 StateID) +TString CMasterTemplate::StateByID(u32 StateID) { auto it = mStates.find(StateID); @@ -51,18 +51,18 @@ std::string CMasterTemplate::StateByID(u32 StateID) return "Invalid"; } -std::string CMasterTemplate::StateByID(const CFourCC& State) +TString CMasterTemplate::StateByID(const CFourCC& State) { return StateByID(State.ToLong()); } -std::string CMasterTemplate::StateByIndex(u32 Index) +TString CMasterTemplate::StateByIndex(u32 Index) { auto it = mStates.begin(); return (std::next(it, Index))->second; } -std::string CMasterTemplate::MessageByID(u32 MessageID) +TString CMasterTemplate::MessageByID(u32 MessageID) { auto it = mMessages.find(MessageID); @@ -72,12 +72,12 @@ std::string CMasterTemplate::MessageByID(u32 MessageID) return "Invalid"; } -std::string CMasterTemplate::MessageByID(const CFourCC& MessageID) +TString CMasterTemplate::MessageByID(const CFourCC& MessageID) { return MessageByID(MessageID.ToLong()); } -std::string CMasterTemplate::MessageByIndex(u32 Index) +TString CMasterTemplate::MessageByIndex(u32 Index) { auto it = mMessages.begin(); return (std::next(it, Index))->second; diff --git a/Resource/script/CMasterTemplate.h b/Resource/script/CMasterTemplate.h index 16f2bffa..80df1119 100644 --- a/Resource/script/CMasterTemplate.h +++ b/Resource/script/CMasterTemplate.h @@ -13,14 +13,14 @@ class CMasterTemplate friend class CTemplateWriter; EGame mGame; - std::string mGameName; - std::string mSourceFile; + TString mGameName; + TString mSourceFile; u32 mVersion; bool mFullyLoaded; std::map mTemplates; - std::map mStates; - std::map mMessages; + std::map mStates; + std::map mMessages; bool mHasPropList; std::map mPropertyList; @@ -38,12 +38,12 @@ public: CScriptTemplate* TemplateByID(u32 ObjectID); CScriptTemplate* TemplateByID(const CFourCC& ObjectID); CScriptTemplate* TemplateByIndex(u32 Index); - std::string StateByID(u32 StateID); - std::string StateByID(const CFourCC& StateID); - std::string StateByIndex(u32 Index); - std::string MessageByID(u32 MessageID); - std::string MessageByID(const CFourCC& MessageID); - std::string MessageByIndex(u32 Index); + TString StateByID(u32 StateID); + TString StateByID(const CFourCC& StateID); + TString StateByIndex(u32 Index); + TString MessageByID(u32 MessageID); + TString MessageByID(const CFourCC& MessageID); + TString MessageByIndex(u32 Index); CPropertyTemplate* GetProperty(u32 PropertyID); bool HasPropertyList(); bool IsLoadedSuccessfully(); diff --git a/Resource/script/CProperty.cpp b/Resource/script/CProperty.cpp index e9c9a1a0..cdffab36 100644 --- a/Resource/script/CProperty.cpp +++ b/Resource/script/CProperty.cpp @@ -25,17 +25,16 @@ CPropertyBase* CPropertyStruct::PropertyByID(u32 ID) CPropertyBase* CPropertyStruct::PropertyByIDString(const TIDString& str) { // Resolve namespace - std::string::size_type nsStart = str.find_first_of(":"); - std::string::size_type propStart = nsStart + 1; + u32 nsStart = str.IndexOf(":"); // String has namespace; the requested property is within a struct - if (nsStart != std::string::npos) + if (nsStart != -1) { - std::string strStructID = str.substr(0, nsStart); - if (!StringUtil::IsHexString(strStructID)) return nullptr; + TString strStructID = str.Truncate(nsStart); + if (!strStructID.IsHexString()) return nullptr; - u32 structID = StringUtil::ToInt32(strStructID); - std::string propName = str.substr(propStart, str.length() - propStart); + u32 structID = strStructID.ToInt32(); + TString propName = str.ChopFront(nsStart + 1); CPropertyStruct *pStruct = StructByID(structID); if (!pStruct) return nullptr; @@ -45,8 +44,8 @@ CPropertyBase* CPropertyStruct::PropertyByIDString(const TIDString& str) // No namespace; fetch the property from this struct else { - if (StringUtil::IsHexString(str)) - return PropertyByID(StringUtil::ToInt32(str)); + if (str.IsHexString()) + return PropertyByID(str.ToInt32()); else return nullptr; } diff --git a/Resource/script/CProperty.h b/Resource/script/CProperty.h index aaf39168..17aadc90 100644 --- a/Resource/script/CProperty.h +++ b/Resource/script/CProperty.h @@ -12,13 +12,13 @@ #include "EPropertyType.h" #include #include +#include #include -#include #include class CScriptTemplate; -typedef std::string TIDString; +typedef TString TIDString; /* * CPropertyBase is the base class, containing just some virtual function definitions @@ -34,7 +34,7 @@ public: inline virtual EPropertyType Type() = 0; inline CPropertyTemplate *Template() { return mpTemplate; } inline void SetTemplate(CPropertyTemplate *_tmp) { mpTemplate = _tmp; } - inline std::string Name() { return mpTemplate->Name(); } + inline TString Name() { return mpTemplate->Name(); } inline u32 ID() { return mpTemplate->PropertyID(); } }; @@ -62,7 +62,7 @@ typedef __CProperty CLongProperty; typedef __CProperty CEnumProperty; typedef __CProperty CBitfieldProperty; typedef __CProperty CFloatProperty; -typedef __CProperty CStringProperty; +typedef __CProperty CStringProperty; typedef __CProperty CVector3Property; typedef __CProperty CColorProperty; typedef __CProperty CFileProperty; @@ -101,7 +101,7 @@ public: mToken = CToken(v); } } - const CStringList& AllowedExtensions() + const TStringList& AllowedExtensions() { return static_cast(Template())->Extensions(); } diff --git a/Resource/script/CPropertyTemplate.cpp b/Resource/script/CPropertyTemplate.cpp index 4a6d2bc5..ba4ea092 100644 --- a/Resource/script/CPropertyTemplate.cpp +++ b/Resource/script/CPropertyTemplate.cpp @@ -1,7 +1,7 @@ #include "CPropertyTemplate.h" #include -EPropertyType PropStringToPropEnum(std::string prop) +EPropertyType PropStringToPropEnum(const TString& prop) { if (prop == "bool") return eBoolProperty; if (prop == "byte") return eByteProperty; @@ -21,7 +21,7 @@ EPropertyType PropStringToPropEnum(std::string prop) return eInvalidProperty; } -std::string PropEnumToPropString(EPropertyType prop) +TString PropEnumToPropString(EPropertyType prop) { switch (prop) { @@ -96,20 +96,20 @@ CPropertyTemplate* CStructTemplate::PropertyByID(u32 ID) return nullptr; } -CPropertyTemplate* CStructTemplate::PropertyByIDString(const std::string& str) +CPropertyTemplate* CStructTemplate::PropertyByIDString(const TIDString& str) { // Resolve namespace - std::string::size_type nsStart = str.find_first_of("::"); - std::string::size_type propStart = nsStart + 2; + u32 nsStart = str.IndexOf(":"); + u32 propStart = nsStart + 1; // String has namespace; the requested property is within a struct - if (nsStart != std::string::npos) + if (nsStart != -1) { - std::string strStructID = str.substr(0, nsStart); - if (!StringUtil::IsHexString(strStructID)) return nullptr; + TString strStructID = str.SubString(0, nsStart); + if (!strStructID.IsHexString()) return nullptr; - u32 structID = StringUtil::ToInt32(strStructID); - std::string propName = str.substr(propStart, str.length() - propStart); + u32 structID = strStructID.ToInt32(); + TString propName = str.SubString(propStart, str.Length() - propStart); CStructTemplate *pStruct = StructByID(structID); if (!pStruct) return nullptr; @@ -120,8 +120,8 @@ CPropertyTemplate* CStructTemplate::PropertyByIDString(const std::string& str) else { // ID string lookup - if (StringUtil::IsHexString(str)) - return PropertyByID(std::stoul(str, 0, 16)); + if (str.IsHexString()) + return PropertyByID(str.ToInt32()); else return nullptr; } @@ -147,7 +147,7 @@ CStructTemplate* CStructTemplate::StructByID(u32 ID) return nullptr; } -CStructTemplate* CStructTemplate::StructByIDString(const std::string& str) +CStructTemplate* CStructTemplate::StructByIDString(const TString& str) { CPropertyTemplate *pProp = PropertyByIDString(str); @@ -158,7 +158,7 @@ CStructTemplate* CStructTemplate::StructByIDString(const std::string& str) } // ************ DEBUG ************ -void CStructTemplate::DebugPrintProperties(std::string base) +void CStructTemplate::DebugPrintProperties(TString base) { base = base + Name() + "::"; for (auto it = mProperties.begin(); it != mProperties.end(); it++) diff --git a/Resource/script/CPropertyTemplate.h b/Resource/script/CPropertyTemplate.h index eba0cfdb..9118fc47 100644 --- a/Resource/script/CPropertyTemplate.h +++ b/Resource/script/CPropertyTemplate.h @@ -2,11 +2,12 @@ #define CPROPERTYTEMPLATE #include "EPropertyType.h" -#include +#include #include -#include #include +typedef TString TIDString; + class CPropertyTemplate { friend class CTemplateLoader; @@ -14,7 +15,7 @@ class CPropertyTemplate protected: EPropertyType mPropType; - std::string mPropName; + TString mPropName; u32 mPropID; public: CPropertyTemplate(u32 ID) @@ -22,7 +23,7 @@ public: { } - CPropertyTemplate(EPropertyType type, std::string name, u32 ID) + CPropertyTemplate(EPropertyType type, TString name, u32 ID) : mPropType(type), mPropName(name), mPropID(ID) @@ -34,7 +35,7 @@ public: return mPropType; } - inline std::string Name() const + inline TString Name() const { return mPropName; } @@ -44,7 +45,7 @@ public: return mPropID; } - inline void SetName(const std::string& Name) + inline void SetName(const TString& Name) { mPropName = Name; } @@ -55,11 +56,11 @@ class CFileTemplate : public CPropertyTemplate friend class CTemplateLoader; friend class CTemplateWriter; - CStringList mAcceptedExtensions; + TStringList mAcceptedExtensions; public: CFileTemplate(u32 ID) : CPropertyTemplate(ID) { mPropType = eFileProperty; } - CFileTemplate(const std::string& name, u32 ID, const CStringList& extensions) + CFileTemplate(const TString& name, u32 ID, const TStringList& extensions) : CPropertyTemplate(ID) { mPropType = eFileProperty; @@ -72,7 +73,7 @@ public: return eFileProperty; } - const CStringList& Extensions() const + const TStringList& Extensions() const { return mAcceptedExtensions; } @@ -85,14 +86,14 @@ class CEnumTemplate : public CPropertyTemplate struct SEnumerator { - std::string Name; + TString Name; u32 ID; - SEnumerator(const std::string& _name, u32 _ID) + SEnumerator(const TString& _name, u32 _ID) : Name(_name), ID(_ID) {} }; std::vector mEnumerators; - std::string mSourceFile; + TString mSourceFile; public: CEnumTemplate(u32 ID) @@ -101,7 +102,7 @@ public: mPropType = eEnumProperty; } - CEnumTemplate(const std::string& name, u32 ID) + CEnumTemplate(const TString& name, u32 ID) : CPropertyTemplate(eEnumProperty, name, ID) {} @@ -133,7 +134,7 @@ public: else return -1; } - std::string EnumeratorName(u32 enumIndex) + TString EnumeratorName(u32 enumIndex) { if (mEnumerators.size() > enumIndex) return mEnumerators[enumIndex].Name; @@ -149,14 +150,14 @@ class CBitfieldTemplate : public CPropertyTemplate struct SBitFlag { - std::string Name; + TString Name; u32 Mask; - SBitFlag(const std::string& _name, u32 _mask) + SBitFlag(const TString& _name, u32 _mask) : Name(_name), Mask(_mask) {} }; std::vector mBitFlags; - std::string mSourceFile; + TString mSourceFile; public: CBitfieldTemplate(u32 ID) @@ -165,7 +166,7 @@ public: mPropType = eBitfieldProperty; } - CBitfieldTemplate(const std::string& name, u32 ID) + CBitfieldTemplate(const TString& name, u32 ID) : CPropertyTemplate(eBitfieldProperty, name, ID) {} @@ -179,7 +180,7 @@ public: return mBitFlags.size(); } - std::string FlagName(u32 index) + TString FlagName(u32 index) { return mBitFlags[index].Name; } @@ -197,7 +198,7 @@ class CStructTemplate : public CPropertyTemplate bool mIsSingleProperty; std::vector mProperties; - std::string mSourceFile; + TString mSourceFile; public: CStructTemplate(); ~CStructTemplate(); @@ -207,11 +208,11 @@ public: u32 Count() const; CPropertyTemplate* PropertyByIndex(u32 index); CPropertyTemplate* PropertyByID(u32 ID); - CPropertyTemplate* PropertyByIDString(const std::string& str); + CPropertyTemplate* PropertyByIDString(const TIDString& str); CStructTemplate* StructByIndex(u32 index); CStructTemplate* StructByID(u32 ID); - CStructTemplate* StructByIDString(const std::string& str); - void DebugPrintProperties(std::string base); + CStructTemplate* StructByIDString(const TIDString& str); + void DebugPrintProperties(TString base); }; #endif // CPROPERTYTEMPLATE diff --git a/Resource/script/CScriptLayer.cpp b/Resource/script/CScriptLayer.cpp index f9028b00..dad5f566 100644 --- a/Resource/script/CScriptLayer.cpp +++ b/Resource/script/CScriptLayer.cpp @@ -44,7 +44,7 @@ void CScriptLayer::Reserve(u32 amount) } // ************* GETTERS ************* -std::string CScriptLayer::Name() +TString CScriptLayer::Name() { return mLayerName; } @@ -79,7 +79,7 @@ CScriptObject* CScriptLayer::ObjectByID(u32 ID) } // ************* SETTERS ************* -void CScriptLayer::SetName(std::string name) +void CScriptLayer::SetName(const TString& name) { mLayerName = name; } diff --git a/Resource/script/CScriptLayer.h b/Resource/script/CScriptLayer.h index 9817dbe9..02199532 100644 --- a/Resource/script/CScriptLayer.h +++ b/Resource/script/CScriptLayer.h @@ -8,7 +8,7 @@ class CScriptLayer { - std::string mLayerName; + TString mLayerName; bool mActive; bool mVisible; std::vector mObjects; @@ -23,14 +23,14 @@ public: void Reserve(u32 amount); // Getters and Setters - std::string Name(); + TString Name(); bool IsActive(); bool IsVisible(); u32 GetNumObjects(); CScriptObject* ObjectByIndex(u32 index); CScriptObject* ObjectByID(u32 ID); - void SetName(std::string name); + void SetName(const TString& name); void SetActive(bool active); void SetVisible(bool visible); diff --git a/Resource/script/CScriptObject.cpp b/Resource/script/CScriptObject.cpp index d0909e92..8ee8607a 100644 --- a/Resource/script/CScriptObject.cpp +++ b/Resource/script/CScriptObject.cpp @@ -58,7 +58,7 @@ CPropertyBase* CScriptObject::PropertyByIndex(u32 index) const return mpProperties->PropertyByIndex(index); } -CPropertyBase* CScriptObject::PropertyByIDString(std::string str) const +CPropertyBase* CScriptObject::PropertyByIDString(const TString& str) const { return mpProperties->PropertyByIDString(str); } @@ -123,7 +123,7 @@ const SLink& CScriptObject::OutLink(u32 index) const return mOutConnections[index]; } -std::string CScriptObject::InstanceName() const +TString CScriptObject::InstanceName() const { if (mpInstanceName) return mpInstanceName->Get(); @@ -178,7 +178,7 @@ void CScriptObject::SetScale(const CVector3f& newScale) if (mpScale) mpScale->Set(newScale); } -void CScriptObject::SetName(const std::string& newName) +void CScriptObject::SetName(const TString& newName) { if (mpInstanceName) mpInstanceName->Set(newName); } diff --git a/Resource/script/CScriptObject.h b/Resource/script/CScriptObject.h index 3baf403e..7e803200 100644 --- a/Resource/script/CScriptObject.h +++ b/Resource/script/CScriptObject.h @@ -53,7 +53,7 @@ public: CPropertyStruct* Properties() const; u32 NumProperties() const; CPropertyBase* PropertyByIndex(u32 index) const; - CPropertyBase* PropertyByIDString(std::string str) const; + CPropertyBase* PropertyByIDString(const TIDString& str) const; u32 ObjectTypeID() const; u32 InstanceID() const; u32 NumInLinks() const; @@ -64,12 +64,12 @@ public: CVector3f Position() const; CVector3f Rotation() const; CVector3f Scale() const; - std::string InstanceName() const; + TString InstanceName() const; bool IsActive() const; void SetPosition(const CVector3f& newPos); void SetRotation(const CVector3f& newRot); void SetScale(const CVector3f& newScale); - void SetName(const std::string& newName); + void SetName(const TString& newName); void SetActive(bool isActive); CPropertyStruct* LightParameters() const; CModel* GetDisplayModel() const; diff --git a/Resource/script/CScriptTemplate.cpp b/Resource/script/CScriptTemplate.cpp index e80128be..aa0a616d 100644 --- a/Resource/script/CScriptTemplate.cpp +++ b/Resource/script/CScriptTemplate.cpp @@ -25,7 +25,7 @@ CMasterTemplate* CScriptTemplate::MasterTemplate() return mpMaster; } -std::string CScriptTemplate::TemplateName(s32 propCount) const +TString CScriptTemplate::TemplateName(s32 propCount) const { // Return original name if there is only one property set // or if caller doesn't want to distinguish between sets @@ -40,7 +40,7 @@ std::string CScriptTemplate::TemplateName(s32 propCount) const return mTemplateName + " (Invalid)"; } -std::string CScriptTemplate::PropertySetNameByCount(s32 propCount) const +TString CScriptTemplate::PropertySetNameByCount(s32 propCount) const { for (auto it = mPropertySets.begin(); it != mPropertySets.end(); it++) if (it->pBaseStruct->Count() == propCount) @@ -49,7 +49,7 @@ std::string CScriptTemplate::PropertySetNameByCount(s32 propCount) const return ""; } -std::string CScriptTemplate::PropertySetNameByIndex(u32 index) const +TString CScriptTemplate::PropertySetNameByIndex(u32 index) const { if (index < NumPropertySets()) return mPropertySets[index].SetName; @@ -97,7 +97,7 @@ void CScriptTemplate::DebugPrintProperties(int propCount) template t TFetchProperty(CPropertyStruct *pProperties, const TIDString& ID) { - if (ID.empty()) return nullptr; + if (ID.IsEmpty()) return nullptr; CPropertyBase *pProp = pProperties->PropertyByIDString(ID); if (pProp && (pProp->Type() == propType)) @@ -173,7 +173,7 @@ EVolumeShape CScriptTemplate::VolumeShape(CScriptObject *pObj) return it->Shape; } - Log::Error(TemplateName() + " instance " + StringUtil::ToHexString(pObj->InstanceID(), true, true, 8) + " has unexpected volume shape value of " + StringUtil::ToHexString((u32) v, true, true)); + Log::Error(TemplateName() + " instance " + TString::HexString(pObj->InstanceID(), true, true, 8) + " has unexpected volume shape value of " + TString::HexString((u32) v, true, true)); return eInvalidShape; } @@ -219,7 +219,7 @@ CModel* CScriptTemplate::FindDisplayModel(CPropertyStruct *pProperties) // File if (it->AssetSource == SEditorAsset::eFile) { - std::string path = "../resources/" + it->AssetLocation; + TString path = "../resources/" + it->AssetLocation; pRes = gResCache.GetResource(path); } @@ -258,7 +258,7 @@ CCollisionMeshGroup* CScriptTemplate::FindCollision(CPropertyStruct *pProperties // File if (it->AssetSource == SEditorAsset::eFile) { - std::string path = "../resources/" + it->AssetLocation; + TString path = "../resources/" + it->AssetLocation; pRes = gResCache.GetResource(path); } @@ -284,7 +284,7 @@ CCollisionMeshGroup* CScriptTemplate::FindCollision(CPropertyStruct *pProperties bool CScriptTemplate::HasPosition() { - return (!mPositionIDString.empty()); + return (!mPositionIDString.IsEmpty()); } // ************ OBJECT TRACKING ************ diff --git a/Resource/script/CScriptTemplate.h b/Resource/script/CScriptTemplate.h index b4a11da8..454fcdfa 100644 --- a/Resource/script/CScriptTemplate.h +++ b/Resource/script/CScriptTemplate.h @@ -16,7 +16,7 @@ class CMasterTemplate; class CScriptObject; -typedef std::string TIDString; +typedef TString TIDString; /* * CScriptTemplate is a class that encases the data contained in one of the XML templates. @@ -41,7 +41,7 @@ public: private: struct SPropertySet { - std::string SetName; + TString SetName; CStructTemplate *pBaseStruct; }; @@ -64,8 +64,8 @@ private: std::list mObjectList; ERotationType mRotationType; EScaleType mScaleType; - std::string mTemplateName; - std::string mSourceFile; + TString mTemplateName; + TString mSourceFile; u32 mObjectID; bool mVisible; @@ -93,9 +93,9 @@ public: ~CScriptTemplate(); CMasterTemplate* MasterTemplate(); - std::string TemplateName(s32 propCount = -1) const; - std::string PropertySetNameByCount(s32 propCount) const; - std::string PropertySetNameByIndex(u32 index) const; + TString TemplateName(s32 propCount = -1) const; + TString PropertySetNameByCount(s32 propCount) const; + TString PropertySetNameByIndex(u32 index) const; u32 NumPropertySets() const; ERotationType RotationType() const; EScaleType ScaleType() const; diff --git a/Resource/script/EPropertyType.h b/Resource/script/EPropertyType.h index d7349353..beddc933 100644 --- a/Resource/script/EPropertyType.h +++ b/Resource/script/EPropertyType.h @@ -1,7 +1,7 @@ #ifndef EPROPERTYTYPE #define EPROPERTYTYPE -#include +#include enum EPropertyType { @@ -24,8 +24,8 @@ enum EPropertyType }; // functions defined in CScriptTemplate.cpp -EPropertyType PropStringToPropEnum(std::string prop); -std::string PropEnumToPropString(EPropertyType prop); +EPropertyType PropStringToPropEnum(const TString& prop); +TString PropEnumToPropString(EPropertyType prop); #endif // EPROPERTYTYPE diff --git a/Scene/CSceneNode.cpp b/Scene/CSceneNode.cpp index 57853f52..df2b76e6 100644 --- a/Scene/CSceneNode.cpp +++ b/Scene/CSceneNode.cpp @@ -45,7 +45,7 @@ CSceneNode::~CSceneNode() } // ************ VIRTUAL ************ -std::string CSceneNode::PrefixedName() const +TString CSceneNode::PrefixedName() const { return Name(); } @@ -287,7 +287,7 @@ const CTransform4f& CSceneNode::Transform() } // ************ GETTERS ************ -std::string CSceneNode::Name() const +TString CSceneNode::Name() const { return mName; } @@ -399,7 +399,7 @@ bool CSceneNode::InheritsScale() const } // ************ SETTERS ************ -void CSceneNode::SetName(const std::string& Name) +void CSceneNode::SetName(const TString& Name) { mName = Name; } diff --git a/Scene/CSceneNode.h b/Scene/CSceneNode.h index 357319d2..669fa604 100644 --- a/Scene/CSceneNode.h +++ b/Scene/CSceneNode.h @@ -31,7 +31,7 @@ private: protected: static u32 smNumNodes; - std::string mName; + TString mName; CSceneNode *mpParent; CSceneManager *mpScene; @@ -53,7 +53,7 @@ public: explicit CSceneNode(CSceneManager *pScene, CSceneNode *pParent = 0); virtual ~CSceneNode(); virtual ENodeType NodeType() = 0; - virtual std::string PrefixedName() const; + virtual TString PrefixedName() const; virtual void Draw(ERenderOptions options) = 0; virtual void DrawAsset(ERenderOptions options, u32 asset) = 0; virtual void DrawSelection(); @@ -80,7 +80,7 @@ public: const CTransform4f& Transform(); // Getters - std::string Name() const; + TString Name() const; CSceneNode* Parent() const; CSceneManager* Scene(); CVector3f LocalPosition() const; @@ -100,7 +100,7 @@ public: bool InheritsScale() const; // Setters - void SetName(const std::string& Name); + void SetName(const TString& Name); void SetPosition(const CVector3f& position); void SetRotation(const CQuaternion& rotation); void SetRotation(const CVector3f& rotEuler); diff --git a/Scene/CScriptNode.cpp b/Scene/CScriptNode.cpp index 1d3c088d..60cf6c2a 100644 --- a/Scene/CScriptNode.cpp +++ b/Scene/CScriptNode.cpp @@ -92,7 +92,7 @@ ENodeType CScriptNode::NodeType() return eScriptNode; } -std::string CScriptNode::PrefixedName() const +TString CScriptNode::PrefixedName() const { return "[" + mpInstance->Template()->TemplateName() + "] " + mpInstance->InstanceName(); } diff --git a/Scene/CScriptNode.h b/Scene/CScriptNode.h index cb8dcc3b..fd395f8f 100644 --- a/Scene/CScriptNode.h +++ b/Scene/CScriptNode.h @@ -23,7 +23,7 @@ class CScriptNode : public CSceneNode public: CScriptNode(CSceneManager *pScene, CSceneNode *pParent = 0, CScriptObject *pObject = 0); ENodeType NodeType(); - std::string PrefixedName() const; + TString PrefixedName() const; void AddToRenderer(CRenderer *pRenderer, const CFrustumPlanes& frustum); void Draw(ERenderOptions Options); void DrawAsset(ERenderOptions Options, u32 Asset); diff --git a/UI/CBasicViewport.h b/UI/CBasicViewport.h index 5622e0df..8b23e1c9 100644 --- a/UI/CBasicViewport.h +++ b/UI/CBasicViewport.h @@ -68,10 +68,10 @@ public slots: protected slots: virtual void CheckUserInput() {} virtual void Paint() {} - virtual void ContextMenu(QContextMenuEvent *pEvent) {} + virtual void ContextMenu(QContextMenuEvent* /*pEvent*/) {} virtual void OnResize() {} - virtual void OnMouseClick(QMouseEvent *pEvent) {} - virtual void OnMouseRelease(QMouseEvent *pEvent) {} + virtual void OnMouseClick(QMouseEvent* /*pEvent*/) {} + virtual void OnMouseRelease(QMouseEvent* /*pEvent*/) {} private: void ProcessInput(double DeltaTime); diff --git a/UI/CModelEditorWindow.cpp b/UI/CModelEditorWindow.cpp index ebf1bbb7..92d62595 100644 --- a/UI/CModelEditorWindow.cpp +++ b/UI/CModelEditorWindow.cpp @@ -4,8 +4,9 @@ #include #include +#include "UICommon.h" #include "WResourceSelector.h" -#include +#include #include #include #include @@ -176,8 +177,8 @@ void CModelEditorWindow::SetActiveModel(CModel *pModel) for (u32 iMat = 0; iMat < numMats; iMat++) { - std::string matName = pModel->GetMaterialByIndex(0, iMat)->Name(); - ui->MatSelectionComboBox->addItem(QString::fromStdString(matName)); + TString matName = pModel->GetMaterialByIndex(0, iMat)->Name(); + ui->MatSelectionComboBox->addItem(TO_QSTRING(matName)); } ui->MatSelectionComboBox->setCurrentIndex(0); @@ -223,7 +224,7 @@ void CModelEditorWindow::SetActiveMaterial(int MatIndex) ui->DestBlendComboBox->setCurrentIndex(DstFac); if (Settings & CMaterial::eIndStage) - ui->IndTextureResSelector->SetText(QString::fromStdString(mpCurrentMat->IndTexture()->FullSource())); + ui->IndTextureResSelector->SetText(TO_QSTRING(mpCurrentMat->IndTexture()->FullSource())); else ui->IndTextureResSelector->SetText(""); @@ -250,7 +251,7 @@ void CModelEditorWindow::SetActiveMaterial(int MatIndex) { CMaterialPass *pPass = mpCurrentMat->Pass(iPass); - QTableWidgetItem *pItemA = new QTableWidgetItem("Pass #" + QString::number(iPass + 1) + ": " + QString::fromStdString(pPass->NamedType())); + QTableWidgetItem *pItemA = new QTableWidgetItem("Pass #" + QString::number(iPass + 1) + ": " + TO_QSTRING(pPass->NamedType())); QTableWidgetItem *pItemB = new QTableWidgetItem(); if (pPass->IsEnabled()) @@ -307,7 +308,7 @@ void CModelEditorWindow::SetActivePass(int PassIndex) CTexture *pPassTex = mpCurrentPass->Texture(); if (pPassTex) - ui->PassTextureResSelector->SetText(QString::fromStdString(pPassTex->FullSource())); + ui->PassTextureResSelector->SetText(TO_QSTRING(pPassTex->FullSource())); else ui->PassTextureResSelector->SetText(""); @@ -683,13 +684,14 @@ void CModelEditorWindow::UpdateAnimParamUI(int Mode) void CModelEditorWindow::on_actionConvert_to_DDS_triggered() { - QString TexFilename = QFileDialog::getOpenFileName(this, "Retro Texture (*.TXTR)", "", "*.TXTR"); - if (TexFilename.isEmpty()) return; + QString Input = QFileDialog::getOpenFileName(this, "Retro Texture (*.TXTR)", "", "*.TXTR"); + if (Input.isEmpty()) return; - CTexture *Tex = (CTexture*) gResCache.GetResource(TexFilename.toStdString()); - std::string OutName = StringUtil::GetPathWithoutExtension(TexFilename.toStdString()) + ".dds"; + TString TexFilename = Input.toStdString(); + CTexture *Tex = (CTexture*) gResCache.GetResource(TexFilename); + TString OutName = TexFilename.GetFilePathWithoutExtension() + ".dds"; - CFileOutStream Out(OutName, IOUtil::LittleEndian); + CFileOutStream Out(OutName.ToStdString(), IOUtil::LittleEndian); if (!Out.IsValid()) QMessageBox::warning(this, "Error", "Couldn't open output DDS!"); else @@ -709,8 +711,8 @@ void CModelEditorWindow::on_actionOpen_triggered() if (pModel) { SetActiveModel(pModel); - setWindowTitle("Prime World Editor - Model Editor: " + QString::fromStdString(pModel->Source())); - mOutputFilename = QString::fromStdString(pModel->FullSource()); + setWindowTitle("Prime World Editor - Model Editor: " + TO_QSTRING(pModel->Source())); + mOutputFilename = TO_QSTRING(pModel->FullSource()); } gResCache.Clean(); @@ -802,6 +804,6 @@ void CModelEditorWindow::on_actionSave_as_triggered() mOutputFilename = filename; on_actionSave_triggered(); - std::string name = StringUtil::GetFileNameWithExtension(filename.toStdString()); - setWindowTitle("Prime World Editor - Model Editor: " + QString::fromStdString(name)); + TString name = TString(filename.toStdString()); + setWindowTitle("Prime World Editor - Model Editor: " + TO_QSTRING(name)); } diff --git a/UI/CStartWindow.cpp b/UI/CStartWindow.cpp index b190f0bb..18caacf5 100644 --- a/UI/CStartWindow.cpp +++ b/UI/CStartWindow.cpp @@ -6,6 +6,7 @@ #include "CModelEditorWindow.h" #include "CWorldEditor.h" +#include "UICommon.h" #include CStartWindow::CStartWindow(QWidget *parent) : @@ -30,7 +31,7 @@ void CStartWindow::on_actionOpen_MLVL_triggered() QString WorldFile = QFileDialog::getOpenFileName(this, "Open MLVL", "", "Metroid Prime World (*.MLVL)"); if (WorldFile.isEmpty()) return; - gResCache.SetFolder(StringUtil::GetFileDirectory(WorldFile.toStdString())); + gResCache.SetFolder(TString(WorldFile.toStdString()).GetFileDirectory()); mpWorld = (CWorld*) gResCache.GetResource(WorldFile.toStdString()); mWorldToken = CToken(mpWorld); mpWorldEditor->close(); @@ -44,9 +45,9 @@ void CStartWindow::FillWorldUI() CStringTable *pWorldName = mpWorld->GetWorldName(); if (pWorldName) { - std::wstring WorldName = pWorldName->GetString("ENGL", 0); - ui->WorldNameLabel->setText( QString("") + QString::fromStdWString(WorldName) + QString("") ); - ui->WorldNameSTRGLineEdit->setText( QString::fromStdString(pWorldName->Source()) ); + TWideString WorldName = pWorldName->GetString("ENGL", 0); + ui->WorldNameLabel->setText( QString("") + TO_QSTRING(WorldName) + QString("") ); + ui->WorldNameSTRGLineEdit->setText(TO_QSTRING(pWorldName->Source())); } else { @@ -56,25 +57,25 @@ void CStartWindow::FillWorldUI() CStringTable *pDarkWorldName = mpWorld->GetDarkWorldName(); if (pDarkWorldName) - ui->DarkWorldNameSTRGLineEdit->setText( QString::fromStdString(pDarkWorldName->Source()) ); + ui->DarkWorldNameSTRGLineEdit->setText(TO_QSTRING(pDarkWorldName->Source())); else ui->DarkWorldNameSTRGLineEdit->clear(); CModel *pDefaultSkybox = mpWorld->GetDefaultSkybox(); if (pDefaultSkybox) - ui->DefaultSkyboxCMDLLineEdit->setText( QString::fromStdString(pDefaultSkybox->Source()) ); + ui->DefaultSkyboxCMDLLineEdit->setText(TO_QSTRING(pDefaultSkybox->Source())); else ui->DefaultSkyboxCMDLLineEdit->clear(); CResource *pSaveWorld = mpWorld->GetSaveWorld(); if (pSaveWorld) - ui->WorldSAVWLineEdit->setText( QString::fromStdString(pSaveWorld->Source()) ); + ui->WorldSAVWLineEdit->setText(TO_QSTRING(pSaveWorld->Source())); else ui->WorldSAVWLineEdit->clear(); CResource *pMapWorld = mpWorld->GetMapWorld(); if (pMapWorld) - ui->WorldMAPWLineEdit->setText( QString::fromStdString(pMapWorld->Source()) ); + ui->WorldMAPWLineEdit->setText(TO_QSTRING(pMapWorld->Source())); else ui->WorldMAPWLineEdit->clear(); @@ -86,7 +87,7 @@ void CStartWindow::FillWorldUI() for (u32 iArea = 0; iArea < NumAreas; iArea++) { CStringTable *pAreaName = mpWorld->GetAreaName(iArea); - QString AreaName = (pAreaName != nullptr) ? QString::fromStdWString(pAreaName->GetString("ENGL", 0)) : QString("!!") + QString::fromStdString(mpWorld->GetAreaInternalName(iArea)); + QString AreaName = (pAreaName != nullptr) ? TO_QSTRING(pAreaName->GetString("ENGL", 0)) : QString("!!") + TO_QSTRING(mpWorld->GetAreaInternalName(iArea)); ui->AreaSelectComboBox->addItem(AreaName); } } @@ -102,22 +103,22 @@ void CStartWindow::FillAreaUI() ui->AreaSelectComboBox->setCurrentIndex(mSelectedAreaIndex); ui->AreaSelectComboBox->blockSignals(false); - ui->AreaNameLineEdit->setText( QString::fromStdString(mpWorld->GetAreaInternalName(mSelectedAreaIndex))); + ui->AreaNameLineEdit->setText(TO_QSTRING(mpWorld->GetAreaInternalName(mSelectedAreaIndex))); CStringTable *pAreaName = mpWorld->GetAreaName(mSelectedAreaIndex); if (pAreaName) - ui->AreaNameSTRGLineEdit->setText( QString::fromStdString( pAreaName->Source() )); + ui->AreaNameSTRGLineEdit->setText(TO_QSTRING(pAreaName->Source())); else ui->AreaNameSTRGLineEdit->clear(); u64 MREA = mpWorld->GetAreaResourceID(mSelectedAreaIndex); - std::string MREAStr; + TString MREAStr; if (MREA & 0xFFFFFFFF00000000) - MREAStr = StringUtil::ToString(MREA); + MREAStr = TString::FromInt64(MREA, 16); else - MREAStr = StringUtil::ToString( (u32) MREA ); + MREAStr = TString::FromInt32(MREA, 8); - ui->AreaMREALineEdit->setText(QString::fromStdString(MREAStr) + QString(".MREA") ); + ui->AreaMREALineEdit->setText(TO_QSTRING(MREAStr) + QString(".MREA")); u32 NumAttachedAreas = mpWorld->GetAreaAttachedCount(mSelectedAreaIndex); ui->AttachedAreasList->clear(); @@ -130,9 +131,9 @@ void CStartWindow::FillAreaUI() QString AttachedStr; if (AttachedAreaSTRG) - AttachedStr = QString::fromStdWString(AttachedAreaSTRG->GetString("ENGL", 0) ); + AttachedStr = TO_QSTRING(AttachedAreaSTRG->GetString("ENGL", 0)); else - AttachedStr = QString("!!") + QString::fromStdString(mpWorld->GetAreaInternalName(AttachedAreaIndex)); + AttachedStr = QString("!!") + TO_QSTRING(mpWorld->GetAreaInternalName(AttachedAreaIndex)); ui->AttachedAreasList->addItem(AttachedStr); } diff --git a/UI/CWorldEditor.cpp b/UI/CWorldEditor.cpp index a28715a9..3fe1f53d 100644 --- a/UI/CWorldEditor.cpp +++ b/UI/CWorldEditor.cpp @@ -11,6 +11,7 @@ #include "WDraggableSpinBox.h" #include "WVectorEditor.h" #include "undo/UndoCommands.h" +#include "UICommon.h" #include "WorldEditor/CLayerEditor.h" #include "WorldEditor/WModifyTab.h" @@ -164,7 +165,7 @@ void CWorldEditor::UpdateStatusBar() CSceneNode *pHoverNode = ui->MainViewport->HoverNode(); if (pHoverNode && (pHoverNode->NodeType() != eStaticNode)) - StatusText = QString::fromStdString(pHoverNode->Name()); + StatusText = TO_QSTRING(pHoverNode->Name()); } } @@ -181,7 +182,7 @@ void CWorldEditor::UpdateSelectionUI() QString SelectionText; if (mSelection.size() == 1) - SelectionText = QString::fromStdString(mSelection.front()->Name()); + SelectionText = TO_QSTRING(mSelection.front()->Name()); else if (mSelection.size() > 1) SelectionText = QString("%1 objects selected").arg(mSelection.size()); diff --git a/UI/CWorldEditorWindow.cpp b/UI/CWorldEditorWindow.cpp index 9e13def9..b9820549 100644 --- a/UI/CWorldEditorWindow.cpp +++ b/UI/CWorldEditorWindow.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include "CBasicViewport.h" @@ -206,8 +206,8 @@ void CWorldEditorWindow::setupInstanceViewLayers() for (u32 o = 0; o < object_count; o++) { PrimeObject object = m->getObject(l, o); - std::string name = object.getStringProperty("Name"); - if (name.empty()) name = "[no name]"; + TString name = object.getStringProperty("Name"); + if (name.IsEmpty()) name = "[no name]"; QTreeWidgetItem* obj = new QTreeWidgetItem; obj->setText(0, QString::fromStdString(name)); diff --git a/UI/UICommon.h b/UI/UICommon.h index 86330fe5..32428686 100644 --- a/UI/UICommon.h +++ b/UI/UICommon.h @@ -3,11 +3,37 @@ #include #include +#include + +#define TO_QSTRING(str) UICommon::ToQString(str) +#define TO_TSTRING(str) UICommon::ToTString(str) +#define TO_TWIDESTRING(str) UICommon::ToTWideSTring(str) namespace UICommon { extern QMap FilterMap; QString ExtensionFilterString(const QString& extension); + +// TString/TWideString <-> QString +inline QString ToQString(const TString& str) +{ + return QString::fromStdString(str.ToStdString()); +} + +inline QString ToQString(const TWideString& str) +{ + return QString::fromStdWString(str.ToStdString()); +} + +inline TString ToTString(const QString& str) +{ + return TString(str.toStdString()); +} + +inline TWideString ToTWideString(const QString& str) +{ + return TWideString(str.toStdWString()); +} } #endif // UICOMMON diff --git a/UI/WAnimParamsEditor.cpp b/UI/WAnimParamsEditor.cpp index 3d3dff06..ea401146 100644 --- a/UI/WAnimParamsEditor.cpp +++ b/UI/WAnimParamsEditor.cpp @@ -1,4 +1,6 @@ #include "WAnimParamsEditor.h" + +#include "UICommon.h" #include #include @@ -139,7 +141,7 @@ void WAnimParamsEditor::SetupUI() if (pSet) for (u32 iChar = 0; iChar < pSet->getNodeCount(); iChar++) - mpCharComboBox->addItem(QString::fromStdString(pSet->getNodeName(iChar))); + mpCharComboBox->addItem(TO_QSTRING(pSet->getNodeName(iChar))); mpCharComboBox->setCurrentIndex(mParams.CharacterIndex()); mpLabels[1] = new QLabel("Character", this); diff --git a/UI/WPropertyEditor.cpp b/UI/WPropertyEditor.cpp index c0daa9bd..115759d9 100644 --- a/UI/WPropertyEditor.cpp +++ b/UI/WPropertyEditor.cpp @@ -1,4 +1,5 @@ #include "WPropertyEditor.h" +#include "UICommon.h" #include "WDraggableSpinBox.h" #include "WIntegralSpinBox.h" #include "WResourceSelector.h" @@ -71,8 +72,8 @@ void WPropertyEditor::CreateEditor() delete mUI.EditorWidget; // Set name - mUI.PropertyName->setText(QString::fromStdString(mpProperty->Name())); - mUI.PropertyName->setToolTip(QString::fromStdString(mpProperty->Name())); + mUI.PropertyName->setText(TO_QSTRING(mpProperty->Name())); + mUI.PropertyName->setToolTip(TO_QSTRING(mpProperty->Name())); // Set editor widget switch (mpProperty->Type()) @@ -144,8 +145,8 @@ void WPropertyEditor::CreateEditor() for (u32 iEnum = 0; iEnum < pTemplate->NumEnumerators(); iEnum++) { - std::string name = pTemplate->EnumeratorName(iEnum); - pComboBox->addItem(QString::fromStdString(name)); + TString name = pTemplate->EnumeratorName(iEnum); + pComboBox->addItem(TO_QSTRING(name)); } u32 index = pEnumCast->Get(); @@ -168,15 +169,15 @@ void WPropertyEditor::CreateEditor() QVBoxLayout *pBitfieldLayout = new QVBoxLayout(pGroupBox); pBitfieldLayout->setContentsMargins(5,5,5,5); pGroupBox->setLayout(pBitfieldLayout); - pGroupBox->setTitle(QString::fromStdString(pBitfieldCast->Name())); + pGroupBox->setTitle(TO_QSTRING(pBitfieldCast->Name())); mUI.PropertyName->hide(); for (u32 iFlag = 0; iFlag < pTemplate->NumFlags(); iFlag++) { - std::string flagName = pTemplate->FlagName(iFlag); + TString flagName = pTemplate->FlagName(iFlag); long mask = pTemplate->FlagMask(iFlag); - QCheckBox *pCheckBox = new QCheckBox(QString::fromStdString(flagName), pGroupBox); + QCheckBox *pCheckBox = new QCheckBox(TO_QSTRING(flagName), pGroupBox); pCheckBox->setChecked((value & mask) != 0); pBitfieldLayout->addWidget(pCheckBox); } @@ -206,7 +207,7 @@ void WPropertyEditor::CreateEditor() CStringProperty *pStringCast = static_cast(mpProperty); QLineEdit *pLineEdit = new QLineEdit(this); - pLineEdit->setText(QString::fromStdString(pStringCast->Get())); + pLineEdit->setText(TO_QSTRING(pStringCast->Get())); pLineEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); //pLineEdit->setCursorPosition(0); @@ -226,7 +227,7 @@ void WPropertyEditor::CreateEditor() pGroupLayout->setContentsMargins(0,0,0,0); pGroupBox->setLayout(pGroupLayout); - pGroupBox->setTitle(QString::fromStdString(mpProperty->Name())); + pGroupBox->setTitle(TO_QSTRING(mpProperty->Name())); pVectorEditor->SetValue(pVector3Cast->Get()); pVectorEditor->SetOrientation(Qt::Vertical); mUI.PropertyName->hide(); @@ -272,7 +273,7 @@ void WPropertyEditor::CreateEditor() QVBoxLayout *pStructLayout = new QVBoxLayout(pGroupBox); pStructLayout->setContentsMargins(5,5,5,5); pGroupBox->setLayout(pStructLayout); - pGroupBox->setTitle(QString::fromStdString(pStructCast->Name())); + pGroupBox->setTitle(TO_QSTRING(pStructCast->Name())); mUI.PropertyName->hide(); for (u32 p = 0; p < pStructCast->Count(); p++) @@ -292,7 +293,7 @@ void WPropertyEditor::CreateEditor() CAnimationParameters params = pAnimCast->Get(); WAnimParamsEditor *pEditor = new WAnimParamsEditor(params, this); - pEditor->SetTitle(QString::fromStdString(pAnimCast->Name())); + pEditor->SetTitle(TO_QSTRING(pAnimCast->Name())); mUI.PropertyName->hide(); mUI.EditorWidget = pEditor; @@ -400,7 +401,7 @@ void WPropertyEditor::UpdateEditor() { CStringProperty *pStringCast = static_cast(mpProperty); QLineEdit *pLineEdit = static_cast(mUI.EditorWidget); - pLineEdit->setText(QString::fromStdString(pStringCast->Get())); + pLineEdit->setText(TO_QSTRING(pStringCast->Get())); pLineEdit->setCursorPosition(0); break; } @@ -470,8 +471,8 @@ void WPropertyEditor::UpdateEditor() void WPropertyEditor::CreateLabelText() { - mUI.PropertyName->setText(QString::fromStdString(mpProperty->Name())); + mUI.PropertyName->setText(TO_QSTRING(mpProperty->Name())); QFontMetrics metrics(mUI.PropertyName->font()); - QString text = metrics.elidedText(QString::fromStdString(mpProperty->Name()), Qt::ElideRight, mUI.PropertyName->width()); + QString text = metrics.elidedText(TO_QSTRING(mpProperty->Name()), Qt::ElideRight, mUI.PropertyName->width()); mUI.PropertyName->setText(text); } diff --git a/UI/WResourceSelector.cpp b/UI/WResourceSelector.cpp index e9276fa8..a8eea379 100644 --- a/UI/WResourceSelector.cpp +++ b/UI/WResourceSelector.cpp @@ -105,7 +105,7 @@ bool WResourceSelector::IsSupportedExtension(const QString& extension) bool WResourceSelector::HasSupportedExtension(CResource* pRes) { - return IsSupportedExtension( QString::fromStdString( StringUtil::GetExtension(pRes->FullSource()) ) ); + return IsSupportedExtension(TO_QSTRING(pRes->FullSource().GetFileExtension())); } // ************ GETTERS ************ @@ -139,7 +139,7 @@ void WResourceSelector::SetResource(CResource *pRes) if (pRes) { mResourceValid = HasSupportedExtension(pRes); - mUI.LineEdit->setText(QString::fromStdString(pRes->FullSource())); + mUI.LineEdit->setText(TO_QSTRING(pRes->FullSource())); } else @@ -154,15 +154,15 @@ void WResourceSelector::SetResource(CResource *pRes) void WResourceSelector::SetAllowedExtensions(const QString& extension) { - CStringList list = StringUtil::Tokenize(extension.toStdString(), ","); + TStringList list = TString(extension.toStdString()).Split(","); SetAllowedExtensions(list); } -void WResourceSelector::SetAllowedExtensions(const CStringList& extensions) +void WResourceSelector::SetAllowedExtensions(const TStringList& extensions) { mSupportedExtensions.clear(); for (auto it = extensions.begin(); it != extensions.end(); it++) - mSupportedExtensions << QString::fromStdString(*it); + mSupportedExtensions << TO_QSTRING(*it); } void WResourceSelector::SetText(const QString& ResPath) @@ -263,10 +263,10 @@ void WResourceSelector::LoadResource(const QString& ResPath) mpResource = nullptr; mResToken.Unlock(); - std::string pathStr = ResPath.toStdString(); - std::string ext = StringUtil::GetExtension(pathStr); + TString pathStr = ResPath.toStdString(); + TString ext = pathStr.GetFileExtension(); - if (IsSupportedExtension( QString::fromStdString(ext) )) + if (IsSupportedExtension(TO_QSTRING(ext))) { if ((ext != "MREA") && (ext != "MLVL")) { diff --git a/UI/WResourceSelector.h b/UI/WResourceSelector.h index 279f29e9..2ae8296f 100644 --- a/UI/WResourceSelector.h +++ b/UI/WResourceSelector.h @@ -66,7 +66,7 @@ public: void SetResource(CResource *pRes); void SetAllowedExtensions(const QString& extension); void SetAllowedExtensions(const QStringList& extensions); - void SetAllowedExtensions(const CStringList& extensions); + void SetAllowedExtensions(const TStringList& extensions); void SetText(const QString& ResPath); void SetEditButtonEnabled(bool Enabled); void SetExportButtonEnabled(bool Enabled); diff --git a/UI/WStringPreviewPanel.cpp b/UI/WStringPreviewPanel.cpp index 42721f08..6ea6e409 100644 --- a/UI/WStringPreviewPanel.cpp +++ b/UI/WStringPreviewPanel.cpp @@ -1,4 +1,5 @@ #include "WStringPreviewPanel.h" +#include "UICommon.h" #include #include #include @@ -38,7 +39,7 @@ void WStringPreviewPanel::SetResource(CResource *pRes) for (u32 iStr = 0; iStr < pString->GetStringCount(); iStr++) { - QString text = QString::fromStdWString(pString->GetString("ENGL", iStr)); + QString text = TO_QSTRING(pString->GetString("ENGL", iStr)); QLabel *pLabel = new QLabel(text, this); pLabel->setWordWrap(true); pLabel->setFrameStyle(QFrame::Plain | QFrame::Box); diff --git a/UI/WTexturePreviewPanel.cpp b/UI/WTexturePreviewPanel.cpp index b154fdb2..c780d8ad 100644 --- a/UI/WTexturePreviewPanel.cpp +++ b/UI/WTexturePreviewPanel.cpp @@ -1,5 +1,7 @@ #include "WTexturePreviewPanel.h" #include "ui_WTexturePreviewPanel.h" + +#include "UICommon.h" #include "WTextureGLWidget.h" WTexturePreviewPanel::WTexturePreviewPanel(QWidget *parent, CTexture *pTexture) : @@ -27,8 +29,8 @@ void WTexturePreviewPanel::SetResource(CResource *pRes) if (pTexture) { - std::string Name = StringUtil::GetFileNameWithExtension(pTexture->Source()); - ui->TextureNameLabel->setText( QString::fromStdString(Name) ); + TString Name = pTexture->Source(); + ui->TextureNameLabel->setText( TO_QSTRING(Name) ); QString TexInfo; TexInfo += QString::number(pTexture->Width()) + "x" + QString::number(pTexture->Height()); diff --git a/UI/WorldEditor/CLayerEditor.cpp b/UI/WorldEditor/CLayerEditor.cpp index e87e4afe..3596779e 100644 --- a/UI/WorldEditor/CLayerEditor.cpp +++ b/UI/WorldEditor/CLayerEditor.cpp @@ -1,5 +1,6 @@ #include "CLayerEditor.h" #include "ui_CLayerEditor.h" +#include "../UICommon.h" CLayerEditor::CLayerEditor(QWidget *parent) : QDialog(parent), @@ -38,7 +39,7 @@ void CLayerEditor::SetCurrentIndex(int index) QModelIndex ModelIndex = mpModel->index(index); mpCurrentLayer = mpModel->Layer(ModelIndex); - ui->NameLineEdit->setText(QString::fromStdString(mpCurrentLayer->Name())); + ui->NameLineEdit->setText(TO_QSTRING(mpCurrentLayer->Name())); ui->ActiveCheckBox->setChecked(mpCurrentLayer->IsActive()); } diff --git a/UI/WorldEditor/CLayerModel.cpp b/UI/WorldEditor/CLayerModel.cpp index d77543c6..fb8703e3 100644 --- a/UI/WorldEditor/CLayerModel.cpp +++ b/UI/WorldEditor/CLayerModel.cpp @@ -1,4 +1,5 @@ #include "CLayerModel.h" +#include "../UICommon.h" CLayerModel::CLayerModel(QObject *pParent) : QAbstractListModel(pParent) { @@ -20,7 +21,7 @@ int CLayerModel::rowCount(const QModelIndex &parent) const QVariant CLayerModel::data(const QModelIndex &index, int role) const { if (mpArea && (role == Qt::DisplayRole) && (index.row() < rowCount(QModelIndex()))) - return QString::fromStdString(Layer(index)->Name()); + return TO_QSTRING(Layer(index)->Name()); return QVariant::Invalid; } diff --git a/UI/WorldEditor/CLinkModel.cpp b/UI/WorldEditor/CLinkModel.cpp index aa9b05c6..795bcac5 100644 --- a/UI/WorldEditor/CLinkModel.cpp +++ b/UI/WorldEditor/CLinkModel.cpp @@ -1,4 +1,5 @@ #include "CLinkModel.h" +#include "../UICommon.h" #include #include @@ -54,8 +55,8 @@ QVariant CLinkModel::data(const QModelIndex &index, int role) const CScriptObject *pTargetObj = mpObject->Area()->GetInstanceByID(link.ObjectID); if (pTargetObj) { - QString ObjType = QString("[%1] ").arg(QString::fromStdString(pTargetObj->Template()->TemplateName())); - return ObjType + QString::fromStdString(pTargetObj->InstanceName()); + QString ObjType = QString("[%1] ").arg(UICommon::ToQString(pTargetObj->Template()->TemplateName())); + return ObjType + UICommon::ToQString(pTargetObj->InstanceName()); } else { QString strID = QString::number(link.ObjectID, 16); @@ -66,14 +67,14 @@ QVariant CLinkModel::data(const QModelIndex &index, int role) const case 1: // Column 1 - State { - std::string StateName = mpObject->MasterTemplate()->StateByID(link.State); - return QString::fromStdString(StateName); + TString StateName = mpObject->MasterTemplate()->StateByID(link.State); + return UICommon::ToQString(StateName); } case 2: // Column 2 - Message { - std::string MessageName = mpObject->MasterTemplate()->MessageByID(link.Message); - return QString::fromStdString(MessageName); + TString MessageName = mpObject->MasterTemplate()->MessageByID(link.Message); + return UICommon::ToQString(MessageName); } default: diff --git a/UI/WorldEditor/CTypesInstanceModel.cpp b/UI/WorldEditor/CTypesInstanceModel.cpp index ba3154aa..d4c05bd9 100644 --- a/UI/WorldEditor/CTypesInstanceModel.cpp +++ b/UI/WorldEditor/CTypesInstanceModel.cpp @@ -1,4 +1,5 @@ #include "CTypesInstanceModel.h" +#include "../UICommon.h" #include #include #include @@ -219,9 +220,9 @@ QVariant CTypesInstanceModel::data(const QModelIndex &index, int role) const { if (index.column() == 0) { if (mModelType == eLayers) - return QString::fromStdString(mpEditor->ActiveArea()->GetScriptLayer(index.row())->Name()); + return TO_QSTRING(mpEditor->ActiveArea()->GetScriptLayer(index.row())->Name()); else - return QString::fromStdString(mTemplateList[index.row()]->TemplateName()); + return TO_QSTRING(mTemplateList[index.row()]->TemplateName()); } // todo: show/hide button in column 2 else @@ -235,14 +236,14 @@ QVariant CTypesInstanceModel::data(const QModelIndex &index, int role) const CScriptObject *pObj = static_cast(index.internalPointer()); if (index.column() == 0) - return QString::fromStdString(pObj->InstanceName()); + return TO_QSTRING(pObj->InstanceName()); else if (index.column() == 1) { if (mModelType == eLayers) - return QString::fromStdString(pObj->Template()->TemplateName()); + return TO_QSTRING(pObj->Template()->TemplateName()); else if (mModelType == eTypes) - return QString::fromStdString(pObj->Layer()->Name()); + return TO_QSTRING(pObj->Layer()->Name()); } else