Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_num_get.h
Go to the documentation of this file.
1
32#ifndef _RWSTD_LOC_NUM_GET_H_INCLUDED
33#define _RWSTD_LOC_NUM_GET_H_INCLUDED
34
35
36#if __GNUG__ >= 3
37# pragma GCC system_header
38#endif // gcc >= 3
39
40
41#include <loc/_facet.h>
42#include <rw/_ioiter.h>
43#include <rw/_iosfwd.h>
44#include <rw/_traits.h>
45#include <rw/_defs.h>
46
47
49
50
51// 22.2.2.1
53template <class _CharT, class _InputIter = istreambuf_iterator<_CharT> >
54struct num_get: _RW::__rw_facet
55{
56 typedef _CharT char_type;
57 typedef _InputIter iter_type;
58
59 static _RW::__rw_facet_id id;
60
61 explicit num_get (_RWSTD_SIZE_T __refs = 0)
62 : _RW::__rw_facet (__refs) { }
63
64#ifndef _RWSTD_NO_NATIVE_BOOL
65
66 iter_type get (iter_type __begin, iter_type __end, ios_base &__flags,
67 _RWSTD_IOSTATE &__err, bool &__val) const {
68 _RWSTD_ASSERT_RANGE (__begin, __end);
69 return do_get (__begin, __end, __flags, __err, __val);
70 }
71
72#endif // _RWSTD_NO_NATIVE_BOOL
73
74 iter_type get (iter_type __begin, iter_type __end, ios_base &__flags,
75 _RWSTD_IOSTATE &__err, unsigned short &__val) const {
76 _RWSTD_ASSERT_RANGE (__begin, __end);
77 return do_get (__begin, __end, __flags, __err, __val);
78 }
79
80#ifndef _RWSTD_NO_EXT_NUM_GET
81
82 // extension
83 iter_type
84 get (iter_type, iter_type, ios_base&, _RWSTD_IOSTATE&, short&) const;
85
86 // extension
87 iter_type
88 get (iter_type, iter_type, ios_base&, _RWSTD_IOSTATE&, int&) const;
89
90#endif // _RWSTD_NO_EXT_NUM_GET
91
92 iter_type get (iter_type __begin, iter_type __end, ios_base &__flags,
93 _RWSTD_IOSTATE &__err, unsigned int &__val) const {
94 _RWSTD_ASSERT_RANGE (__begin, __end);
95 return do_get (__begin, __end, __flags, __err, __val);
96 }
97
98 iter_type get (iter_type __begin, iter_type __end, ios_base &__flags,
99 _RWSTD_IOSTATE &__err, long &__val) const {
100 _RWSTD_ASSERT_RANGE (__begin, __end);
101 return do_get (__begin, __end, __flags, __err, __val);
102 }
103
104 iter_type get (iter_type __begin, iter_type __end, ios_base &__flags,
105 _RWSTD_IOSTATE &__err, unsigned long &__val) const {
106 _RWSTD_ASSERT_RANGE (__begin, __end);
107 return do_get (__begin, __end, __flags, __err, __val);
108 }
109
110 iter_type get (iter_type __begin, iter_type __end, ios_base &__flags,
111 _RWSTD_IOSTATE &__err, float &__val) const {
112 _RWSTD_ASSERT_RANGE (__begin, __end);
113 return do_get (__begin, __end, __flags, __err, __val);
114 }
115
116 iter_type get (iter_type __begin, iter_type __end, ios_base &__flags,
117 _RWSTD_IOSTATE &__err, double &__val) const {
118 _RWSTD_ASSERT_RANGE (__begin, __end);
119 return do_get (__begin, __end, __flags, __err, __val);
120 }
121
122#ifndef _RWSTD_LONG_DOUBLE
123
124 iter_type get (iter_type __begin, iter_type __end, ios_base &__flags,
125 _RWSTD_IOSTATE &__err, long double &__val) const {
126 _RWSTD_ASSERT_RANGE (__begin, __end);
127 return do_get (__begin, __end, __flags, __err, __val);
128 }
129
130#endif // _RWSTD_LONG_DOUBLE
131
132 iter_type get (iter_type __begin, iter_type __end, ios_base &__flags,
133 _RWSTD_IOSTATE &__err, void* &__val) const {
134 _RWSTD_ASSERT_RANGE (__begin, __end);
135 return do_get (__begin, __end, __flags, __err, __val);
136 }
137
138
139#ifdef _RWSTD_LONG_LONG
140
141 // extension
142 iter_type get (iter_type __begin, iter_type __end, ios_base &__flags,
143 _RWSTD_IOSTATE &__err, _RWSTD_LONG_LONG &__val) const {
144 _RWSTD_ASSERT_RANGE (__begin, __end);
145 return do_get (__begin, __end, __flags, __err, __val);
146 }
147
148 // extension
149 iter_type get (iter_type __begin, iter_type __end, ios_base &__flags,
150 _RWSTD_IOSTATE &__err,
151 unsigned _RWSTD_LONG_LONG &__val) const {
152 _RWSTD_ASSERT_RANGE (__begin, __end);
153 return do_get (__begin, __end, __flags, __err, __val);
154 }
155#endif // _RWSTD_LONG_LONG
156
157
158protected:
159
160#ifndef _RWSTD_NO_NATIVE_BOOL
161
162 virtual iter_type
163 do_get (iter_type, iter_type, ios_base&, _RWSTD_IOSTATE&, bool&) const;
164
165#endif // _RWSTD_NO_NATIVE_BOOL
166
167 virtual iter_type
168 do_get (iter_type __begin, iter_type __end, ios_base &__flags,
169 _RWSTD_IOSTATE &__err, unsigned short &__val) const {
170 return _C_get (__begin, __end, __flags, __err, _C_ushort, &__val);
171 }
172
173 virtual iter_type
174 do_get (iter_type __begin, iter_type __end, ios_base &__flags,
175 _RWSTD_IOSTATE &__err, unsigned int &__val) const {
176 return _C_get (__begin, __end, __flags, __err, _C_uint, &__val);
177 }
178
179 virtual iter_type
180 do_get (iter_type __begin, iter_type __end, ios_base &__flags,
181 _RWSTD_IOSTATE &__err, long &__val) const {
182 return _C_get (__begin, __end, __flags, __err, _C_long, &__val);
183 }
184
185 virtual iter_type
186 do_get (iter_type __begin, iter_type __end, ios_base &__flags,
187 _RWSTD_IOSTATE &__err, unsigned long &__val) const {
188 return _C_get (__begin, __end, __flags, __err, _C_ulong, &__val);
189 }
190
191 virtual iter_type
192 do_get (iter_type __begin, iter_type __end, ios_base &__flags,
193 _RWSTD_IOSTATE &__err, float &__val) const {
194 return _C_get (__begin, __end, __flags, __err, _C_float, &__val);
195 }
196
197 virtual iter_type
198 do_get (iter_type __begin, iter_type __end, ios_base &__flags,
199 _RWSTD_IOSTATE &__err, double &__val) const {
200 return _C_get (__begin, __end, __flags, __err, _C_double, &__val);
201 }
202
203#ifndef _RWSTD_LONG_DOUBLE
204
205 virtual iter_type
206 do_get (iter_type __begin, iter_type __end, ios_base &__flags,
207 _RWSTD_IOSTATE &__err, long double &__val) const {
208 return _C_get (__begin, __end, __flags, __err, _C_ldouble, &__val);
209 }
210
211#endif // _RWSTD_LONG_DOUBLE
212
213 virtual iter_type
214 do_get (iter_type __begin, iter_type __end, ios_base &__flags,
215 _RWSTD_IOSTATE &__err, void* &__val) const {
216 return _C_get (__begin, __end, __flags, __err, _C_pvoid, &__val);
217 }
218
219#ifdef _RWSTD_LONG_LONG
220
221 // extension
222 virtual iter_type
223 do_get (iter_type __begin, iter_type __end, ios_base &__flags,
224 _RWSTD_IOSTATE &__err, _RWSTD_LONG_LONG &__val) const {
225 return _C_get (__begin, __end, __flags, __err, _C_llong, &__val);
226 }
227
228 // extension
229 virtual iter_type
230 do_get (iter_type __begin, iter_type __end, ios_base &__flags,
231 _RWSTD_IOSTATE &__err, unsigned _RWSTD_LONG_LONG &__val) const {
232 return _C_get (__begin, __end, __flags, __err, _C_ullong, &__val);
233 }
234
235
236#endif // _RWSTD_LONG_LONG
237
238private:
239
240 iter_type
241 _C_get (iter_type, iter_type, ios_base&,
242 _RWSTD_IOSTATE&, int, void*) const;
243};
244
245
246#ifndef _RWSTD_NO_SPECIALIZED_FACET_ID
247
249_RW::__rw_facet_id num_get<char, istreambuf_iterator<char> >::id;
250
251# ifndef _RWSTD_NO_WCHAR_T
252
254_RW::__rw_facet_id num_get<wchar_t, istreambuf_iterator<wchar_t> >::id;
255
256# endif // _RWSTD_NO_WCHAR_T
257#endif // _RWSTD_NO_SPECIALIZED_FACET_ID
258
259} // namespace std
260
261
263
264inline short
265__rw_check_overflow_short (long __lval, _RWSTD_FMTFLAGS __flags,
266 _RWSTD_IOSTATE &__err)
267{
268#if _RWSTD_SHRT_MAX < _RWSTD_LONG_MAX
269
270 long __shrt_min;
271 long __shrt_max;
272
273 if ( __lval < 0
274 || (__flags & _RW::__rw_basefield) == _RW::__rw_dec) {
275 // decimal parsing overflows outside the range below
276 __shrt_max = long (_RWSTD_SHRT_MAX);
277 __shrt_min = long (_RWSTD_SHRT_MIN);
278 }
279 else {
280 // other than decimal parsing overflows outside the range below
281 // (unreliable if basefield is 0 and the sequence is decimal)
282 __shrt_max = long (_RWSTD_USHRT_MAX);
283 __shrt_min = long (_RWSTD_USHRT_MIN);
284 }
285
286 // lwg issue 23: check for overflow
287 if (__lval < __shrt_min) {
288 __err |= _RW::__rw_failbit;
289 return short (_RWSTD_SHRT_MIN);
290 }
291 else if (__lval > __shrt_max) {
292 __err |= _RW::__rw_failbit;
293 return short (_RWSTD_SHRT_MAX);
294 }
295
296#else // if LONG_MAX <= SHRT_MAX
297
298 _RWSTD_UNUSED (__flags);
299 _RWSTD_UNUSED (__err);
300
301#endif // _RWSTD_SHRT_MAX < _RWSTD_LONG_MAX
302
303 return _RWSTD_STATIC_CAST (short, __lval);
304}
305
306inline int
307__rw_check_overflow_int (long __lval, _RWSTD_FMTFLAGS __flags,
308 _RWSTD_IOSTATE &__err)
309{
310#if _RWSTD_INT_MAX < _RWSTD_LONG_MAX
311
312 long __int_min;
313 long __int_max;
314
315 if ( __lval < 0
316 || (__flags & _RW::__rw_basefield) == _RW::__rw_dec) {
317 // decimal parsing overflows outside the range below
318 __int_max = long (_RWSTD_INT_MAX);
319 __int_min = long (_RWSTD_INT_MIN);
320 }
321 else {
322 // other than decimal parsing overflows outside the range below
323 // (unreliable if basefield is 0 and the sequence is decimal)
324 __int_max = long (_RWSTD_UINT_MAX);
325 __int_min = long (_RWSTD_UINT_MIN);
326 }
327
328 // lwg issue 23: check for overflow
329 if (__lval < __int_min) {
330 __err |= _RW::__rw_failbit;
331 return int (_RWSTD_INT_MIN);
332 }
333 else if (__lval > __int_max) {
334 __err |= _RW::__rw_failbit;
335 return int (_RWSTD_INT_MAX);
336 }
337
338#else // if LONG_MAX <= INT_MAX
339
340 _RWSTD_UNUSED (__flags);
341 _RWSTD_UNUSED (__err);
342
343#endif // _RWSTD_INT_MAX < _RWSTD_LONG_MAX
344
345 return _RWSTD_STATIC_CAST (int, __lval);
346}
347
348} // namespace __rw
349
350
351#if _RWSTD_DEFINE_TEMPLATE_FIRST (_NUM_GET)
352# include <loc/_num_get.cc>
353#endif // _RWSTD_DEFINE_TEMPLATE_FIRST (_NUM_GET)
354
355
356#ifdef _RWSTD_MSVC
357# pragma warning (push)
358# pragma warning (disable: 4231)
359#endif // _RWSTD_MSVC
360
361
363
364#if _RWSTD_INSTANTIATE (_NUM_GET, _CHAR)
365
366_RWSTD_INSTANTIATE_1 (struct _RWSTD_TI_EXPORT num_get<char>);
367
368#endif // _RWSTD_INSTANTIATE (_NUM_GET, _CHAR)
369
370#if _RWSTD_INSTANTIATE (_NUM_GET, _WCHAR_T)
371
372_RWSTD_INSTANTIATE_1 (struct _RWSTD_TI_EXPORT num_get<wchar_t>);
373
374#endif // _RWSTD_INSTANTIATE (_NUM_GET, _WCHAR_T)
375
376} // namespace std
377
378
379#ifdef _RWSTD_MSVC
380# pragma warning (pop)
381#endif // _RWSTD_MSVC
382
383
384#if _RWSTD_DEFINE_TEMPLATE_LAST (_NUM_GET)
385# include <loc/_num_get.cc>
386#endif // _RWSTD_DEFINE_TEMPLATE_LAST (_NUM_GET)
387
388
389#endif // _RWSTD_LOC_NUM_GET_H_INCLUDED
#define _RWSTD_SPECIALIZED_CLASS
#define _RWSTD_LONG_LONG
#define _RWSTD_INSTANTIATE_1(arg)
Definition _defs.h:1374
#define _RWSTD_UNUSED(arg)
Definition _defs.h:972
#define _RWSTD_STATIC_CAST(T, x)
Definition _defs.h:534
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _EXPORT
Definition _defs.h:498
#define _RWSTD_ASSERT_RANGE(ign1, ign2)
Definition _defs.h:1247
#define _RWSTD_TI_EXPORT
Definition _defs.h:1331
#define _RWSTD_FMTFLAGS
Definition _iosfwd.h:92
#define _RWSTD_IOSTATE
Definition _iosfwd.h:91
Definition json.h:5363