2002-01-04 Benjamin Kosnik <bkoz@redhat.com>
[official-gcc.git] / libstdc++-v3 / include / bits / localefwd.h
blob558ccabe2dea0d1eef36476cafd219085a26792a
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 /** @file localefwd.h
35 * This is an internal header file, included by other library headers.
36 * You should not attempt to use it directly.
39 #ifndef _CPP_BITS_LOCCORE_H
40 #define _CPP_BITS_LOCCORE_H 1
42 #pragma GCC system_header
44 #include <bits/c++config.h>
45 #include <bits/c++locale.h> // Defines __c_locale, config-specific includes
46 #include <climits> // For CHAR_BIT
47 #include <cctype> // For isspace, etc.
48 #include <string> // For string
49 #include <bits/functexcept.h>
51 namespace std
53 // NB: Don't instantiate required wchar_t facets if no wchar_t support.
54 #ifdef _GLIBCPP_USE_WCHAR_T
55 # define _GLIBCPP_NUM_FACETS 28
56 #else
57 # define _GLIBCPP_NUM_FACETS 14
58 #endif
60 // 22.1.1 Locale
61 template<typename _Tp, typename _Alloc>
62 class vector;
63 class locale;
65 // 22.1.3 Convenience interfaces
66 template<typename _CharT>
67 inline bool
68 isspace(_CharT, const locale&);
70 template<typename _CharT>
71 inline bool
72 isprint(_CharT, const locale&);
74 template<typename _CharT>
75 inline bool
76 iscntrl(_CharT, const locale&);
78 template<typename _CharT>
79 inline bool
80 isupper(_CharT, const locale&);
82 template<typename _CharT>
83 inline bool
84 islower(_CharT, const locale&);
86 template<typename _CharT>
87 inline bool
88 isalpha(_CharT, const locale&);
90 template<typename _CharT>
91 inline bool
92 isdigit(_CharT, const locale&);
94 template<typename _CharT>
95 inline bool
96 ispunct(_CharT, const locale&);
98 template<typename _CharT>
99 inline bool
100 isxdigit(_CharT, const locale&);
102 template<typename _CharT>
103 inline bool
104 isalnum(_CharT, const locale&);
106 template<typename _CharT>
107 inline bool
108 isgraph(_CharT, const locale&);
110 template<typename _CharT>
111 inline _CharT
112 toupper(_CharT, const locale&);
114 template<typename _CharT>
115 inline _CharT
116 tolower(_CharT, const locale&);
119 // 22.2.1 and 22.2.1.3 ctype
120 class ctype_base;
121 template<typename _CharT>
122 class ctype;
123 template<> class ctype<char>;
124 #ifdef _GLIBCPP_USE_WCHAR_T
125 template<> class ctype<wchar_t>;
126 #endif
127 template<typename _CharT>
128 class ctype_byname;
129 // NB: Specialized for char and wchar_t in locale_facets.h.
131 class codecvt_base;
132 class __enc_traits;
133 template<typename _InternT, typename _ExternT, typename _StateT>
134 class codecvt;
135 template<> class codecvt<char, char, mbstate_t>;
136 #ifdef _GLIBCPP_USE_WCHAR_T
137 template<> class codecvt<wchar_t, char, mbstate_t>;
138 #endif
139 template<typename _InternT, typename _ExternT, typename _StateT>
140 class codecvt_byname;
142 // 22.2.2 and 22.2.3 numeric
143 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
144 class num_get;
145 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
146 class num_put;
147 template<typename _CharT> class numpunct;
148 template<typename _CharT> class numpunct_byname;
150 // 22.2.4 collation
151 template<typename _CharT>
152 class collate;
153 template<typename _CharT> class
154 collate_byname;
156 // 22.2.5 date and time
157 class time_base;
158 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
159 class time_get;
160 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
161 class time_get_byname;
162 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
163 class time_put;
164 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
165 class time_put_byname;
167 // 22.2.6 money
168 class money_base;
169 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
170 class money_get;
171 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
172 class money_put;
173 template<typename _CharT, bool _Intl = false>
174 class moneypunct;
175 template<typename _CharT, bool _Intl = false>
176 class moneypunct_byname;
178 // 22.2.7 message retrieval
179 class messages_base;
180 template<typename _CharT>
181 class messages;
182 template<typename _CharT>
183 class messages_byname;
185 // 22.1.1 Class locale
186 class locale
188 public:
189 // Types:
190 typedef unsigned int category;
192 // Forward decls and friends:
193 class facet;
194 class id;
195 class _Impl;
197 friend class facet;
198 friend class _Impl;
200 template<typename _Facet>
201 friend const _Facet&
202 use_facet(const locale&);
204 template<typename _Facet>
205 friend bool
206 has_facet(const locale&) throw();
208 // Category values:
209 // NB: Order must match _S_facet_categories definition in locale.cc
210 static const category none = 0;
211 static const category ctype = 1L << 0;
212 static const category numeric = 1L << 1;
213 static const category collate = 1L << 2;
214 static const category time = 1L << 3;
215 static const category monetary = 1L << 4;
216 static const category messages = 1L << 5;
217 static const category all = (collate | ctype | monetary |
218 numeric | time | messages);
220 // Construct/copy/destroy:
221 locale() throw();
223 locale(const locale& __other) throw();
225 explicit
226 locale(const char* __std_name);
228 locale(const locale& __base, const char* __s, category __cat);
230 locale(const locale& __base, const locale& __add, category __cat);
232 template<typename _Facet>
233 locale(const locale& __other, _Facet* __f);
235 ~locale() throw();
237 const locale&
238 operator=(const locale& __other) throw();
240 template<typename _Facet>
241 locale
242 combine(const locale& __other) const;
244 // Locale operations:
245 string
246 name() const;
248 bool
249 operator==(const locale& __other) const throw ();
251 inline bool
252 operator!=(const locale& __other) const throw ()
253 { return !(this->operator==(__other)); }
255 template<typename _Char, typename _Traits, typename _Alloc>
256 bool
257 operator()(const basic_string<_Char, _Traits, _Alloc>& __s1,
258 const basic_string<_Char, _Traits, _Alloc>& __s2) const;
260 // Global locale objects:
261 static locale
262 global(const locale&);
264 static const locale&
265 classic();
267 private:
268 // The (shared) implementation
269 _Impl* _M_impl;
271 // The "C" reference locale
272 static _Impl* _S_classic;
274 // Current global reference locale
275 static _Impl* _S_global;
277 static const size_t _S_num_categories = 6;
278 static const size_t _S_num_facets = _GLIBCPP_NUM_FACETS;
280 explicit
281 locale(_Impl*) throw();
283 static inline void
284 _S_initialize()
286 if (!_S_classic)
287 classic();
290 static category
291 _S_normalize_category(category);
293 void
294 _M_coalesce(const locale& __base, const locale& __add, category __cat);
298 // locale implementation object
299 class locale::_Impl
301 public:
302 // Types.
303 typedef vector<facet*, allocator<facet*> > __vec_facet;
305 // Friends.
306 friend class locale;
307 friend class locale::facet;
309 template<typename _Facet>
310 friend const _Facet&
311 use_facet(const locale&);
313 template<typename _Facet>
314 friend bool
315 has_facet(const locale&) throw();
317 private:
318 // Data Members.
319 size_t _M_references;
320 __vec_facet* _M_facets;
321 string _M_names[_S_num_categories];
322 static const locale::id* const _S_id_ctype[];
323 static const locale::id* const _S_id_numeric[];
324 static const locale::id* const _S_id_collate[];
325 static const locale::id* const _S_id_time[];
326 static const locale::id* const _S_id_monetary[];
327 static const locale::id* const _S_id_messages[];
328 static const locale::id* const* const _S_facet_categories[];
330 inline void
331 _M_add_reference() throw()
332 { ++_M_references; } // XXX MT
334 inline void
335 _M_remove_reference() throw()
337 if (--_M_references == 0) // XXX MT
339 try
340 { delete this; }
341 catch(...)
346 _Impl(const _Impl&, size_t);
347 _Impl(string __name, size_t);
348 ~_Impl() throw();
350 inline bool
351 _M_check_same_name()
353 bool __ret = true;
354 for (size_t i = 0; i < _S_num_categories - 1; ++i)
355 __ret &= _M_names[i] == _M_names[i + 1];
356 return __ret;
359 void
360 _M_replace_categories(const _Impl*, category);
362 void
363 _M_replace_category(const _Impl*, const locale::id* const*);
365 void
366 _M_replace_facet(const _Impl*, const locale::id*);
368 void
369 _M_install_facet(const locale::id*, facet*);
371 template<typename _Facet>
372 inline void
373 _M_init_facet(_Facet* __facet)
374 { _M_install_facet(&_Facet::id, __facet); }
377 template<typename _Facet>
378 locale::locale(const locale& __other, _Facet* __f)
380 _M_impl = new _Impl(*__other._M_impl, 1);
381 _M_impl->_M_install_facet(&_Facet::id, __f);
382 for (size_t __i = 0; __i < _S_num_categories; ++__i)
383 _M_impl->_M_names[__i] = "*";
386 // 22.1.1.1.2 Class locale::facet
387 class locale::facet
389 friend class locale;
390 friend class locale::_Impl;
391 friend class __enc_traits;
393 protected:
394 // Contains data from the underlying "C" library for default "C"
395 // and "POSIX" locales.
396 static __c_locale _S_c_locale;
398 explicit
399 facet(size_t __refs = 0) throw();
401 virtual
402 ~facet();
404 static void
405 _S_create_c_locale(__c_locale& __cloc, const char* __s);
407 static __c_locale
408 _S_clone_c_locale(__c_locale& __cloc);
410 static void
411 _S_destroy_c_locale(__c_locale& __cloc);
413 private:
414 size_t _M_references;
416 void
417 _M_add_reference() throw();
419 void
420 _M_remove_reference() throw();
422 facet(const facet&); // not defined
424 void
425 operator=(const facet&); // not defined
429 // 22.1.1.1.3 Class locale::id
430 class locale::id
432 private:
433 friend class locale;
434 friend class locale::_Impl;
435 template<typename _Facet>
436 friend const _Facet&
437 use_facet(const locale&);
438 template<typename _Facet>
439 friend bool
440 has_facet(const locale&) throw ();
442 // NB: There is no accessor for _M_index because it may be used
443 // before the constructor is run; the effect of calling a member
444 // function (even an inline) would be undefined.
445 mutable size_t _M_index;
447 // Last id number assigned
448 static size_t _S_highwater;
450 void
451 operator=(const id&); // not defined
453 id(const id&); // not defined
455 public:
456 // NB: This class is always a static data member, and thus can be
457 // counted on to be zero-initialized.
458 id();
461 template<typename _Facet>
462 const _Facet&
463 use_facet(const locale& __loc);
465 template<typename _Facet>
466 bool
467 has_facet(const locale& __loc) throw();
468 } // namespace std
470 #endif