williamr@2
|
1 |
/*
|
williamr@4
|
2 |
* Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
|
williamr@4
|
3 |
*
|
williamr@4
|
4 |
* Copyright (c) 1999
|
williamr@4
|
5 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@2
|
6 |
*
|
williamr@2
|
7 |
* Copyright (c) 1999
|
williamr@2
|
8 |
* Boris Fomitchev
|
williamr@2
|
9 |
*
|
williamr@2
|
10 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@2
|
11 |
* or implied. Any use is at your own risk.
|
williamr@2
|
12 |
*
|
williamr@4
|
13 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@2
|
14 |
* without fee, provided the above notices are retained on all copies.
|
williamr@2
|
15 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@2
|
16 |
* provided the above notices are retained, and a notice that the code was
|
williamr@2
|
17 |
* modified is included with the above copyright notice.
|
williamr@2
|
18 |
*
|
williamr@4
|
19 |
*/
|
williamr@2
|
20 |
// WARNING: This is an internal header file, included by other C++
|
williamr@2
|
21 |
// standard library headers. You should not attempt to use this header
|
williamr@2
|
22 |
// file directly.
|
williamr@2
|
23 |
|
williamr@2
|
24 |
|
williamr@2
|
25 |
#ifndef _STLP_INTERNAL_LOCALE_H
|
williamr@2
|
26 |
#define _STLP_INTERNAL_LOCALE_H
|
williamr@2
|
27 |
|
williamr@4
|
28 |
#ifndef _STLP_INTERNAL_CSTDLIB
|
williamr@4
|
29 |
# include <stl/_cstdlib.h>
|
williamr@2
|
30 |
#endif
|
williamr@2
|
31 |
|
williamr@4
|
32 |
#ifndef _STLP_INTERNAL_CWCHAR
|
williamr@4
|
33 |
# include <stl/_cwchar.h>
|
williamr@2
|
34 |
#endif
|
williamr@2
|
35 |
|
williamr@2
|
36 |
#ifndef _STLP_INTERNAL_THREADS_H
|
williamr@4
|
37 |
# include <stl/_threads.h>
|
williamr@2
|
38 |
#endif
|
williamr@2
|
39 |
|
williamr@2
|
40 |
#ifndef _STLP_STRING_FWD_H
|
williamr@4
|
41 |
# include <stl/_string_fwd.h>
|
williamr@2
|
42 |
#endif
|
williamr@2
|
43 |
|
williamr@2
|
44 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
45 |
|
williamr@4
|
46 |
class _Locale_impl; // Forward declaration of opaque type.
|
williamr@4
|
47 |
class ios_base;
|
williamr@4
|
48 |
class locale;
|
williamr@2
|
49 |
|
williamr@2
|
50 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
51 |
bool __locale_do_operator_call (const locale& __loc,
|
williamr@4
|
52 |
const basic_string<_CharT, _Traits, _Alloc>& __x,
|
williamr@4
|
53 |
const basic_string<_CharT, _Traits, _Alloc>& __y);
|
williamr@2
|
54 |
|
williamr@4
|
55 |
_STLP_DECLSPEC _Locale_impl * _STLP_CALL _get_Locale_impl( _Locale_impl *locimpl );
|
williamr@4
|
56 |
_STLP_DECLSPEC _Locale_impl * _STLP_CALL _copy_Nameless_Locale_impl( _Locale_impl *locimpl );
|
williamr@4
|
57 |
|
williamr@4
|
58 |
template <class _Facet>
|
williamr@4
|
59 |
bool _HasFacet(const locale& __loc, const _Facet* /*__facet */ ) _STLP_NOTHROW;
|
williamr@4
|
60 |
|
williamr@4
|
61 |
template <class _Facet>
|
williamr@4
|
62 |
_Facet* _UseFacet(const locale& __loc, const _Facet* /* __facet */);
|
williamr@4
|
63 |
|
williamr@4
|
64 |
#if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
|
williamr@4
|
65 |
# define locale _STLP_NO_MEM_T_NAME(loc)
|
williamr@4
|
66 |
#endif
|
williamr@2
|
67 |
|
williamr@2
|
68 |
class _STLP_CLASS_DECLSPEC locale {
|
williamr@2
|
69 |
public:
|
williamr@2
|
70 |
// types:
|
williamr@4
|
71 |
class _STLP_CLASS_DECLSPEC facet : protected _Refcount_Base {
|
williamr@2
|
72 |
protected:
|
williamr@4
|
73 |
/* Here we filter __init_count user value to 0 or 1 because __init_count is a
|
williamr@4
|
74 |
* size_t instance and _Refcount_Base use __stl_atomic_t instances that might
|
williamr@4
|
75 |
* have lower sizeof and generate roll issues. 1 is enough to keep the facet
|
williamr@4
|
76 |
* alive when required.
|
williamr@4
|
77 |
*/
|
williamr@4
|
78 |
explicit facet(size_t __init_count = 0) : _Refcount_Base( __init_count == 0 ? 0 : 1 )
|
williamr@4
|
79 |
{ if (__init_count ) {/* do nothing. to avoid warnings */} }
|
williamr@2
|
80 |
_STLP_DECLSPEC virtual ~facet();
|
williamr@2
|
81 |
friend class locale;
|
williamr@2
|
82 |
friend class _Locale_impl;
|
williamr@4
|
83 |
friend facet * _STLP_CALL _get_facet( facet * );
|
williamr@4
|
84 |
friend void _STLP_CALL _release_facet( facet *& );
|
williamr@4
|
85 |
|
williamr@2
|
86 |
private: // Invalidate assignment and copying.
|
williamr@4
|
87 |
facet(const facet& ) /* : _Refcount_Base(1) {} */;
|
williamr@4
|
88 |
void operator=(const facet&);
|
williamr@2
|
89 |
};
|
williamr@4
|
90 |
|
williamr@4
|
91 |
#if defined (__MVS__) || defined (__OS400__)
|
williamr@2
|
92 |
struct
|
williamr@2
|
93 |
#else
|
williamr@2
|
94 |
class
|
williamr@2
|
95 |
#endif
|
williamr@4
|
96 |
_STLP_CLASS_DECLSPEC id {
|
williamr@2
|
97 |
friend class locale;
|
williamr@2
|
98 |
friend class _Locale_impl;
|
williamr@2
|
99 |
public:
|
williamr@2
|
100 |
size_t _M_index;
|
williamr@4
|
101 |
#if defined(__SYMBIAN32__WSD__)
|
williamr@4
|
102 |
static inline size_t& get_locale_id_S_max();
|
williamr@2
|
103 |
# else
|
williamr@2
|
104 |
static size_t _S_max;
|
williamr@2
|
105 |
# endif
|
williamr@2
|
106 |
};
|
williamr@2
|
107 |
|
williamr@2
|
108 |
typedef int category;
|
williamr@4
|
109 |
#if defined (_STLP_STATIC_CONST_INIT_BUG)
|
williamr@2
|
110 |
enum _Category {
|
williamr@4
|
111 |
#else
|
williamr@2
|
112 |
static const category
|
williamr@4
|
113 |
#endif
|
williamr@2
|
114 |
none = 0x000,
|
williamr@2
|
115 |
collate = 0x010,
|
williamr@2
|
116 |
ctype = 0x020,
|
williamr@2
|
117 |
monetary = 0x040,
|
williamr@2
|
118 |
numeric = 0x100,
|
williamr@2
|
119 |
time = 0x200,
|
williamr@2
|
120 |
messages = 0x400,
|
williamr@2
|
121 |
all = collate | ctype | monetary | numeric | time | messages
|
williamr@4
|
122 |
#if defined (_STLP_STATIC_CONST_INIT_BUG)
|
williamr@2
|
123 |
}
|
williamr@4
|
124 |
#endif
|
williamr@2
|
125 |
;
|
williamr@2
|
126 |
|
williamr@2
|
127 |
// construct/copy/destroy:
|
williamr@4
|
128 |
_STLP_DECLSPEC locale() _STLP_NOTHROW;
|
williamr@2
|
129 |
_STLP_DECLSPEC locale(const locale&) _STLP_NOTHROW;
|
williamr@4
|
130 |
_STLP_DECLSPEC explicit locale(const char *);
|
williamr@2
|
131 |
locale(const locale&, const char*, category);
|
williamr@2
|
132 |
|
williamr@4
|
133 |
#if defined(__SYMBIAN32__WSD__) || defined (__SYMBIAN32__NO_STATIC_IMPORTS__)
|
williamr@4
|
134 |
#define id GetFacetLocaleId()
|
williamr@4
|
135 |
#endif
|
williamr@4
|
136 |
|
williamr@4
|
137 |
#if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
|
williamr@4
|
138 |
template <class _Facet>
|
williamr@4
|
139 |
locale(const locale& __loc, _Facet* __f) {
|
williamr@4
|
140 |
if ( __f != 0 ) {
|
williamr@4
|
141 |
this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) );
|
williamr@4
|
142 |
this->_M_insert(__f, _Facet::id);
|
williamr@4
|
143 |
} else {
|
williamr@4
|
144 |
this->_M_impl = _get_Locale_impl( __loc._M_impl );
|
williamr@4
|
145 |
}
|
williamr@4
|
146 |
}
|
williamr@4
|
147 |
#if defined(__SYMBIAN32__WSD__) || defined (__SYMBIAN32__NO_STATIC_IMPORTS__)
|
williamr@4
|
148 |
#undef id
|
williamr@4
|
149 |
#endif
|
williamr@4
|
150 |
#endif // _STLP_MEMBER_TEMPLATES
|
williamr@4
|
151 |
|
williamr@4
|
152 |
protected:
|
williamr@2
|
153 |
// those are for internal use
|
williamr@2
|
154 |
locale(_Locale_impl*);
|
williamr@2
|
155 |
|
williamr@2
|
156 |
public:
|
williamr@2
|
157 |
|
williamr@2
|
158 |
locale(const locale&, const locale&, category);
|
williamr@2
|
159 |
_STLP_DECLSPEC const locale& operator=(const locale&) _STLP_NOTHROW;
|
williamr@2
|
160 |
|
williamr@4
|
161 |
#if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
|
williamr@4
|
162 |
virtual
|
williamr@2
|
163 |
#endif
|
williamr@4
|
164 |
_STLP_DECLSPEC ~locale() _STLP_NOTHROW;
|
williamr@4
|
165 |
|
williamr@4
|
166 |
#if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS) && \
|
williamr@4
|
167 |
!defined(_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
|
williamr@4
|
168 |
template <class _Facet>
|
williamr@4
|
169 |
locale combine(const locale& __loc) const {
|
williamr@4
|
170 |
_Facet *__facet = 0;
|
williamr@4
|
171 |
if (!_HasFacet(__loc, __facet))
|
williamr@4
|
172 |
_M_throw_runtime_error();
|
williamr@4
|
173 |
|
williamr@4
|
174 |
return locale(*this, _UseFacet(__loc, __facet));
|
williamr@2
|
175 |
}
|
williamr@4
|
176 |
#endif // _STLP_MEMBER_TEMPLATES && !_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
|
williamr@4
|
177 |
|
williamr@2
|
178 |
// locale operations:
|
williamr@4
|
179 |
_STLP_DECLSPEC string name() const;
|
williamr@2
|
180 |
|
williamr@2
|
181 |
_STLP_DECLSPEC bool operator==(const locale&) const;
|
williamr@2
|
182 |
_STLP_DECLSPEC bool operator!=(const locale&) const;
|
williamr@2
|
183 |
|
williamr@4
|
184 |
#if !defined (_STLP_MEMBER_TEMPLATES) || defined (_STLP_INLINE_MEMBER_TEMPLATES) || (defined(__MWERKS__) && __MWERKS__ <= 0x2301)
|
williamr@4
|
185 |
_STLP_DECLSPEC bool operator()(const string& __x, const string& __y) const;
|
williamr@2
|
186 |
# ifndef _STLP_NO_WCHAR_T
|
williamr@4
|
187 |
_STLP_DECLSPEC bool operator()(const wstring& __x, const wstring& __y) const;
|
williamr@2
|
188 |
# endif
|
williamr@4
|
189 |
#elif !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
|
williamr@2
|
190 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@2
|
191 |
bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x,
|
williamr@4
|
192 |
const basic_string<_CharT, _Traits, _Alloc>& __y) const
|
williamr@4
|
193 |
{ return __locale_do_operator_call(*this, __x, __y); }
|
williamr@4
|
194 |
#endif
|
williamr@2
|
195 |
|
williamr@2
|
196 |
// global locale objects:
|
williamr@2
|
197 |
_STLP_DECLSPEC static locale _STLP_CALL global(const locale&);
|
williamr@2
|
198 |
_STLP_DECLSPEC static const locale& _STLP_CALL classic();
|
williamr@2
|
199 |
|
williamr@4
|
200 |
//protected: // Helper functions for locale globals.
|
williamr@2
|
201 |
_STLP_DECLSPEC facet* _M_get_facet(const id&) const;
|
williamr@2
|
202 |
// same, but throws
|
williamr@2
|
203 |
_STLP_DECLSPEC facet* _M_use_facet(const id&) const;
|
williamr@4
|
204 |
_STLP_DECLSPEC static void _STLP_FUNCTION_THROWS _M_throw_runtime_error(const char* = 0);
|
williamr@2
|
205 |
|
williamr@4
|
206 |
protected: // More helper functions.
|
williamr@2
|
207 |
_STLP_DECLSPEC void _M_insert(facet* __f, id& __id);
|
williamr@2
|
208 |
|
williamr@2
|
209 |
// friends:
|
williamr@2
|
210 |
friend class _Locale_impl;
|
williamr@2
|
211 |
friend class ios_base;
|
williamr@2
|
212 |
|
williamr@4
|
213 |
protected: // Data members
|
williamr@2
|
214 |
_Locale_impl* _M_impl;
|
williamr@4
|
215 |
_Locale_impl* _M_get_impl() const { return _M_impl; }
|
williamr@2
|
216 |
};
|
williamr@2
|
217 |
|
williamr@4
|
218 |
#if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
|
williamr@4
|
219 |
# undef locale
|
williamr@4
|
220 |
# define _Locale _STLP_NO_MEM_T_NAME(loc)
|
williamr@4
|
221 |
|
williamr@4
|
222 |
class locale : public _Locale {
|
williamr@4
|
223 |
public:
|
williamr@4
|
224 |
|
williamr@4
|
225 |
// construct/copy/destroy:
|
williamr@4
|
226 |
_STLP_DECLSPEC locale() _STLP_NOTHROW {}
|
williamr@4
|
227 |
locale(const locale& __loc) _STLP_NOTHROW : _Locale(__loc) {}
|
williamr@4
|
228 |
explicit locale(const char *__str) : _Locale(__str) {}
|
williamr@4
|
229 |
locale(const locale& __loc, const char* __str, category __cat)
|
williamr@4
|
230 |
: _Locale(__loc, __str, __cat) {}
|
williamr@4
|
231 |
|
williamr@4
|
232 |
template <class _Facet>
|
williamr@4
|
233 |
locale(const locale& __loc, _Facet* __f) {
|
williamr@4
|
234 |
if ( __f != 0 ) {
|
williamr@4
|
235 |
this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) );
|
williamr@4
|
236 |
this->_M_insert(__f, _Facet::id);
|
williamr@4
|
237 |
} else {
|
williamr@4
|
238 |
this->_M_impl = _get_Locale_impl( __loc._M_impl );
|
williamr@4
|
239 |
}
|
williamr@4
|
240 |
}
|
williamr@4
|
241 |
|
williamr@4
|
242 |
private:
|
williamr@4
|
243 |
// those are for internal use
|
williamr@4
|
244 |
locale(_Locale_impl* __impl) : _Locale(__impl) {}
|
williamr@4
|
245 |
locale(const _Locale& __loc) : _Locale(__loc) {}
|
williamr@4
|
246 |
|
williamr@4
|
247 |
public:
|
williamr@4
|
248 |
|
williamr@4
|
249 |
locale(const locale& __loc1, const locale& __loc2, category __cat)
|
williamr@4
|
250 |
: _Locale(__loc1, __loc2, __cat) {}
|
williamr@4
|
251 |
|
williamr@4
|
252 |
const locale& operator=(const locale& __loc) _STLP_NOTHROW {
|
williamr@4
|
253 |
_Locale::operator=(__loc);
|
williamr@4
|
254 |
return *this;
|
williamr@4
|
255 |
}
|
williamr@4
|
256 |
|
williamr@4
|
257 |
template <class _Facet>
|
williamr@4
|
258 |
locale combine(const locale& __loc) const {
|
williamr@4
|
259 |
_Facet *__facet = 0;
|
williamr@4
|
260 |
if (!_HasFacet(__loc, __facet))
|
williamr@4
|
261 |
_M_throw_runtime_error();
|
williamr@4
|
262 |
|
williamr@4
|
263 |
return locale(*this, _UseFacet(__loc, __facet));
|
williamr@4
|
264 |
}
|
williamr@4
|
265 |
|
williamr@4
|
266 |
// locale operations:
|
williamr@4
|
267 |
bool operator==(const locale& __loc) const { return _Locale::operator==(__loc); }
|
williamr@4
|
268 |
bool operator!=(const locale& __loc) const { return _Locale::operator!=(__loc); }
|
williamr@4
|
269 |
|
williamr@4
|
270 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@4
|
271 |
bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x,
|
williamr@4
|
272 |
const basic_string<_CharT, _Traits, _Alloc>& __y) const
|
williamr@4
|
273 |
{ return __locale_do_operator_call(*this, __x, __y); }
|
williamr@4
|
274 |
|
williamr@4
|
275 |
// global locale objects:
|
williamr@4
|
276 |
static locale _STLP_CALL global(const locale& __loc) {
|
williamr@4
|
277 |
return _Locale::global(__loc);
|
williamr@4
|
278 |
}
|
williamr@4
|
279 |
static const locale& _STLP_CALL classic() {
|
williamr@4
|
280 |
return __STATIC_CAST(const locale&, _Locale::classic());
|
williamr@4
|
281 |
}
|
williamr@4
|
282 |
|
williamr@4
|
283 |
// friends:
|
williamr@4
|
284 |
friend class _Locale_impl;
|
williamr@4
|
285 |
friend class ios_base;
|
williamr@4
|
286 |
};
|
williamr@4
|
287 |
|
williamr@4
|
288 |
#endif /* _STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND */
|
williamr@4
|
289 |
|
williamr@2
|
290 |
//----------------------------------------------------------------------
|
williamr@2
|
291 |
// locale globals
|
williamr@2
|
292 |
|
williamr@4
|
293 |
#ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
|
williamr@2
|
294 |
template <class _Facet>
|
williamr@4
|
295 |
inline const _Facet&
|
williamr@2
|
296 |
_Use_facet<_Facet>::operator *() const
|
williamr@4
|
297 |
#else
|
williamr@2
|
298 |
template <class _Facet> inline const _Facet& use_facet(const locale& __loc)
|
williamr@4
|
299 |
#endif
|
williamr@2
|
300 |
{
|
williamr@4
|
301 |
_Facet *__facet = 0;
|
williamr@4
|
302 |
return *_UseFacet(__loc, __facet);
|
williamr@2
|
303 |
}
|
williamr@2
|
304 |
|
williamr@4
|
305 |
|
williamr@4
|
306 |
#ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
|
williamr@4
|
307 |
template <class _Facet>
|
williamr@2
|
308 |
struct has_facet {
|
williamr@2
|
309 |
const locale& __loc;
|
williamr@2
|
310 |
has_facet(const locale& __p_loc) : __loc(__p_loc) {}
|
williamr@2
|
311 |
operator bool() const _STLP_NOTHROW
|
williamr@4
|
312 |
#else
|
williamr@4
|
313 |
template <class _Facet> inline bool has_facet(const locale& __loc) _STLP_NOTHROW
|
williamr@4
|
314 |
#endif
|
williamr@2
|
315 |
{
|
williamr@4
|
316 |
_Facet *__facet = 0;
|
williamr@4
|
317 |
return _HasFacet(__loc, __facet);
|
williamr@2
|
318 |
}
|
williamr@2
|
319 |
|
williamr@4
|
320 |
#ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
|
williamr@4
|
321 |
}; // close class definition
|
williamr@4
|
322 |
#endif
|
williamr@4
|
323 |
#if defined(__SYMBIAN32__WSD__) || defined (__SYMBIAN32__NO_STATIC_IMPORTS__)
|
williamr@4
|
324 |
#define id GetFacetLocaleId()
|
williamr@4
|
325 |
#endif
|
williamr@2
|
326 |
|
williamr@4
|
327 |
template <class _Facet>
|
williamr@4
|
328 |
bool _HasFacet(const locale& __loc, const _Facet* ) _STLP_NOTHROW
|
williamr@4
|
329 |
{ return (__loc._M_get_facet(_Facet::id) != 0); }
|
williamr@4
|
330 |
|
williamr@4
|
331 |
template <class _Facet>
|
williamr@4
|
332 |
_Facet* _UseFacet(const locale& __loc, const _Facet* )
|
williamr@4
|
333 |
{ return __STATIC_CAST(_Facet*, __loc._M_use_facet(_Facet::id)); }
|
williamr@4
|
334 |
|
williamr@4
|
335 |
#if defined(__SYMBIAN32__WSD__) || defined (__SYMBIAN32__NO_STATIC_IMPORTS__)
|
williamr@4
|
336 |
#undef id
|
williamr@4
|
337 |
#endif
|
williamr@2
|
338 |
_STLP_END_NAMESPACE
|
williamr@2
|
339 |
|
williamr@2
|
340 |
#endif /* _STLP_INTERNAL_LOCALE_H */
|
williamr@2
|
341 |
|
williamr@2
|
342 |
// Local Variables:
|
williamr@2
|
343 |
// mode:C++
|
williamr@2
|
344 |
// End:
|
williamr@2
|
345 |
|