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
00040 #ifndef _CPP_BITS_LOCCORE_H
00041 #define _CPP_BITS_LOCCORE_H 1
00042
00043 #pragma GCC system_header
00044
00045 #include <bits/c++config.h>
00046 #include <bits/c++locale.h>
00047 #include <climits>
00048 #include <cctype>
00049 #include <string>
00050 #include <bits/functexcept.h>
00051 #include <bits/atomicity.h>
00052
00053 namespace std
00054 {
00055
00056 class locale;
00057
00058
00059 template<typename _CharT>
00060 inline bool
00061 isspace(_CharT, const locale&);
00062
00063 template<typename _CharT>
00064 inline bool
00065 isprint(_CharT, const locale&);
00066
00067 template<typename _CharT>
00068 inline bool
00069 iscntrl(_CharT, const locale&);
00070
00071 template<typename _CharT>
00072 inline bool
00073 isupper(_CharT, const locale&);
00074
00075 template<typename _CharT>
00076 inline bool
00077 islower(_CharT, const locale&);
00078
00079 template<typename _CharT>
00080 inline bool
00081 isalpha(_CharT, const locale&);
00082
00083 template<typename _CharT>
00084 inline bool
00085 isdigit(_CharT, const locale&);
00086
00087 template<typename _CharT>
00088 inline bool
00089 ispunct(_CharT, const locale&);
00090
00091 template<typename _CharT>
00092 inline bool
00093 isxdigit(_CharT, const locale&);
00094
00095 template<typename _CharT>
00096 inline bool
00097 isalnum(_CharT, const locale&);
00098
00099 template<typename _CharT>
00100 inline bool
00101 isgraph(_CharT, const locale&);
00102
00103 template<typename _CharT>
00104 inline _CharT
00105 toupper(_CharT, const locale&);
00106
00107 template<typename _CharT>
00108 inline _CharT
00109 tolower(_CharT, const locale&);
00110
00111
00112
00113 class ctype_base;
00114 template<typename _CharT>
00115 class ctype;
00116 template<> class ctype<char>;
00117 #ifdef _GLIBCPP_USE_WCHAR_T
00118 template<> class ctype<wchar_t>;
00119 #endif
00120 template<typename _CharT>
00121 class ctype_byname;
00122
00123
00124 class codecvt_base;
00125 class __enc_traits;
00126 template<typename _InternT, typename _ExternT, typename _StateT>
00127 class codecvt;
00128 template<> class codecvt<char, char, mbstate_t>;
00129 #ifdef _GLIBCPP_USE_WCHAR_T
00130 template<> class codecvt<wchar_t, char, mbstate_t>;
00131 #endif
00132 template<typename _InternT, typename _ExternT, typename _StateT>
00133 class codecvt_byname;
00134
00135
00136 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
00137 class num_get;
00138 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
00139 class num_put;
00140 template<typename _CharT> class numpunct;
00141 template<typename _CharT> class numpunct_byname;
00142
00143
00144 template<typename _CharT>
00145 class collate;
00146 template<typename _CharT> class
00147 collate_byname;
00148
00149
00150 class time_base;
00151 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
00152 class time_get;
00153 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
00154 class time_get_byname;
00155 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
00156 class time_put;
00157 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
00158 class time_put_byname;
00159
00160
00161 class money_base;
00162 template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
00163 class money_get;
00164 template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
00165 class money_put;
00166 template<typename _CharT, bool _Intl = false>
00167 class moneypunct;
00168 template<typename _CharT, bool _Intl = false>
00169 class moneypunct_byname;
00170
00171
00172 class messages_base;
00173 template<typename _CharT>
00174 class messages;
00175 template<typename _CharT>
00176 class messages_byname;
00177
00178
00179 class locale
00180 {
00181 public:
00182
00183 typedef unsigned int category;
00184
00185
00186 class facet;
00187 class id;
00188 class _Impl;
00189
00190 friend class facet;
00191 friend class _Impl;
00192
00193 template<typename _Facet>
00194 friend const _Facet&
00195 use_facet(const locale&);
00196
00197 template<typename _Facet>
00198 friend bool
00199 has_facet(const locale&) throw();
00200
00201
00202
00203 static const category none = 0;
00204 static const category ctype = 1L << 0;
00205 static const category numeric = 1L << 1;
00206 static const category collate = 1L << 2;
00207 static const category time = 1L << 3;
00208 static const category monetary = 1L << 4;
00209 static const category messages = 1L << 5;
00210 static const category all = (ctype | numeric | collate |
00211 time | monetary | messages);
00212
00213
00214 locale() throw();
00215
00216 locale(const locale& __other) throw();
00217
00218 explicit
00219 locale(const char* __s);
00220
00221 locale(const locale& __base, const char* __s, category __cat);
00222
00223 locale(const locale& __base, const locale& __add, category __cat);
00224
00225 template<typename _Facet>
00226 locale(const locale& __other, _Facet* __f);
00227
00228 ~locale() throw();
00229
00230 const locale&
00231 operator=(const locale& __other) throw();
00232
00233 template<typename _Facet>
00234 locale
00235 combine(const locale& __other) const;
00236
00237
00238 string
00239 name() const;
00240
00241 bool
00242 operator==(const locale& __other) const throw ();
00243
00244 inline bool
00245 operator!=(const locale& __other) const throw ()
00246 { return !(this->operator==(__other)); }
00247
00248 template<typename _Char, typename _Traits, typename _Alloc>
00249 bool
00250 operator()(const basic_string<_Char, _Traits, _Alloc>& __s1,
00251 const basic_string<_Char, _Traits, _Alloc>& __s2) const;
00252
00253
00254 static locale
00255 global(const locale&);
00256
00257 static const locale&
00258 classic();
00259
00260 private:
00261
00262 _Impl* _M_impl;
00263
00264
00265 static _Impl* _S_classic;
00266
00267
00268 static _Impl* _S_global;
00269
00270
00271
00272
00273
00274
00275 static const size_t _S_categories_size = 6;
00276
00277
00278
00279
00280
00281
00282 static const size_t _S_extra_categories_size = _GLIBCPP_NUM_CATEGORIES;
00283
00284
00285
00286
00287
00288 static const char* _S_categories[_S_categories_size
00289 + _S_extra_categories_size];
00290
00291 explicit
00292 locale(_Impl*) throw();
00293
00294 static inline void
00295 _S_initialize()
00296 {
00297 if (!_S_classic)
00298 classic();
00299 }
00300
00301 static category
00302 _S_normalize_category(category);
00303
00304 void
00305 _M_coalesce(const locale& __base, const locale& __add, category __cat);
00306 };
00307
00308
00309
00310 class locale::_Impl
00311 {
00312 public:
00313
00314 friend class locale;
00315 friend class locale::facet;
00316
00317 template<typename _Facet>
00318 friend const _Facet&
00319 use_facet(const locale&);
00320
00321 template<typename _Facet>
00322 friend bool
00323 has_facet(const locale&) throw();
00324
00325 private:
00326
00327 _Atomic_word _M_references;
00328 facet** _M_facets;
00329 size_t _M_facets_size;
00330
00331 char* _M_names[_S_categories_size
00332 + _S_extra_categories_size];
00333 static const locale::id* const _S_id_ctype[];
00334 static const locale::id* const _S_id_numeric[];
00335 static const locale::id* const _S_id_collate[];
00336 static const locale::id* const _S_id_time[];
00337 static const locale::id* const _S_id_monetary[];
00338 static const locale::id* const _S_id_messages[];
00339 static const locale::id* const* const _S_facet_categories[];
00340
00341 inline void
00342 _M_add_reference() throw()
00343 { __atomic_add(&_M_references, 1); }
00344
00345 inline void
00346 _M_remove_reference() throw()
00347 {
00348 if (__exchange_and_add(&_M_references, -1) == 1)
00349 {
00350 try
00351 { delete this; }
00352 catch(...)
00353 { }
00354 }
00355 }
00356
00357 _Impl(const _Impl&, size_t);
00358 _Impl(const char*, size_t);
00359 _Impl(facet**, size_t, bool);
00360
00361 ~_Impl() throw();
00362
00363 _Impl(const _Impl&);
00364
00365 void
00366 operator=(const _Impl&);
00367
00368 inline bool
00369 _M_check_same_name()
00370 {
00371 bool __ret = true;
00372 for (size_t __i = 0;
00373 __ret && __i < _S_categories_size + _S_extra_categories_size - 1;
00374 ++__i)
00375 __ret &= (strcmp(_M_names[__i], _M_names[__i + 1]) == 0);
00376 return __ret;
00377 }
00378
00379 void
00380 _M_replace_categories(const _Impl*, category);
00381
00382 void
00383 _M_replace_category(const _Impl*, const locale::id* const*);
00384
00385 void
00386 _M_replace_facet(const _Impl*, const locale::id*);
00387
00388 void
00389 _M_install_facet(const locale::id*, facet*);
00390
00391 template<typename _Facet>
00392 inline void
00393 _M_init_facet(_Facet* __facet)
00394 { _M_install_facet(&_Facet::id, __facet); }
00395 };
00396
00397 template<typename _Facet>
00398 locale::locale(const locale& __other, _Facet* __f)
00399 {
00400 _M_impl = new _Impl(*__other._M_impl, 1);
00401 _M_impl->_M_install_facet(&_Facet::id, __f);
00402 for (size_t __i = 0;
00403 __i < _S_categories_size + _S_extra_categories_size; ++__i)
00404 {
00405 delete [] _M_impl->_M_names[__i];
00406 char* __new = new char[2];
00407 strcpy(__new, "*");
00408 _M_impl->_M_names[__i] = __new;
00409 }
00410 }
00411
00412
00413 class locale::facet
00414 {
00415 private:
00416 friend class locale;
00417 friend class locale::_Impl;
00418
00419 _Atomic_word _M_references;
00420
00421 protected:
00422
00423
00424 static __c_locale _S_c_locale;
00425
00426
00427 static char _S_c_name[2];
00428
00429 explicit
00430 facet(size_t __refs = 0) throw();
00431
00432 virtual
00433 ~facet();
00434
00435 static void
00436 _S_create_c_locale(__c_locale& __cloc, const char* __s,
00437 __c_locale __old = 0);
00438
00439 static __c_locale
00440 _S_clone_c_locale(__c_locale& __cloc);
00441
00442 static void
00443 _S_destroy_c_locale(__c_locale& __cloc);
00444
00445 private:
00446 void
00447 _M_add_reference() throw();
00448
00449 void
00450 _M_remove_reference() throw();
00451
00452 facet(const facet&);
00453
00454 void
00455 operator=(const facet&);
00456 };
00457
00458
00459
00460 class locale::id
00461 {
00462 private:
00463 friend class locale;
00464 friend class locale::_Impl;
00465 template<typename _Facet>
00466 friend const _Facet&
00467 use_facet(const locale&);
00468 template<typename _Facet>
00469 friend bool
00470 has_facet(const locale&) throw ();
00471
00472
00473
00474
00475 mutable size_t _M_index;
00476
00477
00478 static _Atomic_word _S_highwater;
00479
00480 void
00481 operator=(const id&);
00482
00483 id(const id&);
00484
00485 public:
00486
00487
00488 id();
00489
00490 inline size_t
00491 _M_id() const
00492 {
00493 if (!_M_index)
00494 _M_index = 1 + __exchange_and_add(&_S_highwater, 1);
00495 return _M_index - 1;
00496 }
00497 };
00498
00499 template<typename _Facet>
00500 const _Facet&
00501 use_facet(const locale& __loc);
00502
00503 template<typename _Facet>
00504 bool
00505 has_facet(const locale& __loc) throw();
00506 }
00507
00508 #endif