00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _STLP_CHAR_TRAITS_H
00020 #define _STLP_CHAR_TRAITS_H
00021
00022
00023
00024 # if defined (_STLP_OWN_IOSTREAMS) || ! defined (_STLP_USE_NEW_IOSTREAMS)
00025
00026 # if ! defined (_STLP_CSTDDEF)
00027 # include <cstddef>
00028 # endif
00029
00030 # if !defined (_STLP_CWCHAR)
00031 # include <cwchar>
00032 # endif
00033
00034 #if ! defined (_STLP_CSTRING)
00035 # include <cstring>
00036 #endif
00037
00038 #ifndef __TYPE_TRAITS_H
00039 # include <stl/type_traits.h>
00040 #endif
00041
00042 #if defined (_STLP_UNIX) && defined (_STLP_HAS_NO_NEW_C_HEADERS)
00043 #include <sys/types.h>
00044 #endif
00045
00046 #ifdef __BORLANDC__
00047 # include <mem.h>
00048 # include <string.h>
00049 # include <_stddef.h>
00050 class mbstate_t;
00051 #endif
00052
00053 _STLP_BEGIN_NAMESPACE
00054
00055 # ifdef _STLP_OWN_IOSTREAMS
00056
00057 template <class _Tp> class allocator;
00058
00059 #define _STLP_NULL_CHAR_INIT(_ChT) _STLP_DEFAULT_CONSTRUCTED(_ChT)
00060
00061 #if defined (__sgi) && defined (_STLP_HAS_NO_NEW_C_HEADERS)
00062 typedef off64_t streamoff;
00063
00064
00065 #else
00066
00067 typedef long streamoff;
00068 #endif
00069
00070 typedef ptrdiff_t streamsize;
00071
00072
00073
00074
00075 template <class _StateT> class fpos
00076 {
00077 public:
00078 fpos(streamoff __pos) : _M_pos(__pos), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
00079 fpos() : _M_pos(0), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
00080
00081 operator streamoff() const { return _M_pos; }
00082
00083 bool _STLP_CALL operator==(const fpos<_StateT>& __y) const
00084 { return _M_pos == __y._M_pos; }
00085 bool _STLP_CALL operator!=(const fpos<_StateT>& __y) const
00086 { return _M_pos != __y._M_pos; }
00087
00088 fpos<_StateT>& operator+=(streamoff __off) {
00089 _M_pos += __off;
00090 return *this;
00091 }
00092 fpos<_StateT>& operator-=(streamoff __off) {
00093 _M_pos -= __off;
00094 return *this;
00095 }
00096
00097 fpos<_StateT> operator+(streamoff __off) {
00098 fpos<_StateT> __tmp(*this);
00099 __tmp += __off;
00100 return __tmp;
00101 }
00102 fpos<_StateT> operator-(streamoff __off) {
00103 fpos<_StateT> __tmp(*this);
00104 __tmp -= __off;
00105 return __tmp;
00106 }
00107
00108 public:
00109 _StateT state() const { return _M_st; }
00110 void state(_StateT __st) { _M_st = __st; }
00111 private:
00112 streamoff _M_pos;
00113 _StateT _M_st;
00114 };
00115
00116 typedef fpos<mbstate_t> streampos;
00117 typedef fpos<mbstate_t> wstreampos;
00118 # endif
00119
00120
00121
00122 template <class _CharT, class _IntT> class __char_traits_base {
00123 public:
00124 typedef _CharT char_type;
00125 typedef _IntT int_type;
00126 #ifdef _STLP_USE_NEW_IOSTREAMS
00127 typedef streamoff off_type;
00128 typedef streampos pos_type;
00129 # ifdef _STLP_NO_MBSTATE_T
00130 typedef char state_type;
00131 # else
00132 typedef mbstate_t state_type;
00133 # endif
00134 #endif
00135
00136 static void _STLP_CALL assign(char_type& __c1, const char_type& __c2) { __c1 = __c2; }
00137 static bool _STLP_CALL eq(const _CharT& __c1, const _CharT& __c2)
00138 { return __c1 == __c2; }
00139 static bool _STLP_CALL lt(const _CharT& __c1, const _CharT& __c2)
00140 { return __c1 < __c2; }
00141
00142 static int _STLP_CALL compare(const _CharT* __s1, const _CharT* __s2, size_t __n) {
00143 for (size_t __i = 0; __i < __n; ++__i)
00144 if (!eq(__s1[__i], __s2[__i]))
00145 return __s1[__i] < __s2[__i] ? -1 : 1;
00146 return 0;
00147 }
00148
00149 static size_t _STLP_CALL length(const _CharT* __s) {
00150 const _CharT _NullChar = _STLP_DEFAULT_CONSTRUCTED(_CharT);
00151 size_t __i;
00152 for (__i = 0; !eq(__s[__i], _NullChar); ++__i)
00153 {}
00154 return __i;
00155 }
00156
00157 static const _CharT* _STLP_CALL find(const _CharT* __s, size_t __n, const _CharT& __c) {
00158 for ( ; __n > 0 ; ++__s, --__n)
00159 if (eq(*__s, __c))
00160 return __s;
00161 return 0;
00162 }
00163
00164
00165 static _CharT* _STLP_CALL move(_CharT* __s1, const _CharT* __s2, size_t _Sz) {
00166 return (_Sz == 0 ? __s1 : (_CharT*)memmove(__s1, __s2, _Sz * sizeof(_CharT)));
00167 }
00168
00169 static _CharT* _STLP_CALL copy(_CharT* __s1, const _CharT* __s2, size_t __n) {
00170 return (__n == 0 ? __s1 :
00171 (_CharT*)memcpy(__s1, __s2, __n * sizeof(_CharT)));
00172 }
00173
00174 static _CharT* _STLP_CALL assign(_CharT* __s, size_t __n, _CharT __c) {
00175 for (size_t __i = 0; __i < __n; ++__i)
00176 __s[__i] = __c;
00177 return __s;
00178 }
00179
00180 static int_type _STLP_CALL not_eof(const int_type& __c) {
00181 return !eq_int_type(__c, eof()) ? __c : __STATIC_CAST(int_type, 0);
00182 }
00183
00184 static char_type _STLP_CALL to_char_type(const int_type& __c) {
00185 return (char_type)__c;
00186 }
00187
00188 static int_type _STLP_CALL to_int_type(const char_type& __c) {
00189 return (int_type)__c;
00190 }
00191
00192 static bool _STLP_CALL eq_int_type(const int_type& __c1, const int_type& __c2) {
00193 return __c1 == __c2;
00194 }
00195
00196 static int_type _STLP_CALL eof() {
00197 return (int_type)-1;
00198
00199 }
00200 };
00201
00202
00203
00204
00205
00206
00207 template <class _CharT> class char_traits
00208 : public __char_traits_base<_CharT, _CharT>
00209 {};
00210
00211
00212
00213 _STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC char_traits<char>
00214 : public __char_traits_base<char, int>
00215 {
00216 public:
00217 typedef char char_type;
00218 typedef int int_type;
00219 #ifdef _STLP_USE_NEW_IOSTREAMS
00220 typedef streamoff off_type;
00221 # ifndef _STLP_NO_MBSTATE_T
00222 typedef streampos pos_type;
00223 typedef mbstate_t state_type;
00224 # endif
00225 #endif
00226
00227 static char _STLP_CALL to_char_type(const int& __c) {
00228 return (char)(unsigned char)__c;
00229 }
00230
00231 static int _STLP_CALL to_int_type(const char& __c) {
00232 return (unsigned char)__c;
00233 }
00234
00235 static int _STLP_CALL compare(const char* __s1, const char* __s2, size_t __n)
00236 { return memcmp(__s1, __s2, __n); }
00237
00238 static size_t _STLP_CALL length(const char* __s) { return strlen(__s); }
00239
00240 static void _STLP_CALL assign(char& __c1, const char& __c2) { __c1 = __c2; }
00241
00242 static char* _STLP_CALL assign(char* __s, size_t __n, char __c)
00243 { memset(__s, __c, __n); return __s; }
00244 };
00245
00246 # if defined (_STLP_HAS_WCHAR_T)
00247
00248 _STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC char_traits<wchar_t>
00249 : public __char_traits_base<wchar_t, wint_t>
00250 {};
00251 # endif
00252
00253 _STLP_END_NAMESPACE
00254
00255 # else
00256
00257 # include <wrap_std/iosfwd>
00258
00259 # endif
00260
00261 #endif
00262
00263
00264
00265
00266