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.
47 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
49 # define locale _STLP_NO_MEM_T_NAME(loc)
54 template <class _CharT, class _Traits, class _Alloc>
55 bool __locale_do_operator_call (const locale* __that,
56 const basic_string<_CharT, _Traits, _Alloc>& __x,
57 const basic_string<_CharT, _Traits, _Alloc>& __y);
59 _STLP_DECLSPEC _Locale_impl * _STLP_CALL _get_Locale_impl( _Locale_impl *locimpl );
60 _STLP_DECLSPEC _Locale_impl * _STLP_CALL _copy_Nameless_Locale_impl( _Locale_impl *locimpl );
62 class _STLP_CLASS_DECLSPEC locale {
65 class _STLP_CLASS_DECLSPEC facet : protected _Refcount_Base {
67 /* Here we filter __init_count user value to 0 or 1 because __init_count is a
68 * size_t instance and _Refcount_Base use __stl_atomic_t instances that might
69 * have lower sizeof and generate roll issues. 1 is enough to keep the facet
70 * alive when required.
72 explicit facet(size_t __init_count = 0) : _Refcount_Base( __init_count == 0 ? 0 : 1 ) {}
75 friend class _Locale_impl;
76 friend facet * _STLP_CALL _get_facet( facet * );
77 friend void _STLP_CALL _release_facet( facet *& );
79 private: // Invalidate assignment and copying.
80 facet(const facet& ) /* : _Refcount_Base(1) {} */;
81 void operator=(const facet&);
84 #if defined (__MVS__) || defined (__OS400__)
89 _STLP_CLASS_DECLSPEC id {
91 friend class _Locale_impl;
98 #if defined (_STLP_STATIC_CONST_INIT_BUG)
101 static const category
110 all = collate | ctype | monetary | numeric | time | messages
111 #if defined (_STLP_STATIC_CONST_INIT_BUG)
116 // construct/copy/destroy:
118 locale(const locale&) _STLP_NOTHROW;
119 explicit locale(const char *);
120 locale(const locale&, const char*, category);
122 #if defined (_STLP_MEMBER_TEMPLATES) && !defined(_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
123 template <class _Facet>
124 locale(const locale& __loc, _Facet* __f) {
126 this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) );
127 this->_M_insert(__f, _Facet::id);
129 this->_M_impl = _get_Locale_impl( __loc._M_impl );
132 #endif // _STLP_MEMBER_TEMPLATES
135 // those are for internal use
136 locale(_Locale_impl*);
140 locale(const locale&, const locale&, category);
141 const locale& operator=(const locale&) _STLP_NOTHROW;
143 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
146 ~locale() _STLP_NOTHROW;
148 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS) && \
149 !defined(_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
150 template <class _Facet>
151 locale combine(const locale& __loc) {
152 facet* __f = __loc._M_get_facet( _Facet::id );
154 _M_throw_runtime_error();
156 locale __result(__loc._M_impl);
158 __result._M_insert(__f, _Facet::id);
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;
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);
183 // global locale objects:
184 static locale _STLP_CALL global(const locale&);
185 static const locale& _STLP_CALL classic();
187 //protected: // Helper functions for locale globals.
188 facet* _M_get_facet(const id&) const;
190 facet* _M_use_facet(const id&) const;
191 static void _STLP_FUNCTION_THROWS _STLP_CALL _M_throw_runtime_error(const char* = 0);
193 protected: // More helper functions.
194 void _M_insert(facet* __f, id& __id);
197 friend class _Locale_impl;
198 friend class ios_base;
200 protected: // Data members
201 _Locale_impl* _M_impl;
202 _Locale_impl* _M_get_impl() const { return _M_impl; }
205 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
207 # define _Locale _STLP_NO_MEM_T_NAME(loc)
209 class locale : public _Locale {
212 // construct/copy/destroy:
214 locale(const locale& __loc) _STLP_NOTHROW : _Locale(__loc) {}
215 explicit locale(const char *__str) : _Locale(__str) {}
216 locale(const locale& __loc, const char* __str, category __cat)
217 : _Locale(__loc, __str, __cat) {}
219 template <class _Facet>
220 locale(const locale& __loc, _Facet* __f) {
222 this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) );
223 this->_M_insert(__f, _Facet::id);
225 this->_M_impl = _get_Locale_impl( __loc._M_impl );
230 // those are for internal use
231 locale(_Locale_impl* __impl) : _Locale(__impl) {}
232 locale(const _Locale& __loc) : _Locale(__loc) {}
236 locale(const locale& __loc1, const locale& __loc2, category __cat)
237 : _Locale(__loc1, __loc2, __cat) {}
239 const locale& operator=(const locale& __loc) _STLP_NOTHROW {
240 _Locale::operator=(__loc);
244 template <class _Facet>
245 locale combine(const locale& __loc) {
246 facet* __f = __loc._M_get_facet( _Facet::id );
248 _M_throw_runtime_error();
250 locale __result(__loc._M_impl);
252 __result._M_insert(__f, _Facet::id);
257 // locale operations:
258 bool operator==(const locale& __loc) const { return _Locale::operator==(__loc); }
259 bool operator!=(const locale& __loc) const { return _Locale::operator!=(__loc); }
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 */
277 //----------------------------------------------------------------------
280 # ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
281 template <class _Facet>
283 _Use_facet<_Facet>::operator *() const
285 template <class _Facet> inline const _Facet& use_facet(const locale& __loc)
288 return *__STATIC_CAST(const _Facet*,__loc._M_use_facet(_Facet::id));
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
302 return (__loc._M_get_facet(_Facet::id) != 0);
305 # ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
306 // close class definition
312 #endif /* _STLP_INTERNAL_LOCALE_H */