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