Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_traits.h
Go to the documentation of this file.
1
32#ifndef _RWSTD_RW_TRAITS_H_INCLUDED
33#define _RWSTD_RW_TRAITS_H_INCLUDED
34
35#ifndef _RWSTD_RW_IOSFWD_H_INCLUDED
36# include <rw/_iosfwd.h>
37#endif // _RWSTD_RW_IOSFWD_H_INCLUDED
38
39#ifndef _RWSTD_RW_MBSTATE_H_INCLUDED
40# include <rw/_mbstate.h> // for _RWSTD_MBSTATE_T
41#endif // _RWSTD_RW_MBSTATE_H_INCLUDED
42
43
44#if defined (_RWSTDDEBUG) || defined (_RWSTD_EDG_ECCP)
45
46// avoid including <cstring> and <cwchar> in debug mode or when using
47// the vanilla EDG eccp (i.e., in strict conformance mode) to prevent
48// namespace pollutiuon
49
51
52_RWSTD_EXPORT void* __rw_memcpy (void*, const void*, _RWSTD_SIZE_T);
53_RWSTD_EXPORT void* __rw_memmove (void*, const void*, _RWSTD_SIZE_T);
54_RWSTD_EXPORT const void* __rw_memchr (const void*, int, _RWSTD_SIZE_T);
55_RWSTD_EXPORT void* __rw_memset (void*, int, _RWSTD_SIZE_T);
56_RWSTD_EXPORT int __rw_memcmp (const void*, const void*, _RWSTD_SIZE_T);
57_RWSTD_EXPORT _RWSTD_SIZE_T __rw_strlen (const char*);
58
59# ifndef _RWSTD_NO_WCHAR_T
60
61_RWSTD_EXPORT wchar_t* __rw_wmemcpy (wchar_t*, const wchar_t*, _RWSTD_SIZE_T);
62_RWSTD_EXPORT wchar_t* __rw_wmemmove (wchar_t*, const wchar_t*, _RWSTD_SIZE_T);
63_RWSTD_EXPORT const wchar_t*
64__rw_wmemchr (const wchar_t*, wchar_t, _RWSTD_SIZE_T);
65_RWSTD_EXPORT wchar_t* __rw_wmemset (wchar_t*, wchar_t, _RWSTD_SIZE_T);
66_RWSTD_EXPORT int __rw_wmemcmp (const wchar_t*, const wchar_t*, _RWSTD_SIZE_T);
67_RWSTD_EXPORT _RWSTD_SIZE_T __rw_wcslen (const wchar_t*);
68
69# endif // _RWSTD_NO_WCHAR_T
70
71} // namespace __rw
72
73# define _RWSTD_MEMCPY _RW::__rw_memcpy
74# define _RWSTD_MEMCMP _RW::__rw_memcmp
75# define _RWSTD_MEMCHR _RW::__rw_memchr
76# define _RWSTD_MEMMOVE _RW::__rw_memmove
77# define _RWSTD_MEMSET _RW::__rw_memset
78# define _RWSTD_STRLEN _RW::__rw_strlen
79
80# define _RWSTD_WMEMCPY _RW::__rw_wmemcpy
81# define _RWSTD_WMEMCMP _RW::__rw_wmemcmp
82# define _RWSTD_WMEMCHR _RW::__rw_wmemchr
83# define _RWSTD_WMEMMOVE _RW::__rw_wmemmove
84# define _RWSTD_WMEMSET _RW::__rw_wmemset
85# define _RWSTD_WCSLEN _RW::__rw_wcslen
86#else // if !defined (_RWSTDDEBUG) && !defined (_RWSTD_EDG_ECCP)
87
88# if 4 <= __GNUG__ && !defined (__INTEL_COMPILER)
89 // use gcc 4.x intrinsic functions
90# define _RWSTD_MEMCPY __builtin_memcpy
91# define _RWSTD_MEMCMP __builtin_memcmp
92# define _RWSTD_MEMMOVE __builtin_memmove
93# define _RWSTD_MEMSET __builtin_memset
94# define _RWSTD_STRLEN __builtin_strlen
95
96# if 4 < __GNUG__ || 3 <= __GNUC_MINOR__
97 // __builtin_memchr() is only available in gcc 4.3 and beyond
98# define _RWSTD_MEMCHR __builtin_memchr
99# else // gcc < 4.3
100# include _RWSTD_CSTRING // for memchr()
101# define _RWSTD_MEMCHR _RWSTD_C::memchr
102# endif // gcc 4.3
103# else // gcc < 4.0
104# include _RWSTD_CSTRING // for memcmp(), ...
105
106# define _RWSTD_MEMCPY _RWSTD_C::memcpy
107# define _RWSTD_MEMCMP _RWSTD_C::memcmp
108# define _RWSTD_MEMMOVE _RWSTD_C::memmove
109# define _RWSTD_MEMSET _RWSTD_C::memset
110# define _RWSTD_STRLEN _RWSTD_C::strlen
111# define _RWSTD_MEMCHR _RWSTD_C::memchr
112# endif // gcc 4.0
113
114# include _RWSTD_CWCHAR // wmemcmp(), ...
115
116# ifndef _RWSTD_NO_WMEMCPY
117# define _RWSTD_WMEMCPY _RWSTD_C::wmemcpy
118# elif !defined (_RWSTD_NO_WCHAR_T)
119
121
122_RWSTD_EXPORT wchar_t*
123__rw_wmemcpy (wchar_t*, const wchar_t*, _RWSTD_SIZE_T);
124
125
126} // namespace __rw
127
128# define _RWSTD_WMEMCPY _RW::__rw_wmemcpy
129# endif // _RWSTD_NO_WMEMCPY
130
131# ifndef _RWSTD_NO_WMEMCMP
132# define _RWSTD_WMEMCMP wmemcmp
133# elif !defined (_RWSTD_NO_WCHAR_T)
134
136
138__rw_wmemcmp (const wchar_t*, const wchar_t*, _RWSTD_SIZE_T);
139
140
141} // namespace __rw
142
143# define _RWSTD_WMEMCMP _RW::__rw_wmemcmp
144# endif // _RWSTD_NO_WMEMCMP
145
146# ifndef _RWSTD_NO_WMEMMOVE
147# define _RWSTD_WMEMMOVE _RWSTD_C::wmemmove
148# elif !defined (_RWSTD_NO_WCHAR_T)
149
151
152_RWSTD_EXPORT wchar_t*
153__rw_wmemmove (wchar_t*, const wchar_t*, _RWSTD_SIZE_T);
154
155
156} // namespace __rw
157
158# define _RWSTD_WMEMMOVE _RW::__rw_wmemmove
159# endif // _RWSTD_NO_WMEMMOVE
160
161# ifndef _RWSTD_NO_WMEMSET
162# define _RWSTD_WMEMSET _RWSTD_C::wmemset
163# elif !defined (_RWSTD_NO_WCHAR_T)
164
166
167_RWSTD_EXPORT wchar_t*
168__rw_wmemset (wchar_t*, wchar_t, _RWSTD_SIZE_T);
169
170
171} // namespace __rw
172
173# define _RWSTD_WMEMSET _RW::__rw_wmemset
174# endif // _RWSTD_NO_WMEMSET
175
176# ifndef _RWSTD_NO_WCSLEN
177# define _RWSTD_WCSLEN _RWSTD_C::wcslen
178# elif !defined (_RWSTD_NO_WCHAR_T)
179
181
182_RWSTD_EXPORT _RWSTD_SIZE_T
183__rw_wcslen (const wchar_t*);
184
185
186} // namespace __rw
187
188# define _RWSTD_WCSLEN _RW::__rw_wcslen
189# endif // _RWSTD_NO_WCSLEN
190
191# ifndef _RWSTD_NO_WMEMCHR
192# define _RWSTD_WMEMCHR _RWSTD_C::wmemchr
193# elif !defined (_RWSTD_NO_WCHAR_T)
194
196
197_RWSTD_EXPORT const wchar_t*
198__rw_wmemchr (const wchar_t*, wchar_t, _RWSTD_SIZE_T);
199
200
201} // namespace __rw
202
203# define _RWSTD_WMEMCHR _RW::__rw_wmemchr
204# endif // _RWSTD_NO_WMEMCHR
205
206#endif // !_RWSTDDEBUG && !(vanilla EDG eccp demo)
207
208
210
211
212// 27.4.1, p2
213// the C++ type ptrdiff_t is the same as the POSIX ssize_t suggested
214// to be used here in 27.4.2, Footnote 266, except for Win64 where
215// the former is 64 bits while the latter is only 32 bits wide
216typedef _RWSTD_PTRDIFF_T streamsize;
217
218
219// 27.4.3
220template <class _StateT>
221class fpos
222{
223public:
224
225 typedef _StateT state_type;
226
227#ifndef _RWSTD_NO_POD_ZERO_INIT
228
229 fpos (_RWSTD_STREAMOFF __off = 0,
230 const state_type &__state = state_type ())
231 : _C_pos (__off),
232 _C_state (__state)
233 { }
234
235#else // if defined (_RWSTD_NO_POD_ZERO_INIT)
236
237 fpos (_RWSTD_STREAMOFF __off = 0)
238 : _C_pos (__off) {
239 _RWSTD_MEMSET (&_C_state, 0, sizeof _C_state);
240 }
241
242 fpos (_RWSTD_STREAMOFF __off, const state_type &__state)
243 : _C_pos (__off),
244 _C_state (__state)
245 { }
246
247#endif // _RWSTD_NO_POD_ZERO_INIT
248
249 operator _RWSTD_STREAMOFF () const {
250 return _C_pos;
251 }
252
253 // 27.4.3.1, p1
254 void state (state_type __state) {
255 _C_state = __state;
256 }
257
258 // 27.4.3.1, p2
259 state_type state () const {
260 return _C_state;
261 }
262
263 // 27.4.3.2, p1: Table 88
264 fpos& operator-= (_RWSTD_STREAMOFF __off) {
265 return _C_pos -= __off, *this;
266 }
267
268 fpos& operator+= (_RWSTD_STREAMOFF __off) {
269 return _C_pos += __off, *this;
270 }
271
272 fpos operator- (_RWSTD_STREAMOFF __off) const {
273 return fpos (*this) -= __off;
274 }
275
276 fpos operator+ (_RWSTD_STREAMOFF __off) const {
277 return fpos (*this) += __off;
278 }
279
280 // equality and relational operators provided
281 // via the conversion operator to streamoff
282
283private:
284
285 _RWSTD_STREAMOFF _C_pos; // signed displacement
286 state_type _C_state; // conversion state
287};
288
289
290template <class _CharT>
291struct char_traits;
292
293
294#ifndef _RWSTD_NO_EXT_CHAR_TRAITS_PRIMARY
295
296template <class _CharT>
297struct char_traits
298{
299 typedef _CharT char_type;
300 typedef int int_type;
301 typedef _RWSTD_STREAMOFF off_type;
302 typedef _RWSTD_MBSTATE_T state_type;
303 typedef fpos<state_type> pos_type;
304
305 static int_type eof () {
306 return -1;
307 }
308
309 static void assign (char_type& __c1, const char_type& __c2) {
310 __c1 = __c2;
311 }
312
313 static bool eq (const char_type& __c1, const char_type& __c2) {
314 return __c1 == __c2;
315 }
316
317 static bool lt (const char_type& __c1, const char_type& __c2) {
318 return __c1 < __c2;
319 }
320
321 static int
322 compare (const char_type* __s1, const char_type* __s2, _RWSTD_SIZE_T __n) {
323 for (_RWSTD_SIZE_T __i = 0; __i != __n; ++__i) {
324 if (!eq (__s1[__i], __s2[__i])) {
325 return lt (__s1[__i], __s2[__i]) ? -1 : 1;
326 }
327 }
328 return 0;
329 }
330
331 static _RWSTD_SIZE_T length (const char_type *__s) {
332 _RWSTD_SIZE_T __len = 0;
333 while (!eq (*__s++, char_type ()))
334 ++__len;
335 return __len;
336 }
337
338 static const char_type*
339 find (const char_type* __s, _RWSTD_SIZE_T __n, const char_type& __c) {
340 while (__n-- > 0 && !eq (*__s, __c) )
341 ++__s;
342 return eq (*__s, __c) ? __s : 0;
343 }
344
345 static char_type*
346 move (char_type* __s1, const char_type* __s2, _RWSTD_SIZE_T __n) {
347 _RWSTD_MEMMOVE (__s1, __s2, __n * sizeof (char_type));
348 return __s1;
349 }
350
351 static char_type*
352 copy (char_type *__dst, const char_type *__src, _RWSTD_SIZE_T __n) {
353 _RWSTD_MEMCPY (_RWSTD_STATIC_CAST (void*, __dst),
354 _RWSTD_STATIC_CAST (const void*, __src),
355 __n * sizeof (char_type));
356 return __dst;
357 }
358
359 static char_type*
360 assign (char_type* __s, _RWSTD_SIZE_T __n, char_type __c) {
361 char_type* __tmp = __s;
362 while (__n-- > 0)
363 assign (*__tmp++, __c);
364 return __s;
365 }
366
367 static bool eq_int_type (const int_type& __c1, const int_type& __c2) {
368 return __c1 == __c2;
369 }
370
371 static int_type not_eof (const int_type& __c) {
372 return eq_int_type (eof (), __c) ? 0 : __c;
373 }
374
375 static char_type to_char_type (const int_type& __c) {
376 // cast to prevent warnings for unusual types
377 return _RWSTD_STATIC_CAST (char_type, __c);
378 }
379
380 static int_type to_int_type (const char_type& __c) {
381 // cast to prevent warnings for unusual types
382 return _RWSTD_STATIC_CAST (int_type, __c);
383 }
384};
385
386#endif // _RWSTD_NO_EXT_CHAR_TRAITS_PRIMARY
387
388
389// 21.1.3.1
391struct char_traits<char>
392{
393 typedef char char_type;
394 typedef _RWSTD_INT_T int_type;
395 typedef _RWSTD_STREAMOFF off_type;
396 typedef _RWSTD_MBSTATE_T state_type;
397 typedef fpos<state_type> pos_type;
398
399 static int_type eof () {
400 return int_type (_RWSTD_EOF);
401 }
402
403 static void assign (char_type& __c1, const char_type& __c2){
404 __c1 = __c2;
405 }
406
407 static bool eq (const char_type& __c1, const char_type& __c2) {
408 return __c1 == __c2;
409 }
410
411 static bool lt (const char_type& __c1, const char_type& __c2) {
412 // lwg issue 467: cast arguments to unsigned char
413 // to get the same result as memcmp(&c1, &c2) < 0
414 return _RWSTD_STATIC_CAST (unsigned char, __c1)
415 < _RWSTD_STATIC_CAST (unsigned char, __c2);
416 }
417
418 static int
419 compare (const char_type* __s1, const char_type* __s2, _RWSTD_SIZE_T __n) {
420 return _RWSTD_MEMCMP (__s1, __s2, __n);
421 }
422
423 static const char_type*
424 find (const char_type* __s, _RWSTD_SIZE_T __n, const char_type& __c) {
425 // cast to const void* used to get around a gcc 2.95 bug
426 // that prevents a static_cast from void* --> const T*
427 // (only occurs if memchr() isn't overloaded on const)
428 return _RWSTD_STATIC_CAST (
429 const char_type*, (const void*)_RWSTD_MEMCHR (
430 __s, _RWSTD_STATIC_CAST (unsigned char, __c), __n));
431 }
432
433 static _RWSTD_SIZE_T length (const char_type *__s) {
434 return _RWSTD_STRLEN (__s);
435 }
436
437 static char_type*
438 move (char_type* __s1, const char_type* __s2, _RWSTD_SIZE_T __n) {
439 _RWSTD_MEMMOVE (__s1, __s2, __n);
440 return __s1;
441 }
442
443 static char_type*
444 copy (char_type *__dst, const char_type *__src, _RWSTD_SIZE_T __n) {
445 _RWSTD_MEMCPY (__dst, __src, __n);
446 return __dst;
447 }
448
449 static char_type*
450 assign (char_type* __s, _RWSTD_SIZE_T __n, char_type __c) {
451 _RWSTD_MEMSET (__s, __c, __n);
452 return __s;
453 }
454
455 static bool eq_int_type (const int_type& __c1, const int_type& __c2) {
456 return __c1 == __c2;
457 }
458
459 static int_type not_eof (const int_type& __c) {
460 return eq_int_type (eof (), __c) ? 0 : __c;
461 }
462
463 static char_type to_char_type (const int_type& __c) {
464 return _RWSTD_STATIC_CAST (char_type, __c);
465 }
466
467 static int_type to_int_type (const char_type& __c) {
468 // make sure (signed char)'\xff' converts to 255 and not -1
469 return _RWSTD_STATIC_CAST (unsigned char, __c);
470 }
471};
472
473
474#ifndef _RWSTD_NO_WCHAR_T
475
476// 21.1.3.2
478struct char_traits<wchar_t>
479{
480 typedef wchar_t char_type;
481 typedef _RWSTD_WINT_T int_type;
482 typedef _RWSTD_STREAMOFF off_type;
483 typedef _RWSTD_MBSTATE_T state_type;
484 typedef fpos<state_type> pos_type;
485
486 static int_type eof () {
487 return int_type (_RWSTD_WEOF);
488 }
489
490 static void assign (char_type& __c1, const char_type& __c2) {
491 __c1 = __c2;
492 }
493
494 static bool eq (const char_type& __c1, const char_type& __c2) {
495 return __c1 == __c2;
496 }
497
498 static bool lt (const char_type& __c1, const char_type& __c2) {
499 return __c1 < __c2;
500 }
501
502 static int
503 compare (const char_type* __s1, const char_type* __s2, _RWSTD_SIZE_T __n) {
504 return _RWSTD_WMEMCMP (__s1, __s2, __n);
505 }
506
507 static _RWSTD_SIZE_T length (const char_type *__s) {
508 // [harmless] cast necessary on CygWin
509 return _RWSTD_WCSLEN (_RWSTD_CONST_CAST (char_type*, __s));
510 }
511
512 static const char_type*
513 find (const char_type* __s, _RWSTD_SIZE_T __n, const char_type& __c) {
514 // const cast in case of a const-incorrect wmemchr()
515 return _RWSTD_STATIC_CAST (const char_type*,
516 _RWSTD_WMEMCHR (_RWSTD_CONST_CAST (char_type*, __s),
517 __c, __n));
518 }
519
520 static char_type*
521 copy (char_type *__dst, const char_type *__src, _RWSTD_SIZE_T __n) {
522 _RWSTD_WMEMCPY (__dst, __src, __n);
523 return __dst;
524 }
525
526 static char_type*
527 move (char_type* __s1, const char_type* __s2, _RWSTD_SIZE_T __n) {
528 _RWSTD_WMEMMOVE (__s1, __s2, __n);
529 return __s1;
530 }
531
532 static char_type*
533 assign (char_type* __s, _RWSTD_SIZE_T __n, char_type __c) {
534 _RWSTD_WMEMSET (__s, __c, __n);
535 return __s;
536 }
537
538 static bool eq_int_type (const int_type& __c1, const int_type& __c2) {
539 return __c1 == __c2;
540 }
541
542 static int_type not_eof (const int_type& __c) {
543 return eq_int_type (eof (), __c) ? 0 : __c;
544 }
545
546 static char_type to_char_type (const int_type& __c) {
547 return __c;
548 }
549
550 static int_type to_int_type (const char_type& __c) {
551 return __c;
552 }
553};
554
555#endif // _RWSTD_NO_WCHAR_T
556
557
558} // namespace std
559
560
561#endif // _RWSTD_RW_TRAITS_H_INCLUDED
const minus< T > & operator-(const minus< T > &lhs, const minus< T > &rhs)
#define _RWSTD_SPECIALIZED_CLASS
void operator+(typename A< T >::I, const A< T > &)
unsigned short wchar_t
#define _RWSTD_EXPORT
Definition _defs.h:485
#define _RWSTD_INT_T
Definition _defs.h:1272
#define _RWSTD_STATIC_CAST(T, x)
Definition _defs.h:534
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_STREAMOFF
Definition _defs.h:761
#define _RWSTD_CONST_CAST(T, x)
Definition _defs.h:536
#define _RWSTD_WINT_T
Definition _defs.h:1266
#define _RWSTD_MBSTATE_T
Definition _mbstate.h:199
#define _RWSTD_WMEMCPY
Definition _traits.h:117
#define _RWSTD_WMEMMOVE
Definition _traits.h:147
#define _RWSTD_WMEMSET
Definition _traits.h:162
#define _RWSTD_WMEMCMP
Definition _traits.h:132
#define _RWSTD_WCSLEN
Definition _traits.h:177
#define _RWSTD_MEMMOVE
Definition _traits.h:108
#define _RWSTD_MEMCMP
Definition _traits.h:107
#define _RWSTD_MEMCPY
Definition _traits.h:106
#define _RWSTD_MEMSET
Definition _traits.h:109
#define _RWSTD_WMEMCHR
Definition _traits.h:192
#define _RWSTD_MEMCHR
Definition _traits.h:111
#define _RWSTD_STRLEN
Definition _traits.h:110
Definition json.h:5363