2 //===--------------------------- iomanip ----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_IOMANIP
12 #define _LIBCPP_IOMANIP
17 // types T1, T2, ... are unspecified implementation types
18 T1 resetiosflags(ios_base::fmtflags mask);
19 T2 setiosflags (ios_base::fmtflags mask);
21 template<charT> T4 setfill(charT c);
22 T5 setprecision(int n);
24 template <class moneyT> T7 get_money(moneyT& mon, bool intl = false);
25 template <class charT, class moneyT> T8 put_money(const moneyT& mon, bool intl = false);
26 template <class charT> T9 get_time(struct tm* tmb, const charT* fmt);
27 template <class charT> T10 put_time(const struct tm* tmb, const charT* fmt);
36 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
37 #pragma GCC system_header
40 _LIBCPP_BEGIN_NAMESPACE_STD
46 ios_base::fmtflags __mask_;
48 _LIBCPP_INLINE_VISIBILITY
49 explicit __iom_t1(ios_base::fmtflags __m) : __mask_(__m) {}
51 template <class _CharT, class _Traits>
53 _LIBCPP_INLINE_VISIBILITY
54 basic_istream<_CharT, _Traits>&
55 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t1& __x)
57 __is.unsetf(__x.__mask_);
61 template <class _CharT, class _Traits>
63 _LIBCPP_INLINE_VISIBILITY
64 basic_ostream<_CharT, _Traits>&
65 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t1& __x)
67 __os.unsetf(__x.__mask_);
72 inline _LIBCPP_INLINE_VISIBILITY
74 resetiosflags(ios_base::fmtflags __mask)
76 return __iom_t1(__mask);
83 ios_base::fmtflags __mask_;
85 _LIBCPP_INLINE_VISIBILITY
86 explicit __iom_t2(ios_base::fmtflags __m) : __mask_(__m) {}
88 template <class _CharT, class _Traits>
90 _LIBCPP_INLINE_VISIBILITY
91 basic_istream<_CharT, _Traits>&
92 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t2& __x)
94 __is.setf(__x.__mask_);
98 template <class _CharT, class _Traits>
100 _LIBCPP_INLINE_VISIBILITY
101 basic_ostream<_CharT, _Traits>&
102 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t2& __x)
104 __os.setf(__x.__mask_);
109 inline _LIBCPP_INLINE_VISIBILITY
111 setiosflags(ios_base::fmtflags __mask)
113 return __iom_t2(__mask);
122 _LIBCPP_INLINE_VISIBILITY
123 explicit __iom_t3(int __b) : __base_(__b) {}
125 template <class _CharT, class _Traits>
127 _LIBCPP_INLINE_VISIBILITY
128 basic_istream<_CharT, _Traits>&
129 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t3& __x)
131 __is.setf(__x.__base_ == 8 ? ios_base::oct :
132 __x.__base_ == 10 ? ios_base::dec :
133 __x.__base_ == 16 ? ios_base::hex :
134 ios_base::fmtflags(0), ios_base::basefield);
138 template <class _CharT, class _Traits>
140 _LIBCPP_INLINE_VISIBILITY
141 basic_ostream<_CharT, _Traits>&
142 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t3& __x)
144 __os.setf(__x.__base_ == 8 ? ios_base::oct :
145 __x.__base_ == 10 ? ios_base::dec :
146 __x.__base_ == 16 ? ios_base::hex :
147 ios_base::fmtflags(0), ios_base::basefield);
152 inline _LIBCPP_INLINE_VISIBILITY
156 return __iom_t3(__base);
161 template<class _CharT>
166 _LIBCPP_INLINE_VISIBILITY
167 explicit __iom_t4(_CharT __c) : __fill_(__c) {}
169 template <class _Traits>
171 _LIBCPP_INLINE_VISIBILITY
172 basic_ostream<_CharT, _Traits>&
173 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t4& __x)
175 __os.fill(__x.__fill_);
180 template<class _CharT>
181 inline _LIBCPP_INLINE_VISIBILITY
185 return __iom_t4<_CharT>(__c);
194 _LIBCPP_INLINE_VISIBILITY
195 explicit __iom_t5(int __n) : __n_(__n) {}
197 template <class _CharT, class _Traits>
199 _LIBCPP_INLINE_VISIBILITY
200 basic_istream<_CharT, _Traits>&
201 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t5& __x)
203 __is.precision(__x.__n_);
207 template <class _CharT, class _Traits>
209 _LIBCPP_INLINE_VISIBILITY
210 basic_ostream<_CharT, _Traits>&
211 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t5& __x)
213 __os.precision(__x.__n_);
218 inline _LIBCPP_INLINE_VISIBILITY
220 setprecision(int __n)
222 return __iom_t5(__n);
231 _LIBCPP_INLINE_VISIBILITY
232 explicit __iom_t6(int __n) : __n_(__n) {}
234 template <class _CharT, class _Traits>
236 _LIBCPP_INLINE_VISIBILITY
237 basic_istream<_CharT, _Traits>&
238 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t6& __x)
240 __is.width(__x.__n_);
244 template <class _CharT, class _Traits>
246 _LIBCPP_INLINE_VISIBILITY
247 basic_ostream<_CharT, _Traits>&
248 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t6& __x)
250 __os.width(__x.__n_);
255 inline _LIBCPP_INLINE_VISIBILITY
259 return __iom_t6(__n);
264 template <class _MoneyT> class __iom_t7;
266 template <class _CharT, class _Traits, class _MoneyT>
267 basic_istream<_CharT, _Traits>&
268 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x);
270 template <class _MoneyT>
276 _LIBCPP_INLINE_VISIBILITY
277 __iom_t7(_MoneyT& __mon, bool __intl)
278 : __mon_(__mon), __intl_(__intl) {}
280 template <class _CharT, class _Traits, class _Mp>
282 basic_istream<_CharT, _Traits>&
283 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_Mp>& __x);
286 template <class _CharT, class _Traits, class _MoneyT>
287 basic_istream<_CharT, _Traits>&
288 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x)
290 #ifndef _LIBCPP_NO_EXCEPTIONS
293 #endif // _LIBCPP_NO_EXCEPTIONS
294 typename basic_istream<_CharT, _Traits>::sentry __s(__is);
297 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
298 typedef money_get<_CharT, _Ip> _Fp;
299 ios_base::iostate __err = ios_base::goodbit;
300 const _Fp& __mf = use_facet<_Fp>(__is.getloc());
301 __mf.get(_Ip(__is), _Ip(), __x.__intl_, __is, __err, __x.__mon_);
302 __is.setstate(__err);
304 #ifndef _LIBCPP_NO_EXCEPTIONS
308 __is.__set_badbit_and_consider_rethrow();
310 #endif // _LIBCPP_NO_EXCEPTIONS
314 template <class _MoneyT>
315 inline _LIBCPP_INLINE_VISIBILITY
317 get_money(_MoneyT& __mon, bool __intl = false)
319 return __iom_t7<_MoneyT>(__mon, __intl);
324 template <class _MoneyT> class __iom_t8;
326 template <class _CharT, class _Traits, class _MoneyT>
327 basic_ostream<_CharT, _Traits>&
328 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x);
330 template <class _MoneyT>
333 const _MoneyT& __mon_;
336 _LIBCPP_INLINE_VISIBILITY
337 __iom_t8(const _MoneyT& __mon, bool __intl)
338 : __mon_(__mon), __intl_(__intl) {}
340 template <class _CharT, class _Traits, class _Mp>
342 basic_ostream<_CharT, _Traits>&
343 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_Mp>& __x);
346 template <class _CharT, class _Traits, class _MoneyT>
347 basic_ostream<_CharT, _Traits>&
348 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x)
350 #ifndef _LIBCPP_NO_EXCEPTIONS
353 #endif // _LIBCPP_NO_EXCEPTIONS
354 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
357 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
358 typedef money_put<_CharT, _Op> _Fp;
359 const _Fp& __mf = use_facet<_Fp>(__os.getloc());
360 if (__mf.put(_Op(__os), __x.__intl_, __os, __os.fill(), __x.__mon_).failed())
361 __os.setstate(ios_base::badbit);
363 #ifndef _LIBCPP_NO_EXCEPTIONS
367 __os.__set_badbit_and_consider_rethrow();
369 #endif // _LIBCPP_NO_EXCEPTIONS
373 template <class _MoneyT>
374 inline _LIBCPP_INLINE_VISIBILITY
376 put_money(const _MoneyT& __mon, bool __intl = false)
378 return __iom_t8<_MoneyT>(__mon, __intl);
383 template <class _CharT> class __iom_t9;
385 template <class _CharT, class _Traits>
386 basic_istream<_CharT, _Traits>&
387 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x);
389 template <class _CharT>
393 const _CharT* __fmt_;
395 _LIBCPP_INLINE_VISIBILITY
396 __iom_t9(tm* __tm, const _CharT* __fmt)
397 : __tm_(__tm), __fmt_(__fmt) {}
399 template <class _Cp, class _Traits>
401 basic_istream<_Cp, _Traits>&
402 operator>>(basic_istream<_Cp, _Traits>& __is, const __iom_t9<_Cp>& __x);
405 template <class _CharT, class _Traits>
406 basic_istream<_CharT, _Traits>&
407 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x)
409 #ifndef _LIBCPP_NO_EXCEPTIONS
412 #endif // _LIBCPP_NO_EXCEPTIONS
413 typename basic_istream<_CharT, _Traits>::sentry __s(__is);
416 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
417 typedef time_get<_CharT, _Ip> _Fp;
418 ios_base::iostate __err = ios_base::goodbit;
419 const _Fp& __tf = use_facet<_Fp>(__is.getloc());
420 __tf.get(_Ip(__is), _Ip(), __is, __err, __x.__tm_,
421 __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_));
422 __is.setstate(__err);
424 #ifndef _LIBCPP_NO_EXCEPTIONS
428 __is.__set_badbit_and_consider_rethrow();
430 #endif // _LIBCPP_NO_EXCEPTIONS
434 template <class _CharT>
435 inline _LIBCPP_INLINE_VISIBILITY
437 get_time(tm* __tm, const _CharT* __fmt)
439 return __iom_t9<_CharT>(__tm, __fmt);
444 template <class _CharT> class __iom_t10;
446 template <class _CharT, class _Traits>
447 basic_ostream<_CharT, _Traits>&
448 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x);
450 template <class _CharT>
454 const _CharT* __fmt_;
456 _LIBCPP_INLINE_VISIBILITY
457 __iom_t10(const tm* __tm, const _CharT* __fmt)
458 : __tm_(__tm), __fmt_(__fmt) {}
460 template <class _Cp, class _Traits>
462 basic_ostream<_Cp, _Traits>&
463 operator<<(basic_ostream<_Cp, _Traits>& __os, const __iom_t10<_Cp>& __x);
466 template <class _CharT, class _Traits>
467 basic_ostream<_CharT, _Traits>&
468 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x)
470 #ifndef _LIBCPP_NO_EXCEPTIONS
473 #endif // _LIBCPP_NO_EXCEPTIONS
474 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
477 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
478 typedef time_put<_CharT, _Op> _Fp;
479 const _Fp& __tf = use_facet<_Fp>(__os.getloc());
480 if (__tf.put(_Op(__os), __os, __os.fill(), __x.__tm_,
481 __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_)).failed())
482 __os.setstate(ios_base::badbit);
484 #ifndef _LIBCPP_NO_EXCEPTIONS
488 __os.__set_badbit_and_consider_rethrow();
490 #endif // _LIBCPP_NO_EXCEPTIONS
494 template <class _CharT>
495 inline _LIBCPP_INLINE_VISIBILITY
497 put_time(const tm* __tm, const _CharT* __fmt)
499 return __iom_t10<_CharT>(__tm, __fmt);
502 _LIBCPP_END_NAMESPACE_STD
504 #endif // _LIBCPP_IOMANIP