williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* Copyright (c) 1996,1997
|
williamr@2
|
3 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@2
|
4 |
*
|
williamr@2
|
5 |
* Copyright (c) 1999
|
williamr@2
|
6 |
* Boris Fomitchev
|
williamr@2
|
7 |
*
|
williamr@2
|
8 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@2
|
9 |
* or implied. Any use is at your own risk.
|
williamr@2
|
10 |
*
|
williamr@2
|
11 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@2
|
12 |
* without fee, provided the above notices are retained on all copies.
|
williamr@2
|
13 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@2
|
14 |
* provided the above notices are retained, and a notice that the code was
|
williamr@2
|
15 |
* modified is included with the above copyright notice.
|
williamr@2
|
16 |
*
|
williamr@2
|
17 |
*/
|
williamr@2
|
18 |
|
williamr@2
|
19 |
#ifndef _STLP_CHAR_TRAITS_H
|
williamr@2
|
20 |
#define _STLP_CHAR_TRAITS_H
|
williamr@2
|
21 |
|
williamr@2
|
22 |
// Define char_traits
|
williamr@2
|
23 |
|
williamr@4
|
24 |
#ifndef _STLP_INTERNAL_CSTDDEF
|
williamr@4
|
25 |
# include <stl/_cstddef.h>
|
williamr@2
|
26 |
#endif
|
williamr@2
|
27 |
|
williamr@4
|
28 |
#ifndef _STLP_INTERNAL_CSTRING
|
williamr@4
|
29 |
# include <stl/_cstring.h>
|
williamr@4
|
30 |
#endif
|
williamr@4
|
31 |
|
williamr@4
|
32 |
#if defined (__unix) || defined (N_PLAT_NLM)
|
williamr@4
|
33 |
# include <sys/types.h> // For off_t
|
williamr@2
|
34 |
#endif /* __unix */
|
williamr@2
|
35 |
|
williamr@2
|
36 |
#ifdef __BORLANDC__
|
williamr@4
|
37 |
# include _STLP_NATIVE_C_HEADER(mem.h)
|
williamr@4
|
38 |
# include _STLP_NATIVE_C_HEADER(string.h)
|
williamr@4
|
39 |
# include _STLP_NATIVE_C_HEADER(_stddef.h)
|
williamr@2
|
40 |
#endif
|
williamr@2
|
41 |
|
williamr@4
|
42 |
#ifndef _STLP_INTERNAL_CONSTRUCT_H
|
williamr@4
|
43 |
# include <stl/_construct.h>
|
williamr@2
|
44 |
#endif
|
williamr@2
|
45 |
|
williamr@4
|
46 |
#ifndef _STLP_INTERNAL_CWCHAR
|
williamr@2
|
47 |
# include <stl/_cwchar.h>
|
williamr@4
|
48 |
#endif
|
williamr@2
|
49 |
|
williamr@2
|
50 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
51 |
|
williamr@2
|
52 |
template <class _Tp> class allocator;
|
williamr@2
|
53 |
|
williamr@2
|
54 |
#define _STLP_NULL_CHAR_INIT(_ChT) _STLP_DEFAULT_CONSTRUCTED(_ChT)
|
williamr@2
|
55 |
|
williamr@2
|
56 |
#if defined (__sgi) && defined (_STLP_HAS_NO_NEW_C_HEADERS) /* IRIX */
|
williamr@4
|
57 |
typedef off64_t streamoff;
|
williamr@4
|
58 |
#elif defined(_STLP_WCE)
|
williamr@2
|
59 |
typedef long streamoff;
|
williamr@4
|
60 |
#elif defined (_STLP_WIN32)
|
williamr@4
|
61 |
# if defined (_STLP_LONG_LONG) && !defined (__CYGWIN__)
|
williamr@4
|
62 |
//The Win32 file io API support 64 bits access so streamoff and streamsize
|
williamr@4
|
63 |
//has to reflect that. Do not change the stringbuf behavior.
|
williamr@4
|
64 |
typedef _STLP_LONG_LONG streamoff;
|
williamr@4
|
65 |
# else
|
williamr@4
|
66 |
typedef ptrdiff_t streamoff;
|
williamr@4
|
67 |
# endif
|
williamr@4
|
68 |
#else // __unix
|
williamr@4
|
69 |
# ifdef _STLP_USE_DEFAULT_FILE_OFFSET
|
williamr@4
|
70 |
typedef off_t streamoff;
|
williamr@4
|
71 |
# elif defined(_LARGEFILE_SOURCE) || defined(_LARGEFILE64_SOURCE) /* || defined(__USE_FILE_OFFSET64) */ \
|
williamr@4
|
72 |
/* || (defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)) */ /* || defined (__sgi) && defined (_STLP_HAS_NO_NEW_C_HEADERS) */
|
williamr@4
|
73 |
typedef off64_t streamoff;
|
williamr@4
|
74 |
# else
|
williamr@4
|
75 |
typedef off_t streamoff;
|
williamr@4
|
76 |
# endif
|
williamr@4
|
77 |
#endif /* ___unix */
|
williamr@2
|
78 |
|
williamr@4
|
79 |
#if defined (_STLP_WIN32)
|
williamr@4
|
80 |
typedef streamoff streamsize;
|
williamr@4
|
81 |
#else
|
williamr@2
|
82 |
typedef ptrdiff_t streamsize;
|
williamr@4
|
83 |
#endif
|
williamr@2
|
84 |
|
williamr@2
|
85 |
// Class fpos, which represents a position within a file. (The C++
|
williamr@2
|
86 |
// standard calls for it to be defined in <ios>. This implementation
|
williamr@2
|
87 |
// moves it to <iosfwd>, which is included by <ios>.)
|
williamr@4
|
88 |
template <class _StateT> class fpos {
|
williamr@2
|
89 |
public: // From table 88 of the C++ standard.
|
williamr@2
|
90 |
fpos(streamoff __pos) : _M_pos(__pos), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
|
williamr@2
|
91 |
fpos() : _M_pos(0), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
|
williamr@2
|
92 |
|
williamr@2
|
93 |
operator streamoff() const { return _M_pos; }
|
williamr@2
|
94 |
|
williamr@4
|
95 |
bool operator==(const fpos& __y) const
|
williamr@4
|
96 |
{ return _M_pos == __y._M_pos; }
|
williamr@4
|
97 |
bool operator!=(const fpos& __y) const
|
williamr@4
|
98 |
{ return _M_pos != __y._M_pos; }
|
williamr@2
|
99 |
|
williamr@4
|
100 |
fpos& operator+=(streamoff __off) {
|
williamr@2
|
101 |
_M_pos += __off;
|
williamr@2
|
102 |
return *this;
|
williamr@2
|
103 |
}
|
williamr@4
|
104 |
fpos& operator-=(streamoff __off) {
|
williamr@2
|
105 |
_M_pos -= __off;
|
williamr@2
|
106 |
return *this;
|
williamr@2
|
107 |
}
|
williamr@2
|
108 |
|
williamr@4
|
109 |
fpos operator+(streamoff __off) {
|
williamr@4
|
110 |
fpos __tmp(*this);
|
williamr@2
|
111 |
__tmp += __off;
|
williamr@2
|
112 |
return __tmp;
|
williamr@2
|
113 |
}
|
williamr@4
|
114 |
fpos operator-(streamoff __off) {
|
williamr@4
|
115 |
fpos __tmp(*this);
|
williamr@2
|
116 |
__tmp -= __off;
|
williamr@2
|
117 |
return __tmp;
|
williamr@2
|
118 |
}
|
williamr@2
|
119 |
|
williamr@2
|
120 |
public: // Manipulation of the state member.
|
williamr@2
|
121 |
_StateT state() const { return _M_st; }
|
williamr@2
|
122 |
void state(_StateT __st) { _M_st = __st; }
|
williamr@2
|
123 |
private:
|
williamr@2
|
124 |
streamoff _M_pos;
|
williamr@2
|
125 |
_StateT _M_st;
|
williamr@2
|
126 |
};
|
williamr@2
|
127 |
|
williamr@4
|
128 |
#if !defined (_STLP_NO_MBSTATE_T)
|
williamr@2
|
129 |
typedef fpos<mbstate_t> streampos;
|
williamr@2
|
130 |
typedef fpos<mbstate_t> wstreampos;
|
williamr@4
|
131 |
#endif
|
williamr@2
|
132 |
|
williamr@2
|
133 |
// Class __char_traits_base.
|
williamr@4
|
134 |
template <class _CharT, class _IntT>
|
williamr@4
|
135 |
class __char_traits_base {
|
williamr@2
|
136 |
public:
|
williamr@2
|
137 |
typedef _CharT char_type;
|
williamr@2
|
138 |
typedef _IntT int_type;
|
williamr@2
|
139 |
typedef streamoff off_type;
|
williamr@2
|
140 |
typedef streampos pos_type;
|
williamr@4
|
141 |
#if defined (_STLP_NO_MBSTATE_T)
|
williamr@2
|
142 |
typedef char state_type;
|
williamr@4
|
143 |
#else
|
williamr@2
|
144 |
typedef mbstate_t state_type;
|
williamr@4
|
145 |
#endif
|
williamr@2
|
146 |
|
williamr@2
|
147 |
static void _STLP_CALL assign(char_type& __c1, const char_type& __c2) { __c1 = __c2; }
|
williamr@4
|
148 |
static bool _STLP_CALL eq(const char_type& __c1, const char_type& __c2)
|
williamr@4
|
149 |
{ return __c1 == __c2; }
|
williamr@4
|
150 |
static bool _STLP_CALL lt(const char_type& __c1, const char_type& __c2)
|
williamr@4
|
151 |
{ return __c1 < __c2; }
|
williamr@2
|
152 |
|
williamr@4
|
153 |
static int _STLP_CALL compare(const char_type* __s1, const char_type* __s2, size_t __n) {
|
williamr@2
|
154 |
for (size_t __i = 0; __i < __n; ++__i)
|
williamr@2
|
155 |
if (!eq(__s1[__i], __s2[__i]))
|
williamr@2
|
156 |
return __s1[__i] < __s2[__i] ? -1 : 1;
|
williamr@2
|
157 |
return 0;
|
williamr@2
|
158 |
}
|
williamr@2
|
159 |
|
williamr@4
|
160 |
static size_t _STLP_CALL length(const char_type* __s) {
|
williamr@4
|
161 |
const char_type _NullChar = _STLP_DEFAULT_CONSTRUCTED(char_type);
|
williamr@4
|
162 |
size_t __i(0);
|
williamr@4
|
163 |
for (; !eq(__s[__i], _NullChar); ++__i) {}
|
williamr@2
|
164 |
return __i;
|
williamr@2
|
165 |
}
|
williamr@2
|
166 |
|
williamr@4
|
167 |
static const char_type* _STLP_CALL find(const char_type* __s, size_t __n, const char_type& __c) {
|
williamr@2
|
168 |
for ( ; __n > 0 ; ++__s, --__n)
|
williamr@2
|
169 |
if (eq(*__s, __c))
|
williamr@2
|
170 |
return __s;
|
williamr@2
|
171 |
return 0;
|
williamr@2
|
172 |
}
|
williamr@2
|
173 |
|
williamr@4
|
174 |
static char_type* _STLP_CALL move(char_type* __s1, const char_type* __s2, size_t _Sz)
|
williamr@4
|
175 |
{ return (_Sz == 0 ? __s1 : (char_type*)memmove(__s1, __s2, _Sz * sizeof(char_type))); }
|
williamr@2
|
176 |
|
williamr@4
|
177 |
static char_type* _STLP_CALL copy(char_type* __s1, const char_type* __s2, size_t __n) {
|
williamr@4
|
178 |
return (__n == 0 ? __s1 :
|
williamr@4
|
179 |
(char_type*)memcpy(__s1, __s2, __n * sizeof(char_type)));
|
williamr@2
|
180 |
}
|
williamr@2
|
181 |
|
williamr@4
|
182 |
static char_type* _STLP_CALL assign(char_type* __s, size_t __n, char_type __c) {
|
williamr@2
|
183 |
for (size_t __i = 0; __i < __n; ++__i)
|
williamr@2
|
184 |
__s[__i] = __c;
|
williamr@2
|
185 |
return __s;
|
williamr@2
|
186 |
}
|
williamr@2
|
187 |
|
williamr@4
|
188 |
static int_type _STLP_CALL not_eof(const int_type& __c)
|
williamr@4
|
189 |
{ return !eq_int_type(__c, eof()) ? __c : __STATIC_CAST(int_type, 0); }
|
williamr@2
|
190 |
|
williamr@4
|
191 |
static char_type _STLP_CALL to_char_type(const int_type& __c)
|
williamr@4
|
192 |
{ return (char_type)__c; }
|
williamr@2
|
193 |
|
williamr@4
|
194 |
static int_type _STLP_CALL to_int_type(const char_type& __c)
|
williamr@4
|
195 |
{ return (int_type)__c; }
|
williamr@2
|
196 |
|
williamr@4
|
197 |
static bool _STLP_CALL eq_int_type(const int_type& __c1, const int_type& __c2)
|
williamr@4
|
198 |
{ return __c1 == __c2; }
|
williamr@2
|
199 |
|
williamr@4
|
200 |
static int_type _STLP_CALL eof()
|
williamr@4
|
201 |
{ return (int_type)-1; }
|
williamr@2
|
202 |
};
|
williamr@2
|
203 |
|
williamr@2
|
204 |
// Generic char_traits class. Note that this class is provided only
|
williamr@2
|
205 |
// as a base for explicit specialization; it is unlikely to be useful
|
williamr@2
|
206 |
// as is for any particular user-defined type. In particular, it
|
williamr@2
|
207 |
// *will not work* for a non-POD type.
|
williamr@2
|
208 |
|
williamr@4
|
209 |
template <class _CharT>
|
williamr@4
|
210 |
class char_traits
|
williamr@4
|
211 |
: public __char_traits_base<_CharT, _CharT> {};
|
williamr@2
|
212 |
|
williamr@2
|
213 |
// Specialization for char.
|
williamr@2
|
214 |
|
williamr@4
|
215 |
_STLP_TEMPLATE_NULL
|
williamr@4
|
216 |
class _STLP_CLASS_DECLSPEC char_traits<char>
|
williamr@4
|
217 |
: public __char_traits_base<char, int> {
|
williamr@2
|
218 |
public:
|
williamr@2
|
219 |
typedef char char_type;
|
williamr@2
|
220 |
typedef int int_type;
|
williamr@2
|
221 |
typedef streamoff off_type;
|
williamr@4
|
222 |
#if !defined (_STLP_NO_MBSTATE_T)
|
williamr@2
|
223 |
typedef streampos pos_type;
|
williamr@2
|
224 |
typedef mbstate_t state_type;
|
williamr@4
|
225 |
#endif
|
williamr@2
|
226 |
|
williamr@4
|
227 |
static char _STLP_CALL to_char_type(const int& __c)
|
williamr@4
|
228 |
{ return (char)(unsigned char)__c; }
|
williamr@2
|
229 |
|
williamr@4
|
230 |
static int _STLP_CALL to_int_type(const char& __c)
|
williamr@4
|
231 |
{ return (unsigned char)__c; }
|
williamr@2
|
232 |
|
williamr@2
|
233 |
static int _STLP_CALL compare(const char* __s1, const char* __s2, size_t __n)
|
williamr@4
|
234 |
{ return memcmp(__s1, __s2, __n); }
|
williamr@2
|
235 |
|
williamr@4
|
236 |
static size_t _STLP_CALL length(const char* __s)
|
williamr@4
|
237 |
{ return strlen(__s); }
|
williamr@2
|
238 |
|
williamr@4
|
239 |
static void _STLP_CALL assign(char& __c1, const char& __c2)
|
williamr@4
|
240 |
{ __c1 = __c2; }
|
williamr@2
|
241 |
|
williamr@4
|
242 |
static char* _STLP_CALL assign(char* __s, size_t __n, char __c) {
|
williamr@4
|
243 |
memset(__s, __c, __n);
|
williamr@4
|
244 |
return __s;
|
williamr@4
|
245 |
}
|
williamr@2
|
246 |
};
|
williamr@2
|
247 |
|
williamr@4
|
248 |
#if defined (_STLP_HAS_WCHAR_T)
|
williamr@2
|
249 |
// Specialization for wchar_t.
|
williamr@4
|
250 |
_STLP_TEMPLATE_NULL
|
williamr@4
|
251 |
class _STLP_CLASS_DECLSPEC char_traits<wchar_t>
|
williamr@4
|
252 |
: public __char_traits_base<wchar_t, wint_t> {
|
williamr@4
|
253 |
# if !defined (_STLP_NO_NATIVE_WIDE_FUNCTIONS) && !defined (_STLP_WCHAR_HPACC_EXCLUDE)
|
williamr@4
|
254 |
public:
|
williamr@4
|
255 |
# if !defined (N_PLAT_NLM)
|
williamr@4
|
256 |
# if !defined (__BORLANDC__)
|
williamr@4
|
257 |
static wchar_t* _STLP_CALL move(wchar_t* __dest, const wchar_t* __src, size_t __n)
|
williamr@4
|
258 |
{ return wmemmove(__dest, __src, __n); }
|
williamr@4
|
259 |
# endif
|
williamr@4
|
260 |
|
williamr@4
|
261 |
static wchar_t* _STLP_CALL copy(wchar_t* __dest, const wchar_t* __src, size_t __n)
|
williamr@4
|
262 |
{ return wmemcpy(__dest, __src, __n); }
|
williamr@4
|
263 |
|
williamr@4
|
264 |
# if !defined (__DMC__) && !defined (__BORLANDC__)
|
williamr@4
|
265 |
static int _STLP_CALL compare(const wchar_t* __s1, const wchar_t* __s2, size_t __n)
|
williamr@4
|
266 |
{ return wmemcmp(__s1, __s2, __n); }
|
williamr@4
|
267 |
# endif
|
williamr@4
|
268 |
|
williamr@4
|
269 |
static wchar_t* _STLP_CALL assign(wchar_t* __s, size_t __n, wchar_t __c)
|
williamr@4
|
270 |
{ return wmemset(__s, __c, __n); }
|
williamr@4
|
271 |
# endif
|
williamr@4
|
272 |
|
williamr@4
|
273 |
static size_t _STLP_CALL length(const wchar_t* __s)
|
williamr@4
|
274 |
{ return wcslen(__s); }
|
williamr@4
|
275 |
|
williamr@4
|
276 |
static void _STLP_CALL assign(wchar_t& __c1, const wchar_t& __c2)
|
williamr@4
|
277 |
{ __c1 = __c2; }
|
williamr@4
|
278 |
# endif
|
williamr@4
|
279 |
};
|
williamr@4
|
280 |
#endif
|
williamr@2
|
281 |
|
williamr@2
|
282 |
_STLP_END_NAMESPACE
|
williamr@2
|
283 |
|
williamr@2
|
284 |
#endif /* _STLP_CHAR_TRAITS_H */
|
williamr@2
|
285 |
|
williamr@2
|
286 |
// Local Variables:
|
williamr@2
|
287 |
// mode:C++
|
williamr@2
|
288 |
// End:
|