GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / toolchains / hndtools-arm-linux-2.6.36-uclibc-4.5.3 / arm-brcm-linux-uclibcgnueabi / include / c++ / 4.5.3 / bits / char_traits.h
blob412e75a2ec01bee45c5ab9c0197fa7bbc14ba880
1 // Character Traits for use by standard string and iostream -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 // 2006, 2007, 2008, 2009, 2010
5 // Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // Under Section 7 of GPL version 3, you are granted additional
19 // permissions described in the GCC Runtime Library Exception, version
20 // 3.1, as published by the Free Software Foundation.
22 // You should have received a copy of the GNU General Public License and
23 // a copy of the GCC Runtime Library Exception along with this program;
24 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 // <http://www.gnu.org/licenses/>.
27 /** @file char_traits.h
28 * This is an internal header file, included by other library headers.
29 * You should not attempt to use it directly.
33 // ISO C++ 14882: 21 Strings library
36 #ifndef _CHAR_TRAITS_H
37 #define _CHAR_TRAITS_H 1
39 #pragma GCC system_header
41 #include <bits/stl_algobase.h> // std::copy, std::fill_n
42 #include <bits/postypes.h> // For streampos
43 #include <cwchar> // For WEOF, wmemmove, wmemset, etc.
45 #ifndef _GLIBCXX_STDIO_MACROS
46 # include <cstdio> // For EOF
47 # define _CHAR_TRAITS_EOF EOF
48 #else
49 # define _CHAR_TRAITS_EOF (-1)
50 #endif
52 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
54 /**
55 * @brief Mapping from character type to associated types.
57 * @note This is an implementation class for the generic version
58 * of char_traits. It defines int_type, off_type, pos_type, and
59 * state_type. By default these are unsigned long, streamoff,
60 * streampos, and mbstate_t. Users who need a different set of
61 * types, but who don't need to change the definitions of any function
62 * defined in char_traits, can specialize __gnu_cxx::_Char_types
63 * while leaving __gnu_cxx::char_traits alone. */
64 template<typename _CharT>
65 struct _Char_types
67 typedef unsigned long int_type;
68 typedef std::streampos pos_type;
69 typedef std::streamoff off_type;
70 typedef std::mbstate_t state_type;
74 /**
75 * @brief Base class used to implement std::char_traits.
77 * @note For any given actual character type, this definition is
78 * probably wrong. (Most of the member functions are likely to be
79 * right, but the int_type and state_type typedefs, and the eof()
80 * member function, are likely to be wrong.) The reason this class
81 * exists is so users can specialize it. Classes in namespace std
82 * may not be specialized for fundamental types, but classes in
83 * namespace __gnu_cxx may be.
85 * See http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt05ch13s03.html
86 * for advice on how to make use of this class for @a unusual character
87 * types. Also, check out include/ext/pod_char_traits.h.
89 template<typename _CharT>
90 struct char_traits
92 typedef _CharT char_type;
93 typedef typename _Char_types<_CharT>::int_type int_type;
94 typedef typename _Char_types<_CharT>::pos_type pos_type;
95 typedef typename _Char_types<_CharT>::off_type off_type;
96 typedef typename _Char_types<_CharT>::state_type state_type;
98 static void
99 assign(char_type& __c1, const char_type& __c2)
100 { __c1 = __c2; }
102 static bool
103 eq(const char_type& __c1, const char_type& __c2)
104 { return __c1 == __c2; }
106 static bool
107 lt(const char_type& __c1, const char_type& __c2)
108 { return __c1 < __c2; }
110 static int
111 compare(const char_type* __s1, const char_type* __s2, std::size_t __n);
113 static std::size_t
114 length(const char_type* __s);
116 static const char_type*
117 find(const char_type* __s, std::size_t __n, const char_type& __a);
119 static char_type*
120 move(char_type* __s1, const char_type* __s2, std::size_t __n);
122 static char_type*
123 copy(char_type* __s1, const char_type* __s2, std::size_t __n);
125 static char_type*
126 assign(char_type* __s, std::size_t __n, char_type __a);
128 static char_type
129 to_char_type(const int_type& __c)
130 { return static_cast<char_type>(__c); }
132 static int_type
133 to_int_type(const char_type& __c)
134 { return static_cast<int_type>(__c); }
136 static bool
137 eq_int_type(const int_type& __c1, const int_type& __c2)
138 { return __c1 == __c2; }
140 static int_type
141 eof()
142 { return static_cast<int_type>(_CHAR_TRAITS_EOF); }
144 static int_type
145 not_eof(const int_type& __c)
146 { return !eq_int_type(__c, eof()) ? __c : to_int_type(char_type()); }
149 template<typename _CharT>
151 char_traits<_CharT>::
152 compare(const char_type* __s1, const char_type* __s2, std::size_t __n)
154 for (std::size_t __i = 0; __i < __n; ++__i)
155 if (lt(__s1[__i], __s2[__i]))
156 return -1;
157 else if (lt(__s2[__i], __s1[__i]))
158 return 1;
159 return 0;
162 template<typename _CharT>
163 std::size_t
164 char_traits<_CharT>::
165 length(const char_type* __p)
167 std::size_t __i = 0;
168 while (!eq(__p[__i], char_type()))
169 ++__i;
170 return __i;
173 template<typename _CharT>
174 const typename char_traits<_CharT>::char_type*
175 char_traits<_CharT>::
176 find(const char_type* __s, std::size_t __n, const char_type& __a)
178 for (std::size_t __i = 0; __i < __n; ++__i)
179 if (eq(__s[__i], __a))
180 return __s + __i;
181 return 0;
184 template<typename _CharT>
185 typename char_traits<_CharT>::char_type*
186 char_traits<_CharT>::
187 move(char_type* __s1, const char_type* __s2, std::size_t __n)
189 return static_cast<_CharT*>(__builtin_memmove(__s1, __s2,
190 __n * sizeof(char_type)));
193 template<typename _CharT>
194 typename char_traits<_CharT>::char_type*
195 char_traits<_CharT>::
196 copy(char_type* __s1, const char_type* __s2, std::size_t __n)
198 // NB: Inline std::copy so no recursive dependencies.
199 std::copy(__s2, __s2 + __n, __s1);
200 return __s1;
203 template<typename _CharT>
204 typename char_traits<_CharT>::char_type*
205 char_traits<_CharT>::
206 assign(char_type* __s, std::size_t __n, char_type __a)
208 // NB: Inline std::fill_n so no recursive dependencies.
209 std::fill_n(__s, __n, __a);
210 return __s;
213 _GLIBCXX_END_NAMESPACE
215 _GLIBCXX_BEGIN_NAMESPACE(std)
217 // 21.1
219 * @brief Basis for explicit traits specializations.
221 * @note For any given actual character type, this definition is
222 * probably wrong. Since this is just a thin wrapper around
223 * __gnu_cxx::char_traits, it is possible to achieve a more
224 * appropriate definition by specializing __gnu_cxx::char_traits.
226 * See http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt05ch13s03.html
227 * for advice on how to make use of this class for @a unusual character
228 * types. Also, check out include/ext/pod_char_traits.h.
230 template<class _CharT>
231 struct char_traits : public __gnu_cxx::char_traits<_CharT>
232 { };
235 /// 21.1.3.1 char_traits specializations
236 template<>
237 struct char_traits<char>
239 typedef char char_type;
240 typedef int int_type;
241 typedef streampos pos_type;
242 typedef streamoff off_type;
243 typedef mbstate_t state_type;
245 static void
246 assign(char_type& __c1, const char_type& __c2)
247 { __c1 = __c2; }
249 static bool
250 eq(const char_type& __c1, const char_type& __c2)
251 { return __c1 == __c2; }
253 static bool
254 lt(const char_type& __c1, const char_type& __c2)
255 { return __c1 < __c2; }
257 static int
258 compare(const char_type* __s1, const char_type* __s2, size_t __n)
259 { return __builtin_memcmp(__s1, __s2, __n); }
261 static size_t
262 length(const char_type* __s)
263 { return __builtin_strlen(__s); }
265 static const char_type*
266 find(const char_type* __s, size_t __n, const char_type& __a)
267 { return static_cast<const char_type*>(__builtin_memchr(__s, __a, __n)); }
269 static char_type*
270 move(char_type* __s1, const char_type* __s2, size_t __n)
271 { return static_cast<char_type*>(__builtin_memmove(__s1, __s2, __n)); }
273 static char_type*
274 copy(char_type* __s1, const char_type* __s2, size_t __n)
275 { return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n)); }
277 static char_type*
278 assign(char_type* __s, size_t __n, char_type __a)
279 { return static_cast<char_type*>(__builtin_memset(__s, __a, __n)); }
281 static char_type
282 to_char_type(const int_type& __c)
283 { return static_cast<char_type>(__c); }
285 // To keep both the byte 0xff and the eof symbol 0xffffffff
286 // from ending up as 0xffffffff.
287 static int_type
288 to_int_type(const char_type& __c)
289 { return static_cast<int_type>(static_cast<unsigned char>(__c)); }
291 static bool
292 eq_int_type(const int_type& __c1, const int_type& __c2)
293 { return __c1 == __c2; }
295 static int_type
296 eof()
297 { return static_cast<int_type>(_CHAR_TRAITS_EOF); }
299 static int_type
300 not_eof(const int_type& __c)
301 { return (__c == eof()) ? 0 : __c; }
305 #ifdef _GLIBCXX_USE_WCHAR_T
306 /// 21.1.3.2 char_traits specializations
307 template<>
308 struct char_traits<wchar_t>
310 typedef wchar_t char_type;
311 typedef wint_t int_type;
312 typedef streamoff off_type;
313 typedef wstreampos pos_type;
314 typedef mbstate_t state_type;
316 static void
317 assign(char_type& __c1, const char_type& __c2)
318 { __c1 = __c2; }
320 static bool
321 eq(const char_type& __c1, const char_type& __c2)
322 { return __c1 == __c2; }
324 static bool
325 lt(const char_type& __c1, const char_type& __c2)
326 { return __c1 < __c2; }
328 static int
329 compare(const char_type* __s1, const char_type* __s2, size_t __n)
330 { return wmemcmp(__s1, __s2, __n); }
332 static size_t
333 length(const char_type* __s)
334 { return wcslen(__s); }
336 static const char_type*
337 find(const char_type* __s, size_t __n, const char_type& __a)
338 { return wmemchr(__s, __a, __n); }
340 static char_type*
341 move(char_type* __s1, const char_type* __s2, size_t __n)
342 { return wmemmove(__s1, __s2, __n); }
344 static char_type*
345 copy(char_type* __s1, const char_type* __s2, size_t __n)
346 { return wmemcpy(__s1, __s2, __n); }
348 static char_type*
349 assign(char_type* __s, size_t __n, char_type __a)
350 { return wmemset(__s, __a, __n); }
352 static char_type
353 to_char_type(const int_type& __c)
354 { return char_type(__c); }
356 static int_type
357 to_int_type(const char_type& __c)
358 { return int_type(__c); }
360 static bool
361 eq_int_type(const int_type& __c1, const int_type& __c2)
362 { return __c1 == __c2; }
364 static int_type
365 eof()
366 { return static_cast<int_type>(WEOF); }
368 static int_type
369 not_eof(const int_type& __c)
370 { return eq_int_type(__c, eof()) ? 0 : __c; }
372 #endif //_GLIBCXX_USE_WCHAR_T
374 _GLIBCXX_END_NAMESPACE
376 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) \
377 && defined(_GLIBCXX_USE_C99_STDINT_TR1))
379 #include <cstdint>
381 _GLIBCXX_BEGIN_NAMESPACE(std)
383 template<>
384 struct char_traits<char16_t>
386 typedef char16_t char_type;
387 typedef uint_least16_t int_type;
388 typedef streamoff off_type;
389 typedef u16streampos pos_type;
390 typedef mbstate_t state_type;
392 static void
393 assign(char_type& __c1, const char_type& __c2)
394 { __c1 = __c2; }
396 static bool
397 eq(const char_type& __c1, const char_type& __c2)
398 { return __c1 == __c2; }
400 static bool
401 lt(const char_type& __c1, const char_type& __c2)
402 { return __c1 < __c2; }
404 static int
405 compare(const char_type* __s1, const char_type* __s2, size_t __n)
407 for (size_t __i = 0; __i < __n; ++__i)
408 if (lt(__s1[__i], __s2[__i]))
409 return -1;
410 else if (lt(__s2[__i], __s1[__i]))
411 return 1;
412 return 0;
415 static size_t
416 length(const char_type* __s)
418 size_t __i = 0;
419 while (!eq(__s[__i], char_type()))
420 ++__i;
421 return __i;
424 static const char_type*
425 find(const char_type* __s, size_t __n, const char_type& __a)
427 for (size_t __i = 0; __i < __n; ++__i)
428 if (eq(__s[__i], __a))
429 return __s + __i;
430 return 0;
433 static char_type*
434 move(char_type* __s1, const char_type* __s2, size_t __n)
436 return (static_cast<char_type*>
437 (__builtin_memmove(__s1, __s2, __n * sizeof(char_type))));
440 static char_type*
441 copy(char_type* __s1, const char_type* __s2, size_t __n)
443 return (static_cast<char_type*>
444 (__builtin_memcpy(__s1, __s2, __n * sizeof(char_type))));
447 static char_type*
448 assign(char_type* __s, size_t __n, char_type __a)
450 for (size_t __i = 0; __i < __n; ++__i)
451 assign(__s[__i], __a);
452 return __s;
455 static char_type
456 to_char_type(const int_type& __c)
457 { return char_type(__c); }
459 static int_type
460 to_int_type(const char_type& __c)
461 { return int_type(__c); }
463 static bool
464 eq_int_type(const int_type& __c1, const int_type& __c2)
465 { return __c1 == __c2; }
467 static int_type
468 eof()
469 { return static_cast<int_type>(-1); }
471 static int_type
472 not_eof(const int_type& __c)
473 { return eq_int_type(__c, eof()) ? 0 : __c; }
476 template<>
477 struct char_traits<char32_t>
479 typedef char32_t char_type;
480 typedef uint_least32_t int_type;
481 typedef streamoff off_type;
482 typedef u32streampos pos_type;
483 typedef mbstate_t state_type;
485 static void
486 assign(char_type& __c1, const char_type& __c2)
487 { __c1 = __c2; }
489 static bool
490 eq(const char_type& __c1, const char_type& __c2)
491 { return __c1 == __c2; }
493 static bool
494 lt(const char_type& __c1, const char_type& __c2)
495 { return __c1 < __c2; }
497 static int
498 compare(const char_type* __s1, const char_type* __s2, size_t __n)
500 for (size_t __i = 0; __i < __n; ++__i)
501 if (lt(__s1[__i], __s2[__i]))
502 return -1;
503 else if (lt(__s2[__i], __s1[__i]))
504 return 1;
505 return 0;
508 static size_t
509 length(const char_type* __s)
511 size_t __i = 0;
512 while (!eq(__s[__i], char_type()))
513 ++__i;
514 return __i;
517 static const char_type*
518 find(const char_type* __s, size_t __n, const char_type& __a)
520 for (size_t __i = 0; __i < __n; ++__i)
521 if (eq(__s[__i], __a))
522 return __s + __i;
523 return 0;
526 static char_type*
527 move(char_type* __s1, const char_type* __s2, size_t __n)
529 return (static_cast<char_type*>
530 (__builtin_memmove(__s1, __s2, __n * sizeof(char_type))));
533 static char_type*
534 copy(char_type* __s1, const char_type* __s2, size_t __n)
536 return (static_cast<char_type*>
537 (__builtin_memcpy(__s1, __s2, __n * sizeof(char_type))));
540 static char_type*
541 assign(char_type* __s, size_t __n, char_type __a)
543 for (size_t __i = 0; __i < __n; ++__i)
544 assign(__s[__i], __a);
545 return __s;
548 static char_type
549 to_char_type(const int_type& __c)
550 { return char_type(__c); }
552 static int_type
553 to_int_type(const char_type& __c)
554 { return int_type(__c); }
556 static bool
557 eq_int_type(const int_type& __c1, const int_type& __c2)
558 { return __c1 == __c2; }
560 static int_type
561 eof()
562 { return static_cast<int_type>(-1); }
564 static int_type
565 not_eof(const int_type& __c)
566 { return eq_int_type(__c, eof()) ? 0 : __c; }
569 _GLIBCXX_END_NAMESPACE
571 #endif
573 #undef _CHAR_TRAITS_EOF
575 #endif // _CHAR_TRAITS_H