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
00037
00038
00039
00040 #ifndef _LOCALE_CLASSES_H
00041 #define _LOCALE_CLASSES_H 1
00042
00043 #pragma GCC system_header
00044
00045 #include <bits/localefwd.h>
00046 #include <cstring>
00047 #include <string>
00048 #include <ext/atomicity.h>
00049
00050 _GLIBCXX_BEGIN_NAMESPACE(std)
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 class locale
00067 {
00068 public:
00069
00070
00071 typedef int category;
00072
00073
00074 class facet;
00075 class id;
00076 class _Impl;
00077
00078 friend class facet;
00079 friend class _Impl;
00080
00081 template<typename _Facet>
00082 friend bool
00083 has_facet(const locale&) throw();
00084
00085 template<typename _Facet>
00086 friend const _Facet&
00087 use_facet(const locale&);
00088
00089 template<typename _Cache>
00090 friend struct __use_cache;
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 static const category none = 0;
00105 static const category ctype = 1L << 0;
00106 static const category numeric = 1L << 1;
00107 static const category collate = 1L << 2;
00108 static const category time = 1L << 3;
00109 static const category monetary = 1L << 4;
00110 static const category messages = 1L << 5;
00111 static const category all = (ctype | numeric | collate |
00112 time | monetary | messages);
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 locale() throw();
00124
00125
00126
00127
00128
00129
00130
00131
00132 locale(const locale& __other) throw();
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 explicit
00143 locale(const char* __s);
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 locale(const locale& __base, const char* __s, category __cat);
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 locale(const locale& __base, const locale& __add, category __cat);
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 template<typename _Facet>
00183 locale(const locale& __other, _Facet* __f);
00184
00185
00186 ~locale() throw();
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 const locale&
00197 operator=(const locale& __other) throw();
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 template<typename _Facet>
00212 locale
00213 combine(const locale& __other) const;
00214
00215
00216
00217
00218
00219
00220 string
00221 name() const;
00222
00223
00224
00225
00226
00227
00228
00229
00230 bool
00231 operator==(const locale& __other) const throw ();
00232
00233
00234
00235
00236
00237
00238
00239 inline bool
00240 operator!=(const locale& __other) const throw ()
00241 { return !(this->operator==(__other)); }
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 template<typename _Char, typename _Traits, typename _Alloc>
00259 bool
00260 operator()(const basic_string<_Char, _Traits, _Alloc>& __s1,
00261 const basic_string<_Char, _Traits, _Alloc>& __s2) const;
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 static locale
00275 global(const locale&);
00276
00277
00278
00279
00280 static const locale&
00281 classic();
00282
00283 private:
00284
00285 _Impl* _M_impl;
00286
00287
00288 static _Impl* _S_classic;
00289
00290
00291 static _Impl* _S_global;
00292
00293
00294
00295
00296
00297 static const char* const* const _S_categories;
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 enum { _S_categories_size = 6 + _GLIBCXX_NUM_CATEGORIES };
00310
00311 #ifdef __GTHREADS
00312 static __gthread_once_t _S_once;
00313 #endif
00314
00315 explicit
00316 locale(_Impl*) throw();
00317
00318 static void
00319 _S_initialize();
00320
00321 static void
00322 _S_initialize_once();
00323
00324 static category
00325 _S_normalize_category(category);
00326
00327 void
00328 _M_coalesce(const locale& __base, const locale& __add, category __cat);
00329 };
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 class locale::facet
00343 {
00344 private:
00345 friend class locale;
00346 friend class locale::_Impl;
00347
00348 mutable _Atomic_word _M_refcount;
00349
00350
00351 static __c_locale _S_c_locale;
00352
00353
00354 static const char _S_c_name[2];
00355
00356 #ifdef __GTHREADS
00357 static __gthread_once_t _S_once;
00358 #endif
00359
00360 static void
00361 _S_initialize_once();
00362
00363 protected:
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373 explicit
00374 facet(size_t __refs = 0) throw() : _M_refcount(__refs ? 1 : 0)
00375 { }
00376
00377
00378 virtual
00379 ~facet();
00380
00381 static void
00382 _S_create_c_locale(__c_locale& __cloc, const char* __s,
00383 __c_locale __old = 0);
00384
00385 static __c_locale
00386 _S_clone_c_locale(__c_locale& __cloc);
00387
00388 static void
00389 _S_destroy_c_locale(__c_locale& __cloc);
00390
00391
00392
00393 static __c_locale
00394 _S_get_c_locale();
00395
00396 static const char*
00397 _S_get_c_name();
00398
00399 private:
00400 inline void
00401 _M_add_reference() const throw()
00402 { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
00403
00404 inline void
00405 _M_remove_reference() const throw()
00406 {
00407 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1)
00408 {
00409 try
00410 { delete this; }
00411 catch (...)
00412 { }
00413 }
00414 }
00415
00416 facet(const facet&);
00417
00418 facet&
00419 operator=(const facet&);
00420 };
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433 class locale::id
00434 {
00435 private:
00436 friend class locale;
00437 friend class locale::_Impl;
00438
00439 template<typename _Facet>
00440 friend const _Facet&
00441 use_facet(const locale&);
00442
00443 template<typename _Facet>
00444 friend bool
00445 has_facet(const locale&) throw ();
00446
00447
00448
00449
00450 mutable size_t _M_index;
00451
00452
00453 static _Atomic_word _S_refcount;
00454
00455 void
00456 operator=(const id&);
00457
00458 id(const id&);
00459
00460 public:
00461
00462
00463
00464 id() { }
00465
00466 size_t
00467 _M_id() const;
00468 };
00469
00470
00471
00472 class locale::_Impl
00473 {
00474 public:
00475
00476 friend class locale;
00477 friend class locale::facet;
00478
00479 template<typename _Facet>
00480 friend bool
00481 has_facet(const locale&) throw();
00482
00483 template<typename _Facet>
00484 friend const _Facet&
00485 use_facet(const locale&);
00486
00487 template<typename _Cache>
00488 friend struct __use_cache;
00489
00490 private:
00491
00492 _Atomic_word _M_refcount;
00493 const facet** _M_facets;
00494 size_t _M_facets_size;
00495 const facet** _M_caches;
00496 char** _M_names;
00497 static const locale::id* const _S_id_ctype[];
00498 static const locale::id* const _S_id_numeric[];
00499 static const locale::id* const _S_id_collate[];
00500 static const locale::id* const _S_id_time[];
00501 static const locale::id* const _S_id_monetary[];
00502 static const locale::id* const _S_id_messages[];
00503 static const locale::id* const* const _S_facet_categories[];
00504
00505 inline void
00506 _M_add_reference() throw()
00507 { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
00508
00509 inline void
00510 _M_remove_reference() throw()
00511 {
00512 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1)
00513 {
00514 try
00515 { delete this; }
00516 catch(...)
00517 { }
00518 }
00519 }
00520
00521 _Impl(const _Impl&, size_t);
00522 _Impl(const char*, size_t);
00523 _Impl(size_t) throw();
00524
00525 ~_Impl() throw();
00526
00527 _Impl(const _Impl&);
00528
00529 void
00530 operator=(const _Impl&);
00531
00532 inline bool
00533 _M_check_same_name()
00534 {
00535 bool __ret = true;
00536 if (_M_names[1])
00537
00538 for (size_t __i = 0; __ret && __i < _S_categories_size - 1; ++__i)
00539 __ret = std::strcmp(_M_names[__i], _M_names[__i + 1]) == 0;
00540 return __ret;
00541 }
00542
00543 void
00544 _M_replace_categories(const _Impl*, category);
00545
00546 void
00547 _M_replace_category(const _Impl*, const locale::id* const*);
00548
00549 void
00550 _M_replace_facet(const _Impl*, const locale::id*);
00551
00552 void
00553 _M_install_facet(const locale::id*, const facet*);
00554
00555 template<typename _Facet>
00556 inline void
00557 _M_init_facet(_Facet* __facet)
00558 { _M_install_facet(&_Facet::id, __facet); }
00559
00560 void
00561 _M_install_cache(const facet*, size_t);
00562 };
00563
00564 template<typename _Facet>
00565 locale::locale(const locale& __other, _Facet* __f)
00566 {
00567 _M_impl = new _Impl(*__other._M_impl, 1);
00568
00569 try
00570 { _M_impl->_M_install_facet(&_Facet::id, __f); }
00571 catch(...)
00572 {
00573 _M_impl->_M_remove_reference();
00574 __throw_exception_again;
00575 }
00576 delete [] _M_impl->_M_names[0];
00577 _M_impl->_M_names[0] = 0;
00578 }
00579
00580 _GLIBCXX_END_NAMESPACE
00581
00582 #endif