Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_locale.h
Go to the documentation of this file.
1
32#ifndef _RWSTD_LOC_LOCALE_INCLUDED
33#define _RWSTD_LOC_LOCALE_INCLUDED
34
35
36#include <string>
37
38#include <loc/_facet.h>
39#include <rw/_defs.h>
40
41
43
44enum __rw_locale_category {
45 __rw_cat_none = 0x0100,
46 __rw_cat_collate = 0x0200,
47 __rw_cat_ctype = 0x0400,
48 __rw_cat_monetary = 0x0800,
49 __rw_cat_numeric = 0x1000,
50 __rw_cat_time = 0x2000,
51 __rw_cat_messages = 0x4000,
52 __rw_cat_all = 0x7e00
53};
54
55
56class _RWSTD_EXPORT __rw_locale;
57
58inline const __rw_facet*
59__rw_get_std_facet (const _STD::locale&, __rw_facet::_C_facet_type,
60 __rw_facet::_C_ctor_t*);
61
62inline const __rw_facet*
63__rw_get_facet_by_id (const _STD::locale&,
64 const __rw_facet_id&,
65 const __rw_facet*);
66
67// called from has_facet and use_facet to strips top level
68// const-qualifier from the type of Facet
69template <class _Facet>
70inline const __rw_facet*
71__rw_get_facet (const _STD::locale&, const _Facet*);
72
73} // namespace __rw
74
75
77
78
79// 22.1.2, p1
80template <class _Facet>
81inline const _Facet&
82use_facet (const locale &__loc _RWSTD_DUMMY_ARG (const _Facet* = 0))
83{
84 // Facet could be a const SomeFacet; strip the const qualifier
85 // and, for non-standard facets, use dynamic_cast to make sure
86 // that the dynamic type of `pfacet' is the same as Facet
87 const _RW::__rw_facet* const __pfacet =
88 _RW::__rw_get_facet (__loc, (_Facet*)0);
89
90 _RWSTD_REQUIRES (__pfacet,
92 _RWSTD_FUNC ("use_facet (const locale&)")));
93
94 return *_RWSTD_STATIC_CAST (const _Facet*, __pfacet);
95}
96
97
98// 22.1.2, p5
99template <class _Facet>
100inline bool
101has_facet (const locale &__loc _RWSTD_DUMMY_ARG (const _Facet* = 0))
102{
103 // Facet could be a const SomeFacet; strip the const qualifier
104 const _RW::__rw_facet* const __pfacet =
105 _RW::__rw_get_facet (__loc, (_Facet*)0);
106
107 return 0 != __pfacet;
108}
109
110
111// forward declare standard facets before referencing them below
112_EXPORT template <class _InternT, class _ExternT, class _StateT>
113class codecvt;
114
115_EXPORT template <class _CharT>
116class collate;
117
118_EXPORT template <class _CharT>
119class ctype;
120
121_EXPORT template <class _CharT, class _Iter>
122struct money_get;
123
124_EXPORT template <class _CharT, class _Iter>
125struct money_put;
126
127_EXPORT template <class _CharT, bool _Intl>
128struct moneypunct;
129
130_EXPORT template <class _CharT, class _Iter>
131struct num_get;
132
133_EXPORT template <class _CharT, class _Iter>
134struct num_put;
135
136_EXPORT template <class _CharT>
137struct numpunct;
138
139_EXPORT template <class _CharT, class _Iter>
140class time_get;
141
142_EXPORT template <class _CharT, class _Iter>
143struct time_put;
144
145_EXPORT template <class _CharT>
146class messages;
147
148
149// 22.1.1
150struct _RWSTD_CLASS_EXPORT locale
151{
152 // 22.1.1.1.1, p1
153 typedef int category;
154
155 // 22.1.1.1.2
156 typedef _RW::__rw_facet facet;
157
158 // 22.1.1.1.3
159 typedef _RW::__rw_facet_id id;
160
161 // values (including none) must not conflict with any LC_XXX constants
162 _RWSTD_STATIC_CONST (category, none = _RW::__rw_cat_none);
163 _RWSTD_STATIC_CONST (category, collate = _RW::__rw_cat_collate);
164 _RWSTD_STATIC_CONST (category, ctype = _RW::__rw_cat_ctype);
165 _RWSTD_STATIC_CONST (category, monetary = _RW::__rw_cat_monetary);
166 _RWSTD_STATIC_CONST (category, numeric = _RW::__rw_cat_numeric);
167 _RWSTD_STATIC_CONST (category, time = _RW::__rw_cat_time);
168 _RWSTD_STATIC_CONST (category, messages = _RW::__rw_cat_messages);
169 _RWSTD_STATIC_CONST (category, all = _RW::__rw_cat_all);
170
171 // 22.1.1.2, p1
172 _RWSTD_MEMBER_EXPORT locale () _THROWS (());
173
174 // 22.1.1.2, p3
175 _RWSTD_MEMBER_EXPORT locale (const locale&) _THROWS (());
176
177 // 22.1.1.2, p6
178 _RWSTD_MEMBER_EXPORT explicit locale (const char*);
179
180 // 22.1.1.2, p9
181 _RWSTD_MEMBER_EXPORT locale (const locale&, const char*, category);
182
183 // 22.1.1.2, p12
184 template <class _Facet>
185 locale (const locale&, _Facet*);
186
187#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
188
189 // 22.1.1.3, p1
190 template <class _Facet>
191 locale combine (const locale&) const;
192
193#endif // _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
194
195 // 22.1.1.4, p3
196 template <class _CharT, class _Traits, class _Allocator>
197 bool operator() (const basic_string<_CharT, _Traits, _Allocator>&,
198 const basic_string<_CharT, _Traits, _Allocator>&) const;
199
200 // 22.1.1.2, p14
201 _RWSTD_MEMBER_EXPORT locale (const locale&, const locale&, category);
202
203 // 22.1.1.2, p16
204 _RWSTD_MEMBER_EXPORT ~locale() _THROWS (());
205
206 // 22.1.1.2, p4
207 _RWSTD_MEMBER_EXPORT const locale& operator= (const locale&) _THROWS (());
208
209 // 22.1.1.3, p5
210 _RWSTD_MEMBER_EXPORT string name () const;
211
212 // 22.1.1.4, p1
213 _RWSTD_MEMBER_EXPORT bool operator== (const locale&) const;
214
215 // 22.1.1.4, p2
216 _RWSTD_MEMBER_EXPORT bool operator!= (const locale &__rhs) const {
217 return !(*this == __rhs);
218 }
219
220 // 22.1.1.5, p1
221 _RWSTD_MEMBER_EXPORT static locale global (const locale&);
222
223 // 22.1.1.5, p4
224 _RWSTD_MEMBER_EXPORT static const locale& classic ();
225
226private:
227
228 _RWSTD_MEMBER_EXPORT explicit locale (_RW::__rw_locale &__rhs)
229 _THROWS (())
230 : _C_body (&__rhs) { }
231
232 _RWSTD_MEMBER_EXPORT locale (_RW::__rw_locale&, const facet*);
233
234 _RW::__rw_locale *_C_body; // reference-counted body
235
236#if defined (__SUNPRO_CC) && __SUNPRO_CC <= 0x540
237
238 // working around a SunPro member access control bug (see PR #25910)
239public:
240
241#endif // SunPro <= 5.4
242
243 // (try to) retrieve a facet from a locale given an id
244 // may initialize the id if it isn't initialized yet
245 _RWSTD_MEMBER_EXPORT const facet*
246 _C_get_facet (const id&) const;
247
248 _RWSTD_MEMBER_EXPORT const facet*
249 _C_get_std_facet (facet::_C_facet_type, facet::_C_ctor_t*) const;
250
251 friend class _RW::__rw_locale;
252 friend struct _RW::__rw_access;
253
254 // function arguments below are qualified to work around
255 // a SunPro 5.5 and prior bug (PR #28626)
256 friend const facet*
257 _RW::__rw_get_std_facet (const _STD::locale&,
258 _RW::__rw_facet::_C_facet_type,
259 _RW::__rw_facet::_C_ctor_t*);
260
261 friend const _RW::__rw_facet*
262 _RW::__rw_get_facet_by_id (const _STD::locale&,
263 const _RW::__rw_facet_id&,
264 const _RW::__rw_facet*);
265};
266
267} // namespace std
268
269
271
272inline const __rw_facet*
273__rw_get_facet_by_id (const _STD::locale &__loc,
274 const __rw_facet_id &__id,
275 const __rw_facet*)
276{
277 // initialize Facet::id and retrieve facet if it's installed
278 return __loc._C_get_facet (__id);
279}
280
281
282template <class _Facet>
283inline const __rw_facet*
284__rw_get_facet (const _STD::locale &__loc, const _Facet *__dummy)
285{
286 // resolves either to one of the overloads of __rw_get_facet_by_id
287 // defined for the set of standard facets or the overload for the base
288 // locale::facet* if _Facet is not derived from any of the former
289 const __rw_facet* const __pfacet =
290 __rw_get_facet_by_id (__loc, _Facet::id, __dummy);
291
292 return _RWSTD_DYNAMIC_CAST (const _Facet*, __pfacet);
293}
294
295
296inline const __rw_facet*
297__rw_get_std_facet (const _STD::locale &__loc,
298 __rw_facet::_C_facet_type __type,
299 __rw_facet::_C_ctor_t *__ctor)
300{
301 // expose an implementation detail of locale body for efficiency
302 struct _Facets {
303 __rw_facet *__facets [__rw_facet::_C_last_type / 2];
304 };
305
306 const _Facets* const __pfacets =
307 _RWSTD_REINTERPRET_CAST (const _Facets*, __loc._C_body);
308
309 _RWSTD_ASSERT (0 != __pfacets);
310
311 const __rw_facet *__facet = __pfacets->__facets [__type >> 1];
312
313 if (!__facet)
314 __facet = __loc._C_get_std_facet (__type, __ctor);
315
316#if !defined (__HP_aCC) || _RWSTD_HP_aCC_MINOR > 3800
317
318 // working around an HP aCC ICE (PR #28838)
319 _RWSTD_ASSERT (0 != __facet);
320
321#endif // HP aCC
322
323 return __facet;
324}
325
326
327// functions' type must be __rw_facet::_C_ctor_t
328// i.e., as if they were declared as follows:
329// __rw_facet::_C_ctor_t __rw_ct_ctype;
330// the declaration above causes a Compaq C++ 6.5 ICE (PR #30188)
331_RWSTD_EXPORT __rw_facet* __rw_ct_ctype (_RWSTD_SIZE_T, const char*);
332_RWSTD_EXPORT __rw_facet* __rw_ct_numpunct (_RWSTD_SIZE_T, const char*);
333_RWSTD_EXPORT __rw_facet* __rw_ct_num_get (_RWSTD_SIZE_T, const char*);
334_RWSTD_EXPORT __rw_facet* __rw_ct_num_put (_RWSTD_SIZE_T, const char*);
335
336
337#define _RWSTD_OVERLOAD_GET_FACET(F) \
338 _RWSTD_EXPORT const __rw_facet* \
339 __rw_get_facet_by_id (const _STD::locale&, \
340 const __rw_facet_id&, const F*)
341
342#define _Facet(name, T, U) _STD::name<T, U >
343
344#define _InIter(T) _STD::istreambuf_iterator< T, _STD::char_traits<T > >
345#define _OutIter(T) _STD::ostreambuf_iterator< T, _STD::char_traits<T > >
346
347// convenience typedefs to allow them to be used as macro arguments
348typedef _STD::codecvt<char, char, _RWSTD_MBSTATE_T> __rw_codecvt_c;
349typedef _Facet (moneypunct, char, false) __rw_mpunct_c_0;
350typedef _Facet (moneypunct, char, true) __rw_mpunct_c_1;
351typedef _Facet (money_get, char, _InIter (char)) __rw_mget_c;
352typedef _Facet (money_put, char, _OutIter (char)) __rw_mput_c;
353typedef _Facet (num_get, char, _InIter (char)) __rw_nget_c;
354typedef _Facet (num_put, char, _OutIter (char)) __rw_nput_c;
355typedef _Facet (time_get, char, _InIter (char)) __rw_tget_c;
356typedef _Facet (time_put, char, _OutIter (char)) __rw_tput_c;
357
358
359// inline definitions of heavily used use_facet specializations
360// for iostream efficiency
361
363inline const __rw_facet*
364__rw_get_facet (const _STD::locale &__loc, const _STD::ctype<char>*)
365{
366 return __rw_get_std_facet (__loc, __rw_facet::_C_ctype,
367 __rw_ct_ctype);
368}
369
370
372inline const __rw_facet*
373__rw_get_facet (const _STD::locale &__loc, const _STD::numpunct<char>*)
374{
375 return __rw_get_std_facet (__loc, __rw_facet::_C_numpunct,
376 __rw_ct_numpunct);
377}
378
379
381inline const __rw_facet*
382__rw_get_facet (const _STD::locale &__loc, const __rw_nget_c*)
383{
384 return __rw_get_std_facet (__loc, __rw_facet::_C_num_get,
385 __rw_ct_num_get);
386}
387
388
390inline const __rw_facet*
391__rw_get_facet (const _STD::locale &__loc, const __rw_nput_c*)
392{
393 return __rw_get_std_facet (__loc, __rw_facet::_C_num_put,
394 __rw_ct_num_put);
395}
396
397
398// declarations of __rw_get_facet_by_id overloads
399_RWSTD_OVERLOAD_GET_FACET (_STD::ctype<char>);
400_RWSTD_OVERLOAD_GET_FACET (__rw_codecvt_c);
401_RWSTD_OVERLOAD_GET_FACET (_STD::collate<char>);
402_RWSTD_OVERLOAD_GET_FACET (__rw_mget_c);
403_RWSTD_OVERLOAD_GET_FACET (__rw_mput_c);
404_RWSTD_OVERLOAD_GET_FACET (__rw_mpunct_c_0);
405_RWSTD_OVERLOAD_GET_FACET (__rw_mpunct_c_1);
406_RWSTD_OVERLOAD_GET_FACET (__rw_nget_c);
407_RWSTD_OVERLOAD_GET_FACET (__rw_nput_c);
408_RWSTD_OVERLOAD_GET_FACET (_STD::numpunct<char>);
409_RWSTD_OVERLOAD_GET_FACET (__rw_tget_c);
410_RWSTD_OVERLOAD_GET_FACET (__rw_tput_c);
411_RWSTD_OVERLOAD_GET_FACET (_STD::messages<char>);
412
413#ifndef _RWSTD_NO_WCHAR_T
414
415typedef _STD::codecvt<wchar_t, char, _RWSTD_MBSTATE_T> __rw_codecvt_w;
416typedef _Facet (moneypunct, wchar_t, false) __rw_mpunct_w_0;
417typedef _Facet (moneypunct, wchar_t, true) __rw_mpunct_w_1;
418typedef _Facet (money_get, wchar_t, _InIter (wchar_t)) __rw_mget_w;
419typedef _Facet (money_put, wchar_t, _OutIter (wchar_t)) __rw_mput_w;
420typedef _Facet (num_get, wchar_t, _InIter (wchar_t)) __rw_nget_w;
421typedef _Facet (num_put, wchar_t, _OutIter (wchar_t)) __rw_nput_w;
422typedef _Facet (time_get, wchar_t, _InIter (wchar_t)) __rw_tget_w;
423typedef _Facet (time_put, wchar_t, _OutIter (wchar_t)) __rw_tput_w;
424
425_RWSTD_OVERLOAD_GET_FACET (_STD::ctype<wchar_t>);
426_RWSTD_OVERLOAD_GET_FACET (__rw_codecvt_w);
427_RWSTD_OVERLOAD_GET_FACET (_STD::collate<wchar_t>);
428_RWSTD_OVERLOAD_GET_FACET (__rw_mget_w);
429_RWSTD_OVERLOAD_GET_FACET (__rw_mput_w);
430_RWSTD_OVERLOAD_GET_FACET (__rw_mpunct_w_0);
431_RWSTD_OVERLOAD_GET_FACET (__rw_mpunct_w_1);
432_RWSTD_OVERLOAD_GET_FACET (__rw_nget_w);
433_RWSTD_OVERLOAD_GET_FACET (__rw_nput_w);
434_RWSTD_OVERLOAD_GET_FACET (_STD::numpunct<wchar_t>);
435_RWSTD_OVERLOAD_GET_FACET (__rw_tget_w);
436_RWSTD_OVERLOAD_GET_FACET (__rw_tput_w);
437_RWSTD_OVERLOAD_GET_FACET (_STD::messages<wchar_t>);
438
439#endif // _RWSTD_NO_WCHAR_T
440
441// clean up
442#undef _RWSTD_OVERLOAD_GET_FACET
443#undef _Facet
444#undef _InIter
445#undef _OutIter
446
447
448} // namespace __rw
449
450
452
453
454template <class _Facet>
455inline locale::locale (const locale &__rhs, _Facet *__facet)
456 : _C_body (0)
457{
458 // initialize facet's member id to point to Facet::id
459 if (__facet && !__facet->_C_pid) {
460 // unusual cast (to size_t** rather than size_t*&)
461 // done to work around an HP aCC 3.3x bug
462 *_RWSTD_CONST_CAST (_RWSTD_SIZE_T**, &__facet->_C_pid) =
463 &_Facet::id._C_id;
464 }
465
466 // uninitialized Facet::id will be initialized by has_facet<>()
467
468 // prevent passing `facet' the ctor if it is installed in `rhs'
469 // to potentially avoid creating a whole new locale body
470 if (_RW::__rw_get_facet (__rhs, (_Facet*)0) == __facet)
471 __facet = 0;
472
473 *this = locale (*__rhs._C_body, __facet);
474}
475
476
477#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
478
479template <class _Facet>
480inline locale locale::combine (const locale &__rhs) const
481{
482 // unitialized Facet::id will be initialized by has_facet<>()
483
484 _RWSTD_REQUIRES (has_facet<_Facet>(__rhs),
486 _RWSTD_FUNC ("locale::combine (const locale&)"),
487 _Facet::id._C_id, __rhs.name ().c_str ()));
488
489 return locale (*this, &use_facet<_Facet>(__rhs));
490}
491
492#endif // _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
493
494
495template <class _CharT, class _Traits, class _Allocator>
496inline bool
497locale::operator() (const basic_string<_CharT, _Traits, _Allocator> &__x,
498 const basic_string<_CharT, _Traits, _Allocator> &__y) const
499{
500 // qualify collate to distinguish it from locale::collate
501 return use_facet<_STD::collate<_CharT> >(*this)
502 .compare (__x.data (), __x.data () + __x.length (),
503 __y.data (), __y.data () + __y.length ()) < 0;
504}
505
506
507} // namespace std
508
509
510#endif // _RWSTD_LOC_LOCALE_INCLUDED
#define _THROWS()
#define _RWSTD_CLASS_EXPORT
Definition _defs.h:486
#define _STD
Definition _defs.h:571
#define _RWSTD_REQUIRES(pred, args)
Definition _defs.h:1132
#define _RWSTD_EXPORT
Definition _defs.h:485
#define _RWSTD_DUMMY_ARG(ignore)
Definition _defs.h:1535
#define _RWSTD_MEMBER_EXPORT
Definition _defs.h:487
#define _RWSTD_DYNAMIC_CAST(T, x)
Definition _defs.h:544
#define _RWSTD_REINTERPRET_CAST(T, x)
Definition _defs.h:535
#define _RWSTD_STATIC_CAST(T, x)
Definition _defs.h:534
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_FUNC(ignore)
Definition _defs.h:1120
#define _EXPORT
Definition _defs.h:498
#define _RWSTD_ASSERT(ignore)
Definition _defs.h:1108
#define _RWSTD_STATIC_CONST(type, init)
Definition _defs.h:989
#define _RWSTD_CONST_CAST(T, x)
Definition _defs.h:536
#define _RWSTD_SPECIALIZED_FUNCTION
Definition _defs.h:556
#define _RWSTD_ERROR_FACET_NOT_FOUND
Definition _error.h:104
#define _RWSTD_ERROR_BAD_CAST
Definition _error.h:88
#define _RWSTD_OVERLOAD_GET_FACET(F)
#define _Facet(name, T, U)
#define _InIter(T)
#define _OutIter(T)
const char * name
Definition codecvt1.cpp:72
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14737
bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14762
Definition json.h:5363
#define true
Definition stdbool.h:25
A local time-of-day.