/home/ntakagi/work/STLport-5.1.5/stlport/stl/_locale.hGo to the documentation of this file.00001 /* 00002 * Copyright (c) 1999 00003 * Silicon Graphics Computer Systems, Inc. 00004 * 00005 * Copyright (c) 1999 00006 * Boris Fomitchev 00007 * 00008 * This material is provided "as is", with absolutely no warranty expressed 00009 * or implied. Any use is at your own risk. 00010 * 00011 * Permission to use or copy this software for any purpose is hereby granted 00012 * without fee, provided the above notices are retained on all copies. 00013 * Permission to modify the code and to distribute modified code is granted, 00014 * provided the above notices are retained, and a notice that the code was 00015 * modified is included with the above copyright notice. 00016 * 00017 */ 00018 // WARNING: This is an internal header file, included by other C++ 00019 // standard library headers. You should not attempt to use this header 00020 // file directly. 00021 00022 00023 #ifndef _STLP_INTERNAL_LOCALE_H 00024 #define _STLP_INTERNAL_LOCALE_H 00025 00026 #ifndef _STLP_INTERNAL_CSTDLIB 00027 # include <stl/_cstdlib.h> 00028 #endif 00029 00030 #ifndef _STLP_INTERNAL_CWCHAR 00031 # include <stl/_cwchar.h> 00032 #endif 00033 00034 #ifndef _STLP_INTERNAL_THREADS_H 00035 # include <stl/_threads.h> 00036 #endif 00037 00038 #ifndef _STLP_STRING_FWD_H 00039 # include <stl/_string_fwd.h> 00040 #endif 00041 00042 _STLP_BEGIN_NAMESPACE 00043 00044 class _Locale_impl; // Forward declaration of opaque type. 00045 class ios_base; 00046 class locale; 00047 00048 template <class _CharT, class _Traits, class _Alloc> 00049 bool __locale_do_operator_call (const locale& __loc, 00050 const basic_string<_CharT, _Traits, _Alloc>& __x, 00051 const basic_string<_CharT, _Traits, _Alloc>& __y); 00052 00053 _STLP_DECLSPEC _Locale_impl * _STLP_CALL _get_Locale_impl( _Locale_impl *locimpl ); 00054 _STLP_DECLSPEC _Locale_impl * _STLP_CALL _copy_Nameless_Locale_impl( _Locale_impl *locimpl ); 00055 00056 template <class _Facet> 00057 bool _HasFacet(const locale& __loc, const _Facet* __facet) _STLP_NOTHROW; 00058 00059 template <class _Facet> 00060 _Facet* _UseFacet(const locale& __loc, const _Facet* __facet); 00061 00062 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00063 # define locale _STLP_NO_MEM_T_NAME(loc) 00064 #endif 00065 00066 class _STLP_CLASS_DECLSPEC locale { 00067 public: 00068 // types: 00069 class _STLP_CLASS_DECLSPEC facet : protected _Refcount_Base { 00070 protected: 00071 /* Here we filter __init_count user value to 0 or 1 because __init_count is a 00072 * size_t instance and _Refcount_Base use __stl_atomic_t instances that might 00073 * have lower sizeof and generate roll issues. 1 is enough to keep the facet 00074 * alive when required. 00075 */ 00076 explicit facet(size_t __init_count = 0) : _Refcount_Base( __init_count == 0 ? 0 : 1 ) {} 00077 virtual ~facet(); 00078 friend class locale; 00079 friend class _Locale_impl; 00080 friend facet * _STLP_CALL _get_facet( facet * ); 00081 friend void _STLP_CALL _release_facet( facet *& ); 00082 00083 private: // Invalidate assignment and copying. 00084 facet(const facet& ) /* : _Refcount_Base(1) {} */; 00085 void operator=(const facet&); 00086 }; 00087 00088 #if defined (__MVS__) || defined (__OS400__) 00089 struct 00090 #else 00091 class 00092 #endif 00093 _STLP_CLASS_DECLSPEC id { 00094 friend class locale; 00095 friend class _Locale_impl; 00096 public: 00097 size_t _M_index; 00098 static size_t _S_max; 00099 }; 00100 00101 typedef int category; 00102 #if defined (_STLP_STATIC_CONST_INIT_BUG) 00103 enum _Category { 00104 #else 00105 static const category 00106 #endif 00107 none = 0x000, 00108 collate = 0x010, 00109 ctype = 0x020, 00110 monetary = 0x040, 00111 numeric = 0x100, 00112 time = 0x200, 00113 messages = 0x400, 00114 all = collate | ctype | monetary | numeric | time | messages 00115 #if defined (_STLP_STATIC_CONST_INIT_BUG) 00116 } 00117 #endif 00118 ; 00119 00120 // construct/copy/destroy: 00121 locale() _STLP_NOTHROW; 00122 locale(const locale&) _STLP_NOTHROW; 00123 explicit locale(const char *); 00124 locale(const locale&, const char*, category); 00125 00126 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00127 template <class _Facet> 00128 locale(const locale& __loc, _Facet* __f) { 00129 if ( __f != 0 ) { 00130 this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) ); 00131 this->_M_insert(__f, _Facet::id); 00132 } else { 00133 this->_M_impl = _get_Locale_impl( __loc._M_impl ); 00134 } 00135 } 00136 #endif // _STLP_MEMBER_TEMPLATES 00137 00138 protected: 00139 // those are for internal use 00140 locale(_Locale_impl*); 00141 00142 public: 00143 00144 locale(const locale&, const locale&, category); 00145 const locale& operator=(const locale&) _STLP_NOTHROW; 00146 00147 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00148 virtual 00149 #endif 00150 ~locale() _STLP_NOTHROW; 00151 00152 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS) && \ 00153 !defined(_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00154 template <class _Facet> 00155 locale combine(const locale& __loc) const { 00156 _Facet *__facet = 0; 00157 if (!_HasFacet(__loc, __facet)) 00158 _M_throw_runtime_error(); 00159 00160 return locale(*this, _UseFacet(__loc, __facet)); 00161 } 00162 #endif // _STLP_MEMBER_TEMPLATES && !_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS 00163 00164 // locale operations: 00165 string name() const; 00166 00167 bool operator==(const locale&) const; 00168 bool operator!=(const locale&) const; 00169 00170 #if !defined (_STLP_MEMBER_TEMPLATES) || defined (_STLP_INLINE_MEMBER_TEMPLATES) || (defined(__MWERKS__) && __MWERKS__ <= 0x2301) 00171 bool operator()(const string& __x, const string& __y) const; 00172 # ifndef _STLP_NO_WCHAR_T 00173 bool operator()(const wstring& __x, const wstring& __y) const; 00174 # endif 00175 #elif !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00176 template <class _CharT, class _Traits, class _Alloc> 00177 bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x, 00178 const basic_string<_CharT, _Traits, _Alloc>& __y) const 00179 { return __locale_do_operator_call(*this, __x, __y); } 00180 #endif 00181 00182 // global locale objects: 00183 static locale _STLP_CALL global(const locale&); 00184 static const locale& _STLP_CALL classic(); 00185 00186 //protected: // Helper functions for locale globals. 00187 facet* _M_get_facet(const id&) const; 00188 // same, but throws 00189 facet* _M_use_facet(const id&) const; 00190 static void _STLP_FUNCTION_THROWS _STLP_CALL _M_throw_runtime_error(const char* = 0); 00191 00192 protected: // More helper functions. 00193 void _M_insert(facet* __f, id& __id); 00194 00195 // friends: 00196 friend class _Locale_impl; 00197 friend class ios_base; 00198 00199 protected: // Data members 00200 _Locale_impl* _M_impl; 00201 _Locale_impl* _M_get_impl() const { return _M_impl; } 00202 }; 00203 00204 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00205 # undef locale 00206 # define _Locale _STLP_NO_MEM_T_NAME(loc) 00207 00208 class locale : public _Locale { 00209 public: 00210 00211 // construct/copy/destroy: 00212 locale() _STLP_NOTHROW {} 00213 locale(const locale& __loc) _STLP_NOTHROW : _Locale(__loc) {} 00214 explicit locale(const char *__str) : _Locale(__str) {} 00215 locale(const locale& __loc, const char* __str, category __cat) 00216 : _Locale(__loc, __str, __cat) {} 00217 00218 template <class _Facet> 00219 locale(const locale& __loc, _Facet* __f) { 00220 if ( __f != 0 ) { 00221 this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) ); 00222 this->_M_insert(__f, _Facet::id); 00223 } else { 00224 this->_M_impl = _get_Locale_impl( __loc._M_impl ); 00225 } 00226 } 00227 00228 private: 00229 // those are for internal use 00230 locale(_Locale_impl* __impl) : _Locale(__impl) {} 00231 locale(const _Locale& __loc) : _Locale(__loc) {} 00232 00233 public: 00234 00235 locale(const locale& __loc1, const locale& __loc2, category __cat) 00236 : _Locale(__loc1, __loc2, __cat) {} 00237 00238 const locale& operator=(const locale& __loc) _STLP_NOTHROW { 00239 _Locale::operator=(__loc); 00240 return *this; 00241 } 00242 00243 template <class _Facet> 00244 locale combine(const locale& __loc) const { 00245 _Facet *__facet = 0; 00246 if (!_HasFacet(__loc, __facet)) 00247 _M_throw_runtime_error(); 00248 00249 return locale(*this, _UseFacet(__loc, __facet)); 00250 } 00251 00252 // locale operations: 00253 bool operator==(const locale& __loc) const { return _Locale::operator==(__loc); } 00254 bool operator!=(const locale& __loc) const { return _Locale::operator!=(__loc); } 00255 00256 template <class _CharT, class _Traits, class _Alloc> 00257 bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x, 00258 const basic_string<_CharT, _Traits, _Alloc>& __y) const 00259 { return __locale_do_operator_call(*this, __x, __y); } 00260 00261 // global locale objects: 00262 static locale _STLP_CALL global(const locale& __loc) { 00263 return _Locale::global(__loc); 00264 } 00265 static const locale& _STLP_CALL classic() { 00266 return __STATIC_CAST(const locale&, _Locale::classic()); 00267 } 00268 00269 // friends: 00270 friend class _Locale_impl; 00271 friend class ios_base; 00272 }; 00273 00274 #endif /* _STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND */ 00275 00276 //---------------------------------------------------------------------- 00277 // locale globals 00278 00279 #ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS 00280 template <class _Facet> 00281 inline const _Facet& 00282 _Use_facet<_Facet>::operator *() const 00283 #else 00284 template <class _Facet> inline const _Facet& use_facet(const locale& __loc) 00285 #endif 00286 { 00287 _Facet *__facet = 0; 00288 return *_UseFacet(__loc, __facet); 00289 } 00290 00291 00292 #ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS 00293 template <class _Facet> 00294 struct has_facet { 00295 const locale& __loc; 00296 has_facet(const locale& __p_loc) : __loc(__p_loc) {} 00297 operator bool() const _STLP_NOTHROW 00298 #else 00299 template <class _Facet> inline bool has_facet(const locale& __loc) _STLP_NOTHROW 00300 #endif 00301 { 00302 _Facet *__facet = 0; 00303 return _HasFacet(__loc, __facet); 00304 } 00305 00306 #ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS 00307 }; // close class definition 00308 #endif 00309 00310 template <class _Facet> 00311 bool _HasFacet(const locale& __loc, const _Facet* __facet) _STLP_NOTHROW 00312 { return (__loc._M_get_facet(_Facet::id) != 0); } 00313 00314 template <class _Facet> 00315 _Facet* _UseFacet(const locale& __loc, const _Facet* __facet) 00316 { return __STATIC_CAST(_Facet*, __loc._M_use_facet(_Facet::id)); } 00317 00318 _STLP_END_NAMESPACE 00319 00320 #endif /* _STLP_INTERNAL_LOCALE_H */ 00321 00322 // Local Variables: 00323 // mode:C++ 00324 // End: 00325
Generated on Mon Mar 10 15:32:30 2008 by ![]() |