00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef _LOCALE_CLASSES_H
00037 #define _LOCALE_CLASSES_H 1
00038
00039 #pragma GCC system_header
00040
00041 #include <bits/localefwd.h>
00042 #include <string>
00043 #include <ext/atomicity.h>
00044
00045 _GLIBCXX_BEGIN_NAMESPACE(std)
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 class locale
00062 {
00063 public:
00064
00065
00066 typedef int category;
00067
00068
00069 class facet;
00070 class id;
00071 class _Impl;
00072
00073 friend class facet;
00074 friend class _Impl;
00075
00076 template<typename _Facet>
00077 friend bool
00078 has_facet(const locale&) throw();
00079
00080 template<typename _Facet>
00081 friend const _Facet&
00082 use_facet(const locale&);
00083
00084 template<typename _Cache>
00085 friend struct __use_cache;
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 static const category none = 0;
00098 static const category ctype = 1L << 0;
00099 static const category numeric = 1L << 1;
00100 static const category collate = 1L << 2;
00101 static const category time = 1L << 3;
00102 static const category monetary = 1L << 4;
00103 static const category messages = 1L << 5;
00104 static const category all = (ctype | numeric | collate |
00105 time | monetary | messages);
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 locale() throw();
00117
00118
00119
00120
00121
00122
00123
00124
00125 locale(const locale& __other) throw();
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 explicit
00136 locale(const char* __s);
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 locale(const locale& __base, const char* __s, category __cat);
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 locale(const locale& __base, const locale& __add, category __cat);
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 template<typename _Facet>
00176 locale(const locale& __other, _Facet* __f);
00177
00178
00179 ~locale() throw();
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 const locale&
00190 operator=(const locale& __other) throw();
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 template<typename _Facet>
00205 locale
00206 combine(const locale& __other) const;
00207
00208
00209
00210
00211
00212
00213 string
00214 name() const;
00215
00216
00217
00218
00219
00220
00221
00222
00223 bool
00224 operator==(const locale& __other) const throw ();
00225
00226
00227
00228
00229
00230
00231
00232 bool
00233 operator!=(const locale& __other) const throw ()
00234 { return !(this->operator==(__other)); }
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 template<typename _Char, typename _Traits, typename _Alloc>
00252 bool
00253 operator()(const basic_string<_Char, _Traits, _Alloc>& __s1,
00254 const basic_string<_Char, _Traits, _Alloc>& __s2) const;
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 static locale
00268 global(const locale&);
00269
00270
00271
00272
00273 static const locale&
00274 classic();
00275
00276 private:
00277
00278 _Impl* _M_impl;
00279
00280
00281 static _Impl* _S_classic;
00282
00283
00284 static _Impl* _S_global;
00285
00286
00287
00288
00289
00290 static const char* const* const _S_categories;
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 enum { _S_categories_size = 6 + _GLIBCXX_NUM_CATEGORIES };
00303
00304 #ifdef __GTHREADS
00305 static __gthread_once_t _S_once;
00306 #endif
00307
00308 explicit
00309 locale(_Impl*) throw();
00310
00311 static void
00312 _S_initialize();
00313
00314 static void
00315 _S_initialize_once() throw ();
00316
00317 static category
00318 _S_normalize_category(category);
00319
00320 void
00321 _M_coalesce(const locale& __base, const locale& __add, category __cat);
00322 };
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335 class locale::facet
00336 {
00337 private:
00338 friend class locale;
00339 friend class locale::_Impl;
00340
00341 mutable _Atomic_word _M_refcount;
00342
00343
00344 static __c_locale _S_c_locale;
00345
00346
00347 static const char _S_c_name[2];
00348
00349 #ifdef __GTHREADS
00350 static __gthread_once_t _S_once;
00351 #endif
00352
00353 static void
00354 _S_initialize_once();
00355
00356 protected:
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366 explicit
00367 facet(size_t __refs = 0) throw() : _M_refcount(__refs ? 1 : 0)
00368 { }
00369
00370
00371 virtual
00372 ~facet();
00373
00374 static void
00375 _S_create_c_locale(__c_locale& __cloc, const char* __s,
00376 __c_locale __old = 0);
00377
00378 static __c_locale
00379 _S_clone_c_locale(__c_locale& __cloc) throw ();
00380
00381 static void
00382 _S_destroy_c_locale(__c_locale& __cloc);
00383
00384 static __c_locale
00385 _S_lc_ctype_c_locale(__c_locale __cloc, const char* __s);
00386
00387
00388
00389 static __c_locale
00390 _S_get_c_locale();
00391
00392 _GLIBCXX_CONST static const char*
00393 _S_get_c_name() throw ();
00394
00395 private:
00396 void
00397 _M_add_reference() const throw()
00398 { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
00399
00400 void
00401 _M_remove_reference() const throw()
00402 {
00403 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1)
00404 {
00405 __try
00406 { delete this; }
00407 __catch(...)
00408 { }
00409 }
00410 }
00411
00412 facet(const facet&);
00413
00414 facet&
00415 operator=(const facet&);
00416 };
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429 class locale::id
00430 {
00431 private:
00432 friend class locale;
00433 friend class locale::_Impl;
00434
00435 template<typename _Facet>
00436 friend const _Facet&
00437 use_facet(const locale&);
00438
00439 template<typename _Facet>
00440 friend bool
00441 has_facet(const locale&) throw ();
00442
00443
00444
00445
00446 mutable size_t _M_index;
00447
00448
00449 static _Atomic_word _S_refcount;
00450
00451 void
00452 operator=(const id&);
00453
00454 id(const id&);
00455
00456 public:
00457
00458
00459
00460 id() { }
00461
00462 size_t
00463 _M_id() const throw ();
00464 };
00465
00466
00467
00468 class locale::_Impl
00469 {
00470 public:
00471
00472 friend class locale;
00473 friend class locale::facet;
00474
00475 template<typename _Facet>
00476 friend bool
00477 has_facet(const locale&) throw();
00478
00479 template<typename _Facet>
00480 friend const _Facet&
00481 use_facet(const locale&);
00482
00483 template<typename _Cache>
00484 friend struct __use_cache;
00485
00486 private:
00487
00488 _Atomic_word _M_refcount;
00489 const facet** _M_facets;
00490 size_t _M_facets_size;
00491 const facet** _M_caches;
00492 char** _M_names;
00493 static const locale::id* const _S_id_ctype[];
00494 static const locale::id* const _S_id_numeric[];
00495 static const locale::id* const _S_id_collate[];
00496 static const locale::id* const _S_id_time[];
00497 static const locale::id* const _S_id_monetary[];
00498 static const locale::id* const _S_id_messages[];
00499 static const locale::id* const* const _S_facet_categories[];
00500
00501 void
00502 _M_add_reference() throw()
00503 { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
00504
00505 void
00506 _M_remove_reference() throw()
00507 {
00508 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1)
00509 {
00510 __try
00511 { delete this; }
00512 __catch(...)
00513 { }
00514 }
00515 }
00516
00517 _Impl(const _Impl&, size_t);
00518 _Impl(const char*, size_t);
00519 _Impl(size_t) throw();
00520
00521 ~_Impl() throw();
00522
00523 _Impl(const _Impl&);
00524
00525 void
00526 operator=(const _Impl&);
00527
00528 bool
00529 _M_check_same_name()
00530 {
00531 bool __ret = true;
00532 if (_M_names[1])
00533
00534 for (size_t __i = 0; __ret && __i < _S_categories_size - 1; ++__i)
00535 __ret = __builtin_strcmp(_M_names[__i], _M_names[__i + 1]) == 0;
00536 return __ret;
00537 }
00538
00539 void
00540 _M_replace_categories(const _Impl*, category);
00541
00542 void
00543 _M_replace_category(const _Impl*, const locale::id* const*);
00544
00545 void
00546 _M_replace_facet(const _Impl*, const locale::id*);
00547
00548 void
00549 _M_install_facet(const locale::id*, const facet*);
00550
00551 template<typename _Facet>
00552 void
00553 _M_init_facet(_Facet* __facet)
00554 { _M_install_facet(&_Facet::id, __facet); }
00555
00556 void
00557 _M_install_cache(const facet*, size_t);
00558 };
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572 template<typename _Facet>
00573 bool
00574 has_facet(const locale& __loc) throw();
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589 template<typename _Facet>
00590 const _Facet&
00591 use_facet(const locale& __loc);
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606 template<typename _CharT>
00607 class collate : public locale::facet
00608 {
00609 public:
00610
00611
00612
00613 typedef _CharT char_type;
00614 typedef basic_string<_CharT> string_type;
00615
00616
00617 protected:
00618
00619
00620 __c_locale _M_c_locale_collate;
00621
00622 public:
00623
00624 static locale::id id;
00625
00626
00627
00628
00629
00630
00631
00632
00633 explicit
00634 collate(size_t __refs = 0)
00635 : facet(__refs), _M_c_locale_collate(_S_get_c_locale())
00636 { }
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647 explicit
00648 collate(__c_locale __cloc, size_t __refs = 0)
00649 : facet(__refs), _M_c_locale_collate(_S_clone_c_locale(__cloc))
00650 { }
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664 int
00665 compare(const _CharT* __lo1, const _CharT* __hi1,
00666 const _CharT* __lo2, const _CharT* __hi2) const
00667 { return this->do_compare(__lo1, __hi1, __lo2, __hi2); }
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683 string_type
00684 transform(const _CharT* __lo, const _CharT* __hi) const
00685 { return this->do_transform(__lo, __hi); }
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697 long
00698 hash(const _CharT* __lo, const _CharT* __hi) const
00699 { return this->do_hash(__lo, __hi); }
00700
00701
00702 int
00703 _M_compare(const _CharT*, const _CharT*) const throw ();
00704
00705 size_t
00706 _M_transform(_CharT*, const _CharT*, size_t) const throw ();
00707
00708 protected:
00709
00710 virtual
00711 ~collate()
00712 { _S_destroy_c_locale(_M_c_locale_collate); }
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726 virtual int
00727 do_compare(const _CharT* __lo1, const _CharT* __hi1,
00728 const _CharT* __lo2, const _CharT* __hi2) const;
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742 virtual string_type
00743 do_transform(const _CharT* __lo, const _CharT* __hi) const;
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755 virtual long
00756 do_hash(const _CharT* __lo, const _CharT* __hi) const;
00757 };
00758
00759 template<typename _CharT>
00760 locale::id collate<_CharT>::id;
00761
00762
00763 template<>
00764 int
00765 collate<char>::_M_compare(const char*, const char*) const throw ();
00766
00767 template<>
00768 size_t
00769 collate<char>::_M_transform(char*, const char*, size_t) const throw ();
00770
00771 #ifdef _GLIBCXX_USE_WCHAR_T
00772 template<>
00773 int
00774 collate<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const throw ();
00775
00776 template<>
00777 size_t
00778 collate<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const throw ();
00779 #endif
00780
00781
00782 template<typename _CharT>
00783 class collate_byname : public collate<_CharT>
00784 {
00785 public:
00786
00787
00788 typedef _CharT char_type;
00789 typedef basic_string<_CharT> string_type;
00790
00791
00792 explicit
00793 collate_byname(const char* __s, size_t __refs = 0)
00794 : collate<_CharT>(__refs)
00795 {
00796 if (__builtin_strcmp(__s, "C") != 0
00797 && __builtin_strcmp(__s, "POSIX") != 0)
00798 {
00799 this->_S_destroy_c_locale(this->_M_c_locale_collate);
00800 this->_S_create_c_locale(this->_M_c_locale_collate, __s);
00801 }
00802 }
00803
00804 protected:
00805 virtual
00806 ~collate_byname() { }
00807 };
00808
00809 _GLIBCXX_END_NAMESPACE
00810
00811 #ifndef _GLIBCXX_EXPORT_TEMPLATE
00812 # include <bits/locale_classes.tcc>
00813 #endif
00814
00815 #endif