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>
54 // NB: Don't instantiate required wchar_t facets if no wchar_t support.
55 #ifdef _GLIBCPP_USE_WCHAR_T
56 # define _GLIBCPP_NUM_FACETS 28
58 # define _GLIBCPP_NUM_FACETS 14
62 template<typename _Tp, typename _Alloc>
66 // 22.1.3 Convenience interfaces
67 template<typename _CharT>
69 isspace(_CharT, const locale&);
71 template<typename _CharT>
73 isprint(_CharT, const locale&);
75 template<typename _CharT>
77 iscntrl(_CharT, const locale&);
79 template<typename _CharT>
81 isupper(_CharT, const locale&);
83 template<typename _CharT>
85 islower(_CharT, const locale&);
87 template<typename _CharT>
89 isalpha(_CharT, const locale&);
91 template<typename _CharT>
93 isdigit(_CharT, const locale&);
95 template<typename _CharT>
97 ispunct(_CharT, const locale&);
99 template<typename _CharT>
101 isxdigit(_CharT, const locale&);
103 template<typename _CharT>
105 isalnum(_CharT, const locale&);
107 template<typename _CharT>
109 isgraph(_CharT, const locale&);
111 template<typename _CharT>
113 toupper(_CharT, const locale&);
115 template<typename _CharT>
117 tolower(_CharT, const locale&);
120 // 22.2.1 and 22.2.1.3 ctype
122 template<typename _CharT>
124 template<> class ctype<char>;
125 #ifdef _GLIBCPP_USE_WCHAR_T
126 template<> class ctype<wchar_t>;
128 template<typename _CharT>
130 // NB: Specialized for char and wchar_t in locale_facets.h.
134 template<typename _InternT, typename _ExternT, typename _StateT>
136 template<> class codecvt<char, char, mbstate_t>;
137 #ifdef _GLIBCPP_USE_WCHAR_T
138 template<> class codecvt<wchar_t, char, mbstate_t>;
140 template<typename _InternT, typename _ExternT, typename _StateT>
141 class codecvt_byname;
143 // 22.2.2 and 22.2.3 numeric
144 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
146 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
148 template<typename _CharT> class numpunct;
149 template<typename _CharT> class numpunct_byname;
152 template<typename _CharT>
154 template<typename _CharT> class
157 // 22.2.5 date and time
159 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
161 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
162 class time_get_byname;
163 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
165 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
166 class time_put_byname;
170 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
172 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
174 template<typename _CharT, bool _Intl = false>
176 template<typename _CharT, bool _Intl = false>
177 class moneypunct_byname;
179 // 22.2.7 message retrieval
181 template<typename _CharT>
183 template<typename _CharT>
184 class messages_byname;
186 // 22.1.1 Class locale
191 typedef unsigned int category;
193 // Forward decls and friends:
201 template<typename _Facet>
203 use_facet(const locale&);
205 template<typename _Facet>
207 has_facet(const locale&) throw();
210 // NB: Order must match _S_facet_categories definition in locale.cc
211 static const category none = 0;
212 static const category ctype = 1L << 0;
213 static const category numeric = 1L << 1;
214 static const category collate = 1L << 2;
215 static const category time = 1L << 3;
216 static const category monetary = 1L << 4;
217 static const category messages = 1L << 5;
218 static const category all = (collate | ctype | monetary |
219 numeric | time | messages);
221 // Construct/copy/destroy:
224 locale(const locale& __other) throw();
227 locale(const char* __std_name);
229 locale(const locale& __base, const char* __s, category __cat);
231 locale(const locale& __base, const locale& __add, category __cat);
233 template<typename _Facet>
234 locale(const locale& __other, _Facet* __f);
239 operator=(const locale& __other) throw();
241 template<typename _Facet>
243 combine(const locale& __other) const;
245 // Locale operations:
250 operator==(const locale& __other) const throw ();
253 operator!=(const locale& __other) const throw ()
254 { return !(this->operator==(__other)); }
256 template<typename _Char, typename _Traits, typename _Alloc>
258 operator()(const basic_string<_Char, _Traits, _Alloc>& __s1,
259 const basic_string<_Char, _Traits, _Alloc>& __s2) const;
261 // Global locale objects:
263 global(const locale&);
269 // The (shared) implementation
272 // The "C" reference locale
273 static _Impl* _S_classic;
275 // Current global reference locale
276 static _Impl* _S_global;
278 static const size_t _S_num_categories = 6;
279 static const size_t _S_num_facets = _GLIBCPP_NUM_FACETS;
282 locale(_Impl*) throw();
292 _S_normalize_category(category);
295 _M_coalesce(const locale& __base, const locale& __add, category __cat);
299 // Implementation object for locale
304 typedef vector<facet*, allocator<facet*> > __vec_facet;
308 friend class locale::facet;
310 template<typename _Facet>
312 use_facet(const locale&);
314 template<typename _Facet>
316 has_facet(const locale&) throw();
320 size_t _M_references;
321 __vec_facet* _M_facets;
322 string _M_names[_S_num_categories];
323 static const locale::id* const _S_id_ctype[];
324 static const locale::id* const _S_id_numeric[];
325 static const locale::id* const _S_id_collate[];
326 static const locale::id* const _S_id_time[];
327 static const locale::id* const _S_id_monetary[];
328 static const locale::id* const _S_id_messages[];
329 static const locale::id* const* const _S_facet_categories[];
332 _M_add_reference() throw()
333 { ++_M_references; } // XXX MT
336 _M_remove_reference() throw()
338 if (--_M_references == 0) // XXX MT
347 _Impl(const _Impl&, size_t);
348 _Impl(string __name, size_t);
355 for (size_t i = 0; i < _S_num_categories - 1; ++i)
356 __ret &= _M_names[i] == _M_names[i + 1];
361 _M_replace_categories(const _Impl*, category);
364 _M_replace_category(const _Impl*, const locale::id* const*);
367 _M_replace_facet(const _Impl*, const locale::id*);
370 _M_install_facet(const locale::id*, facet*);
372 template<typename _Facet>
374 _M_init_facet(_Facet* __facet)
375 { _M_install_facet(&_Facet::id, __facet); }
378 template<typename _Facet>
379 locale::locale(const locale& __other, _Facet* __f)
381 _M_impl = new _Impl(*__other._M_impl, 1);
382 _M_impl->_M_install_facet(&_Facet::id, __f);
383 for (size_t __i = 0; __i < _S_num_categories; ++__i)
384 _M_impl->_M_names[__i] = "*";
387 // 22.1.1.1.2 Class locale::facet
391 friend class locale::_Impl;
392 friend class __enc_traits;
395 size_t _M_references;
398 // Contains data from the underlying "C" library for default "C"
399 // or "POSIX" locale.
400 static __c_locale _S_c_locale;
403 facet(size_t __refs = 0) throw();
409 _S_create_c_locale(__c_locale& __cloc, const char* __s);
412 _S_clone_c_locale(__c_locale& __cloc);
415 _S_destroy_c_locale(__c_locale& __cloc);
419 _M_add_reference() throw();
422 _M_remove_reference() throw();
424 facet(const facet&); // Not defined.
427 operator=(const facet&); // Not defined.
431 // 22.1.1.1.3 Class locale::id
436 friend class locale::_Impl;
437 template<typename _Facet>
439 use_facet(const locale&);
440 template<typename _Facet>
442 has_facet(const locale&) throw ();
444 // NB: There is no accessor for _M_index because it may be used
445 // before the constructor is run; the effect of calling a member
446 // function (even an inline) would be undefined.
447 mutable size_t _M_index;
449 // Last id number assigned
450 static size_t _S_highwater;
453 operator=(const id&); // not defined
455 id(const id&); // not defined
458 // NB: This class is always a static data member, and thus can be
459 // counted on to be zero-initialized.
463 template<typename _Facet>
465 use_facet(const locale& __loc);
467 template<typename _Facet>
469 has_facet(const locale& __loc) throw();