Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===------------------------ iostream.cpp --------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "__std_stream" |
| 11 | #include "string" |
Howard Hinnant | 1378397 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 12 | #include "new" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 13 | |
| 14 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 15 | |
Howard Hinnant | 903439f | 2013-03-19 21:34:48 +0000 | [diff] [blame] | 16 | static mbstate_t state_types[6] = {}; |
| 17 | |
Howard Hinnant | cbdd089 | 2012-05-31 19:31:14 +0000 | [diff] [blame] | 18 | _ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin [sizeof(__stdinbuf <char>)]; |
| 19 | _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)]; |
| 20 | _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)]; |
| 21 | _ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin [sizeof(__stdinbuf <wchar_t>)]; |
| 22 | _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)]; |
| 23 | _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 24 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 25 | _ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin [sizeof(istream)]; |
| 26 | _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cout[sizeof(ostream)]; |
| 27 | _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)]; |
| 28 | _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char clog[sizeof(ostream)]; |
| 29 | _ALIGNAS_TYPE (wistream) _LIBCPP_FUNC_VIS char wcin [sizeof(wistream)]; |
| 30 | _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)]; |
| 31 | _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)]; |
| 32 | _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 33 | |
| 34 | ios_base::Init __start_std_streams; |
| 35 | |
| 36 | ios_base::Init::Init() |
| 37 | { |
Howard Hinnant | 903439f | 2013-03-19 21:34:48 +0000 | [diff] [blame] | 38 | istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin, state_types+0) ); |
| 39 | ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout, state_types+1)); |
| 40 | ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, state_types+2)); |
Howard Hinnant | 1378397 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 41 | ::new(clog) ostream(cerr_ptr->rdbuf()); |
| 42 | cin_ptr->tie(cout_ptr); |
| 43 | _VSTD::unitbuf(*cerr_ptr); |
| 44 | cerr_ptr->tie(cout_ptr); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 45 | |
Howard Hinnant | 903439f | 2013-03-19 21:34:48 +0000 | [diff] [blame] | 46 | wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin, state_types+3) ); |
| 47 | wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, state_types+4)); |
| 48 | wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, state_types+5)); |
Howard Hinnant | 1378397 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 49 | ::new(wclog) wostream(wcerr_ptr->rdbuf()); |
| 50 | wcin_ptr->tie(wcout_ptr); |
| 51 | _VSTD::unitbuf(*wcerr_ptr); |
| 52 | wcerr_ptr->tie(wcout_ptr); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | ios_base::Init::~Init() |
| 56 | { |
Joerg Sonnenberger | d3b5b6b | 2013-04-27 19:12:36 +0000 | [diff] [blame] | 57 | ostream* cout_ptr = reinterpret_cast<ostream*>(cout); |
| 58 | ostream* clog_ptr = reinterpret_cast<ostream*>(clog); |
Howard Hinnant | 1378397 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 59 | cout_ptr->flush(); |
| 60 | clog_ptr->flush(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 61 | |
Joerg Sonnenberger | d3b5b6b | 2013-04-27 19:12:36 +0000 | [diff] [blame] | 62 | wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout); |
| 63 | wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog); |
Howard Hinnant | 1378397 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 64 | wcout_ptr->flush(); |
| 65 | wclog_ptr->flush(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | _LIBCPP_END_NAMESPACE_STD |