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 | |
Howard Hinnant | c4aec23 | 2013-03-19 21:34:48 +0000 | [diff] [blame] | 16 | static mbstate_t state_types[6] = {}; |
| 17 | |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame^] | 18 | _ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin [sizeof(istream)]; |
Howard Hinnant | 62cad69 | 2012-05-31 19:31:14 +0000 | [diff] [blame] | 19 | _ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin [sizeof(__stdinbuf <char>)]; |
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 | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame^] | 22 | |
| 23 | _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cout[sizeof(ostream)]; |
| 24 | _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)]; |
| 25 | _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)]; |
Howard Hinnant | 62cad69 | 2012-05-31 19:31:14 +0000 | [diff] [blame] | 26 | _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)]; |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame^] | 27 | |
| 28 | _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)]; |
| 29 | _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)]; |
| 30 | _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)]; |
Howard Hinnant | 62cad69 | 2012-05-31 19:31:14 +0000 | [diff] [blame] | 31 | _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 32 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 33 | _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char clog[sizeof(ostream)]; |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 34 | _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 | |
| 36 | ios_base::Init __start_std_streams; |
| 37 | |
| 38 | ios_base::Init::Init() |
| 39 | { |
Howard Hinnant | c4aec23 | 2013-03-19 21:34:48 +0000 | [diff] [blame] | 40 | istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin, state_types+0) ); |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame^] | 41 | wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin, state_types+3) ); |
Howard Hinnant | c4aec23 | 2013-03-19 21:34:48 +0000 | [diff] [blame] | 42 | ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout, state_types+1)); |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame^] | 43 | wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, state_types+4)); |
Howard Hinnant | c4aec23 | 2013-03-19 21:34:48 +0000 | [diff] [blame] | 44 | ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, state_types+2)); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 45 | ::new(clog) ostream(cerr_ptr->rdbuf()); |
Howard Hinnant | c4aec23 | 2013-03-19 21:34:48 +0000 | [diff] [blame] | 46 | wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, state_types+5)); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 47 | ::new(wclog) wostream(wcerr_ptr->rdbuf()); |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame^] | 48 | |
| 49 | cin_ptr->tie(cout_ptr); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 50 | wcin_ptr->tie(wcout_ptr); |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame^] | 51 | _VSTD::unitbuf(*cerr_ptr); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 52 | _VSTD::unitbuf(*wcerr_ptr); |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame^] | 53 | cerr_ptr->tie(cout_ptr); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 54 | wcerr_ptr->tie(wcout_ptr); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | ios_base::Init::~Init() |
| 58 | { |
Joerg Sonnenberger | b5bfdec | 2013-04-27 19:12:36 +0000 | [diff] [blame] | 59 | ostream* cout_ptr = reinterpret_cast<ostream*>(cout); |
Joerg Sonnenberger | b5bfdec | 2013-04-27 19:12:36 +0000 | [diff] [blame] | 60 | wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout); |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame^] | 61 | cout_ptr->flush(); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 62 | wcout_ptr->flush(); |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame^] | 63 | |
| 64 | ostream* clog_ptr = reinterpret_cast<ostream*>(clog); |
| 65 | wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog); |
| 66 | clog_ptr->flush(); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 67 | wclog_ptr->flush(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | _LIBCPP_END_NAMESPACE_STD |