1 // Locale support -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 // ISO C++ 14882: 22.1 Locales
36 * This is an internal header file, included by other library headers.
37 * You should not attempt to use it directly.
40 #ifndef _CPP_BITS_LOCCORE_H
41 #define _CPP_BITS_LOCCORE_H 1
43 #pragma GCC system_header
45 #include <bits/c++config.h>
46 #include <bits/c++locale.h> // Defines __c_locale, config-specific includes
47 #include <climits> // For CHAR_BIT
48 #include <cctype> // For isspace, etc.
49 #include <string> // For string.
50 #include <bits/functexcept.h>
51 #include <bits/atomicity.h>
58 // 22.1.3 Convenience interfaces
59 template<typename _CharT>
61 isspace(_CharT, const locale&);
63 template<typename _CharT>
65 isprint(_CharT, const locale&);
67 template<typename _CharT>
69 iscntrl(_CharT, const locale&);
71 template<typename _CharT>
73 isupper(_CharT, const locale&);
75 template<typename _CharT>
77 islower(_CharT, const locale&);
79 template<typename _CharT>
81 isalpha(_CharT, const locale&);
83 template<typename _CharT>
85 isdigit(_CharT, const locale&);
87 template<typename _CharT>
89 ispunct(_CharT, const locale&);
91 template<typename _CharT>
93 isxdigit(_CharT, const locale&);
95 template<typename _CharT>
97 isalnum(_CharT, const locale&);
99 template<typename _CharT>
101 isgraph(_CharT, const locale&);
103 template<typename _CharT>
105 toupper(_CharT, const locale&);
107 template<typename _CharT>
109 tolower(_CharT, const locale&);
112 // 22.2.1 and 22.2.1.3 ctype
114 template<typename _CharT>
116 template<> class ctype<char>;
117 #ifdef _GLIBCPP_USE_WCHAR_T
118 template<> class ctype<wchar_t>;
120 template<typename _CharT>
122 // NB: Specialized for char and wchar_t in locale_facets.h.
126 template<typename _InternT, typename _ExternT, typename _StateT>
128 template<> class codecvt<char, char, mbstate_t>;
129 #ifdef _GLIBCPP_USE_WCHAR_T
130 template<> class codecvt<wchar_t, char, mbstate_t>;
132 template<typename _InternT, typename _ExternT, typename _StateT>
133 class codecvt_byname;
135 // 22.2.2 and 22.2.3 numeric
136 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
138 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
140 template<typename _CharT> class numpunct;
141 template<typename _CharT> class numpunct_byname;
144 template<typename _CharT>
146 template<typename _CharT> class
149 // 22.2.5 date and time
151 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
153 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
154 class time_get_byname;
155 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
157 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
158 class time_put_byname;
162 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
164 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
166 template<typename _CharT, bool _Intl = false>
168 template<typename _CharT, bool _Intl = false>
169 class moneypunct_byname;
171 // 22.2.7 message retrieval
173 template<typename _CharT>
175 template<typename _CharT>
176 class messages_byname;
178 // 22.1.1 Class locale
183 typedef unsigned int category;
185 // Forward decls and friends:
193 template<typename _Facet>
195 use_facet(const locale&);
197 template<typename _Facet>
199 has_facet(const locale&) throw();
202 // NB: Order must match _S_facet_categories definition in locale.cc
203 static const category none = 0;
204 static const category ctype = 1L << 0;
205 static const category numeric = 1L << 1;
206 static const category collate = 1L << 2;
207 static const category time = 1L << 3;
208 static const category monetary = 1L << 4;
209 static const category messages = 1L << 5;
210 static const category all = (collate | ctype | monetary |
211 numeric | time | messages);
213 // Construct/copy/destroy:
216 locale(const locale& __other) throw();
219 locale(const char* __s);
221 locale(const locale& __base, const char* __s, category __cat);
223 locale(const locale& __base, const locale& __add, category __cat);
225 template<typename _Facet>
226 locale(const locale& __other, _Facet* __f);
231 operator=(const locale& __other) throw();
233 template<typename _Facet>
235 combine(const locale& __other) const;
237 // Locale operations:
242 operator==(const locale& __other) const throw ();
245 operator!=(const locale& __other) const throw ()
246 { return !(this->operator==(__other)); }
248 template<typename _Char, typename _Traits, typename _Alloc>
250 operator()(const basic_string<_Char, _Traits, _Alloc>& __s1,
251 const basic_string<_Char, _Traits, _Alloc>& __s2) const;
253 // Global locale objects:
255 global(const locale&);
261 // The (shared) implementation
264 // The "C" reference locale
265 static _Impl* _S_classic;
267 // Current global reference locale
268 static _Impl* _S_global;
270 static const size_t _S_num_categories = 6;
273 locale(_Impl*) throw();
283 _S_normalize_category(category);
286 _M_coalesce(const locale& __base, const locale& __add, category __cat);
290 // Implementation object for locale
296 friend class locale::facet;
298 template<typename _Facet>
300 use_facet(const locale&);
302 template<typename _Facet>
304 has_facet(const locale&) throw();
308 _Atomic_word _M_references;
310 size_t _M_facets_size;
311 const char* _M_names[_S_num_categories];
312 static const locale::id* const _S_id_ctype[];
313 static const locale::id* const _S_id_numeric[];
314 static const locale::id* const _S_id_collate[];
315 static const locale::id* const _S_id_time[];
316 static const locale::id* const _S_id_monetary[];
317 static const locale::id* const _S_id_messages[];
318 static const locale::id* const* const _S_facet_categories[];
321 _M_add_reference() throw()
322 { __atomic_add(&_M_references, 1); }
325 _M_remove_reference() throw()
327 if (__exchange_and_add(&_M_references, -1) == 1)
336 _Impl(const _Impl&, size_t);
337 _Impl(const char*, size_t);
338 _Impl(facet**, size_t, bool);
342 _Impl(const _Impl&); // Not defined.
345 operator=(const _Impl&); // Not defined.
351 for (size_t i = 0; __ret && i < _S_num_categories - 1; ++i)
352 __ret &= (strcmp(_M_names[i], _M_names[i + 1]) == 0);
357 _M_replace_categories(const _Impl*, category);
360 _M_replace_category(const _Impl*, const locale::id* const*);
363 _M_replace_facet(const _Impl*, const locale::id*);
366 _M_install_facet(const locale::id*, facet*);
368 template<typename _Facet>
370 _M_init_facet(_Facet* __facet)
371 { _M_install_facet(&_Facet::id, __facet); }
374 template<typename _Facet>
375 locale::locale(const locale& __other, _Facet* __f)
377 _M_impl = new _Impl(*__other._M_impl, 1);
378 _M_impl->_M_install_facet(&_Facet::id, __f);
379 for (size_t __i = 0; __i < _S_num_categories; ++__i)
380 _M_impl->_M_names[__i] = "*";
383 // 22.1.1.1.2 Class locale::facet
388 friend class locale::_Impl;
390 _Atomic_word _M_references;
393 // Contains data from the underlying "C" library for default "C"
394 // or "POSIX" locale.
395 static __c_locale _S_c_locale;
398 facet(size_t __refs = 0) throw();
404 _S_create_c_locale(__c_locale& __cloc, const char* __s,
405 __c_locale __old = 0);
408 _S_clone_c_locale(__c_locale& __cloc);
411 _S_destroy_c_locale(__c_locale& __cloc);
415 _M_add_reference() throw();
418 _M_remove_reference() throw();
420 facet(const facet&); // Not defined.
423 operator=(const facet&); // Not defined.
427 // 22.1.1.1.3 Class locale::id
432 friend class locale::_Impl;
433 template<typename _Facet>
435 use_facet(const locale&);
436 template<typename _Facet>
438 has_facet(const locale&) throw ();
440 // NB: There is no accessor for _M_index because it may be used
441 // before the constructor is run; the effect of calling a member
442 // function (even an inline) would be undefined.
443 mutable size_t _M_index;
445 // Last id number assigned.
446 static _Atomic_word _S_highwater;
449 operator=(const id&); // Not defined.
451 id(const id&); // Not defined.
454 // NB: This class is always a static data member, and thus can be
455 // counted on to be zero-initialized.
462 _M_index = 1 + __exchange_and_add(&_S_highwater, 1);
467 template<typename _Facet>
469 use_facet(const locale& __loc);
471 template<typename _Facet>
473 has_facet(const locale& __loc) throw();