Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_numpunct.h
Go to the documentation of this file.
1
32#ifndef _RWSTD_LOC_NUMPUNCT_H_INCLUDED
33#define _RWSTD_LOC_NUMPUNCT_H_INCLUDED
34
35
36#if __GNUG__ >= 3
37# pragma GCC system_header
38#endif // gcc >= 3
39
40
41#include <string>
42#include <loc/_facet.h>
43#include <loc/_punct.h>
44#include <rw/_defs.h>
45
46
48
49
50// FIXME: provide just required specializations when #defined
51// #ifndef _RWSTD_NO_EXT_NUMPUNCT_PRIMARY
52
53// 22.2.3.1
55template <class _CharT>
56struct numpunct: _RW::__rw_facet
57{
58 typedef _CharT char_type;
59 typedef
60 basic_string<char_type, char_traits<char_type>, allocator<char_type> >
61 string_type;
62
63 explicit numpunct (_RWSTD_SIZE_T __ref = 0)
64 : _RW::__rw_facet (__ref), _C_flags (0) { }
65
66 virtual ~numpunct ();
67
68 // 22.2.3.1.1, p1
69 char_type decimal_point () const;
70
71 // 22.2.3.1.1, p2
72 char_type thousands_sep () const;
73
74 // 22.2.3.1.1, p3
75 string grouping () const;
76
77 // 22.2.3.1.1, p4
78 string_type truename () const;
79
80 // 22.2.3.1.1, p4
81 string_type falsename () const;
82
83 static _RW::__rw_facet_id id;
84
85protected:
86
87 // 22.2.3.1.2, p1
88 virtual char_type do_decimal_point () const {
89 return *_RW::__rw_get_punct (this, _RW::__rw_dp, char_type ());
90 }
91
92 // 22.2.3.1.2, p2
93 virtual char_type do_thousands_sep () const {
94 return *_RW::__rw_get_punct (this, _RW::__rw_ts, char_type ());
95 }
96
97 // 22.2.3.1.2, p3
98 virtual string do_grouping () const {
99 return _RWSTD_REINTERPRET_CAST (const char*,
100 _RW::__rw_get_punct (this, _RW::__rw_gr, char_type ()));
101 }
102
103 // 22.2.3.1.2, p4
104 virtual string_type do_truename () const {
105 return _RW::__rw_get_punct (this, _RW::__rw_tn, char_type ());
106 }
107
108 // 22.2.3.1.2, p4
109 virtual string_type do_falsename () const {
110 return _RW::__rw_get_punct (this, _RW::__rw_fn, char_type ());
111 }
112
113private:
114
115 int _C_flags; // bitmap of "cached data valid" flags
116 string _C_grouping; // cached results of virtual members
117 string_type _C_truename;
118 string_type _C_falsename;
119 char_type _C_decimal_point;
120 char_type _C_thousands_sep;
121};
122
123
124#ifndef _RWSTD_NO_SPECIALIZED_FACET_ID
125
127_RW::__rw_facet_id numpunct<char>::id;
128
129# ifndef _RWSTD_NO_WCHAR_T
130
132_RW::__rw_facet_id numpunct<wchar_t>::id;
133
134# endif // _RWSTD_NO_WCHAR_T
135#endif // _RWSTD_NO_SPECIALIZED_FACET_ID
136
137
138template <class _CharT>
139inline typename numpunct<_CharT>::char_type
140numpunct<_CharT>::decimal_point () const
141{
142 if (!(_C_flags & _RW::__rw_dp)) {
143
144 numpunct* const __self = _RWSTD_CONST_CAST (numpunct*, this);
145
146 // [try to] get the decimal point first (may throw)
147 // then set a flag to avoid future initializations
148 __self->_C_decimal_point = do_decimal_point ();
149 __self->_C_flags |= _RW::__rw_dp;
150 }
151
152 return _C_decimal_point;
153}
154
155
156template <class _CharT>
157inline typename numpunct<_CharT>::char_type
158numpunct<_CharT>::thousands_sep () const
159{
160 if (!(_C_flags & _RW::__rw_ts)) {
161
162 numpunct* const __self = _RWSTD_CONST_CAST (numpunct*, this);
163
164 // [try to] get the thousands_sep first (may throw)
165 // then set a flag to avoid future initializations
166 __self->_C_thousands_sep = do_thousands_sep ();
167 __self->_C_flags |= _RW::__rw_ts;
168 }
169
170 return _C_thousands_sep;
171}
172
173
174template <class _CharT>
175inline string numpunct<_CharT>::grouping () const
176{
177 if (!(_C_flags & _RW::__rw_gr)) {
178
179 numpunct* const __self = _RWSTD_CONST_CAST (numpunct*, this);
180
181 // [try to] get the grouping first (may throw)
182 // then set a flag to avoid future initializations
183 __self->_C_grouping = do_grouping ();
184 __self->_C_flags |= _RW::__rw_gr;
185 }
186
187 return _C_grouping;
188}
189
190
191template <class _CharT>
192inline typename numpunct<_CharT>::string_type
193numpunct<_CharT>::truename () const
194{
195 if (!(_C_flags & _RW::__rw_tn)) {
196
197 numpunct* const __self = _RWSTD_CONST_CAST (numpunct*, this);
198
199 // [try to] get the true name first (may throw)
200 // then set a flag to avoid future initializations
201 __self->_C_truename = do_truename ();
202 __self->_C_flags |= _RW::__rw_tn;
203 }
204
205 return _C_truename;
206}
207
208
209template <class _CharT>
210inline typename numpunct<_CharT>::string_type
211numpunct<_CharT>::falsename () const
212{
213 if (!(_C_flags & _RW::__rw_fn)) {
214
215 numpunct* const __self = _RWSTD_CONST_CAST (numpunct*, this);
216
217 // [try to] get the false name first (may throw)
218 // then set a flag to avoid future initializations
219 __self->_C_falsename = do_falsename ();
220 __self->_C_flags |= _RW::__rw_fn;
221 }
222
223 return _C_falsename;
224}
225
226// #endif _RWSTD_NO_EXT_NUMPUNCT_PRIMARY
227
228
229// 22.2.3.2
230template <class _CharT>
231class numpunct_byname: public numpunct<_CharT>
232{
233 char _C_namebuf [32];
234
235public:
236
237 explicit numpunct_byname (const char *__name, _RWSTD_SIZE_T __refs = 0)
238 : numpunct<_CharT>(__refs) {
239 this->_C_set_name (__name, _C_namebuf, sizeof _C_namebuf);
240 }
241
242 virtual ~numpunct_byname () _RWSTD_ATTRIBUTE_NOTHROW;
243};
244
245} // namespace std
246
247
248#if _RWSTD_DEFINE_TEMPLATE_FIRST (_NUMPUNCT)
249# include <loc/_numpunct.cc>
250#endif // _RWSTD_DEFINE_TEMPLATE_FIRST (_NUMPUNCT)
251
252
253#ifdef _RWSTD_MSVC
254# pragma warning (push)
255# pragma warning (disable: 4231)
256#endif // _RWSTD_MSVC
257
258
260
261#if _RWSTD_INSTANTIATE (_NUMPUNCT, _CHAR)
262
263_RWSTD_INSTANTIATE_1 (struct _RWSTD_TI_EXPORT numpunct<char>);
264
265#endif // _RWSTD_INSTANTIATE (_NUMPUNCT, _CHAR)
266
267#if _RWSTD_INSTANTIATE (_NUMPUNCT, _WCHAR_T)
268
269_RWSTD_INSTANTIATE_1 (struct _RWSTD_TI_EXPORT numpunct<wchar_t>);
270
271#endif // _RWSTD_INSTANTIATE (_NUMPUNCT, _WCHAR_T)
272
273} // namespace std
274
275
276#ifdef _RWSTD_MSVC
277# pragma warning (pop)
278#endif // _RWSTD_MSVC
279
280
281#if _RWSTD_DEFINE_TEMPLATE_LAST (_NUMPUNCT)
282# include <loc/_numpunct.cc>
283#endif // _RWSTD_DEFINE_TEMPLATE_LAST (_NUMPUNCT)
284
285
286#endif // _RWSTD_LOC_NUMPUNCT_H_INCLUDED
#define _RWSTD_SPECIALIZED_CLASS
#define _RWSTD_INSTANTIATE_1(arg)
Definition _defs.h:1374
#define _RWSTD_REINTERPRET_CAST(T, x)
Definition _defs.h:535
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_ATTRIBUTE_NOTHROW
Definition _defs.h:1179
#define _EXPORT
Definition _defs.h:498
#define _RWSTD_TI_EXPORT
Definition _defs.h:1331
#define _RWSTD_CONST_CAST(T, x)
Definition _defs.h:536
Definition json.h:5363