00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef _POD_CHAR_TRAITS_H
00033 #define _POD_CHAR_TRAITS_H 1
00034
00035 #include <string>
00036
00037 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
00038
00039
00040
00041
00042
00043
00044 template<typename V, typename I, typename S = std::mbstate_t>
00045 struct character
00046 {
00047 typedef V value_type;
00048 typedef I int_type;
00049 typedef S state_type;
00050 typedef character<V, I, S> char_type;
00051
00052 value_type value;
00053
00054 template<typename V2>
00055 static char_type
00056 from(const V2& v)
00057 {
00058 char_type ret = { static_cast<value_type>(v) };
00059 return ret;
00060 }
00061
00062 template<typename V2>
00063 static V2
00064 to(const char_type& c)
00065 {
00066 V2 ret = { static_cast<V2>(c.value) };
00067 return ret;
00068 }
00069
00070 };
00071
00072 template<typename V, typename I, typename S>
00073 inline bool
00074 operator==(const character<V, I, S>& lhs, const character<V, I, S>& rhs)
00075 { return lhs.value == rhs.value; }
00076
00077 template<typename V, typename I, typename S>
00078 inline bool
00079 operator<(const character<V, I, S>& lhs, const character<V, I, S>& rhs)
00080 { return lhs.value < rhs.value; }
00081
00082 _GLIBCXX_END_NAMESPACE
00083
00084 _GLIBCXX_BEGIN_NAMESPACE(std)
00085
00086
00087 template<typename V, typename I, typename S>
00088 struct char_traits<__gnu_cxx::character<V, I, S> >
00089 {
00090 typedef __gnu_cxx::character<V, I, S> char_type;
00091 typedef typename char_type::int_type int_type;
00092 typedef typename char_type::state_type state_type;
00093 typedef fpos<state_type> pos_type;
00094 typedef streamoff off_type;
00095
00096 static void
00097 assign(char_type& __c1, const char_type& __c2)
00098 { __c1 = __c2; }
00099
00100 static bool
00101 eq(const char_type& __c1, const char_type& __c2)
00102 { return __c1 == __c2; }
00103
00104 static bool
00105 lt(const char_type& __c1, const char_type& __c2)
00106 { return __c1 < __c2; }
00107
00108 static int
00109 compare(const char_type* __s1, const char_type* __s2, size_t __n)
00110 {
00111 for (size_t __i = 0; __i < __n; ++__i)
00112 if (!eq(__s1[__i], __s2[__i]))
00113 return lt(__s1[__i], __s2[__i]) ? -1 : 1;
00114 return 0;
00115 }
00116
00117 static size_t
00118 length(const char_type* __s)
00119 {
00120 const char_type* __p = __s;
00121 while (__p->value)
00122 ++__p;
00123 return (__p - __s);
00124 }
00125
00126 static const char_type*
00127 find(const char_type* __s, size_t __n, const char_type& __a)
00128 {
00129 for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p)
00130 if (*__p == __a)
00131 return __p;
00132 return 0;
00133 }
00134
00135 static char_type*
00136 move(char_type* __s1, const char_type* __s2, size_t __n)
00137 {
00138 return static_cast<char_type*>
00139 (__builtin_memmove(__s1, __s2, __n * sizeof(char_type)));
00140 }
00141
00142 static char_type*
00143 copy(char_type* __s1, const char_type* __s2, size_t __n)
00144 {
00145 std::copy(__s2, __s2 + __n, __s1);
00146 return __s1;
00147 }
00148
00149 static char_type*
00150 assign(char_type* __s, size_t __n, char_type __a)
00151 {
00152 std::fill_n(__s, __n, __a);
00153 return __s;
00154 }
00155
00156 static char_type
00157 to_char_type(const int_type& __i)
00158 { return char_type::template from(__i); }
00159
00160 static int_type
00161 to_int_type(const char_type& __c)
00162 { return char_type::template to<int_type>(__c); }
00163
00164 static bool
00165 eq_int_type(const int_type& __c1, const int_type& __c2)
00166 { return __c1 == __c2; }
00167
00168 static int_type
00169 eof()
00170 {
00171 int_type __r = { -1 };
00172 return __r;
00173 }
00174
00175 static int_type
00176 not_eof(const int_type& __c)
00177 { return eq_int_type(__c, eof()) ? int_type() : __c; }
00178 };
00179
00180 _GLIBCXX_END_NAMESPACE
00181
00182 #endif