2001-02-05 Benjamin Kosnik <bkoz@redhat.com>
[official-gcc.git] / libstdc++-v3 / include / bits / locale_facets.h
blob6d71b81bd829df202add25f7fa8e7410a7d510d3
1 // Locale support -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 // ISO C++ 14882: 22.1 Locales
34 // Warning: this file is not meant for user inclusion. Use <locale>.
36 #ifndef _CPP_BITS_LOCFACETS_H
37 #define _CPP_BITS_LOCFACETS_H 1
39 #include <bits/std_ctime.h> // For struct tm
40 #include <bits/std_ios.h> // For ios_base
41 #ifdef _GLIBCPP_USE_WCHAR_T
42 # include <langinfo.h> // For codecvt
43 # include <bits/std_cwctype.h> // For wctype_t
44 # include <iconv.h> // For codecvt using iconv, iconv_t
45 #endif
47 namespace std
49 // 22.2.1.1 Template class ctype
50 // Include host-specific ctype enums for ctype_base.
51 #include <bits/ctype_base.h>
53 // __ctype_abstract_base is the common base for ctype<_CharT>.
54 template<typename _CharT>
55 class __ctype_abstract_base : public locale::facet, public ctype_base
57 public:
58 // Types:
59 typedef _CharT char_type;
61 bool
62 is(mask __m, char_type __c) const
63 { return this->do_is(__m, __c); }
65 const char_type*
66 is(const char_type *__lo, const char_type *__hi, mask *__vec) const
67 { return this->do_is(__lo, __hi, __vec); }
69 const char_type*
70 scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
71 { return this->do_scan_is(__m, __lo, __hi); }
73 const char_type*
74 scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
75 { return this->do_scan_not(__m, __lo, __hi); }
77 char_type
78 toupper(char_type __c) const
79 { return this->do_toupper(__c); }
81 const char_type*
82 toupper(char_type *__low, const char_type* __high) const
83 { return this->do_toupper(__low, __high); }
85 char_type
86 tolower(char_type __c) const
87 { return this->do_tolower(__c); }
89 const char_type*
90 tolower(char_type* __low, const char_type* __high) const
91 { return this->do_tolower(__low, __high); }
93 char_type
94 widen(char __c) const
95 { return this->do_widen(__c); }
97 const char*
98 widen(const char* __low, const char* __high, char_type* __to) const
99 { return this->do_widen(__low, __high, __to); }
101 char
102 narrow(char_type __c, char __dfault) const
103 { return this->do_narrow(__c, __dfault); }
105 const char_type*
106 narrow(const char_type* __low, const char_type* __high,
107 char __dfault, char *__to) const
108 { return this->do_narrow(__low, __high, __dfault, __to); }
110 protected:
111 explicit
112 __ctype_abstract_base(size_t __refs = 0): locale::facet(__refs) { }
114 virtual
115 ~__ctype_abstract_base() { }
117 virtual bool
118 do_is(mask __m, char_type __c) const = 0;
120 virtual const char_type*
121 do_is(const char_type* __lo, const char_type* __hi,
122 mask* __vec) const = 0;
124 virtual const char_type*
125 do_scan_is(mask __m, const char_type* __lo,
126 const char_type* __hi) const = 0;
128 virtual const char_type*
129 do_scan_not(mask __m, const char_type* __lo,
130 const char_type* __hi) const = 0;
132 virtual char_type
133 do_toupper(char_type) const = 0;
135 virtual const char_type*
136 do_toupper(char_type* __low, const char_type* __high) const = 0;
138 virtual char_type
139 do_tolower(char_type) const = 0;
141 virtual const char_type*
142 do_tolower(char_type* __low, const char_type* __high) const = 0;
144 virtual char_type
145 do_widen(char) const = 0;
147 virtual const char*
148 do_widen(const char* __low, const char* __high,
149 char_type* __dest) const = 0;
151 virtual char
152 do_narrow(char_type, char __dfault) const = 0;
154 virtual const char_type*
155 do_narrow(const char_type* __low, const char_type* __high,
156 char __dfault, char* __dest) const = 0;
159 // NB: Generic, mostly useless implementation.
160 template<typename _CharT>
161 class ctype : public __ctype_abstract_base<_CharT>
163 public:
164 // Types:
165 typedef _CharT char_type;
166 typedef typename ctype::mask mask;
168 explicit
169 ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { }
171 static locale::id id;
173 protected:
174 virtual
175 ~ctype() { }
178 template<typename _CharT>
179 locale::id ctype<_CharT>::id;
181 // 22.2.1.3 ctype specializations
182 template<>
183 class ctype<char> : public __ctype_abstract_base<char>
185 public:
186 // Types:
187 typedef char char_type;
189 private:
190 // Data Members:
191 bool _M_del;
192 __to_type const& _M_toupper;
193 __to_type const& _M_tolower;
194 const mask* const& _M_ctable;
195 const mask* _M_table;
197 public:
198 static locale::id id;
199 static const size_t table_size = 1 + static_cast<unsigned char>(-1);
201 explicit
202 ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0);
204 inline bool
205 is(mask __m, char __c) const;
207 inline const char*
208 is(const char* __low, const char* __high, mask* __vec) const;
210 inline const char*
211 scan_is(mask __m, const char* __low, const char* __high) const;
213 inline const char*
214 scan_not(mask __m, const char* __low, const char* __high) const;
216 protected:
217 virtual
218 ~ctype();
220 const mask*
221 table() const throw()
222 { return _M_table; }
224 const mask*
225 classic_table() throw()
226 { return _M_ctable; }
228 virtual bool
229 do_is(mask __m, char_type __c) const;
231 virtual const char_type*
232 do_is(const char_type* __lo, const char_type* __hi,
233 mask* __vec) const;
235 virtual const char_type*
236 do_scan_is(mask __m, const char_type* __lo,
237 const char_type* __hi) const;
239 virtual const char_type*
240 do_scan_not(mask __m, const char_type* __lo,
241 const char_type* __hi) const;
243 virtual char_type
244 do_toupper(char_type) const;
246 virtual const char_type*
247 do_toupper(char_type* __low, const char_type* __high) const;
249 virtual char_type
250 do_tolower(char_type) const;
252 virtual const char_type*
253 do_tolower(char_type* __low, const char_type* __high) const;
255 virtual char_type
256 do_widen(char) const;
258 virtual const char*
259 do_widen(const char* __low, const char* __high,
260 char_type* __dest) const;
262 virtual char
263 do_narrow(char_type, char __dfault) const;
265 virtual const char_type*
266 do_narrow(const char_type* __low, const char_type* __high,
267 char __dfault, char* __dest) const;
270 template<>
271 const ctype<char>&
272 use_facet<ctype<char> >(const locale& __loc);
274 #ifdef _GLIBCPP_USE_WCHAR_T
275 // ctype<wchar_t> specialization
276 template<>
277 class ctype<wchar_t> : public __ctype_abstract_base<wchar_t>
279 public:
280 // Types:
281 typedef wchar_t char_type;
282 typedef wctype_t __wmask_type;
284 // Data Members:
285 static locale::id id;
287 explicit
288 ctype(size_t __refs = 0);
290 protected:
291 __wmask_type
292 _M_convert_to_wmask(const mask __m) const;
294 virtual
295 ~ctype();
297 virtual bool
298 do_is(mask __m, char_type __c) const;
300 virtual const char_type*
301 do_is(const char_type* __lo, const char_type* __hi,
302 mask* __vec) const;
304 virtual const char_type*
305 do_scan_is(mask __m, const char_type* __lo,
306 const char_type* __hi) const;
308 virtual const char_type*
309 do_scan_not(mask __m, const char_type* __lo,
310 const char_type* __hi) const;
312 virtual char_type
313 do_toupper(char_type) const;
315 virtual const char_type*
316 do_toupper(char_type* __low, const char_type* __high) const;
318 virtual char_type
319 do_tolower(char_type) const;
321 virtual const char_type*
322 do_tolower(char_type* __low, const char_type* __high) const;
324 virtual char_type
325 do_widen(char) const;
327 virtual const char*
328 do_widen(const char* __low, const char* __high,
329 char_type* __dest) const;
331 virtual char
332 do_narrow(char_type, char __dfault) const;
334 virtual const char_type*
335 do_narrow(const char_type* __low, const char_type* __high,
336 char __dfault, char* __dest) const;
340 template<>
341 const ctype<wchar_t>&
342 use_facet<ctype<wchar_t> >(const locale& __loc);
343 #endif //_GLIBCPP_USE_WCHAR_T
345 // Include host-specific ctype inlines.
346 #include <bits/ctype_inline.h>
348 // 22.2.1.2 Template class ctype_byname
349 template<typename _CharT>
350 class ctype_byname : public ctype<_CharT>
352 public:
353 typedef _CharT char_type;
355 explicit
356 ctype_byname(const char*, size_t __refs = 0);
358 protected:
359 virtual
360 ~ctype_byname() { }
363 // 22.2.1.4 Class ctype_byname specialization
364 template<>
365 ctype_byname<char>::ctype_byname(const char*, size_t refs);
368 // 22.2.1.5 Template class codecvt
369 #include <bits/codecvt.h>
371 template<typename _CharT, typename _InIter>
372 class _Numeric_get; // forward
374 // _Format_cache holds the information extracted from the numpunct<>
375 // and moneypunct<> facets in a form optimized for parsing and
376 // formatting. It is stored via a void* pointer in the pword()
377 // array of an iosbase object passed to the _get and _put facets.
378 // NB: contains no user-serviceable parts.
379 template<typename _CharT>
380 class _Format_cache
382 public:
383 // Types:
384 typedef _CharT char_type;
385 typedef char_traits<_CharT> traits_type;
386 typedef basic_string<_CharT> string_type;
387 typedef typename string_type::size_type size_type;
389 // Forward decls and Friends:
390 friend class locale;
391 template<typename _Char, typename _InIter>
392 friend class _Numeric_get;
393 friend class num_get<_CharT>;
394 friend class num_put<_CharT>;
395 friend class time_get<_CharT>;
396 friend class money_get<_CharT>;
397 friend class time_put<_CharT>;
398 friend class money_put<_CharT>;
400 // Data Members:
402 // ios_base::pword() reserved cell
403 static int _S_pword_ix;
405 // True iff data members are consistent with the current locale,
406 // ie imbue sets this to false.
407 bool _M_valid;
409 // A list of valid numeric literals: for the standard "C" locale,
410 // this would usually be: "-+xX0123456789abcdef0123456789ABCDEF"
411 static const char _S_literals[];
413 // NB: Code depends on the order of definitions of the names
414 // these are indices into _S_literals, above.
415 // This string is formatted for putting, not getting. (output, not input)
416 enum
418 _S_minus,
419 _S_plus,
420 _S_x,
421 _S_X,
422 _S_digits,
423 _S_digits_end = _S_digits + 16,
424 _S_udigits = _S_digits_end,
425 _S_udigits_end = _S_udigits + 16,
426 _S_ee = _S_digits + 14, // For scientific notation, 'E'
427 _S_Ee = _S_udigits + 14 // For scientific notation, 'e'
430 // The sign used to separate decimal values: for standard US
431 // locales, this would usually be: "."
432 // Abstracted from numpunct::decimal_point().
433 char_type _M_decimal_point;
435 // The sign used to separate groups of digits into smaller
436 // strings that the eye can parse with less difficulty: for
437 // standard US locales, this would usually be: ","
438 // Abstracted from numpunct::thousands_sep().
439 char_type _M_thousands_sep;
441 // However the US's "false" and "true" are translated.
442 // From numpunct::truename() and numpunct::falsename(), respectively.
443 string_type _M_truename;
444 string_type _M_falsename;
446 // If we are checking groupings. This should be equivalent to
447 // numpunct::groupings().size() != 0
448 bool _M_use_grouping;
450 // If we are using numpunct's groupings, this is the current
451 // grouping string in effect (from numpunct::grouping()).
452 string _M_grouping;
454 _Format_cache();
456 ~_Format_cache() throw() { }
458 // Given a member of the ios heirarchy as an argument, extract
459 // out all the current formatting information into a
460 // _Format_cache object and return a pointer to it.
461 static _Format_cache<_CharT>*
462 _S_get(ios_base& __ios);
464 void
465 _M_populate(ios_base&);
467 static void
468 _S_callback(ios_base::event __event, ios_base& __ios, int __ix) throw();
471 template<typename _CharT>
472 int _Format_cache<_CharT>::_S_pword_ix;
474 template<typename _CharT>
475 const char _Format_cache<_CharT>::
476 _S_literals[] = "-+xX0123456789abcdef0123456789ABCDEF";
478 template<> _Format_cache<char>::_Format_cache();
479 #ifdef _GLIBCPP_USE_WCHAR_T
480 template<> _Format_cache<wchar_t>::_Format_cache();
481 #endif
483 // _Numeric_get is used by num_get, money_get, and time_get to help
484 // in parsing out numbers.
485 template<typename _CharT, typename _InIter>
486 class _Numeric_get
488 public:
489 // Types:
490 typedef _CharT char_type;
491 typedef _InIter iter_type;
493 // Forward decls and Friends:
494 template<typename _Char, typename _InIterT>
495 friend class num_get;
496 template<typename _Char, typename _InIterT>
497 friend class time_get;
498 template<typename _Char, typename _InIterT>
499 friend class money_get;
500 template<typename _Char, typename _InIterT>
501 friend class num_put;
502 template<typename _Char, typename _InIterT>
503 friend class time_put;
504 template<typename _Char, typename _InIterT>
505 friend class money_put;
507 private:
508 explicit
509 _Numeric_get() { }
511 virtual
512 ~_Numeric_get() { }
514 iter_type
515 _M_get_digits(iter_type __in, iter_type __end) const;
518 template<typename _CharT, typename _InIter>
519 class num_get : public locale::facet
521 public:
522 // Types:
523 typedef _CharT char_type;
524 typedef _InIter iter_type;
525 typedef char_traits<_CharT> __traits_type;
527 static locale::id id;
529 explicit
530 num_get(size_t __refs = 0) : locale::facet(__refs) { }
532 iter_type
533 get(iter_type __in, iter_type __end, ios_base& __io,
534 ios_base::iostate& __err, bool& __v) const
535 { return do_get(__in, __end, __io, __err, __v); }
537 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
538 iter_type
539 get(iter_type __in, iter_type __end, ios_base& __io,
540 ios_base::iostate& __err, short& __v) const
541 { return do_get(__in, __end, __io, __err, __v); }
543 iter_type
544 get(iter_type __in, iter_type __end, ios_base& __io,
545 ios_base::iostate& __err, int& __v) const
546 { return do_get(__in, __end, __io, __err, __v); }
547 #endif
549 iter_type
550 get(iter_type __in, iter_type __end, ios_base& __io,
551 ios_base::iostate& __err, long& __v) const
552 { return do_get(__in, __end, __io, __err, __v); }
554 #ifdef _GLIBCPP_USE_LONG_LONG
555 iter_type
556 get(iter_type __in, iter_type __end, ios_base& __io,
557 ios_base::iostate& __err, long long& __v) const
558 { return do_get(__in, __end, __io, __err, __v); }
559 #endif
561 iter_type
562 get(iter_type __in, iter_type __end, ios_base& __io,
563 ios_base::iostate& __err, unsigned short& __v) const
564 { return do_get(__in, __end, __io, __err, __v); }
566 iter_type
567 get(iter_type __in, iter_type __end, ios_base& __io,
568 ios_base::iostate& __err, unsigned int& __v) const
569 { return do_get(__in, __end, __io, __err, __v); }
571 iter_type
572 get(iter_type __in, iter_type __end, ios_base& __io,
573 ios_base::iostate& __err, unsigned long& __v) const
574 { return do_get(__in, __end, __io, __err, __v); }
576 #ifdef _GLIBCPP_USE_LONG_LONG
577 iter_type
578 get(iter_type __in, iter_type __end, ios_base& __io,
579 ios_base::iostate& __err, unsigned long long& __v) const
580 { return do_get(__in, __end, __io, __err, __v); }
581 #endif
583 iter_type
584 get(iter_type __in, iter_type __end, ios_base& __io,
585 ios_base::iostate& __err, float& __v) const
586 { return do_get(__in, __end, __io, __err, __v); }
588 iter_type
589 get(iter_type __in, iter_type __end, ios_base& __io,
590 ios_base::iostate& __err, double& __v) const
591 { return do_get(__in, __end, __io, __err, __v); }
593 iter_type
594 get(iter_type __in, iter_type __end, ios_base& __io,
595 ios_base::iostate& __err, long double& __v) const
596 { return do_get(__in, __end, __io, __err, __v); }
598 iter_type
599 get(iter_type __in, iter_type __end, ios_base& __io,
600 ios_base::iostate& __err, void*& __v) const
601 { return do_get(__in, __end, __io, __err, __v); }
603 protected:
604 virtual ~num_get() { }
606 // This consolidates the extraction, storage and
607 // error-processing parts of the do_get(...) overloaded member
608 // functions.
609 // NB: This is specialized for char.
610 void
611 _M_extract(iter_type __beg, iter_type __end, ios_base& __io,
612 ios_base::iostate& __err, char* __xtrc,
613 int& __base, bool __fp = true) const;
615 virtual iter_type
616 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
618 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
619 virtual iter_type
620 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, short&) const;
621 virtual iter_type
622 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, int&) const;
623 #endif
624 virtual iter_type
625 do_get (iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const;
626 #ifdef _GLIBCPP_USE_LONG_LONG
627 virtual iter_type
628 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
629 long long&) const;
630 #endif
631 virtual iter_type
632 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
633 unsigned short&) const;
634 virtual iter_type
635 do_get(iter_type, iter_type, ios_base&,
636 ios_base::iostate& __err, unsigned int&) const;
637 virtual iter_type
638 do_get(iter_type, iter_type, ios_base&,
639 ios_base::iostate& __err, unsigned long&) const;
640 #ifdef _GLIBCPP_USE_LONG_LONG
641 virtual iter_type
642 do_get(iter_type, iter_type, ios_base&,
643 ios_base::iostate& __err, unsigned long long&) const;
644 #endif
645 virtual iter_type
646 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
647 float&) const;
649 virtual iter_type
650 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
651 double&) const;
653 virtual iter_type
654 do_get(iter_type, iter_type, ios_base&,
655 ios_base::iostate& __err, long double&) const;
657 virtual iter_type
658 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
659 void*&) const;
662 template<typename _CharT, typename _InIter>
663 locale::id num_get<_CharT, _InIter>::id;
665 // Declare specialized extraction member function.
666 template<>
667 void
668 num_get<char, istreambuf_iterator<char> >::
669 _M_extract(istreambuf_iterator<char> __beg,
670 istreambuf_iterator<char> __end, ios_base& __io,
671 ios_base::iostate& __err, char* __xtrc,
672 int& __base, bool __fp) const;
674 // _Numeric_put is used by num_put, money_put, and time_put
675 // to help in formatting out numbers.
676 template<typename _CharT, typename _OutIter>
677 class _Numeric_put
679 public:
680 typedef _CharT char_type;
681 typedef _OutIter iter_type;
682 protected:
683 explicit
684 _Numeric_put() { }
686 virtual
687 ~_Numeric_put() { }
690 template<typename _CharT, typename _OutIter>
691 class num_put : public locale::facet
693 public:
694 // Types:
695 typedef _CharT char_type;
696 typedef _OutIter iter_type;
698 static locale::id id;
700 explicit
701 num_put(size_t __refs = 0) : locale::facet(__refs) { }
703 iter_type
704 put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
705 { return do_put(__s, __f, __fill, __v); }
707 iter_type
708 put(iter_type __s, ios_base& __f, char_type __fill, long __v) const
709 { return do_put(__s, __f, __fill, __v); }
711 iter_type
712 put(iter_type __s, ios_base& __f, char_type __fill,
713 unsigned long __v) const
714 { return do_put(__s, __f, __fill, __v); }
716 #ifdef _GLIBCPP_USE_LONG_LONG
717 iter_type
718 put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const
719 { return do_put(__s, __f, __fill, __v); }
721 iter_type
722 put(iter_type __s, ios_base& __f, char_type __fill,
723 unsigned long long __v) const
724 { return do_put(__s, __f, __fill, __v); }
725 #endif
727 iter_type
728 put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
729 { return do_put(__s, __f, __fill, __v); }
731 iter_type
732 put(iter_type __s, ios_base& __f, char_type __fill,
733 long double __v) const
734 { return do_put(__s, __f, __fill, __v); }
736 iter_type
737 put(iter_type __s, ios_base& __f, char_type __fill,
738 const void* __v) const
739 { return do_put(__s, __f, __fill, __v); }
741 protected:
742 virtual
743 ~num_put() { };
745 virtual iter_type
746 do_put(iter_type, ios_base&, char_type __fill, bool __v) const;
748 virtual iter_type
749 do_put(iter_type, ios_base&, char_type __fill, long __v) const;
751 #ifdef _GLIBCPP_USE_LONG_LONG
752 virtual iter_type
753 do_put(iter_type, ios_base&, char_type __fill, long long __v) const;
754 #endif
756 virtual iter_type
757 do_put(iter_type, ios_base&, char_type __fill, unsigned long) const;
759 #ifdef _GLIBCPP_USE_LONG_LONG
760 virtual iter_type
761 do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const;
762 #endif
764 virtual iter_type
765 do_put(iter_type, ios_base&, char_type __fill, double __v) const;
767 virtual iter_type
768 do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
770 virtual iter_type
771 do_put(iter_type, ios_base&, char_type __fill, const void* __v) const;
774 template <typename _CharT, typename _OutIter>
775 locale::id num_put<_CharT, _OutIter>::id;
777 template<typename _CharT>
778 class numpunct : public locale::facet
780 public:
781 // Types:
782 typedef _CharT char_type;
783 typedef basic_string<_CharT> string_type;
785 static locale::id id;
787 private:
788 char_type _M_decimal_point;
789 char_type _M_thousands_sep;
790 string _M_grouping;
791 string_type _M_truename;
792 string_type _M_falsename;
794 public:
795 explicit
796 numpunct(size_t __refs = 0) : locale::facet(__refs)
797 { _M_initialize_numpunct(); }
799 explicit
800 numpunct(__c_locale __cloc, size_t __refs = 0) : locale::facet(__refs)
801 { _M_initialize_numpunct(__cloc); }
803 char_type
804 decimal_point() const
805 { return do_decimal_point(); }
807 char_type
808 thousands_sep() const
809 { return do_thousands_sep(); }
811 string
812 grouping() const
813 { return do_grouping(); }
815 string_type
816 truename() const
817 { return do_truename(); }
819 string_type
820 falsename() const
821 { return do_falsename(); }
823 protected:
824 virtual
825 ~numpunct() { }
827 virtual char_type
828 do_decimal_point() const
829 { return _M_decimal_point; }
831 virtual char_type
832 do_thousands_sep() const
833 { return _M_thousands_sep; }
835 virtual string
836 do_grouping() const
837 { return _M_grouping; }
839 virtual string_type
840 do_truename() const
841 { return _M_truename; }
843 virtual string_type
844 do_falsename() const
845 { return _M_falsename; }
847 // For use at construction time only.
848 void
849 _M_initialize_numpunct(__c_locale __cloc = NULL);
852 template<typename _CharT>
853 locale::id numpunct<_CharT>::id;
855 template<typename _CharT>
856 void
857 numpunct<_CharT>::_M_initialize_numpunct(__c_locale /*__cloc*/)
859 // NB: Cannot be made generic.
862 template<>
863 void
864 numpunct<char>::_M_initialize_numpunct(__c_locale __cloc);
865 #ifdef _GLIBCPP_USE_WCHAR_T
866 template<>
867 void
868 numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc);
869 #endif
872 template<typename _CharT>
873 class numpunct_byname : public numpunct<_CharT>
875 __c_locale _M_c_locale_numpunct;
876 public:
877 typedef _CharT char_type;
878 typedef basic_string<_CharT> string_type;
880 explicit
881 numpunct_byname(const char* __s, size_t __refs = 0)
882 : numpunct<_CharT>(__refs)
884 _S_create_c_locale(_M_c_locale_numpunct, __s);
885 _M_initialize_numpunct(_M_c_locale_numpunct);
888 protected:
889 virtual
890 ~numpunct_byname()
891 { _S_destroy_c_locale(_M_c_locale_numpunct); }
895 template<typename _CharT>
896 class collate : public locale::facet
898 public:
899 // Types:
900 typedef _CharT char_type;
901 typedef basic_string<_CharT> string_type;
903 static locale::id id;
905 explicit
906 collate(size_t __refs = 0) : locale::facet(__refs) { }
908 int
909 compare(const _CharT* __lo1, const _CharT* __hi1,
910 const _CharT* __lo2, const _CharT* __hi2) const
911 { return this->do_compare(__lo1, __hi1, __lo2, __hi2); }
913 string_type
914 transform(const _CharT* __lo, const _CharT* __hi) const
915 { return this->do_transform(__lo, __hi); }
917 long
918 hash(const _CharT* __lo, const _CharT* __hi) const
919 { return this->do_hash(__lo, __hi); }
921 protected:
922 ~collate() { } // virtual
924 virtual int
925 do_compare(const _CharT* __lo1, const _CharT* __hi1,
926 const _CharT* __lo2, const _CharT* __hi2) const;
928 virtual string_type
929 do_transform(const _CharT* __lo, const _CharT* __hi) const;
931 virtual long
932 do_hash(const _CharT* __lo, const _CharT* __hi) const;
935 template<typename _CharT>
936 locale::id collate<_CharT>::id;
938 // Required specializations.
939 template<>
940 int
941 collate<char>::do_compare(const char* __lo1, const char* __hi1,
942 const char* __lo2, const char* __hi2) const;
944 template<>
945 string
946 collate<char>::do_transform(const char* __lo, const char* __hi) const;
948 template<>
949 long
950 collate<char>::do_hash(const char* __lo, const char* __hi) const;
951 #ifdef _GLIBCPP_USE_WCHAR_T
952 template<>
953 int
954 collate<wchar_t>::do_compare(const wchar_t* __lo1, const wchar_t* __hi1,
955 const wchar_t* __lo2,
956 const wchar_t* __hi2) const;
958 template<>
959 wstring
960 collate<wchar_t>::do_transform(const wchar_t* __lo,
961 const wchar_t* __hi) const;
963 template<>
964 long
965 collate<wchar_t>::do_hash(const wchar_t* __lo, const wchar_t* __hi) const;
966 #endif
968 template<typename _CharT>
969 class collate_byname : public collate<_CharT>
971 public:
972 // Types:
973 typedef _CharT char_type;
974 typedef basic_string<_CharT> string_type;
976 explicit
977 collate_byname(const char*, size_t __refs = 0);
979 protected:
980 virtual
981 ~collate_byname() { }
984 template<>
985 collate_byname<char>::collate_byname(const char*, size_t __refs);
986 #ifdef _GLIBCPP_USE_WCHAR_T
987 template<>
988 collate_byname<wchar_t>::collate_byname(const char*, size_t __refs);
989 #endif
991 class time_base
993 public:
994 enum dateorder { no_order, dmy, mdy, ymd, ydm };
997 template<typename _CharT, typename _InIter>
998 class time_get : public locale::facet, public time_base
1000 public:
1001 // Types:
1002 typedef _CharT char_type;
1003 typedef _InIter iter_type;
1005 static locale::id id;
1007 explicit
1008 time_get(size_t __refs = 0)
1009 : locale::facet (__refs), _M_daynames(0), _M_monthnames(0) { }
1011 dateorder
1012 date_order() const
1013 { return do_date_order(); }
1015 iter_type
1016 get_time(iter_type __s, iter_type __end, ios_base& __f,
1017 ios_base::iostate& __err, tm* __t) const
1018 { return do_get_time(__s, __end, __f, __err, __t); }
1020 iter_type
1021 get_date(iter_type __s, iter_type __end, ios_base& __f,
1022 ios_base::iostate& __err, tm* __t) const
1023 { return do_get_date(__s, __end, __f, __err, __t); }
1025 iter_type
1026 get_weekday(iter_type __s, iter_type __end, ios_base& __f,
1027 ios_base::iostate& __err, tm* __t) const
1028 { return do_get_weekday(__s,__end,__f,__err,__t); }
1030 iter_type
1031 get_monthname(iter_type __s, iter_type __end, ios_base& __f,
1032 ios_base::iostate& __err, tm* __t) const
1033 { return do_get_monthname(__s,__end,__f,__err,__t); }
1035 iter_type
1036 get_year(iter_type __s, iter_type __end, ios_base& __f,
1037 ios_base::iostate& __err, tm* __t) const
1038 { return do_get_year(__s,__end,__f,__err,__t); }
1040 protected:
1041 virtual
1042 ~time_get()
1044 delete [] _M_monthnames;
1045 delete [] _M_daynames;
1048 virtual dateorder
1049 do_date_order() const
1050 { return time_base::ymd; }
1052 virtual iter_type
1053 do_get_time(iter_type __s, iter_type /*__end*/, ios_base&,
1054 ios_base::iostate& /*__err*/, tm* /*__t*/) const
1055 { return __s; }
1057 virtual iter_type
1058 do_get_date(iter_type __s, iter_type /*__end*/, ios_base&,
1059 ios_base::iostate& /*__err*/, tm* /*__t*/) const
1060 { return __s; }
1062 virtual iter_type
1063 do_get_weekday(iter_type __s, iter_type __end, ios_base&,
1064 ios_base::iostate& __err, tm* __t) const;
1066 virtual iter_type
1067 do_get_monthname(iter_type __s, iter_type __end, ios_base&,
1068 ios_base::iostate& __err, tm* __t) const;
1070 virtual iter_type
1071 do_get_year(iter_type __s, iter_type /*__end*/, ios_base&,
1072 ios_base::iostate& /*__err*/, tm* /*__t*/) const
1073 { return __s; }
1075 mutable basic_string<_CharT>* _M_daynames;
1076 mutable basic_string<_CharT>* _M_monthnames;
1079 template<typename _CharT, typename _InIter>
1080 locale::id time_get<_CharT, _InIter>::id;
1082 template<typename _CharT, typename _InIter>
1083 class time_get_byname : public time_get<_CharT, _InIter>
1085 public:
1086 typedef _CharT char_type;
1087 typedef _InIter iter_type;
1089 explicit
1090 time_get_byname(const char*, size_t __refs = 0)
1091 : time_get<_CharT, _InIter>(__refs) { }
1092 protected:
1093 virtual
1094 ~time_get_byname() { }
1097 template<typename _CharT, typename _OutIter>
1098 class time_put : public locale::facet, public time_base
1100 public:
1101 typedef _CharT char_type;
1102 typedef _OutIter iter_type;
1104 static locale::id id;
1106 explicit
1107 time_put(size_t __refs = 0) : locale::facet (__refs) { }
1109 // NB: this is a nonvirtual, calls do_put in a loop.
1110 iter_type
1111 put(iter_type __s, ios_base& /*__f*/, char_type /*__fill*/,
1112 const tm* /*__tmb*/, const _CharT* /*__pattern*/,
1113 const _CharT* /*__pat_end*/) const
1114 { return __s; }
1116 iter_type
1117 put(iter_type __s, ios_base& __f, char_type __fill,
1118 const tm* __tmb, char __format, char __modifier = 0) const
1119 { return do_put(__s, __f, __fill, __tmb, __format, __modifier); }
1121 protected:
1122 virtual
1123 ~time_put() { }
1125 virtual iter_type
1126 do_put(iter_type __s, ios_base&, char_type, const tm* /*__t*/,
1127 char /*__format*/, char /*__mod*/) const
1128 { return __s; }
1131 template<typename _CharT, typename _OutIter>
1132 locale::id time_put<_CharT, _OutIter>::id;
1134 template<typename _CharT, typename _OutIter>
1135 class time_put_byname : public time_put<_CharT, _OutIter>
1137 public:
1138 typedef _CharT char_type;
1139 typedef _OutIter iter_type;
1141 explicit
1142 time_put_byname(const char*, size_t __refs = 0)
1143 : time_put<_CharT, _OutIter> (__refs) { }
1145 protected:
1146 virtual
1147 ~time_put_byname() { }
1151 template<typename _CharT, typename _InIter>
1152 class money_get : public locale::facet
1154 public:
1155 typedef _CharT char_type;
1156 typedef _InIter iter_type;
1157 typedef basic_string<_CharT> string_type;
1159 static locale::id id;
1161 explicit
1162 money_get(size_t __refs = 0) : locale::facet(__refs) { }
1164 iter_type
1165 get(iter_type __s, iter_type __end, bool __intl,
1166 ios_base& __f, ios_base::iostate& __err, long double& __units) const
1167 { return do_get(__s, __end, __intl, __f, __err, __units); }
1169 iter_type
1170 get(iter_type __s, iter_type __end, bool __intl, ios_base& __f,
1171 ios_base::iostate& __err, string_type& __digits) const
1172 { return do_get(__s, __end, __intl, __f, __err, __digits); }
1174 protected:
1175 virtual
1176 ~money_get() { }
1178 virtual iter_type
1179 do_get(iter_type __s, iter_type /*__end*/, bool /*__intl*/,
1180 ios_base& /*__io*/, ios_base::iostate& /*__err*/,
1181 long double& /*__units*/) const
1182 { return __s; }
1184 virtual iter_type
1185 do_get(iter_type __s, iter_type /*__end*/, bool /*__intl*/,
1186 ios_base& /*__io*/, ios_base::iostate& /*__err*/,
1187 string_type& /*__digits*/) const
1188 { return __s; }
1191 template<typename _CharT, typename _InIter>
1192 locale::id money_get<_CharT, _InIter>::id;
1194 template<typename _CharT, typename _OutIter>
1195 class money_put : public locale::facet
1197 public:
1198 typedef _CharT char_type;
1199 typedef _OutIter iter_type;
1200 typedef basic_string<_CharT> string_type;
1202 static locale::id id;
1204 explicit
1205 money_put(size_t __refs = 0) : locale::facet(__refs) { }
1207 iter_type
1208 put(iter_type __s, bool __intl, ios_base& __f,
1209 char_type __fill, long double __units) const
1210 { return do_put(__s, __intl, __f, __fill, __units); }
1212 iter_type
1213 put(iter_type __s, bool __intl, ios_base& __f,
1214 char_type __fill, const string_type& __digits) const
1215 { return do_put(__s, __intl, __f, __fill, __digits); }
1217 protected:
1218 virtual
1219 ~money_put() { }
1221 virtual iter_type
1222 do_put(iter_type __s, bool, ios_base& /*__io*/, char_type /*__fill*/,
1223 long double /*__units*/) const
1224 { return __s; }
1226 virtual iter_type
1227 do_put(iter_type __s, bool, ios_base& /*__io*/, char_type /*__fill*/,
1228 const string_type& /*__digits*/) const
1229 { return __s; }
1232 template<typename _CharT, typename _OutIter>
1233 locale::id money_put<_CharT, _OutIter>::id;
1235 struct money_base
1237 enum part { none, space, symbol, sign, value };
1238 struct pattern { char field[4]; };
1240 static const pattern _S_default_pattern;
1242 // Construct and return valid pattern consisting of some combination of:
1243 // space none symbol sign value
1244 static pattern
1245 _S_construct_pattern(char __preceeds, char __space, char __posn);
1248 template<typename _CharT, bool _Intl>
1249 class moneypunct : public locale::facet, public money_base
1251 public:
1252 // Types:
1253 typedef _CharT char_type;
1254 typedef basic_string<_CharT> string_type;
1256 static const bool intl = _Intl;
1257 static locale::id id;
1259 private:
1260 char_type _M_decimal_point;
1261 char_type _M_thousands_sep;
1262 string _M_grouping;
1263 string_type _M_curr_symbol;
1264 string_type _M_positive_sign;
1265 string_type _M_negative_sign;
1266 int _M_frac_digits;
1267 pattern _M_pos_format;
1268 pattern _M_neg_format;
1270 public:
1271 explicit
1272 moneypunct(size_t __refs = 0) : locale::facet(__refs)
1273 { _M_initialize_moneypunct(); }
1275 explicit
1276 moneypunct(__c_locale __cloc, size_t __refs = 0) : locale::facet(__refs)
1277 { _M_initialize_moneypunct(__cloc); }
1279 char_type
1280 decimal_point() const
1281 { return this->do_decimal_point(); }
1283 char_type
1284 thousands_sep() const
1285 { return this->do_thousands_sep(); }
1287 string
1288 grouping() const
1289 { return this->do_grouping(); }
1291 string_type
1292 curr_symbol() const
1293 { return this->do_curr_symbol(); }
1295 string_type
1296 positive_sign() const
1297 { return this->do_positive_sign(); }
1299 string_type
1300 negative_sign() const
1301 { return this->do_negative_sign(); }
1303 int
1304 frac_digits() const
1305 { return this->do_frac_digits(); }
1307 pattern
1308 pos_format() const
1309 { return this->do_pos_format(); }
1311 pattern
1312 neg_format() const
1313 { return this->do_neg_format(); }
1315 protected:
1316 virtual
1317 ~moneypunct() { }
1319 virtual char_type
1320 do_decimal_point() const
1321 { return _M_decimal_point; }
1323 virtual char_type
1324 do_thousands_sep() const
1325 { return _M_thousands_sep; }
1327 virtual string
1328 do_grouping() const
1329 { return _M_grouping; }
1331 virtual string_type
1332 do_curr_symbol() const
1333 { return _M_curr_symbol; }
1335 virtual string_type
1336 do_positive_sign() const
1337 { return _M_positive_sign; }
1339 virtual string_type
1340 do_negative_sign() const
1341 { return _M_negative_sign; }
1343 virtual int
1344 do_frac_digits() const
1345 { return _M_frac_digits; }
1347 virtual pattern
1348 do_pos_format() const
1349 { return _M_pos_format; }
1351 virtual pattern
1352 do_neg_format() const
1353 { return _M_neg_format; }
1355 // For use at construction time only.
1356 void
1357 _M_initialize_moneypunct(__c_locale __cloc = NULL);
1360 template<typename _CharT, bool _Intl>
1361 locale::id moneypunct<_CharT, _Intl>::id;
1363 template<typename _CharT, bool _Intl>
1364 const bool moneypunct<_CharT, _Intl>::intl;
1366 template<typename _CharT, bool _Intl>
1367 void
1368 moneypunct<_CharT, _Intl>::_M_initialize_moneypunct(__c_locale /*__cloc*/)
1370 // NB: Cannot be made generic.
1373 template<>
1374 void
1375 moneypunct<char>::_M_initialize_moneypunct(__c_locale __cloc);
1376 #ifdef _GLIBCPP_USE_WCHAR_T
1377 template<>
1378 void
1379 moneypunct<wchar_t>::_M_initialize_moneypunct(__c_locale __cloc);
1380 #endif
1382 template<typename _CharT, bool _Intl>
1383 class moneypunct_byname : public moneypunct<_CharT, _Intl>
1385 __c_locale _M_c_locale_moneypunct;
1386 public:
1387 typedef _CharT char_type;
1388 typedef basic_string<_CharT> string_type;
1390 static const bool intl = _Intl;
1392 explicit
1393 moneypunct_byname(const char* __s, size_t __refs = 0)
1394 : moneypunct<_CharT, _Intl>(__refs)
1396 _S_create_c_locale(_M_c_locale_moneypunct, __s);
1397 _M_initialize_moneypunct(_M_c_locale_moneypunct);
1400 protected:
1401 virtual
1402 ~moneypunct_byname()
1403 { _S_destroy_c_locale(_M_c_locale_moneypunct); }
1406 template<typename _CharT, bool _Intl>
1407 const bool moneypunct_byname<_CharT, _Intl>::intl;
1410 struct messages_base
1412 typedef int catalog;
1415 template<typename _CharT>
1416 class messages : public locale::facet, public messages_base
1418 public:
1419 typedef _CharT char_type;
1420 typedef basic_string<_CharT> string_type;
1422 static locale::id id;
1424 explicit
1425 messages(size_t __refs = 0) : locale::facet(__refs) { }
1427 catalog
1428 open(const basic_string<char>& __s, const locale& __loc) const
1429 { return do_open(__s, __loc); }
1431 string_type
1432 get(catalog __c, int __set, int __msgid, const string_type& __s) const
1433 { return do_get(__c,__set,__msgid,__s); }
1435 void
1436 close(catalog __c) const
1437 { return do_close(__c); }
1439 protected:
1440 virtual
1441 ~messages() { }
1443 // NB: Probably these should be pure, and implemented only in
1444 // specializations of messages<>. But for now...
1445 virtual catalog
1446 do_open(const basic_string<char>&, const locale&) const
1447 { return 0; }
1449 virtual string_type
1450 do_get(catalog, int, int /*__msgid*/, const string_type& __dfault) const
1451 { return __dfault; }
1453 virtual void
1454 do_close(catalog) const { }
1457 template<typename _CharT>
1458 locale::id messages<_CharT>::id;
1460 template<typename _CharT>
1461 class messages_byname : public messages<_CharT>
1463 public:
1464 typedef _CharT char_type;
1465 typedef basic_string<_CharT> string_type;
1467 explicit
1468 messages_byname(const char*, size_t __refs = 0);
1470 protected:
1471 virtual
1472 ~messages_byname() { }
1475 template<>
1476 messages_byname<char>::messages_byname(const char*, size_t __refs);
1477 #ifdef _GLIBCPP_USE_WCHAR_T
1478 template<>
1479 messages_byname<wchar_t>::messages_byname(const char*, size_t __refs);
1480 #endif
1482 // Subclause convenience interfaces, inlines
1483 // NB: these are inline
1484 // because, when used in a loop, some compilers can hoist the body
1485 // out of the loop; then it's just as fast as the C is*() function.
1486 template<typename _CharT>
1487 inline bool
1488 isspace(_CharT __c, const locale& __loc)
1489 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
1491 template<typename _CharT>
1492 inline bool
1493 isprint(_CharT __c, const locale& __loc)
1494 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); }
1496 template<typename _CharT>
1497 inline bool
1498 iscntrl(_CharT __c, const locale& __loc)
1499 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); }
1501 template<typename _CharT>
1502 inline bool
1503 isupper(_CharT __c, const locale& __loc)
1504 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); }
1506 template<typename _CharT>
1507 inline bool islower(_CharT __c, const locale& __loc)
1508 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); }
1510 template<typename _CharT>
1511 inline bool
1512 isalpha(_CharT __c, const locale& __loc)
1513 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }
1515 template<typename _CharT>
1516 inline bool
1517 isdigit(_CharT __c, const locale& __loc)
1518 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); }
1520 template<typename _CharT>
1521 inline bool
1522 ispunct(_CharT __c, const locale& __loc)
1523 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); }
1525 template<typename _CharT>
1526 inline bool
1527 isxdigit(_CharT __c, const locale& __loc)
1528 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); }
1530 template<typename _CharT>
1531 inline bool
1532 isalnum(_CharT __c, const locale& __loc)
1533 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); }
1535 template<typename _CharT>
1536 inline bool
1537 isgraph(_CharT __c, const locale& __loc)
1538 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); }
1540 template<typename _CharT>
1541 inline _CharT
1542 toupper(_CharT __c, const locale& __loc)
1543 { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
1545 template<typename _CharT>
1546 inline _CharT
1547 tolower(_CharT __c, const locale& __loc)
1548 { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }
1549 } // namespace std
1551 #endif /* _CPP_BITS_LOCFACETS_H */
1553 // Local Variables:
1554 // mode:c++
1555 // End: