williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
|
williamr@2
|
3 |
*
|
williamr@2
|
4 |
* Copyright (c) 1999
|
williamr@2
|
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@2
|
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@2
|
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@2
|
28 |
#ifndef _STLP_CSTDLIB
|
williamr@2
|
29 |
# include <cstdlib>
|
williamr@2
|
30 |
#endif
|
williamr@2
|
31 |
|
williamr@2
|
32 |
#ifndef _STLP_CWCHAR_H
|
williamr@2
|
33 |
# include <stl/_cwchar.h>
|
williamr@2
|
34 |
#endif
|
williamr@2
|
35 |
|
williamr@2
|
36 |
#ifndef _STLP_INTERNAL_THREADS_H
|
williamr@2
|
37 |
# include <stl/_threads.h>
|
williamr@2
|
38 |
#endif
|
williamr@2
|
39 |
|
williamr@2
|
40 |
#ifndef _STLP_STRING_FWD_H
|
williamr@2
|
41 |
# include <stl/_string_fwd.h>
|
williamr@2
|
42 |
#endif
|
williamr@2
|
43 |
|
williamr@2
|
44 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
45 |
|
williamr@2
|
46 |
class _STLP_CLASS_DECLSPEC _Locale_impl; // Forward declaration of opaque type.
|
williamr@2
|
47 |
class _STLP_CLASS_DECLSPEC _Locale; // Forward declaration of opaque type.
|
williamr@2
|
48 |
class _STLP_CLASS_DECLSPEC locale;
|
williamr@2
|
49 |
class _STLP_CLASS_DECLSPEC ios_base;
|
williamr@2
|
50 |
|
williamr@2
|
51 |
|
williamr@2
|
52 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@2
|
53 |
bool
|
williamr@2
|
54 |
__locale_do_operator_call (const locale* __that,
|
williamr@2
|
55 |
const basic_string<_CharT, _Traits, _Alloc >& __x,
|
williamr@2
|
56 |
const basic_string<_CharT, _Traits, _Alloc >& __y);
|
williamr@2
|
57 |
|
williamr@2
|
58 |
# define _BaseFacet locale::facet
|
williamr@2
|
59 |
|
williamr@2
|
60 |
class _STLP_CLASS_DECLSPEC locale {
|
williamr@2
|
61 |
public:
|
williamr@2
|
62 |
// types:
|
williamr@2
|
63 |
|
williamr@2
|
64 |
class
|
williamr@2
|
65 |
#if defined (__SYMBIAN32__) || defined(__GCCE__)
|
williamr@2
|
66 |
_STLP_CLASS_DECLSPEC
|
williamr@2
|
67 |
#else
|
williamr@2
|
68 |
_STLP_DECLSPEC
|
williamr@2
|
69 |
#endif
|
williamr@2
|
70 |
facet : private _Refcount_Base {
|
williamr@2
|
71 |
protected:
|
williamr@2
|
72 |
explicit facet(size_t __no_del = 0) : _Refcount_Base(1), _M_delete(__no_del == 0) {}
|
williamr@2
|
73 |
|
williamr@2
|
74 |
_STLP_DECLSPEC virtual ~facet();
|
williamr@2
|
75 |
friend class locale;
|
williamr@2
|
76 |
friend class _Locale_impl;
|
williamr@2
|
77 |
friend class _Locale;
|
williamr@2
|
78 |
|
williamr@2
|
79 |
private: // Invalidate assignment and copying.
|
williamr@2
|
80 |
facet(const facet& __f) : _Refcount_Base(1), _M_delete(__f._M_delete == 0) {};
|
williamr@2
|
81 |
void operator=(const facet&);
|
williamr@2
|
82 |
|
williamr@2
|
83 |
private: // Data members.
|
williamr@2
|
84 |
const bool _M_delete;
|
williamr@2
|
85 |
};
|
williamr@2
|
86 |
|
williamr@2
|
87 |
#if defined(__MVS__) || defined(__OS400__)
|
williamr@2
|
88 |
struct
|
williamr@2
|
89 |
#else
|
williamr@2
|
90 |
class
|
williamr@2
|
91 |
#endif
|
williamr@2
|
92 |
_STLP_DECLSPEC id {
|
williamr@2
|
93 |
friend class locale;
|
williamr@2
|
94 |
friend class _Locale_impl;
|
williamr@2
|
95 |
public:
|
williamr@2
|
96 |
size_t _M_index;
|
williamr@2
|
97 |
#if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
|
williamr@2
|
98 |
static _STLP_STATIC_MEMBER_DECLSPEC size_t& get_locale_id_S_max();
|
williamr@2
|
99 |
# else
|
williamr@2
|
100 |
static size_t _S_max;
|
williamr@2
|
101 |
# endif
|
williamr@2
|
102 |
};
|
williamr@2
|
103 |
|
williamr@2
|
104 |
typedef int category;
|
williamr@2
|
105 |
# if defined (_STLP_STATIC_CONST_INIT_BUG)
|
williamr@2
|
106 |
enum _Category {
|
williamr@2
|
107 |
# else
|
williamr@2
|
108 |
static const category
|
williamr@2
|
109 |
# endif
|
williamr@2
|
110 |
none = 0x000,
|
williamr@2
|
111 |
collate = 0x010,
|
williamr@2
|
112 |
ctype = 0x020,
|
williamr@2
|
113 |
monetary = 0x040,
|
williamr@2
|
114 |
numeric = 0x100,
|
williamr@2
|
115 |
time = 0x200,
|
williamr@2
|
116 |
messages = 0x400,
|
williamr@2
|
117 |
all = collate | ctype | monetary | numeric | time | messages
|
williamr@2
|
118 |
# if defined (_STLP_STATIC_CONST_INIT_BUG)
|
williamr@2
|
119 |
}
|
williamr@2
|
120 |
# endif
|
williamr@2
|
121 |
;
|
williamr@2
|
122 |
|
williamr@2
|
123 |
// construct/copy/destroy:
|
williamr@2
|
124 |
_STLP_DECLSPEC locale();
|
williamr@2
|
125 |
_STLP_DECLSPEC locale(const locale&) _STLP_NOTHROW;
|
williamr@2
|
126 |
explicit locale(const char *);
|
williamr@2
|
127 |
locale(const locale&, const char*, category);
|
williamr@2
|
128 |
|
williamr@2
|
129 |
// those are for internal use
|
williamr@2
|
130 |
locale(_Locale_impl*);
|
williamr@2
|
131 |
locale(_Locale_impl*, bool);
|
williamr@2
|
132 |
|
williamr@2
|
133 |
public:
|
williamr@2
|
134 |
|
williamr@2
|
135 |
# if defined ( _STLP_MEMBER_TEMPLATES ) /* && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) */
|
williamr@2
|
136 |
template <class _Facet>
|
williamr@2
|
137 |
locale(const locale& __loc, _Facet* __f) : _M_impl(0)
|
williamr@2
|
138 |
{
|
williamr@2
|
139 |
// _M_impl = this->_S_copy_impl(__loc._M_impl, __f != 0);
|
williamr@2
|
140 |
new(this) locale(__loc._M_impl, __f != 0);
|
williamr@2
|
141 |
if (__f != 0)
|
williamr@2
|
142 |
this->_M_insert((facet*)__f, _Facet::GetFacetLocaleId());
|
williamr@2
|
143 |
}
|
williamr@2
|
144 |
# endif
|
williamr@2
|
145 |
|
williamr@2
|
146 |
locale(const locale&, const locale&, category);
|
williamr@2
|
147 |
_STLP_DECLSPEC ~locale() _STLP_NOTHROW;
|
williamr@2
|
148 |
_STLP_DECLSPEC const locale& operator=(const locale&) _STLP_NOTHROW;
|
williamr@2
|
149 |
|
williamr@2
|
150 |
# if !(defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS))
|
williamr@2
|
151 |
template <class _Facet> locale combine(const locale& __loc) const{
|
williamr@2
|
152 |
locale __result(__loc._M_impl, true);
|
williamr@2
|
153 |
#if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
|
williamr@2
|
154 |
if (facet* __f = __loc._M_get_facet(_Facet::GetFacetLocaleId())) {
|
williamr@2
|
155 |
__result._M_insert((facet*)__f, _Facet::GetFacetLocaleId());
|
williamr@2
|
156 |
#else
|
williamr@2
|
157 |
if (facet* __f = __loc._M_get_facet(_Facet::id)) {
|
williamr@2
|
158 |
__result._M_insert((facet*)__f, _Facet::id);
|
williamr@2
|
159 |
#endif
|
williamr@2
|
160 |
__f->_M_incr();
|
williamr@2
|
161 |
}
|
williamr@2
|
162 |
else
|
williamr@2
|
163 |
_M_throw_runtime_error();
|
williamr@2
|
164 |
return __result;
|
williamr@2
|
165 |
}
|
williamr@2
|
166 |
# endif
|
williamr@2
|
167 |
// locale operations:
|
williamr@2
|
168 |
_STLP_DECLSPEC string name() const;
|
williamr@2
|
169 |
|
williamr@2
|
170 |
_STLP_DECLSPEC bool operator==(const locale&) const;
|
williamr@2
|
171 |
_STLP_DECLSPEC bool operator!=(const locale&) const;
|
williamr@2
|
172 |
|
williamr@2
|
173 |
# if ! defined ( _STLP_MEMBER_TEMPLATES ) || defined (_STLP_INLINE_MEMBER_TEMPLATES) || (defined(__MWERKS__) && __MWERKS__ <= 0x2301)
|
williamr@2
|
174 |
bool operator()(const string& __x, const string& __y) const;
|
williamr@2
|
175 |
# ifndef _STLP_NO_WCHAR_T
|
williamr@2
|
176 |
bool operator()(const wstring& __x, const wstring& __y) const;
|
williamr@2
|
177 |
# endif
|
williamr@2
|
178 |
# else
|
williamr@2
|
179 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@2
|
180 |
bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x,
|
williamr@2
|
181 |
const basic_string<_CharT, _Traits, _Alloc>& __y) const {
|
williamr@2
|
182 |
return __locale_do_operator_call(this, __x, __y);
|
williamr@2
|
183 |
}
|
williamr@2
|
184 |
# endif
|
williamr@2
|
185 |
|
williamr@2
|
186 |
// global locale objects:
|
williamr@2
|
187 |
_STLP_DECLSPEC static locale _STLP_CALL global(const locale&);
|
williamr@2
|
188 |
_STLP_DECLSPEC static const locale& _STLP_CALL classic();
|
williamr@2
|
189 |
|
williamr@2
|
190 |
public: // Helper functions for locale globals.
|
williamr@2
|
191 |
_STLP_DECLSPEC facet* _M_get_facet(const id&) const;
|
williamr@2
|
192 |
// same, but throws
|
williamr@2
|
193 |
_STLP_DECLSPEC facet* _M_use_facet(const id&) const;
|
williamr@2
|
194 |
_STLP_DECLSPEC static void _STLP_CALL _M_throw_runtime_error(const char* = 0);
|
williamr@2
|
195 |
static void _STLP_CALL _S_initialize();
|
williamr@2
|
196 |
static void _STLP_CALL _S_uninitialize();
|
williamr@2
|
197 |
|
williamr@2
|
198 |
private: // More helper functions.
|
williamr@2
|
199 |
// static _Locale_impl* _STLP_CALL _S_copy_impl(_Locale_impl*, bool);
|
williamr@2
|
200 |
_STLP_DECLSPEC void _M_insert(facet* __f, id& __id);
|
williamr@2
|
201 |
|
williamr@2
|
202 |
// friends:
|
williamr@2
|
203 |
friend class _Locale_impl;
|
williamr@2
|
204 |
friend class _Locale;
|
williamr@2
|
205 |
friend class ios_base;
|
williamr@2
|
206 |
|
williamr@2
|
207 |
private: // Data members
|
williamr@2
|
208 |
_Locale_impl* _M_impl;
|
williamr@2
|
209 |
};
|
williamr@2
|
210 |
|
williamr@2
|
211 |
//----------------------------------------------------------------------
|
williamr@2
|
212 |
// locale globals
|
williamr@2
|
213 |
|
williamr@2
|
214 |
# ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
|
williamr@2
|
215 |
template <class _Facet>
|
williamr@2
|
216 |
inline const _Facet&
|
williamr@2
|
217 |
_Use_facet<_Facet>::operator *() const
|
williamr@2
|
218 |
# else
|
williamr@2
|
219 |
template <class _Facet> inline const _Facet& use_facet(const locale& __loc)
|
williamr@2
|
220 |
# endif
|
williamr@2
|
221 |
{
|
williamr@2
|
222 |
#if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
|
williamr@2
|
223 |
return *__STATIC_CAST(const _Facet*,__loc._M_use_facet(_Facet::GetFacetLocaleId()));
|
williamr@2
|
224 |
#else
|
williamr@2
|
225 |
return *__STATIC_CAST(const _Facet*,__loc._M_use_facet(_Facet::id));
|
williamr@2
|
226 |
#endif
|
williamr@2
|
227 |
}
|
williamr@2
|
228 |
|
williamr@2
|
229 |
|
williamr@2
|
230 |
# ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
|
williamr@2
|
231 |
template <class _Facet>
|
williamr@2
|
232 |
struct has_facet {
|
williamr@2
|
233 |
const locale& __loc;
|
williamr@2
|
234 |
has_facet(const locale& __p_loc) : __loc(__p_loc) {}
|
williamr@2
|
235 |
operator bool() const _STLP_NOTHROW
|
williamr@2
|
236 |
# else
|
williamr@2
|
237 |
template <class _Facet> inline bool has_facet(const locale& __loc) _STLP_NOTHROW
|
williamr@2
|
238 |
# endif
|
williamr@2
|
239 |
{
|
williamr@2
|
240 |
#if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
|
williamr@2
|
241 |
return (__loc._M_get_facet(_Facet::GetFacetLocaleId()) != 0);
|
williamr@2
|
242 |
#else
|
williamr@2
|
243 |
return (__loc._M_get_facet(_Facet::id) != 0);
|
williamr@2
|
244 |
#endif
|
williamr@2
|
245 |
}
|
williamr@2
|
246 |
|
williamr@2
|
247 |
# ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
|
williamr@2
|
248 |
// close class definition
|
williamr@2
|
249 |
};
|
williamr@2
|
250 |
# endif
|
williamr@2
|
251 |
|
williamr@2
|
252 |
_STLP_END_NAMESPACE
|
williamr@2
|
253 |
|
williamr@2
|
254 |
#endif /* _STLP_INTERNAL_LOCALE_H */
|
williamr@2
|
255 |
|
williamr@2
|
256 |
// Local Variables:
|
williamr@2
|
257 |
// mode:C++
|
williamr@2
|
258 |
// End:
|
williamr@2
|
259 |
|