Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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