On Friday 03 September 2004 09:41, Markus Ottenbacher wrote:
[snip]
> ... or SuSE 8.2/9.1 users (gcc 3.3 and gcc 3.3.3)...
>
> Could anyone explain above mentioned workaround? "making an adapted
> copy-paste of the 'char_traits.h' file" seems rather vague to me.
The standard C++ library distributed with g++ 3.3.x and below properly
forward declares std::char_traits as defined in the C++ standard... but
it doesn't actually implement them. It actually only implements 2
specializations: char and wchar_t. What this means is that if you try
to use std::basic_string with anything other than char or wchar_t, you
will get undefined symbols.
Since this is C++, we can work around this, and have it work on all
standard compliant compilers :) We need to define our own character
type (typedef unsigned int Uchar;), and then implement a specialization
of std::char_traits for our character type. See the attached diff (I
plan on putting this into CVS as soon as I verify it with a few more
compilers). So far, I've checked g++ 3.3, g++ 3.4 and intel 8.0. I'm
going to try intel 7.1 and g++ 3.2 before committing.
> markus
--
Bradley T. Hughes - bhughes at trolltech.com
Trolltech AS - Waldemar Thranes gt. 98 N-0175 Oslo, Norway
Index: lib/Unicode.hh
===================================================================
RCS file: /cvsroot/blackboxwm/blackbox/lib/Unicode.hh,v
retrieving revision 1.3
diff -b -u -r1.3 Unicode.hh
--- lib/Unicode.hh 2 Sep 2004 07:22:08 -0000 1.3
+++ lib/Unicode.hh 3 Sep 2004 08:10:26 -0000
@@ -35,9 +35,14 @@
bool hasUnicode();
/*
+ * Unicode character type.
+ */
+ typedef unsigned int Uchar;
+
+ /*
* Unicode string type.
*/
- typedef std::basic_string<unsigned int> ustring;
+ typedef std::basic_string<Uchar> ustring;
/*
* Converts multibyte locale-encoded string to wide-char Unicode
@@ -63,4 +68,104 @@
} // namespace bt
+/*
+ * Workaround incomplete std::char_traits<> implementation in come
+ * versions of the GNU C++ compiler.
+ */
+#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
+namespace std {
+
+ template<>
+ struct char_traits<bt::Uchar>
+ {
+ typedef bt::Uchar char_type;
+ typedef unsigned int int_type;
+ typedef streampos pos_type;
+ typedef streamoff off_type;
+ typedef mbstate_t state_type;
+
+ static void
+ assign(bt::Uchar &c1, const bt::Uchar &c2)
+ { c1 = c2; }
+
+ static bool
+ eq(const bt::Uchar &c1, const bt::Uchar &c2)
+ { return c1 == c2; }
+
+ static bool
+ lt(const bt::Uchar &c1, const bt::Uchar &c2)
+ { return c1 < c2; }
+
+ static int
+ compare(const bt::Uchar *s1, const bt::Uchar *s2, size_t n) {
+ for (size_t x = 0; x < n; ++x) {
+ if (lt(s1[x], s2[x]))
+ return -1;
+ if (lt(s2[x], s1[x]))
+ return 1;
+ }
+ return 0;
+ }
+
+ static size_t
+ length(const bt::Uchar *s)
+ {
+ size_t x = 0;
+ while (!eq(s[x], bt::Uchar()))
+ ++x;
+ return x;
+ }
+
+ static const bt::Uchar *
+ find(const bt::Uchar *s, std::size_t n, const bt::Uchar &c)
+ {
+ for (std::size_t x = 0; x < n; ++x)
+ if (eq(s[x], c))
+ return s + x;
+ return 0;
+ }
+
+ static bt::Uchar *
+ move(bt::Uchar *d, const bt::Uchar *s, std::size_t n) {
+ return (static_cast<bt::Uchar *>
+ (std::memmove(d, s, n *sizeof(bt::Uchar ))));
+ }
+
+ static bt::Uchar *
+ copy(bt::Uchar *d, const bt::Uchar *s, std::size_t n) {
+ std::copy(s, s + n, d);
+ return d;
+ }
+
+ static bt::Uchar *
+ assign(bt::Uchar *s, std::size_t n, bt::Uchar c) {
+ std::fill_n(s, n, c);
+ return s;
+ }
+
+ static bt::Uchar
+ to_char_type(const unsigned int &c)
+ { return c; }
+
+ static unsigned int
+ to_int_type(const bt::Uchar &c)
+ { return c; }
+
+ static bool
+ eq_int_type(const unsigned int &c1, const unsigned int &c2)
+ { return c1 == c2; }
+
+ static int_type
+ eof()
+ { return static_cast<unsigned int>(EOF); }
+
+ static unsigned int
+ not_eof(const unsigned int &c)
+ { return (c == eof()) ? 0 : c; }
+
+ };
+
+} // namespace std
+#endif // __GNU__ && !__INTEL_COMPILER
+
#endif // __Unicode_hh
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
List archives: http://asgardsrealm.net/lurker/splash/index.html
Trouble? Contact [EMAIL PROTECTED]