3 * Silicon Graphics Computer Systems, Inc.
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
11 * Permission to use or copy this software for any purpose is hereby granted
12 * without fee, provided the above notices are retained on all copies.
13 * Permission to modify the code and to distribute modified code is granted,
14 * provided the above notices are retained, and a notice that the code was
15 * modified is included with the above copyright notice.
18 // WARNING: This is an internal header file, included by other C++
19 // standard library headers. You should not attempt to use this header
23 #ifndef _STLP_INTERNAL_LOCALE_H
24 #define _STLP_INTERNAL_LOCALE_H
26 #ifndef _STLP_INTERNAL_CSTDLIB
27 # include <stl/_cstdlib.h>
30 #ifndef _STLP_INTERNAL_CWCHAR
31 # include <stl/_cwchar.h>
34 #ifndef _STLP_INTERNAL_THREADS_H
35 # include <stl/_threads.h>
38 #ifndef _STLP_STRING_FWD_H
39 # include <stl/_string_fwd.h>
44 class _Locale_impl; // Forward declaration of opaque type.
48 template <class _CharT, class _Traits, class _Alloc>
49 bool __locale_do_operator_call (const locale& __loc,
50 const basic_string<_CharT, _Traits, _Alloc>& __x,
51 const basic_string<_CharT, _Traits, _Alloc>& __y);
53 _STLP_DECLSPEC _Locale_impl * _STLP_CALL _get_Locale_impl( _Locale_impl *locimpl );
54 _STLP_DECLSPEC _Locale_impl * _STLP_CALL _copy_Nameless_Locale_impl( _Locale_impl *locimpl );
56 template <class _Facet>
57 bool _HasFacet(const locale& __loc, const _Facet* __facet) _STLP_NOTHROW;
59 template <class _Facet>
60 _Facet* _UseFacet(const locale& __loc, const _Facet* __facet);
62 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
63 # define locale _STLP_NO_MEM_T_NAME(loc)
66 class _STLP_CLASS_DECLSPEC locale {
69 class _STLP_CLASS_DECLSPEC facet : protected _Refcount_Base {
71 /* Here we filter __init_count user value to 0 or 1 because __init_count is a
72 * size_t instance and _Refcount_Base use __stl_atomic_t instances that might
73 * have lower sizeof and generate roll issues. 1 is enough to keep the facet
74 * alive when required.
76 explicit facet(size_t __init_count = 0) : _Refcount_Base( __init_count == 0 ? 0 : 1 ) {}
79 friend class _Locale_impl;
80 friend facet * _STLP_CALL _get_facet( facet * );
81 friend void _STLP_CALL _release_facet( facet *& );
83 private: // Invalidate assignment and copying.
84 facet(const facet& ) /* : _Refcount_Base(1) {} */;
85 void operator=(const facet&);
88 #if defined (__MVS__) || defined (__OS400__)
93 _STLP_CLASS_DECLSPEC id {
95 friend class _Locale_impl;
101 typedef int category;
102 #if defined (_STLP_STATIC_CONST_INIT_BUG)
105 static const category
114 all = collate | ctype | monetary | numeric | time | messages
115 #if defined (_STLP_STATIC_CONST_INIT_BUG)
120 // construct/copy/destroy:
121 locale() _STLP_NOTHROW;
122 locale(const locale&) _STLP_NOTHROW;
123 explicit locale(const char *);
124 locale(const locale&, const char*, category);
126 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
127 template <class _Facet>
128 locale(const locale& __loc, _Facet* __f) {
130 this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) );
131 this->_M_insert(__f, _Facet::id);
133 this->_M_impl = _get_Locale_impl( __loc._M_impl );
136 #endif // _STLP_MEMBER_TEMPLATES
139 // those are for internal use
140 locale(_Locale_impl*);
144 locale(const locale&, const locale&, category);
145 const locale& operator=(const locale&) _STLP_NOTHROW;
147 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
150 ~locale() _STLP_NOTHROW;
152 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS) && \
153 !defined(_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
154 template <class _Facet>
155 locale combine(const locale& __loc) const {
157 if (!_HasFacet(__loc, __facet))
158 _M_throw_runtime_error();
160 return locale(*this, _UseFacet(__loc, __facet));
162 #endif // _STLP_MEMBER_TEMPLATES && !_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
164 // locale operations:
167 bool operator==(const locale&) const;
168 bool operator!=(const locale&) const;
170 #if !defined (_STLP_MEMBER_TEMPLATES) || defined (_STLP_INLINE_MEMBER_TEMPLATES) || (defined(__MWERKS__) && __MWERKS__ <= 0x2301)
171 bool operator()(const string& __x, const string& __y) const;
172 # ifndef _STLP_NO_WCHAR_T
173 bool operator()(const wstring& __x, const wstring& __y) const;
175 #elif !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
176 template <class _CharT, class _Traits, class _Alloc>
177 bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x,
178 const basic_string<_CharT, _Traits, _Alloc>& __y) const
179 { return __locale_do_operator_call(*this, __x, __y); }
182 // global locale objects:
183 static locale _STLP_CALL global(const locale&);
184 static const locale& _STLP_CALL classic();
186 //protected: // Helper functions for locale globals.
187 facet* _M_get_facet(const id&) const;
189 facet* _M_use_facet(const id&) const;
190 static void _STLP_FUNCTION_THROWS _STLP_CALL _M_throw_runtime_error(const char* = 0);
192 protected: // More helper functions.
193 void _M_insert(facet* __f, id& __id);
196 friend class _Locale_impl;
197 friend class ios_base;
199 protected: // Data members
200 _Locale_impl* _M_impl;
201 _Locale_impl* _M_get_impl() const { return _M_impl; }
204 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
206 # define _Locale _STLP_NO_MEM_T_NAME(loc)
208 class locale : public _Locale {
211 // construct/copy/destroy:
212 locale() _STLP_NOTHROW {}
213 locale(const locale& __loc) _STLP_NOTHROW : _Locale(__loc) {}
214 explicit locale(const char *__str) : _Locale(__str) {}
215 locale(const locale& __loc, const char* __str, category __cat)
216 : _Locale(__loc, __str, __cat) {}
218 template <class _Facet>
219 locale(const locale& __loc, _Facet* __f) {
221 this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) );
222 this->_M_insert(__f, _Facet::id);
224 this->_M_impl = _get_Locale_impl( __loc._M_impl );
229 // those are for internal use
230 locale(_Locale_impl* __impl) : _Locale(__impl) {}
231 locale(const _Locale& __loc) : _Locale(__loc) {}
235 locale(const locale& __loc1, const locale& __loc2, category __cat)
236 : _Locale(__loc1, __loc2, __cat) {}
238 const locale& operator=(const locale& __loc) _STLP_NOTHROW {
239 _Locale::operator=(__loc);
243 template <class _Facet>
244 locale combine(const locale& __loc) const {
246 if (!_HasFacet(__loc, __facet))
247 _M_throw_runtime_error();
249 return locale(*this, _UseFacet(__loc, __facet));
252 // locale operations:
253 bool operator==(const locale& __loc) const { return _Locale::operator==(__loc); }
254 bool operator!=(const locale& __loc) const { return _Locale::operator!=(__loc); }
256 template <class _CharT, class _Traits, class _Alloc>
257 bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x,
258 const basic_string<_CharT, _Traits, _Alloc>& __y) const
259 { return __locale_do_operator_call(*this, __x, __y); }
261 // global locale objects:
262 static locale _STLP_CALL global(const locale& __loc) {
263 return _Locale::global(__loc);
265 static const locale& _STLP_CALL classic() {
266 return __STATIC_CAST(const locale&, _Locale::classic());
270 friend class _Locale_impl;
271 friend class ios_base;
274 #endif /* _STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND */
276 //----------------------------------------------------------------------
279 #ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
280 template <class _Facet>
282 _Use_facet<_Facet>::operator *() const
284 template <class _Facet> inline const _Facet& use_facet(const locale& __loc)
288 return *_UseFacet(__loc, __facet);
292 #ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
293 template <class _Facet>
296 has_facet(const locale& __p_loc) : __loc(__p_loc) {}
297 operator bool() const _STLP_NOTHROW
299 template <class _Facet> inline bool has_facet(const locale& __loc) _STLP_NOTHROW
303 return _HasFacet(__loc, __facet);
306 #ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
307 }; // close class definition
310 template <class _Facet>
311 bool _HasFacet(const locale& __loc, const _Facet* __facet) _STLP_NOTHROW
312 { return (__loc._M_get_facet(_Facet::id) != 0); }
314 template <class _Facet>
315 _Facet* _UseFacet(const locale& __loc, const _Facet* __facet)
316 { return __STATIC_CAST(_Facet*, __loc._M_use_facet(_Facet::id)); }
320 #endif /* _STLP_INTERNAL_LOCALE_H */