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