diff options
author | Brad Davis <[email protected]> | 2014-07-24 16:47:31 -0700 |
---|---|---|
committer | Brad Davis <[email protected]> | 2014-07-24 16:47:31 -0700 |
commit | 0f49ce8fc6aa54224e4c0d6fda8c4527ad39cce1 (patch) | |
tree | da07ebc6a7f75185bda857dd5f1c34710b416a93 /LibOVR/Src/Kernel/OVR_String.h | |
parent | ca79271759ff7eecd22ec5c4db438370fe51d687 (diff) |
0.4 Win-Beta0.4.0
Diffstat (limited to 'LibOVR/Src/Kernel/OVR_String.h')
-rw-r--r-- | LibOVR/Src/Kernel/OVR_String.h | 178 |
1 files changed, 89 insertions, 89 deletions
diff --git a/LibOVR/Src/Kernel/OVR_String.h b/LibOVR/Src/Kernel/OVR_String.h index 0866968..25c4b68 100644 --- a/LibOVR/Src/Kernel/OVR_String.h +++ b/LibOVR/Src/Kernel/OVR_String.h @@ -1,6 +1,6 @@ /************************************************************************************ -PublicHeader: OVR.h +PublicHeader: OVR_Kernel.h Filename : OVR_String.h Content : String UTF8 string implementation with copy-on-write semantics (thread-safe for assignment but not modification). @@ -59,7 +59,7 @@ protected: //Flag_GetLength = 0x7FFFFFFF, // This flag is set if GetLength() == GetSize() for a string. // Avoid extra scanning is Substring and indexing logic. - Flag_LengthIsSizeShift = (sizeof(UPInt)*8 - 1) + Flag_LengthIsSizeShift = (sizeof(size_t)*8 - 1) }; @@ -68,13 +68,13 @@ protected: { // Number of bytes. Will be the same as the number of chars if the characters // are ascii, may not be equal to number of chars in case string data is UTF8. - UPInt Size; - volatile SInt32 RefCount; + size_t Size; + volatile int32_t RefCount; char Data[1]; void AddRef() { - AtomicOps<SInt32>::ExchangeAdd_NoSync(&RefCount, 1); + AtomicOps<int32_t>::ExchangeAdd_NoSync(&RefCount, 1); } // Decrement ref count. This needs to be thread-safe, since // a different thread could have also decremented the ref count. @@ -88,13 +88,13 @@ protected: // checking against 0 needs to made an atomic operation. void Release() { - if ((AtomicOps<SInt32>::ExchangeAdd_NoSync(&RefCount, -1) - 1) == 0) + if ((AtomicOps<int32_t>::ExchangeAdd_NoSync(&RefCount, -1) - 1) == 0) OVR_FREE(this); } - static UPInt GetLengthFlagBit() { return UPInt(1) << Flag_LengthIsSizeShift; } - UPInt GetSize() const { return Size & ~GetLengthFlagBit() ; } - UPInt GetLengthFlag() const { return Size & GetLengthFlagBit(); } + static size_t GetLengthFlagBit() { return size_t(1) << Flag_LengthIsSizeShift; } + size_t GetSize() const { return Size & ~GetLengthFlagBit() ; } + size_t GetLengthFlag() const { return Size & GetLengthFlagBit(); } bool LengthIsSize() const { return GetLengthFlag() != 0; } }; @@ -109,11 +109,11 @@ protected: union { DataDesc* pData; - UPInt HeapTypeBits; + size_t HeapTypeBits; }; typedef union { DataDesc* pData; - UPInt HeapTypeBits; + size_t HeapTypeBits; } DataDescUnion; inline HeapType GetHeapType() const { return (HeapType) (HeapTypeBits & HT_Mask); } @@ -122,7 +122,7 @@ protected: { DataDescUnion u; u.pData = pData; - u.HeapTypeBits = (u.HeapTypeBits & ~(UPInt)HT_Mask); + u.HeapTypeBits = (u.HeapTypeBits & ~(size_t)HT_Mask); return u.pData; } @@ -135,12 +135,12 @@ protected: } - DataDesc* AllocData(UPInt size, UPInt lengthIsSize); - DataDesc* AllocDataCopy1(UPInt size, UPInt lengthIsSize, - const char* pdata, UPInt copySize); - DataDesc* AllocDataCopy2(UPInt size, UPInt lengthIsSize, - const char* pdata1, UPInt copySize1, - const char* pdata2, UPInt copySize2); + DataDesc* AllocData(size_t size, size_t lengthIsSize); + DataDesc* AllocDataCopy1(size_t size, size_t lengthIsSize, + const char* pdata, size_t copySize); + DataDesc* AllocDataCopy2(size_t size, size_t lengthIsSize, + const char* pdata1, size_t copySize1, + const char* pdata2, size_t copySize2); // Special constructor to avoid data initalization when used in derived class. struct NoConstructor { }; @@ -152,7 +152,7 @@ public: struct InitStruct { virtual ~InitStruct() { } - virtual void InitString(char* pbuffer, UPInt size) const = 0; + virtual void InitString(char* pbuffer, size_t size) const = 0; }; @@ -160,10 +160,10 @@ public: String(); String(const char* data); String(const char* data1, const char* pdata2, const char* pdata3 = 0); - String(const char* data, UPInt buflen); + String(const char* data, size_t buflen); String(const String& src); String(const StringBuffer& src); - String(const InitStruct& src, UPInt size); + String(const InitStruct& src, size_t size); explicit String(const wchar_t* data); // Destructor (Captain Obvious guarantees!) @@ -186,68 +186,68 @@ public: const char* ToCStr() const { return GetData()->Data; } // Returns number of bytes - UPInt GetSize() const { return GetData()->GetSize() ; } + size_t GetSize() const { return GetData()->GetSize() ; } // Tells whether or not the string is empty bool IsEmpty() const { return GetSize() == 0; } // Returns number of characters - UPInt GetLength() const; + size_t GetLength() const; // Returns character at the specified index - UInt32 GetCharAt(UPInt index) const; - UInt32 GetFirstCharAt(UPInt index, const char** offset) const; - UInt32 GetNextChar(const char** offset) const; + uint32_t GetCharAt(size_t index) const; + uint32_t GetFirstCharAt(size_t index, const char** offset) const; + uint32_t GetNextChar(const char** offset) const; // Appends a character - void AppendChar(UInt32 ch); + void AppendChar(uint32_t ch); // Append a string - void AppendString(const wchar_t* pstr, SPInt len = -1); - void AppendString(const char* putf8str, SPInt utf8StrSz = -1); + void AppendString(const wchar_t* pstr, intptr_t len = -1); + void AppendString(const char* putf8str, intptr_t utf8StrSz = -1); // Assigned a string with dynamic data (copied through initializer). - void AssignString(const InitStruct& src, UPInt size); + void AssignString(const InitStruct& src, size_t size); // Assigns string with known size. - void AssignString(const char* putf8str, UPInt size); + void AssignString(const char* putf8str, size_t size); // Resize the string to the new size -// void Resize(UPInt _size); +// void Resize(size_t _size); // Removes the character at posAt - void Remove(UPInt posAt, SPInt len = 1); + void Remove(size_t posAt, intptr_t len = 1); // Returns a String that's a substring of this. // -start is the index of the first UTF8 character you want to include. // -end is the index one past the last UTF8 character you want to include. - String Substring(UPInt start, UPInt end) const; + String Substring(size_t start, size_t end) const; // Case-conversion String ToUpper() const; String ToLower() const; // Inserts substr at posAt - String& Insert (const char* substr, UPInt posAt, SPInt len = -1); + String& Insert (const char* substr, size_t posAt, intptr_t len = -1); // Inserts character at posAt - UPInt InsertCharAt(UInt32 c, UPInt posAt); + size_t InsertCharAt(uint32_t c, size_t posAt); // Inserts substr at posAt, which is an index of a character (not byte). // Of size is specified, it is in bytes. -// String& Insert(const UInt32* substr, UPInt posAt, SPInt size = -1); +// String& Insert(const uint32_t* substr, size_t posAt, intptr_t size = -1); // Get Byte index of the character at position = index - UPInt GetByteIndex(UPInt index) const { return (UPInt)UTF8Util::GetByteIndex(index, GetData()->Data); } + size_t GetByteIndex(size_t index) const { return (size_t)UTF8Util::GetByteIndex(index, GetData()->Data); } // Utility: case-insensitive string compare. stricmp() & strnicmp() are not // ANSI or POSIX, do not seem to appear in Linux. static int OVR_STDCALL CompareNoCase(const char* a, const char* b); - static int OVR_STDCALL CompareNoCase(const char* a, const char* b, SPInt len); + static int OVR_STDCALL CompareNoCase(const char* a, const char* b, intptr_t len); // Hash function, case-insensitive - static UPInt OVR_STDCALL BernsteinHashFunctionCIS(const void* pdataIn, UPInt size, UPInt seed = 5381); + static size_t OVR_STDCALL BernsteinHashFunctionCIS(const void* pdataIn, size_t size, size_t seed = 5381); // Hash function, case-sensitive - static UPInt OVR_STDCALL BernsteinHashFunction(const void* pdataIn, UPInt size, UPInt seed = 5381); + static size_t OVR_STDCALL BernsteinHashFunction(const void* pdataIn, size_t size, size_t seed = 5381); // ***** File path parsing helper functions. @@ -343,10 +343,10 @@ public: // Accesses raw bytes const char& operator [] (int index) const { - OVR_ASSERT(index >= 0 && (UPInt)index < GetSize()); + OVR_ASSERT(index >= 0 && (size_t)index < GetSize()); return GetData()->Data[index]; } - const char& operator [] (UPInt index) const + const char& operator [] (size_t index) const { OVR_ASSERT(index < GetSize()); return GetData()->Data[index]; @@ -373,9 +373,9 @@ public: // Hash functor used for strings. struct HashFunctor { - UPInt operator()(const String& data) const + size_t operator()(const String& data) const { - UPInt size = data.GetSize(); + size_t size = data.GetSize(); return String::BernsteinHashFunction((const char*)data, size); } }; @@ -383,14 +383,14 @@ public: // lookup based on NoCaseKey. struct NoCaseHashFunctor { - UPInt operator()(const String& data) const + size_t operator()(const String& data) const { - UPInt size = data.GetSize(); + size_t size = data.GetSize(); return String::BernsteinHashFunctionCIS((const char*)data, size); } - UPInt operator()(const NoCaseKey& data) const + size_t operator()(const NoCaseKey& data) const { - UPInt size = data.pStr->GetSize(); + size_t size = data.pStr->GetSize(); return String::BernsteinHashFunctionCIS((const char*)data.pStr->ToCStr(), size); } }; @@ -404,18 +404,18 @@ public: class StringBuffer { char* pData; - UPInt Size; - UPInt BufferSize; - UPInt GrowSize; + size_t Size; + size_t BufferSize; + size_t GrowSize; mutable bool LengthIsSize; public: // Constructors / Destructor. StringBuffer(); - explicit StringBuffer(UPInt growSize); + explicit StringBuffer(size_t growSize); StringBuffer(const char* data); - StringBuffer(const char* data, UPInt buflen); + StringBuffer(const char* data, size_t buflen); StringBuffer(const String& src); StringBuffer(const StringBuffer& src); explicit StringBuffer(const wchar_t* data); @@ -423,8 +423,8 @@ public: // Modify grow size used for growing/shrinking the buffer. - UPInt GetGrowSize() const { return GrowSize; } - void SetGrowSize(UPInt growSize); + size_t GetGrowSize() const { return GrowSize; } + void SetGrowSize(size_t growSize); // *** General Functions @@ -437,38 +437,38 @@ public: const char* ToCStr() const { return (pData) ? pData : ""; } // Returns number of bytes. - UPInt GetSize() const { return Size ; } + size_t GetSize() const { return Size ; } // Tells whether or not the string is empty. bool IsEmpty() const { return GetSize() == 0; } // Returns number of characters - UPInt GetLength() const; + size_t GetLength() const; // Returns character at the specified index - UInt32 GetCharAt(UPInt index) const; - UInt32 GetFirstCharAt(UPInt index, const char** offset) const; - UInt32 GetNextChar(const char** offset) const; + uint32_t GetCharAt(size_t index) const; + uint32_t GetFirstCharAt(size_t index, const char** offset) const; + uint32_t GetNextChar(const char** offset) const; // Resize the string to the new size - void Resize(UPInt _size); - void Reserve(UPInt _size); + void Resize(size_t _size); + void Reserve(size_t _size); // Appends a character - void AppendChar(UInt32 ch); + void AppendChar(uint32_t ch); // Append a string - void AppendString(const wchar_t* pstr, SPInt len = -1); - void AppendString(const char* putf8str, SPInt utf8StrSz = -1); + void AppendString(const wchar_t* pstr, intptr_t len = -1); + void AppendString(const char* putf8str, intptr_t utf8StrSz = -1); void AppendFormat(const char* format, ...); // Assigned a string with dynamic data (copied through initializer). - //void AssignString(const InitStruct& src, UPInt size); + //void AssignString(const InitStruct& src, size_t size); // Inserts substr at posAt - void Insert (const char* substr, UPInt posAt, SPInt len = -1); + void Insert (const char* substr, size_t posAt, intptr_t len = -1); // Inserts character at posAt - UPInt InsertCharAt(UInt32 c, UPInt posAt); + size_t InsertCharAt(uint32_t c, size_t posAt); // Assignment void operator = (const char* str); @@ -487,10 +487,10 @@ public: // Accesses raw bytes char& operator [] (int index) { - OVR_ASSERT(((UPInt)index) < GetSize()); + OVR_ASSERT(((size_t)index) < GetSize()); return pData[index]; } - char& operator [] (UPInt index) + char& operator [] (size_t index) { OVR_ASSERT(index < GetSize()); return pData[index]; @@ -498,10 +498,10 @@ public: const char& operator [] (int index) const { - OVR_ASSERT(((UPInt)index) < GetSize()); + OVR_ASSERT(((size_t)index) < GetSize()); return pData[index]; } - const char& operator [] (UPInt index) const + const char& operator [] (size_t index) const { OVR_ASSERT(index < GetSize()); return pData[index]; @@ -520,7 +520,7 @@ public: StringDataPtr() : pStr(NULL), Size(0) {} StringDataPtr(const StringDataPtr& p) : pStr(p.pStr), Size(p.Size) {} - StringDataPtr(const char* pstr, UPInt sz) + StringDataPtr(const char* pstr, size_t sz) : pStr(pstr), Size(sz) {} StringDataPtr(const char* pstr) : pStr(pstr), Size((pstr != NULL) ? OVR_strlen(pstr) : 0) {} @@ -532,7 +532,7 @@ public: public: const char* ToCStr() const { return pStr; } - UPInt GetSize() const { return Size; } + size_t GetSize() const { return Size; } bool IsEmpty() const { return GetSize() == 0; } // value is a prefix of this string @@ -550,33 +550,33 @@ public: // Find first character. // init_ind - initial index. - SPInt FindChar(char c, UPInt init_ind = 0) const + intptr_t FindChar(char c, size_t init_ind = 0) const { - for (UPInt i = init_ind; i < GetSize(); ++i) + for (size_t i = init_ind; i < GetSize(); ++i) if (pStr[i] == c) - return static_cast<SPInt>(i); + return static_cast<intptr_t>(i); return -1; } // Find last character. // init_ind - initial index. - SPInt FindLastChar(char c, UPInt init_ind = ~0) const + intptr_t FindLastChar(char c, size_t init_ind = ~0) const { - if (init_ind == (UPInt)~0 || init_ind > GetSize()) + if (init_ind == (size_t)~0 || init_ind > GetSize()) init_ind = GetSize(); else ++init_ind; - for (UPInt i = init_ind; i > 0; --i) + for (size_t i = init_ind; i > 0; --i) if (pStr[i - 1] == c) - return static_cast<SPInt>(i - 1); + return static_cast<intptr_t>(i - 1); return -1; } // Create new object and trim size bytes from the left. - StringDataPtr GetTrimLeft(UPInt size) const + StringDataPtr GetTrimLeft(size_t size) const { // Limit trim size to the size of the string. size = Alg::PMin(GetSize(), size); @@ -584,7 +584,7 @@ public: return StringDataPtr(ToCStr() + size, GetSize() - size); } // Create new object and trim size bytes from the right. - StringDataPtr GetTrimRight(UPInt size) const + StringDataPtr GetTrimRight(size_t size) const { // Limit trim to the size of the string. size = Alg::PMin(GetSize(), size); @@ -596,7 +596,7 @@ public: // Useful for parsing. StringDataPtr GetNextToken(char separator = ':') const { - UPInt cur_pos = 0; + size_t cur_pos = 0; const char* cur_str = ToCStr(); for (; cur_pos < GetSize() && cur_str[cur_pos]; ++cur_pos) @@ -611,7 +611,7 @@ public: } // Trim size bytes from the left. - StringDataPtr& TrimLeft(UPInt size) + StringDataPtr& TrimLeft(size_t size) { // Limit trim size to the size of the string. size = Alg::PMin(GetSize(), size); @@ -621,7 +621,7 @@ public: return *this; } // Trim size bytes from the right. - StringDataPtr& TrimRight(UPInt size) + StringDataPtr& TrimRight(size_t size) { // Limit trim to the size of the string. size = Alg::PMin(GetSize(), size); @@ -636,7 +636,7 @@ public: // Hash functor used string data pointers struct HashFunctor { - UPInt operator()(const StringDataPtr& data) const + size_t operator()(const StringDataPtr& data) const { return String::BernsteinHashFunction(data.ToCStr(), data.GetSize()); } @@ -649,7 +649,7 @@ public: protected: const char* pStr; - UPInt Size; + size_t Size; }; } // OVR |