Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===------------------------ iostream.cpp --------------------------------===// |
| 2 | // |
Howard Hinnant | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | ee11c31 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "__std_stream" |
| 11 | #include "string" |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 12 | #include "new" |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 13 | |
| 14 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 15 | |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame^] | 16 | #ifndef _LIBCPP_HAS_NO_STDIN |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 17 | _ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin [sizeof(istream)]; |
Howard Hinnant | 62cad69 | 2012-05-31 19:31:14 +0000 | [diff] [blame] | 18 | _ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin [sizeof(__stdinbuf <char>)]; |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 19 | static mbstate_t mb_cin; |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 20 | _ALIGNAS_TYPE (wistream) _LIBCPP_FUNC_VIS char wcin [sizeof(wistream)]; |
Howard Hinnant | 62cad69 | 2012-05-31 19:31:14 +0000 | [diff] [blame] | 21 | _ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin [sizeof(__stdinbuf <wchar_t>)]; |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 22 | static mbstate_t mb_wcin; |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame^] | 23 | #endif |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 24 | |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame^] | 25 | #ifndef _LIBCPP_HAS_NO_STDOUT |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 26 | _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cout[sizeof(ostream)]; |
| 27 | _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)]; |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 28 | static mbstate_t mb_cout; |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 29 | _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)]; |
Howard Hinnant | 62cad69 | 2012-05-31 19:31:14 +0000 | [diff] [blame] | 30 | _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)]; |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 31 | static mbstate_t mb_wcout; |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame^] | 32 | #endif |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 33 | |
| 34 | _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)]; |
| 35 | _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)]; |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 36 | static mbstate_t mb_cerr; |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 37 | _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)]; |
Howard Hinnant | 62cad69 | 2012-05-31 19:31:14 +0000 | [diff] [blame] | 38 | _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)]; |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 39 | static mbstate_t mb_wcerr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 40 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 41 | _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char clog[sizeof(ostream)]; |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 42 | _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 43 | |
| 44 | ios_base::Init __start_std_streams; |
| 45 | |
| 46 | ios_base::Init::Init() |
| 47 | { |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame^] | 48 | #ifndef _LIBCPP_HAS_NO_STDIN |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 49 | istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin, &mb_cin)); |
| 50 | wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin, &mb_wcin)); |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame^] | 51 | #endif |
| 52 | #ifndef _LIBCPP_HAS_NO_STDOUT |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 53 | ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout, &mb_cout)); |
| 54 | wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout)); |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame^] | 55 | #endif |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 56 | ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, &mb_cerr)); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 57 | ::new(clog) ostream(cerr_ptr->rdbuf()); |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 58 | wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, &mb_wcerr)); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 59 | ::new(wclog) wostream(wcerr_ptr->rdbuf()); |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 60 | |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame^] | 61 | #if !defined(_LIBCPP_HAS_NO_STDIN) && !defined(_LIBCPP_HAS_NO_STDOUT) |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 62 | cin_ptr->tie(cout_ptr); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 63 | wcin_ptr->tie(wcout_ptr); |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame^] | 64 | #endif |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 65 | _VSTD::unitbuf(*cerr_ptr); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 66 | _VSTD::unitbuf(*wcerr_ptr); |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame^] | 67 | #ifndef _LIBCPP_HAS_NO_STDOUT |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 68 | cerr_ptr->tie(cout_ptr); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 69 | wcerr_ptr->tie(wcout_ptr); |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame^] | 70 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | ios_base::Init::~Init() |
| 74 | { |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame^] | 75 | #ifndef _LIBCPP_HAS_NO_STDOUT |
Joerg Sonnenberger | b5bfdec | 2013-04-27 19:12:36 +0000 | [diff] [blame] | 76 | ostream* cout_ptr = reinterpret_cast<ostream*>(cout); |
Joerg Sonnenberger | b5bfdec | 2013-04-27 19:12:36 +0000 | [diff] [blame] | 77 | wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout); |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 78 | cout_ptr->flush(); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 79 | wcout_ptr->flush(); |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame^] | 80 | #endif |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 81 | |
| 82 | ostream* clog_ptr = reinterpret_cast<ostream*>(clog); |
| 83 | wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog); |
| 84 | clog_ptr->flush(); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 85 | wclog_ptr->flush(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | _LIBCPP_END_NAMESPACE_STD |