OSDN Git Service

Add #pragma system_header to header files.
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / bits / localefwd.h
1 // Locale support -*- C++ -*-
2
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.
10
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.
15
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.
20
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.
29
30 //
31 // ISO C++ 14882: 22.1  Locales
32 //
33
34 #ifndef _CPP_BITS_LOCCORE_H
35 #define _CPP_BITS_LOCCORE_H     1
36
37 #pragma GCC system_header
38
39 #include <bits/c++config.h>
40 #include <bits/c++locale.h>     // Defines __c_locale.
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>
45
46 namespace std
47 {
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 26
51 #else
52 # define  _GLIBCPP_NUM_FACETS 13
53 #endif
54
55   // _Count_ones: compile-time computation of number of 1-bits in a value N
56   // This takes only 5 (or 6) instantiations, doing recursive descent
57   // in parallel -- ncm
58   template<unsigned int _Num, int _Shift = (sizeof(unsigned) * CHAR_BIT)/2,
59            unsigned int _Mask = (~0u >> _Shift) >
60     struct _Count_ones;
61
62   // It is preferable to use enumerators instead of integral static data
63   // members to avoid emission of superflous variables -- gdr.
64   template<unsigned int _Num, unsigned int _Mask>
65     struct _Count_ones<_Num, 0, _Mask> 
66     {
67       enum
68       {
69         _M_count = _Num
70       };
71     };
72
73   template<unsigned int _Num, int _Shift, unsigned int _Mask>
74     struct _Count_ones 
75     {
76       enum
77       {
78         _M_halfcount = _Count_ones<_Num, _Shift/2,
79                                    (_Mask^((~_Mask)>>(_Shift/2))) >::_M_count,
80         _M_count = (_M_halfcount&_Mask) + ((_M_halfcount>>_Shift)&_Mask)
81       };
82     };
83
84   // 22.1.1 Locale
85   template<typename _Tp, typename _Alloc> 
86     class vector;
87   class locale;
88
89   // 22.1.3 Convenience interfaces
90   template<typename _CharT> 
91     inline bool 
92     isspace(_CharT, const locale&);
93
94   template<typename _CharT> 
95     inline bool 
96     isprint(_CharT, const locale&);
97
98   template<typename _CharT> 
99     inline bool 
100     iscntrl(_CharT, const locale&);
101
102   template<typename _CharT> 
103     inline bool 
104     isupper(_CharT, const locale&);
105
106   template<typename _CharT> 
107     inline bool 
108     islower(_CharT, const locale&);
109
110   template<typename _CharT> 
111     inline bool 
112     isalpha(_CharT, const locale&);
113
114   template<typename _CharT> 
115     inline bool 
116     isdigit(_CharT, const locale&);
117
118   template<typename _CharT> 
119     inline bool 
120     ispunct(_CharT, const locale&);
121
122   template<typename _CharT> 
123     inline bool 
124     isxdigit(_CharT, const locale&);
125
126   template<typename _CharT> 
127     inline bool 
128     isalnum(_CharT, const locale&);
129
130   template<typename _CharT> 
131     inline bool 
132     isgraph(_CharT, const locale&);
133
134   template<typename _CharT> 
135     inline _CharT 
136     toupper(_CharT, const locale&);
137
138   template<typename _CharT> 
139     inline _CharT 
140     tolower(_CharT, const locale&);
141
142
143   // 22.2.1 and 22.2.1.3 ctype
144   class ctype_base;
145   template<typename _CharT> 
146     class ctype;
147   template<> class ctype<char>;
148 #ifdef _GLIBCPP_USE_WCHAR_T
149   template<> class ctype<wchar_t>;
150 #endif
151   template<typename _CharT> 
152     class ctype_byname;
153   // NB: Specialized for char and wchar_t in locale_facets.h.
154
155   class codecvt_base;
156   template<typename _InternT, typename _ExternT, typename _StateT>
157     class codecvt;
158   template<> class codecvt<char, char, mbstate_t>;
159 #ifdef _GLIBCPP_USE_WCHAR_T
160   template<> class codecvt<wchar_t, char, mbstate_t>;
161 #endif
162   template<typename _InternT, typename _ExternT, typename _StateT>
163     class codecvt_byname;
164
165   // 22.2.2 and 22.2.3 numeric
166   template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
167     class num_get;
168   template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
169     class num_put;
170   template<typename _CharT> class numpunct;
171   template<typename _CharT> class numpunct_byname;
172
173   // 22.2.4 collation
174   template<typename _CharT> 
175     class collate;
176   template<typename _CharT> class 
177     collate_byname;
178
179   // 22.2.5 date and time
180   class time_base;
181   template<typename _CharT, typename _InIter =  istreambuf_iterator<_CharT> >
182     class time_get;
183   template<typename _CharT, typename _InIter =  istreambuf_iterator<_CharT> >
184     class time_get_byname;
185   template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
186     class time_put;
187   template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
188     class time_put_byname;
189
190   // 22.2.6 money
191   class money_base;
192   template<typename _CharT, typename _InIter =  istreambuf_iterator<_CharT> >
193     class money_get;
194   template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
195     class money_put;
196   template<typename _CharT, bool _Intl = false> 
197     class moneypunct;
198   template<typename _CharT, bool _Intl = false> 
199     class moneypunct_byname;
200
201   // 22.2.7 message retrieval
202   class messages_base;
203   template<typename _CharT> 
204     class messages;
205   template<typename _CharT> 
206     class messages_byname;
207
208   // 22.1.1 Class locale
209   class locale
210   {
211   public:
212     // Types:
213     typedef unsigned int        category;
214
215     // Forward decls and friends:
216     class facet;
217     class id;
218     class _Impl;
219
220     friend class facet;
221     friend class _Impl;
222
223     template<typename _Facet>
224       friend const _Facet& 
225       use_facet(const locale&);
226     
227     template<typename _Facet>
228       friend bool 
229       has_facet(const locale&) throw();
230  
231     // Category values:
232     // NB: Order must match _S_facet_categories definition in locale.cc
233     static const category none          = 0;
234     static const category ctype         = 1L << 0;
235     static const category numeric       = 1L << 1;
236     static const category collate       = 1L << 2;
237     static const category time          = 1L << 3;
238     static const category monetary      = 1L << 4;
239     static const category messages      = 1L << 5;
240     static const category all           = (collate | ctype | monetary |
241                                            numeric | time  | messages);
242
243     // Construct/copy/destroy:
244     locale() throw();
245
246     locale(const locale& __other) throw();
247
248     explicit  
249     locale(const char* __std_name);
250
251     locale(const locale& __base, const char* __s, category __cat);
252
253     locale(const locale& __base, const locale& __add, category __cat);
254
255     template<typename _Facet>
256       locale(const locale& __other, _Facet* __f);
257
258     ~locale() throw();
259
260     const locale&  
261     operator=(const locale& __other) throw();
262
263     template<typename _Facet>
264       locale  
265       combine(const locale& __other);
266
267     // Locale operations:
268     string 
269     name() const;
270
271     bool 
272     operator==(const locale& __other) const throw ();
273
274     inline bool  
275     operator!=(const locale& __other) const throw ()
276     { return !(this->operator==(__other));  }
277
278     template<typename _Char, typename _Traits, typename _Alloc>
279       bool  
280       operator()(const basic_string<_Char, _Traits, _Alloc>& __s1,
281                  const basic_string<_Char, _Traits, _Alloc>& __s2) const;
282
283     // Global locale objects:
284     static locale 
285     global(const locale&);
286
287     static const locale& 
288     classic();
289
290   private:
291     // The (shared) implementation
292     _Impl*              _M_impl;  
293
294     // The "C" reference locale
295     static _Impl*       _S_classic; 
296
297     // Current global reference locale
298     static _Impl*       _S_global;  
299
300     static const size_t _S_num_categories = _Count_ones<all>::_M_count;
301     static const size_t _S_num_facets = _GLIBCPP_NUM_FACETS;
302
303     explicit 
304     locale(_Impl*) throw();
305
306     static inline void  
307     _S_initialize()
308     { if (!_S_classic) classic();  }
309
310     static category  
311     _S_normalize_category(category);
312
313     void
314     _M_coalesce(const locale& __base, const locale& __add, category __cat);
315   };
316
317
318   // locale implementation object
319   class locale::_Impl
320   {
321   public:
322     // Types.
323     typedef vector<facet*, allocator<facet*> >  __vec_facet;
324
325     // Friends.
326     friend class locale;
327     friend class locale::facet;
328
329     template<typename _Facet>
330       friend const _Facet&  
331       use_facet(const locale&);
332
333     template<typename _Facet>
334       friend bool  
335       has_facet(const locale&) throw();
336
337   private:
338     // Data Members.
339     size_t                              _M_references;
340     __vec_facet*                        _M_facets;
341     string                              _M_names[_S_num_categories];
342     __c_locale                          _M_c_locale;
343     static const locale::id* const      _S_id_ctype[];
344     static const locale::id* const      _S_id_numeric[];
345     static const locale::id* const      _S_id_collate[];
346     static const locale::id* const      _S_id_time[];
347     static const locale::id* const      _S_id_monetary[];
348     static const locale::id* const      _S_id_messages[];
349     static const locale::id* const* const _S_facet_categories[];
350
351     inline void 
352     _M_add_reference() throw()
353     { ++_M_references; }  // XXX MT
354
355     inline void 
356     _M_remove_reference() throw()
357     {
358       if (_M_references-- == 0)  // XXX MT
359         {
360           try 
361             { delete this; } 
362           catch(...) 
363             { }
364         }
365     }
366
367     _Impl(const _Impl&, size_t);
368     _Impl(string __name, size_t);
369    ~_Impl() throw();
370
371     bool
372     _M_check_same_name()
373     {
374       bool __ret = true;
375       for (size_t i = 0; i < _S_num_categories - 1; ++i)
376         __ret &= _M_names[i] == _M_names[i + 1];
377       return __ret;
378     }
379     void 
380     _M_replace_categories(const _Impl*, category);
381
382     void 
383     _M_replace_category(const _Impl*, const locale::id* const*);
384
385     void 
386     _M_replace_facet(const _Impl*, const locale::id*);
387
388     void 
389     _M_install_facet(const locale::id*, facet*);
390
391     template<typename _Facet>
392       inline void 
393       _M_init_facet(_Facet* __facet)
394       { _M_install_facet(&_Facet::id, __facet);  }
395   };
396
397   template<typename _Facet>
398     locale::locale(const locale& __other, _Facet* __f)
399     {
400       _M_impl = new _Impl(*__other._M_impl, 1);
401       _M_impl->_M_install_facet(&_Facet::id, __f);
402       for (size_t __i = 0; __i < _S_num_categories; ++__i)
403         _M_impl->_M_names[__i] = "*";
404     }
405
406   // 22.1.1.1.2  Class locale::facet
407   class locale::facet
408   {
409     friend class locale;
410     friend class locale::_Impl;
411
412   protected:
413     explicit 
414     facet(size_t __refs = 0) throw();
415
416     virtual 
417     ~facet() { };
418
419     static void
420     _S_create_c_locale(__c_locale& __cloc, const char* __s);
421
422     static void
423     _S_destroy_c_locale(__c_locale& __cloc);
424
425   private:
426     size_t _M_references;
427
428     void 
429     _M_add_reference() throw();
430
431     void 
432     _M_remove_reference() throw();
433
434     facet(const facet&);  // not defined
435
436     void 
437     operator=(const facet&);  // not defined
438   };
439
440
441   // 22.1.1.1.3 Class locale::id
442   class locale::id
443   {
444   private:
445     friend class locale;
446     friend class locale::_Impl;
447     template<typename _Facet>
448       friend const _Facet&  
449       use_facet(const locale&);
450     template<typename _Facet>
451       friend bool           
452       has_facet(const locale&) throw ();
453
454     // NB: There is no accessor for _M_index because it may be used
455     // before the constructor is run; the effect of calling a member
456     // function (even an inline) would be undefined.
457     mutable size_t      _M_index;
458
459     // Last id number assigned
460     static size_t       _S_highwater;   
461
462     void 
463     operator=(const id&);  // not defined
464
465     id(const id&);  // not defined
466
467   public:
468     // NB: This class is always a static data member, and thus can be
469     // counted on to be zero-initialized.
470     // XXX id() : _M_index(0) { }
471     id() { }
472   };
473
474   template<typename _Facet>
475     const _Facet&
476     use_facet(const locale& __loc);
477
478   template<typename _Facet>
479     bool
480     has_facet(const locale& __loc) throw();
481 } // namespace std
482
483 #endif  /* _CPP_BITS_LOCCORE_H */
484
485 // Local Variables:
486 // mode:c++
487 // End:
488