Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- iomanip ----------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_IOMANIP |
| 12 | #define _LIBCPP_IOMANIP |
| 13 | |
| 14 | /* |
| 15 | iomanip synopsis |
| 16 | |
| 17 | // types T1, T2, ... are unspecified implementation types |
| 18 | T1 resetiosflags(ios_base::fmtflags mask); |
| 19 | T2 setiosflags (ios_base::fmtflags mask); |
| 20 | T3 setbase(int base); |
| 21 | template<charT> T4 setfill(charT c); |
| 22 | T5 setprecision(int n); |
| 23 | T6 setw(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); |
| 28 | |
| 29 | } // std |
| 30 | |
| 31 | */ |
| 32 | |
| 33 | #include <__config> |
| 34 | #include <istream> |
| 35 | |
| 36 | #pragma GCC system_header |
| 37 | |
| 38 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 39 | |
| 40 | // resetiosflags |
| 41 | |
| 42 | class __iom_t1 |
| 43 | { |
| 44 | ios_base::fmtflags __mask_; |
| 45 | public: |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 46 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 47 | explicit __iom_t1(ios_base::fmtflags __m) : __mask_(__m) {} |
| 48 | |
| 49 | template <class _CharT, class _Traits> |
| 50 | friend |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 51 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 52 | basic_istream<_CharT, _Traits>& |
| 53 | operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t1& __x) |
| 54 | { |
| 55 | __is.unsetf(__x.__mask_); |
| 56 | return __is; |
| 57 | } |
| 58 | |
| 59 | template <class _CharT, class _Traits> |
| 60 | friend |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 61 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 62 | basic_ostream<_CharT, _Traits>& |
| 63 | operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t1& __x) |
| 64 | { |
| 65 | __os.unsetf(__x.__mask_); |
| 66 | return __os; |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | inline _LIBCPP_INLINE_VISIBILITY |
| 71 | __iom_t1 |
| 72 | resetiosflags(ios_base::fmtflags __mask) |
| 73 | { |
| 74 | return __iom_t1(__mask); |
| 75 | } |
| 76 | |
| 77 | // setiosflags |
| 78 | |
| 79 | class __iom_t2 |
| 80 | { |
| 81 | ios_base::fmtflags __mask_; |
| 82 | public: |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 83 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 84 | explicit __iom_t2(ios_base::fmtflags __m) : __mask_(__m) {} |
| 85 | |
| 86 | template <class _CharT, class _Traits> |
| 87 | friend |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 88 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 89 | basic_istream<_CharT, _Traits>& |
| 90 | operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t2& __x) |
| 91 | { |
| 92 | __is.setf(__x.__mask_); |
| 93 | return __is; |
| 94 | } |
| 95 | |
| 96 | template <class _CharT, class _Traits> |
| 97 | friend |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 98 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 99 | basic_ostream<_CharT, _Traits>& |
| 100 | operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t2& __x) |
| 101 | { |
| 102 | __os.setf(__x.__mask_); |
| 103 | return __os; |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | inline _LIBCPP_INLINE_VISIBILITY |
| 108 | __iom_t2 |
| 109 | setiosflags(ios_base::fmtflags __mask) |
| 110 | { |
| 111 | return __iom_t2(__mask); |
| 112 | } |
| 113 | |
| 114 | // setbase |
| 115 | |
| 116 | class __iom_t3 |
| 117 | { |
| 118 | int __base_; |
| 119 | public: |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 120 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 121 | explicit __iom_t3(int __b) : __base_(__b) {} |
| 122 | |
| 123 | template <class _CharT, class _Traits> |
| 124 | friend |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 125 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 126 | basic_istream<_CharT, _Traits>& |
| 127 | operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t3& __x) |
| 128 | { |
| 129 | __is.setf(__x.__base_ == 8 ? ios_base::oct : |
| 130 | __x.__base_ == 10 ? ios_base::dec : |
| 131 | __x.__base_ == 16 ? ios_base::hex : |
| 132 | ios_base::fmtflags(0), ios_base::basefield); |
| 133 | return __is; |
| 134 | } |
| 135 | |
| 136 | template <class _CharT, class _Traits> |
| 137 | friend |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 138 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 139 | basic_ostream<_CharT, _Traits>& |
| 140 | operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t3& __x) |
| 141 | { |
| 142 | __os.setf(__x.__base_ == 8 ? ios_base::oct : |
| 143 | __x.__base_ == 10 ? ios_base::dec : |
| 144 | __x.__base_ == 16 ? ios_base::hex : |
| 145 | ios_base::fmtflags(0), ios_base::basefield); |
| 146 | return __os; |
| 147 | } |
| 148 | }; |
| 149 | |
| 150 | inline _LIBCPP_INLINE_VISIBILITY |
| 151 | __iom_t3 |
| 152 | setbase(int __base) |
| 153 | { |
| 154 | return __iom_t3(__base); |
| 155 | } |
| 156 | |
| 157 | // setfill |
| 158 | |
| 159 | template<class _CharT> |
| 160 | class __iom_t4 |
| 161 | { |
| 162 | _CharT __fill_; |
| 163 | public: |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 164 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 165 | explicit __iom_t4(_CharT __c) : __fill_(__c) {} |
| 166 | |
| 167 | template <class _Traits> |
| 168 | friend |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 169 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 170 | basic_ostream<_CharT, _Traits>& |
| 171 | operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t4& __x) |
| 172 | { |
| 173 | __os.fill(__x.__fill_); |
| 174 | return __os; |
| 175 | } |
| 176 | }; |
| 177 | |
| 178 | template<class _CharT> |
| 179 | inline _LIBCPP_INLINE_VISIBILITY |
| 180 | __iom_t4<_CharT> |
| 181 | setfill(_CharT __c) |
| 182 | { |
| 183 | return __iom_t4<_CharT>(__c); |
| 184 | } |
| 185 | |
| 186 | // setprecision |
| 187 | |
| 188 | class __iom_t5 |
| 189 | { |
| 190 | int __n_; |
| 191 | public: |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 192 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 193 | explicit __iom_t5(int __n) : __n_(__n) {} |
| 194 | |
| 195 | template <class _CharT, class _Traits> |
| 196 | friend |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 197 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 198 | basic_istream<_CharT, _Traits>& |
| 199 | operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t5& __x) |
| 200 | { |
| 201 | __is.precision(__x.__n_); |
| 202 | return __is; |
| 203 | } |
| 204 | |
| 205 | template <class _CharT, class _Traits> |
| 206 | friend |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 207 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 208 | basic_ostream<_CharT, _Traits>& |
| 209 | operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t5& __x) |
| 210 | { |
| 211 | __os.precision(__x.__n_); |
| 212 | return __os; |
| 213 | } |
| 214 | }; |
| 215 | |
| 216 | inline _LIBCPP_INLINE_VISIBILITY |
| 217 | __iom_t5 |
| 218 | setprecision(int __n) |
| 219 | { |
| 220 | return __iom_t5(__n); |
| 221 | } |
| 222 | |
| 223 | // setw |
| 224 | |
| 225 | class __iom_t6 |
| 226 | { |
| 227 | int __n_; |
| 228 | public: |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 229 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 230 | explicit __iom_t6(int __n) : __n_(__n) {} |
| 231 | |
| 232 | template <class _CharT, class _Traits> |
| 233 | friend |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 234 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 235 | basic_istream<_CharT, _Traits>& |
| 236 | operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t6& __x) |
| 237 | { |
| 238 | __is.width(__x.__n_); |
| 239 | return __is; |
| 240 | } |
| 241 | |
| 242 | template <class _CharT, class _Traits> |
| 243 | friend |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 244 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 245 | basic_ostream<_CharT, _Traits>& |
| 246 | operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t6& __x) |
| 247 | { |
| 248 | __os.width(__x.__n_); |
| 249 | return __os; |
| 250 | } |
| 251 | }; |
| 252 | |
| 253 | inline _LIBCPP_INLINE_VISIBILITY |
| 254 | __iom_t6 |
| 255 | setw(int __n) |
| 256 | { |
| 257 | return __iom_t6(__n); |
| 258 | } |
| 259 | |
| 260 | // get_money |
| 261 | |
| 262 | template <class _MoneyT> class __iom_t7; |
| 263 | |
| 264 | template <class _CharT, class _Traits, class _MoneyT> |
| 265 | basic_istream<_CharT, _Traits>& |
| 266 | operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x); |
| 267 | |
| 268 | template <class _MoneyT> |
| 269 | class __iom_t7 |
| 270 | { |
| 271 | _MoneyT& __mon_; |
| 272 | bool __intl_; |
| 273 | public: |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 274 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 275 | __iom_t7(_MoneyT& __mon, bool __intl) |
| 276 | : __mon_(__mon), __intl_(__intl) {} |
| 277 | |
| 278 | template <class _CharT, class _Traits, class _M> |
| 279 | friend |
| 280 | basic_istream<_CharT, _Traits>& |
| 281 | operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_M>& __x); |
| 282 | }; |
| 283 | |
| 284 | template <class _CharT, class _Traits, class _MoneyT> |
| 285 | basic_istream<_CharT, _Traits>& |
| 286 | operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x) |
| 287 | { |
| 288 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 289 | try |
| 290 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 291 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 292 | typename basic_istream<_CharT, _Traits>::sentry __s(__is); |
| 293 | if (__s) |
| 294 | { |
| 295 | typedef istreambuf_iterator<_CharT, _Traits> _I; |
| 296 | typedef money_get<_CharT, _I> _F; |
| 297 | ios_base::iostate __err = ios_base::goodbit; |
| 298 | const _F& __mf = use_facet<_F>(__is.getloc()); |
| 299 | __mf.get(_I(__is), _I(), __x.__intl_, __is, __err, __x.__mon_); |
| 300 | __is.setstate(__err); |
| 301 | } |
| 302 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 303 | } |
| 304 | catch (...) |
| 305 | { |
| 306 | __is.__set_badbit_and_consider_rethrow(); |
| 307 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 308 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 309 | return __is; |
| 310 | } |
| 311 | |
| 312 | template <class _MoneyT> |
| 313 | inline _LIBCPP_INLINE_VISIBILITY |
| 314 | __iom_t7<_MoneyT> |
| 315 | get_money(_MoneyT& __mon, bool __intl = false) |
| 316 | { |
| 317 | return __iom_t7<_MoneyT>(__mon, __intl); |
| 318 | } |
| 319 | |
| 320 | // put_money |
| 321 | |
| 322 | template <class _MoneyT> class __iom_t8; |
| 323 | |
| 324 | template <class _CharT, class _Traits, class _MoneyT> |
| 325 | basic_ostream<_CharT, _Traits>& |
| 326 | operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x); |
| 327 | |
| 328 | template <class _MoneyT> |
| 329 | class __iom_t8 |
| 330 | { |
| 331 | const _MoneyT& __mon_; |
| 332 | bool __intl_; |
| 333 | public: |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 334 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 335 | __iom_t8(const _MoneyT& __mon, bool __intl) |
| 336 | : __mon_(__mon), __intl_(__intl) {} |
| 337 | |
| 338 | template <class _CharT, class _Traits, class _M> |
| 339 | friend |
| 340 | basic_ostream<_CharT, _Traits>& |
| 341 | operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_M>& __x); |
| 342 | }; |
| 343 | |
| 344 | template <class _CharT, class _Traits, class _MoneyT> |
| 345 | basic_ostream<_CharT, _Traits>& |
| 346 | operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x) |
| 347 | { |
| 348 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 349 | try |
| 350 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 351 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 352 | typename basic_ostream<_CharT, _Traits>::sentry __s(__os); |
| 353 | if (__s) |
| 354 | { |
| 355 | typedef ostreambuf_iterator<_CharT, _Traits> _O; |
| 356 | typedef money_put<_CharT, _O> _F; |
| 357 | const _F& __mf = use_facet<_F>(__os.getloc()); |
| 358 | if (__mf.put(_O(__os), __x.__intl_, __os, __os.fill(), __x.__mon_).failed()) |
| 359 | __os.setstate(ios_base::badbit); |
| 360 | } |
| 361 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 362 | } |
| 363 | catch (...) |
| 364 | { |
| 365 | __os.__set_badbit_and_consider_rethrow(); |
| 366 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 367 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 368 | return __os; |
| 369 | } |
| 370 | |
| 371 | template <class _MoneyT> |
| 372 | inline _LIBCPP_INLINE_VISIBILITY |
| 373 | __iom_t8<_MoneyT> |
| 374 | put_money(const _MoneyT& __mon, bool __intl = false) |
| 375 | { |
| 376 | return __iom_t8<_MoneyT>(__mon, __intl); |
| 377 | } |
| 378 | |
| 379 | // get_time |
| 380 | |
| 381 | template <class _CharT> class __iom_t9; |
| 382 | |
| 383 | template <class _CharT, class _Traits> |
| 384 | basic_istream<_CharT, _Traits>& |
| 385 | operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x); |
| 386 | |
| 387 | template <class _CharT> |
| 388 | class __iom_t9 |
| 389 | { |
| 390 | tm* __tm_; |
| 391 | const _CharT* __fmt_; |
| 392 | public: |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 393 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 394 | __iom_t9(tm* __tm, const _CharT* __fmt) |
| 395 | : __tm_(__tm), __fmt_(__fmt) {} |
| 396 | |
| 397 | template <class _C, class _Traits> |
| 398 | friend |
| 399 | basic_istream<_C, _Traits>& |
| 400 | operator>>(basic_istream<_C, _Traits>& __is, const __iom_t9<_C>& __x); |
| 401 | }; |
| 402 | |
| 403 | template <class _CharT, class _Traits> |
| 404 | basic_istream<_CharT, _Traits>& |
| 405 | operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x) |
| 406 | { |
| 407 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 408 | try |
| 409 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 410 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 411 | typename basic_istream<_CharT, _Traits>::sentry __s(__is); |
| 412 | if (__s) |
| 413 | { |
| 414 | typedef istreambuf_iterator<_CharT, _Traits> _I; |
| 415 | typedef time_get<_CharT, _I> _F; |
| 416 | ios_base::iostate __err = ios_base::goodbit; |
| 417 | const _F& __tf = use_facet<_F>(__is.getloc()); |
| 418 | __tf.get(_I(__is), _I(), __is, __err, __x.__tm_, |
| 419 | __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_)); |
| 420 | __is.setstate(__err); |
| 421 | } |
| 422 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 423 | } |
| 424 | catch (...) |
| 425 | { |
| 426 | __is.__set_badbit_and_consider_rethrow(); |
| 427 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 428 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 429 | return __is; |
| 430 | } |
| 431 | |
| 432 | template <class _CharT> |
| 433 | inline _LIBCPP_INLINE_VISIBILITY |
| 434 | __iom_t9<_CharT> |
| 435 | get_time(tm* __tm, const _CharT* __fmt) |
| 436 | { |
| 437 | return __iom_t9<_CharT>(__tm, __fmt); |
| 438 | } |
| 439 | |
| 440 | // put_time |
| 441 | |
| 442 | template <class _CharT> class __iom_t10; |
| 443 | |
| 444 | template <class _CharT, class _Traits> |
| 445 | basic_ostream<_CharT, _Traits>& |
| 446 | operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x); |
| 447 | |
| 448 | template <class _CharT> |
| 449 | class __iom_t10 |
| 450 | { |
| 451 | const tm* __tm_; |
| 452 | const _CharT* __fmt_; |
| 453 | public: |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 454 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 455 | __iom_t10(const tm* __tm, const _CharT* __fmt) |
| 456 | : __tm_(__tm), __fmt_(__fmt) {} |
| 457 | |
| 458 | template <class _C, class _Traits> |
| 459 | friend |
| 460 | basic_ostream<_C, _Traits>& |
| 461 | operator<<(basic_ostream<_C, _Traits>& __os, const __iom_t10<_C>& __x); |
| 462 | }; |
| 463 | |
| 464 | template <class _CharT, class _Traits> |
| 465 | basic_ostream<_CharT, _Traits>& |
| 466 | operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x) |
| 467 | { |
| 468 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 469 | try |
| 470 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 471 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 472 | typename basic_ostream<_CharT, _Traits>::sentry __s(__os); |
| 473 | if (__s) |
| 474 | { |
| 475 | typedef ostreambuf_iterator<_CharT, _Traits> _O; |
| 476 | typedef time_put<_CharT, _O> _F; |
| 477 | const _F& __tf = use_facet<_F>(__os.getloc()); |
| 478 | if (__tf.put(_O(__os), __os, __os.fill(), __x.__tm_, |
| 479 | __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_)).failed()) |
| 480 | __os.setstate(ios_base::badbit); |
| 481 | } |
| 482 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 483 | } |
| 484 | catch (...) |
| 485 | { |
| 486 | __os.__set_badbit_and_consider_rethrow(); |
| 487 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 488 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 489 | return __os; |
| 490 | } |
| 491 | |
| 492 | template <class _CharT> |
| 493 | inline _LIBCPP_INLINE_VISIBILITY |
| 494 | __iom_t10<_CharT> |
| 495 | put_time(const tm* __tm, const _CharT* __fmt) |
| 496 | { |
| 497 | return __iom_t10<_CharT>(__tm, __fmt); |
| 498 | } |
| 499 | |
| 500 | _LIBCPP_END_NAMESPACE_STD |
| 501 | |
| 502 | #endif // _LIBCPP_IOMANIP |