From 987a6b7d4ec34880bf74e3953a3592fbc1d352fa Mon Sep 17 00:00:00 2001 From: janwas Date: Fri, 3 Feb 2006 20:36:15 +0000 Subject: [PATCH] fixed wchar_t issues; now correctly separates utf16, CStrW and jschar. NOTE: wchar_t should be defined as a built-in type; no more need to define manually or change project settings. adts: disambiguate iterator type; add operator- as required by VC8 std::equal() implementation precompiled: squelch stupid warning (that informs us that array members are now actually default-initialized as called for by C++) file_cache: remove debug variable This was SVN commit r3464. --- source/i18n/StrImmutable.h | 2 +- source/lib/adts.cpp | 3 ++- source/lib/adts.h | 42 ++++++++++++++++++++++-------- source/lib/precompiled.h | 1 + source/lib/res/file/file_cache.cpp | 2 -- source/ps/CStr.h | 9 +++---- source/ps/utf16string.h | 16 +++--------- 7 files changed, 42 insertions(+), 33 deletions(-) diff --git a/source/i18n/StrImmutable.h b/source/i18n/StrImmutable.h index b0d038a08c..72e500d924 100755 --- a/source/i18n/StrImmutable.h +++ b/source/i18n/StrImmutable.h @@ -48,7 +48,7 @@ namespace I18n } // On non-MSVC, or on MSVC with a native wchar_t type, define jschar separately -#if !MSC_VERSION || !defined(_WCHAR_T_DEFINED) +#if !MSC_VERSION || defined(_NATIVE_WCHAR_T_DEFINED) StrImW(const jschar* s) { ref = new strImW_data; diff --git a/source/lib/adts.cpp b/source/lib/adts.cpp index 321437d753..48e4911fa2 100755 --- a/source/lib/adts.cpp +++ b/source/lib/adts.cpp @@ -76,7 +76,8 @@ static void test_ringbuf() } } TEST(buf.size() == deq.size()); - TEST(equal(buf.begin(), buf.end(), deq.begin())); + RingBuf::iterator begin = buf.begin(), end = buf.end(); + TEST(equal(begin, end, deq.begin())); } } diff --git a/source/lib/adts.h b/source/lib/adts.h index ff81041c7a..151018ca7a 100755 --- a/source/lib/adts.h +++ b/source/lib/adts.h @@ -501,7 +501,7 @@ public: debug_warn("underflow"); } - +#include class iterator { public: @@ -512,25 +512,35 @@ public: typedef T& reference; iterator() : data(0), pos(0) - {} + {} iterator(T* data_, size_t pos_) : data(data_), pos(pos_) - {} + {} T& operator[](int idx) const - { return data[(pos+idx) % n]; } + { return data[(pos+idx) % n]; } T& operator*() const - { return data[pos % n]; } + { return data[pos % n]; } T* operator->() const - { return &**this; } + { return &**this; } iterator& operator++() // pre - { ++pos; return (*this); } + { ++pos; return (*this); } iterator operator++(int) // post - { iterator tmp = *this; ++*this; return tmp; } + { iterator tmp = *this; ++*this; return tmp; } bool operator==(const iterator& rhs) const - { return data == rhs.data && pos == rhs.pos; } + { return data == rhs.data && pos == rhs.pos; } bool operator!=(const iterator& rhs) const - { return !(*this == rhs); } + { return !(*this == rhs); } bool operator<(const iterator& rhs) const - { return (pos < rhs.pos); } + { return (pos < rhs.pos); } + iterator& operator+=(difference_type ofs) + { pos += ofs; return *this; } + iterator& operator-=(difference_type ofs) + { return (*this += -ofs); } + iterator operator+(difference_type ofs) const + { iterator tmp = *this; return (tmp += ofs); } + iterator operator-(difference_type ofs) const + { iterator tmp = *this; return (tmp -= ofs); } + difference_type operator-(const iterator right) const + { return (difference_type)(pos - right.pos); } protected: T* data; @@ -567,6 +577,16 @@ public: { return !(*this == rhs); } bool operator<(const const_iterator& rhs) const { return (pos < rhs.pos); } + iterator& operator+=(difference_type ofs) + { pos += ofs; return *this; } + iterator& operator-=(difference_type ofs) + { return (*this += -ofs); } + iterator operator+(difference_type ofs) const + { iterator tmp = *this; return (tmp += ofs); } + iterator operator-(difference_type ofs) const + { iterator tmp = *this; return (tmp -= ofs); } + difference_type operator-(const iterator right) const + { return (difference_type)(pos - right.pos); } protected: const T* data; diff --git a/source/lib/precompiled.h b/source/lib/precompiled.h index 76f4176f08..c49c5e1ad7 100755 --- a/source/lib/precompiled.h +++ b/source/lib/precompiled.h @@ -21,6 +21,7 @@ # pragma warning(disable:4127) // conditional expression is constant; rationale: see STMT in lib.h. # pragma warning(disable:4996) // function is deprecated # pragma warning(disable:4786) // identifier truncated to 255 chars +# pragma warning(disable:4351) // yes, default init of array entries is desired // .. disabled only for the precompiled headers # pragma warning(disable:4702) // unreachable code (frequent in STL) // .. VS2005 code analysis (very frequent ones) diff --git a/source/lib/res/file/file_cache.cpp b/source/lib/res/file/file_cache.cpp index 52e8e7b4dc..d61678b278 100644 --- a/source/lib/res/file/file_cache.cpp +++ b/source/lib/res/file/file_cache.cpp @@ -23,8 +23,6 @@ // to remain valid. // -static uint block_epoch; - class BlockMgr { static const size_t MAX_BLOCKS = 32; diff --git a/source/ps/CStr.h b/source/ps/CStr.h index 40b35372f1..e4772bd719 100755 --- a/source/ps/CStr.h +++ b/source/ps/CStr.h @@ -92,11 +92,10 @@ public: // Named constructor, to avoid overload overload. static CStr Repeat(CStr String, size_t Reps); - // CStr(8|W) construction from utf16strings, except on MSVC CStrW where - // CStrW === utf16string - #if !(MSC_VERSION && defined(_UNICODE)) - CStr(utf16string String) : std::tstring(String.begin(), String.end()) {} - #endif + // CStr(8|W) construction from utf16strings. + // allowed on MSVC as of 2006-02-03 because utf16string is + // now distinct from CStrW. + CStr(utf16string String) : std::tstring(String.begin(), String.end()) {} // Transparent CStrW/8 conversion. Non-ASCII characters are not // handled correctly. diff --git a/source/ps/utf16string.h b/source/ps/utf16string.h index 9c8d7d2bf4..fa0e2f4b96 100755 --- a/source/ps/utf16string.h +++ b/source/ps/utf16string.h @@ -5,17 +5,9 @@ #ifndef utf16string_H #define utf16string_H -// On Windows, wchar_t is typedef'ed to unsigned short, which conflicts -// with uint16_t (which is also an unsigned short), so just use std::wstring -#if MSC_VERSION - -typedef wchar_t utf16_t; -typedef std::wstring utf16string; -typedef std::wstringstream utf16stringstream; - -// On Linux, wchar_t is 32-bit, so define a new version of it -#else - +// On Linux, wchar_t is 32-bit, so define a new version of it. +// We now use this code on Windows as well, because wchar_t is a +// native type and distinct from utf16_t. #include #include "lib/types.h" @@ -100,6 +92,4 @@ namespace std { }; } -#endif // #if MSC_VERSION / #else - #endif