Home | History | Annotate | Download | only in src
      1 //===------------------------ iostream.cpp --------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #include "__std_stream"
     11 #include "string"
     12 #include "new"
     13 
     14 _LIBCPP_BEGIN_NAMESPACE_STD
     15 
     16 static mbstate_t state_types[6] = {};
     17 
     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>)];
     24 
     25 _ALIGNAS_TYPE (istream) char cin [sizeof(istream)];
     26 _ALIGNAS_TYPE (ostream) char cout[sizeof(ostream)];
     27 _ALIGNAS_TYPE (ostream) char cerr[sizeof(ostream)];
     28 _ALIGNAS_TYPE (ostream) char clog[sizeof(ostream)];
     29 _ALIGNAS_TYPE (wistream) char wcin [sizeof(wistream)];
     30 _ALIGNAS_TYPE (wostream) char wcout[sizeof(wostream)];
     31 _ALIGNAS_TYPE (wostream) char wcerr[sizeof(wostream)];
     32 _ALIGNAS_TYPE (wostream) char wclog[sizeof(wostream)];
     33 
     34 ios_base::Init __start_std_streams;
     35 
     36 ios_base::Init::Init()
     37 {
     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));
     41                         ::new(clog) ostream(cerr_ptr->rdbuf());
     42     cin_ptr->tie(cout_ptr);
     43     _VSTD::unitbuf(*cerr_ptr);
     44     cerr_ptr->tie(cout_ptr);
     45 
     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));
     49                           ::new(wclog) wostream(wcerr_ptr->rdbuf());
     50     wcin_ptr->tie(wcout_ptr);
     51     _VSTD::unitbuf(*wcerr_ptr);
     52     wcerr_ptr->tie(wcout_ptr);
     53 }
     54 
     55 ios_base::Init::~Init()
     56 {
     57     ostream* cout_ptr = reinterpret_cast<ostream*>(cout);
     58     ostream* clog_ptr = reinterpret_cast<ostream*>(clog);
     59     cout_ptr->flush();
     60     clog_ptr->flush();
     61 
     62     wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
     63     wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
     64     wcout_ptr->flush();
     65     wclog_ptr->flush();
     66 }
     67 
     68 _LIBCPP_END_NAMESPACE_STD
     69