2 * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
5 * Silicon Graphics Computer Systems, Inc.
10 * This material is provided "as is", with absolutely no warranty expressed
11 * or implied. Any use is at your own risk.
13 * Permission to use or copy this software for any purpose is hereby granted
14 * without fee, provided the above notices are retained on all copies.
15 * Permission to modify the code and to distribute modified code is granted,
16 * provided the above notices are retained, and a notice that the code was
17 * modified is included with the above copyright notice.
20 // WARNING: This is an internal header file, included by other C++
21 // standard library headers. You should not attempt to use this header
25 #ifndef _STLP_INTERNAL_LOCALE_H
26 #define _STLP_INTERNAL_LOCALE_H
28 #ifndef _STLP_INTERNAL_CSTDLIB
29 # include <stl/_cstdlib.h>
32 #ifndef _STLP_INTERNAL_CWCHAR
33 # include <stl/_cwchar.h>
36 #ifndef _STLP_INTERNAL_THREADS_H
37 # include <stl/_threads.h>
40 #ifndef _STLP_STRING_FWD_H
41 # include <stl/_string_fwd.h>
46 class _Locale_impl; // Forward declaration of opaque type.
50 template <class _CharT, class _Traits, class _Alloc>
51 bool __locale_do_operator_call (const locale& __loc,
52 const basic_string<_CharT, _Traits, _Alloc>& __x,
53 const basic_string<_CharT, _Traits, _Alloc>& __y);
55 _STLP_DECLSPEC _Locale_impl * _STLP_CALL _get_Locale_impl( _Locale_impl *locimpl );
56 _STLP_DECLSPEC _Locale_impl * _STLP_CALL _copy_Nameless_Locale_impl( _Locale_impl *locimpl );
58 template <class _Facet>
59 bool _HasFacet(const locale& __loc, const _Facet* /*__facet */ ) _STLP_NOTHROW;
61 template <class _Facet>
62 _Facet* _UseFacet(const locale& __loc, const _Facet* /* __facet */);
64 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
65 # define locale _STLP_NO_MEM_T_NAME(loc)
68 class _STLP_CLASS_DECLSPEC locale {
71 class _STLP_CLASS_DECLSPEC facet : protected _Refcount_Base {
73 /* Here we filter __init_count user value to 0 or 1 because __init_count is a
74 * size_t instance and _Refcount_Base use __stl_atomic_t instances that might
75 * have lower sizeof and generate roll issues. 1 is enough to keep the facet
76 * alive when required.
78 explicit facet(size_t __init_count = 0) : _Refcount_Base( __init_count == 0 ? 0 : 1 )
79 { if (__init_count ) {/* do nothing. to avoid warnings */} }
80 _STLP_DECLSPEC virtual ~facet();
82 friend class _Locale_impl;
83 friend facet * _STLP_CALL _get_facet( facet * );
84 friend void _STLP_CALL _release_facet( facet *& );
86 private: // Invalidate assignment and copying.
87 facet(const facet& ) /* : _Refcount_Base(1) {} */;
88 void operator=(const facet&);
91 #if defined (__MVS__) || defined (__OS400__)
96 _STLP_CLASS_DECLSPEC id {
98 friend class _Locale_impl;
101 #if defined(__SYMBIAN32__WSD__)
102 static inline size_t& get_locale_id_S_max();
104 static size_t _S_max;
108 typedef int category;
109 #if defined (_STLP_STATIC_CONST_INIT_BUG)
112 static const category
121 all = collate | ctype | monetary | numeric | time | messages
122 #if defined (_STLP_STATIC_CONST_INIT_BUG)
127 // construct/copy/destroy:
128 _STLP_DECLSPEC locale() _STLP_NOTHROW;
129 _STLP_DECLSPEC locale(const locale&) _STLP_NOTHROW;
130 _STLP_DECLSPEC explicit locale(const char *);
131 locale(const locale&, const char*, category);
133 #if defined(__SYMBIAN32__WSD__) || defined (__SYMBIAN32__NO_STATIC_IMPORTS__)
134 #define id GetFacetLocaleId()
137 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
138 template <class _Facet>
139 locale(const locale& __loc, _Facet* __f) {
141 this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) );
142 this->_M_insert(__f, _Facet::id);
144 this->_M_impl = _get_Locale_impl( __loc._M_impl );
147 #if defined(__SYMBIAN32__WSD__) || defined (__SYMBIAN32__NO_STATIC_IMPORTS__)
150 #endif // _STLP_MEMBER_TEMPLATES
153 // those are for internal use
154 locale(_Locale_impl*);
158 locale(const locale&, const locale&, category);
159 _STLP_DECLSPEC const locale& operator=(const locale&) _STLP_NOTHROW;
161 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
164 _STLP_DECLSPEC ~locale() _STLP_NOTHROW;
166 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS) && \
167 !defined(_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
168 template <class _Facet>
169 locale combine(const locale& __loc) const {
171 if (!_HasFacet(__loc, __facet))
172 _M_throw_runtime_error();
174 return locale(*this, _UseFacet(__loc, __facet));
176 #endif // _STLP_MEMBER_TEMPLATES && !_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
178 // locale operations:
179 _STLP_DECLSPEC string name() const;
181 _STLP_DECLSPEC bool operator==(const locale&) const;
182 _STLP_DECLSPEC bool operator!=(const locale&) const;
184 #if !defined (_STLP_MEMBER_TEMPLATES) || defined (_STLP_INLINE_MEMBER_TEMPLATES) || (defined(__MWERKS__) && __MWERKS__ <= 0x2301)
185 _STLP_DECLSPEC bool operator()(const string& __x, const string& __y) const;
186 # ifndef _STLP_NO_WCHAR_T
187 _STLP_DECLSPEC bool operator()(const wstring& __x, const wstring& __y) const;
189 #elif !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
190 template <class _CharT, class _Traits, class _Alloc>
191 bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x,
192 const basic_string<_CharT, _Traits, _Alloc>& __y) const
193 { return __locale_do_operator_call(*this, __x, __y); }
196 // global locale objects:
197 _STLP_DECLSPEC static locale _STLP_CALL global(const locale&);
198 _STLP_DECLSPEC static const locale& _STLP_CALL classic();
200 //protected: // Helper functions for locale globals.
201 _STLP_DECLSPEC facet* _M_get_facet(const id&) const;
203 _STLP_DECLSPEC facet* _M_use_facet(const id&) const;
204 _STLP_DECLSPEC static void _STLP_FUNCTION_THROWS _M_throw_runtime_error(const char* = 0);
206 protected: // More helper functions.
207 _STLP_DECLSPEC void _M_insert(facet* __f, id& __id);
210 friend class _Locale_impl;
211 friend class ios_base;
213 protected: // Data members
214 _Locale_impl* _M_impl;
215 _Locale_impl* _M_get_impl() const { return _M_impl; }
218 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
220 # define _Locale _STLP_NO_MEM_T_NAME(loc)
222 class locale : public _Locale {
225 // construct/copy/destroy:
226 _STLP_DECLSPEC locale() _STLP_NOTHROW {}
227 locale(const locale& __loc) _STLP_NOTHROW : _Locale(__loc) {}
228 explicit locale(const char *__str) : _Locale(__str) {}
229 locale(const locale& __loc, const char* __str, category __cat)
230 : _Locale(__loc, __str, __cat) {}
232 template <class _Facet>
233 locale(const locale& __loc, _Facet* __f) {
235 this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) );
236 this->_M_insert(__f, _Facet::id);
238 this->_M_impl = _get_Locale_impl( __loc._M_impl );
243 // those are for internal use
244 locale(_Locale_impl* __impl) : _Locale(__impl) {}
245 locale(const _Locale& __loc) : _Locale(__loc) {}
249 locale(const locale& __loc1, const locale& __loc2, category __cat)
250 : _Locale(__loc1, __loc2, __cat) {}
252 const locale& operator=(const locale& __loc) _STLP_NOTHROW {
253 _Locale::operator=(__loc);
257 template <class _Facet>
258 locale combine(const locale& __loc) const {
260 if (!_HasFacet(__loc, __facet))
261 _M_throw_runtime_error();
263 return locale(*this, _UseFacet(__loc, __facet));
266 // locale operations:
267 bool operator==(const locale& __loc) const { return _Locale::operator==(__loc); }
268 bool operator!=(const locale& __loc) const { return _Locale::operator!=(__loc); }
270 template <class _CharT, class _Traits, class _Alloc>
271 bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x,
272 const basic_string<_CharT, _Traits, _Alloc>& __y) const
273 { return __locale_do_operator_call(*this, __x, __y); }
275 // global locale objects:
276 static locale _STLP_CALL global(const locale& __loc) {
277 return _Locale::global(__loc);
279 static const locale& _STLP_CALL classic() {
280 return __STATIC_CAST(const locale&, _Locale::classic());
284 friend class _Locale_impl;
285 friend class ios_base;
288 #endif /* _STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND */
290 //----------------------------------------------------------------------
293 #ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
294 template <class _Facet>
296 _Use_facet<_Facet>::operator *() const
298 template <class _Facet> inline const _Facet& use_facet(const locale& __loc)
302 return *_UseFacet(__loc, __facet);
306 #ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
307 template <class _Facet>
310 has_facet(const locale& __p_loc) : __loc(__p_loc) {}
311 operator bool() const _STLP_NOTHROW
313 template <class _Facet> inline bool has_facet(const locale& __loc) _STLP_NOTHROW
317 return _HasFacet(__loc, __facet);
320 #ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
321 }; // close class definition
323 #if defined(__SYMBIAN32__WSD__) || defined (__SYMBIAN32__NO_STATIC_IMPORTS__)
324 #define id GetFacetLocaleId()
327 template <class _Facet>
328 bool _HasFacet(const locale& __loc, const _Facet* ) _STLP_NOTHROW
329 { return (__loc._M_get_facet(_Facet::id) != 0); }
331 template <class _Facet>
332 _Facet* _UseFacet(const locale& __loc, const _Facet* )
333 { return __STATIC_CAST(_Facet*, __loc._M_use_facet(_Facet::id)); }
335 #if defined(__SYMBIAN32__WSD__) || defined (__SYMBIAN32__NO_STATIC_IMPORTS__)
340 #endif /* _STLP_INTERNAL_LOCALE_H */