ReactOS 0.4.15-dev-7677-g8209aa5
_locale.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 1999
3 * Silicon Graphics Computer Systems, Inc.
4 *
5 * Copyright (c) 1999
6 * Boris Fomitchev
7 *
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
10 *
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.
16 *
17 */
18// WARNING: This is an internal header file, included by other C++
19// standard library headers. You should not attempt to use this header
20// file directly.
21
22
23#ifndef _STLP_INTERNAL_LOCALE_H
24#define _STLP_INTERNAL_LOCALE_H
25
26#ifndef _STLP_INTERNAL_CSTDLIB
27# include <stl/_cstdlib.h>
28#endif
29
30#ifndef _STLP_INTERNAL_CWCHAR
31# include <stl/_cwchar.h>
32#endif
33
34#ifndef _STLP_INTERNAL_THREADS_H
35# include <stl/_threads.h>
36#endif
37
38#ifndef _STLP_STRING_FWD_H
39# include <stl/_string_fwd.h>
40#endif
41
42#include <stl/_facets_fwd.h>
43
45
46class _Locale_impl; // Forward declaration of opaque type.
47class locale;
48
49template <class _CharT, class _Traits, class _Alloc>
50bool __locale_do_operator_call(const locale& __loc,
53
56
58
59template <class _Facet>
60bool _HasFacet(const locale& __loc, const _Facet* __facet) _STLP_NOTHROW;
61
62template <class _Facet>
63_Facet* _UseFacet(const locale& __loc, const _Facet* __facet);
64
65template <class _Facet>
66void _InsertFacet(locale& __loc, _Facet* __facet);
67
69
70#if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) || \
71 defined (_STLP_SIGNAL_RUNTIME_COMPATIBILITY) || defined (_STLP_CHECK_RUNTIME_COMPATIBILITY)
72# define locale _STLP_NO_MEM_T_NAME(loc)
73#endif
74
76public:
77 // types:
79 protected:
80 /* Here we filter __init_count user value to 0 or 1 because __init_count is a
81 * size_t instance and _Refcount_Base use __stl_atomic_t instances that might
82 * have lower sizeof and generate roll issues. 1 is enough to keep the facet
83 * alive when required. */
84 explicit facet(size_t __init_count = 0) : _Refcount_Base( __init_count == 0 ? 0 : 1 ) {}
85 virtual ~facet();
86 friend class locale;
87 friend class _Locale_impl;
88 friend facet * _STLP_CALL _get_facet( facet * );
89 friend void _STLP_CALL _release_facet( facet *& );
90
91 private: // Invalidate assignment and copying.
92 facet(const facet& ) /* : _Refcount_Base(1) {} */;
93 void operator=(const facet&);
94 };
95
96#if defined (__MVS__) || defined (__OS400__)
97 struct
98#else
99 class
100#endif
102 public:
103 size_t _M_index;
104 static size_t _S_max;
105 };
106
107 typedef int category;
111 _STLP_STATIC_CONSTANT(category, monetary = 0x040);
115 _STLP_STATIC_CONSTANT(category, all = collate | ctype | monetary | numeric | time | messages);
116
117 // construct/copy/destroy:
120 explicit locale(const char *);
122
123#if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
124 template <class _Facet>
125 locale(const locale& __loc, _Facet* __f) {
126 if ( __f != 0 ) {
127 this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) );
128 _STLP_PRIV _InsertFacet(*this, __f);
129 } else {
130 this->_M_impl = _get_Locale_impl( __loc._M_impl );
131 }
132 }
133#endif
134
135protected:
136 // those are for internal use
138
139public:
140 locale(const locale&, const locale&, category);
141 const locale& operator=(const locale&) _STLP_NOTHROW;
142
143#if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
144protected:
145#endif
147
148public:
149#if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS) && \
150 !defined(_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
151 template <class _Facet>
152 locale combine(const locale& __loc) const {
153 _Facet *__facet = 0;
154 if (!_STLP_PRIV _HasFacet(__loc, __facet))
155 _M_throw_on_combine_error(__loc.name());
156
157 return locale(*this, _STLP_PRIV _UseFacet(__loc, __facet));
158 }
159#endif
160
161 // locale operations:
162 string name() const;
163
164 bool operator==(const locale&) const;
165 bool operator!=(const locale&) const;
166
167#if !defined (_STLP_MEMBER_TEMPLATES) || defined (_STLP_INLINE_MEMBER_TEMPLATES) || (defined(__MWERKS__) && __MWERKS__ <= 0x2301)
168 bool operator()(const string& __x, const string& __y) const;
169# ifndef _STLP_NO_WCHAR_T
170 bool operator()(const wstring& __x, const wstring& __y) const;
171# endif
172#elif !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
173 template <class _CharT, class _Traits, class _Alloc>
174 bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x,
176 { return __locale_do_operator_call(*this, __x, __y); }
177#endif
178
179 // global locale objects:
180#if !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
181 static locale _STLP_CALL global(const locale&);
182#else
183 static _Locale_impl* _STLP_CALL global(const locale&);
184#endif
185 static const locale& _STLP_CALL classic();
186
187//protected: // Helper functions for locale globals.
188 facet* _M_get_facet(const id&) const;
189 // same, but throws
190 facet* _M_use_facet(const id&) const;
191 static void _STLP_FUNCTION_THROWS _STLP_CALL _M_throw_on_combine_error(const string& name);
192 static void _STLP_FUNCTION_THROWS _STLP_CALL _M_throw_on_null_name();
193 static void _STLP_FUNCTION_THROWS _STLP_CALL _M_throw_on_creation_failure(int __err_code,
194 const char* name, const char* facet);
195
196//protected: // More helper functions.
197 void _M_insert(facet* __f, id& __id);
198
199 // friends:
200 friend class _Locale_impl;
201
202protected: // Data members
204 _Locale_impl* _M_get_impl() const { return _M_impl; }
205};
206
207#if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) || \
208 defined (_STLP_SIGNAL_RUNTIME_COMPATIBILITY) || defined (_STLP_CHECK_RUNTIME_COMPATIBILITY)
209# undef locale
210# define _Locale _STLP_NO_MEM_T_NAME(loc)
211
212class locale : public _Locale {
213public:
214
215 // construct/copy/destroy:
217#if defined (_STLP_CHECK_RUNTIME_COMPATIBILITY)
218 _STLP_CHECK_RUNTIME_COMPATIBILITY();
219#endif
220 }
221 locale(const locale& __loc) _STLP_NOTHROW : _Locale(__loc) {}
222 explicit locale(const char *__str) : _Locale(__str) {}
223 locale(const locale& __loc, const char* __str, category __cat)
224 : _Locale(__loc, __str, __cat) {}
225
226 template <class _Facet>
227 locale(const locale& __loc, _Facet* __f)
228 : _Locale(__f != 0 ? _copy_Nameless_Locale_impl(__loc._M_impl) : __loc._M_impl) {
229 if ( __f != 0 ) {
230 _STLP_PRIV _InsertFacet(*this, __f);
231 }
232 }
233
234private:
235 // those are for internal use
236 locale(_Locale_impl* __impl) : _Locale(__impl) {}
237 locale(const _Locale& __loc) : _Locale(__loc) {}
238
239public:
240
241 locale(const locale& __loc1, const locale& __loc2, category __cat)
242 : _Locale(__loc1, __loc2, __cat) {}
243
244 const locale& operator=(const locale& __loc) _STLP_NOTHROW {
245 _Locale::operator=(__loc);
246 return *this;
247 }
248
249 template <class _Facet>
250 locale combine(const locale& __loc) const {
251 _Facet *__facet = 0;
252 if (!_STLP_PRIV _HasFacet(__loc, __facet))
254
255 return locale(*this, _STLP_PRIV _UseFacet(__loc, __facet));
256 }
257
258 // locale operations:
259 bool operator==(const locale& __loc) const { return _Locale::operator==(__loc); }
260 bool operator!=(const locale& __loc) const { return _Locale::operator!=(__loc); }
261
262 template <class _CharT, class _Traits, class _Alloc>
265 { return __locale_do_operator_call(*this, __x, __y); }
266
267 // global locale objects:
268 static locale _STLP_CALL global(const locale& __loc) {
269 return _Locale::global(__loc);
270 }
271 static const locale& _STLP_CALL classic() {
272 return __STATIC_CAST(const locale&, _Locale::classic());
273 }
274
275 // friends:
276 friend class _Locale_impl;
277};
278
279# undef _Locale
280#endif
281
282//----------------------------------------------------------------------
283// locale globals
284
285template <class _Facet>
286inline const _Facet&
287#ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
288_Use_facet<_Facet>::operator *() const
289#else
290use_facet(const locale& __loc)
291#endif
292{
293 _Facet *__facet = 0;
294 return *(_STLP_PRIV _UseFacet(__loc, __facet));
295}
296
297template <class _Facet>
298#ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
299struct has_facet {
300 const locale& __loc;
301 has_facet(const locale& __p_loc) : __loc(__p_loc) {}
302 operator bool() const _STLP_NOTHROW
303#else
304inline bool has_facet(const locale& __loc) _STLP_NOTHROW
305#endif
306{
307 _Facet *__facet = 0;
308 return _STLP_PRIV _HasFacet(__loc, __facet);
309}
310
311#ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
312}; // close class definition
313#endif
314
316
317/* _GetFacetId is a helper function that allow delaying access to
318 * facet id static instance in the library source code to avoid
319 * the other static instances that many compilers are generating
320 * in all dynamic library or executable when instanciating facet
321 * template class.
322 */
323template <class _Facet>
324inline locale::id& _GetFacetId(const _Facet*)
325{ return _Facet::id; }
326
333
334#ifndef _STLP_NO_WCHAR_T
341#endif
342
343template <class _Facet>
344inline bool _HasFacet(const locale& __loc, const _Facet* __facet) _STLP_NOTHROW
345{ return (__loc._M_get_facet(_GetFacetId(__facet)) != 0); }
346
347template <class _Facet>
348inline _Facet* _UseFacet(const locale& __loc, const _Facet* __facet)
349{ return __STATIC_CAST(_Facet*, __loc._M_use_facet(_GetFacetId(__facet))); }
350
351template <class _Facet>
352inline void _InsertFacet(locale& __loc, _Facet* __facet)
353{ __loc._M_insert(__facet, _GetFacetId(__facet)); }
354
356
358
359#endif /* _STLP_INTERNAL_LOCALE_H */
360
361// Local Variables:
362// mode:C++
363// End:
364
bool _STLP_CALL operator!=(const allocator< _T1 > &, const allocator< _T2 > &) _STLP_NOTHROW
Definition: _alloc.h:384
#define _STLP_CALL
Definition: _bc.h:131
bool __locale_do_operator_call(const locale &__loc, const basic_string< _CharT, _Traits, _Alloc > &__x, const basic_string< _CharT, _Traits, _Alloc > &__y)
Definition: _collate.h:162
#define _STLP_PRIV
Definition: _dm.h:70
#define _STLP_NOTHROW
Definition: _intel.h:35
bool __locale_do_operator_call(const locale &__loc, const basic_string< _CharT, _Traits, _Alloc > &__x, const basic_string< _CharT, _Traits, _Alloc > &__y)
Definition: _collate.h:162
const _Facet & use_facet(const locale &__loc)
Definition: _locale.h:290
void _InsertFacet(locale &__loc, _Facet *__facet)
Definition: _locale.h:352
_STLP_MOVE_TO_PRIV_NAMESPACE locale::id & _GetFacetId(const _Facet *)
Definition: _locale.h:324
_STLP_DECLSPEC _Locale_impl *_STLP_CALL _get_Locale_impl(_Locale_impl *locimpl)
bool has_facet(const locale &__loc) _STLP_NOTHROW
Definition: _locale.h:304
_STLP_DECLSPEC _Locale_impl *_STLP_CALL _copy_Nameless_Locale_impl(_Locale_impl *locimpl)
_STLP_MOVE_TO_PRIV_NAMESPACE bool _HasFacet(const locale &__loc, const _Facet *__facet) _STLP_NOTHROW
Definition: _locale.h:344
_Facet * _UseFacet(const locale &__loc, const _Facet *__facet)
Definition: _locale.h:348
Definition: _ctype.h:58
facet(const facet &)
facet(size_t __init_count=0)
Definition: _locale.h:84
void operator=(const facet &)
size_t _M_index
Definition: _locale.h:103
static size_t _S_max
Definition: _locale.h:104
Definition: _locale.h:75
bool operator!=(const locale &) const
Definition: locale.cpp:398
_STLP_STATIC_CONSTANT(category, numeric=0x100)
facet * _M_use_facet(const id &) const
Definition: locale.cpp:381
_Locale_impl * _M_get_impl() const
Definition: _locale.h:204
void _M_insert(facet *__f, id &__id)
Definition: locale.cpp:127
bool operator()(const string &__x, const string &__y) const
Definition: locale.cpp:46
_STLP_STATIC_CONSTANT(category, all=collate|ctype|monetary|numeric|time|messages)
_Locale_impl * _M_impl
Definition: _locale.h:203
_STLP_STATIC_CONSTANT(category, time=0x200)
facet * _M_get_facet(const id &) const
Definition: locale.cpp:377
bool operator==(const locale &) const
Definition: locale.cpp:393
_STLP_STATIC_CONSTANT(category, none=0x000)
const locale & operator=(const locale &) _STLP_NOTHROW
Definition: locale.cpp:368
_STLP_STATIC_CONSTANT(category, ctype=0x020)
_STLP_STATIC_CONSTANT(category, collate=0x010)
string name() const
Definition: locale.cpp:388
static void _STLP_FUNCTION_THROWS _STLP_CALL _M_throw_on_combine_error(const string &name)
Definition: locale.cpp:60
static const locale &_STLP_CALL classic()
Definition: locale.cpp:404
_STLP_STATIC_CONSTANT(category, messages=0x400)
int category
Definition: _locale.h:107
locale() _STLP_NOTHROW
Definition: locale.cpp:118
_STLP_STATIC_CONSTANT(category, monetary=0x040)
int global
Definition: ehframes.cpp:22
#define _STLP_FUNCTION_THROWS
Definition: features.h:872
#define _STLP_MOVE_TO_STD_NAMESPACE
Definition: features.h:525
#define __STATIC_CAST(__x, __y)
Definition: features.h:585
#define _STLP_CLASS_DECLSPEC
Definition: features.h:983
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_END_NAMESPACE
Definition: features.h:503
#define _STLP_DECLSPEC
Definition: features.h:982
#define _STLP_MOVE_TO_PRIV_NAMESPACE
Definition: features.h:524
void _STLP_CALL _release_facet(locale::facet *&f)
Definition: locale_impl.cpp:43
locale::facet *_STLP_CALL _get_facet(locale::facet *f)
Definition: locale_impl.cpp:36
__u16 time
Definition: mkdosfs.c:8
#define bool
Definition: nsiface.idl:72
_In_ size_t _In_z_ _Printf_format_string_ const char _In_ const struct tm _In_opt_ _locale_t _Locale
Definition: time.h:159
Definition: name.c:39
bool operator==(const TKeyDef &t1, const TKeyDef &t2)
Definition: tkeydef.cpp:122
#define const
Definition: zconf.h:233