1 // Locale support -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
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)
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,
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 #ifndef _CPP_BITS_LOCCORE_H
35 #define _CPP_BITS_LOCCORE_H 1
37 #pragma GCC system_header
39 #include <bits/c++config.h>
40 #include <bits/c++locale.h> // Defines __c_locale, config-specific includes
41 #include <bits/std_climits.h> // For CHAR_BIT
42 #include <bits/std_string.h> // For string
43 #include <bits/std_cctype.h> // For isspace, etc.
44 #include <bits/functexcept.h>
48 // NB: Don't instantiate required wchar_t facets if no wchar_t support.
49 #ifdef _GLIBCPP_USE_WCHAR_T
50 # define _GLIBCPP_NUM_FACETS 28
52 # define _GLIBCPP_NUM_FACETS 14
56 template<typename _Tp, typename _Alloc>
60 // 22.1.3 Convenience interfaces
61 template<typename _CharT>
63 isspace(_CharT, const locale&);
65 template<typename _CharT>
67 isprint(_CharT, const locale&);
69 template<typename _CharT>
71 iscntrl(_CharT, const locale&);
73 template<typename _CharT>
75 isupper(_CharT, const locale&);
77 template<typename _CharT>
79 islower(_CharT, const locale&);
81 template<typename _CharT>
83 isalpha(_CharT, const locale&);
85 template<typename _CharT>
87 isdigit(_CharT, const locale&);
89 template<typename _CharT>
91 ispunct(_CharT, const locale&);
93 template<typename _CharT>
95 isxdigit(_CharT, const locale&);
97 template<typename _CharT>
99 isalnum(_CharT, const locale&);
101 template<typename _CharT>
103 isgraph(_CharT, const locale&);
105 template<typename _CharT>
107 toupper(_CharT, const locale&);
109 template<typename _CharT>
111 tolower(_CharT, const locale&);
114 // 22.2.1 and 22.2.1.3 ctype
116 template<typename _CharT>
118 template<> class ctype<char>;
119 #ifdef _GLIBCPP_USE_WCHAR_T
120 template<> class ctype<wchar_t>;
122 template<typename _CharT>
124 // NB: Specialized for char and wchar_t in locale_facets.h.
128 template<typename _InternT, typename _ExternT, typename _StateT>
130 template<> class codecvt<char, char, mbstate_t>;
131 #ifdef _GLIBCPP_USE_WCHAR_T
132 template<> class codecvt<wchar_t, char, mbstate_t>;
134 template<typename _InternT, typename _ExternT, typename _StateT>
135 class codecvt_byname;
137 // 22.2.2 and 22.2.3 numeric
138 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
140 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
142 template<typename _CharT> class numpunct;
143 template<typename _CharT> class numpunct_byname;
146 template<typename _CharT>
148 template<typename _CharT> class
151 // 22.2.5 date and time
153 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
155 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
156 class time_get_byname;
157 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
159 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
160 class time_put_byname;
164 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
166 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
168 template<typename _CharT, bool _Intl = false>
170 template<typename _CharT, bool _Intl = false>
171 class moneypunct_byname;
173 // 22.2.7 message retrieval
175 template<typename _CharT>
177 template<typename _CharT>
178 class messages_byname;
180 // 22.1.1 Class locale
185 typedef unsigned int category;
187 // Forward decls and friends:
195 template<typename _Facet>
197 use_facet(const locale&);
199 template<typename _Facet>
201 has_facet(const locale&) throw();
204 // NB: Order must match _S_facet_categories definition in locale.cc
205 static const category none = 0;
206 static const category ctype = 1L << 0;
207 static const category numeric = 1L << 1;
208 static const category collate = 1L << 2;
209 static const category time = 1L << 3;
210 static const category monetary = 1L << 4;
211 static const category messages = 1L << 5;
212 static const category all = (collate | ctype | monetary |
213 numeric | time | messages);
215 // Construct/copy/destroy:
218 locale(const locale& __other) throw();
221 locale(const char* __std_name);
223 locale(const locale& __base, const char* __s, category __cat);
225 locale(const locale& __base, const locale& __add, category __cat);
227 template<typename _Facet>
228 locale(const locale& __other, _Facet* __f);
233 operator=(const locale& __other) throw();
235 template<typename _Facet>
237 combine(const locale& __other);
239 // Locale operations:
244 operator==(const locale& __other) const throw ();
247 operator!=(const locale& __other) const throw ()
248 { return !(this->operator==(__other)); }
250 template<typename _Char, typename _Traits, typename _Alloc>
252 operator()(const basic_string<_Char, _Traits, _Alloc>& __s1,
253 const basic_string<_Char, _Traits, _Alloc>& __s2) const;
255 // Global locale objects:
257 global(const locale&);
263 // The (shared) implementation
266 // The "C" reference locale
267 static _Impl* _S_classic;
269 // Current global reference locale
270 static _Impl* _S_global;
272 static const size_t _S_num_categories = 6;
273 static const size_t _S_num_facets = _GLIBCPP_NUM_FACETS;
276 locale(_Impl*) throw();
280 { if (!_S_classic) classic(); }
283 _S_normalize_category(category);
286 _M_coalesce(const locale& __base, const locale& __add, category __cat);
290 // locale implementation object
295 typedef vector<facet*, allocator<facet*> > __vec_facet;
299 friend class locale::facet;
301 template<typename _Facet>
303 use_facet(const locale&);
305 template<typename _Facet>
307 has_facet(const locale&) throw();
311 size_t _M_references;
312 __vec_facet* _M_facets;
313 string _M_names[_S_num_categories];
314 static const locale::id* const _S_id_ctype[];
315 static const locale::id* const _S_id_numeric[];
316 static const locale::id* const _S_id_collate[];
317 static const locale::id* const _S_id_time[];
318 static const locale::id* const _S_id_monetary[];
319 static const locale::id* const _S_id_messages[];
320 static const locale::id* const* const _S_facet_categories[];
323 _M_add_reference() throw()
324 { ++_M_references; } // XXX MT
327 _M_remove_reference() throw()
329 if (--_M_references == 0) // XXX MT
338 _Impl(const _Impl&, size_t);
339 _Impl(string __name, size_t);
346 for (size_t i = 0; i < _S_num_categories - 1; ++i)
347 __ret &= _M_names[i] == _M_names[i + 1];
351 _M_replace_categories(const _Impl*, category);
354 _M_replace_category(const _Impl*, const locale::id* const*);
357 _M_replace_facet(const _Impl*, const locale::id*);
360 _M_install_facet(const locale::id*, facet*);
362 template<typename _Facet>
364 _M_init_facet(_Facet* __facet)
365 { _M_install_facet(&_Facet::id, __facet); }
368 template<typename _Facet>
369 locale::locale(const locale& __other, _Facet* __f)
371 _M_impl = new _Impl(*__other._M_impl, 1);
372 _M_impl->_M_install_facet(&_Facet::id, __f);
373 for (size_t __i = 0; __i < _S_num_categories; ++__i)
374 _M_impl->_M_names[__i] = "*";
377 // 22.1.1.1.2 Class locale::facet
381 friend class locale::_Impl;
382 friend class __enc_traits;
386 facet(size_t __refs = 0) throw();
392 _S_create_c_locale(__c_locale& __cloc, const char* __s);
395 _S_clone_c_locale(__c_locale& __cloc);
398 _S_destroy_c_locale(__c_locale& __cloc);
401 size_t _M_references;
404 _M_add_reference() throw();
407 _M_remove_reference() throw();
409 facet(const facet&); // not defined
412 operator=(const facet&); // not defined
416 // 22.1.1.1.3 Class locale::id
421 friend class locale::_Impl;
422 template<typename _Facet>
424 use_facet(const locale&);
425 template<typename _Facet>
427 has_facet(const locale&) throw ();
429 // NB: There is no accessor for _M_index because it may be used
430 // before the constructor is run; the effect of calling a member
431 // function (even an inline) would be undefined.
432 mutable size_t _M_index;
434 // Last id number assigned
435 static size_t _S_highwater;
438 operator=(const id&); // not defined
440 id(const id&); // not defined
443 // NB: This class is always a static data member, and thus can be
444 // counted on to be zero-initialized.
445 // XXX id() : _M_index(0) { }
449 template<typename _Facet>
451 use_facet(const locale& __loc);
453 template<typename _Facet>
455 has_facet(const locale& __loc) throw();