00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
#include <ios>
00036
#include <ostream>
00037
#include <istream>
00038
#include <fstream>
00039
#include <bits/atomicity.h>
00040
#include <ext/stdio_filebuf.h>
00041
#include <ext/stdio_sync_filebuf.h>
00042
00043
namespace __gnu_internal
00044 {
00045
using namespace __gnu_cxx;
00046
00047
00048
extern stdio_sync_filebuf<char> buf_cout_sync;
00049
extern stdio_sync_filebuf<char> buf_cin_sync;
00050
extern stdio_sync_filebuf<char> buf_cerr_sync;
00051
00052
extern stdio_filebuf<char> buf_cout;
00053
extern stdio_filebuf<char> buf_cin;
00054
extern stdio_filebuf<char> buf_cerr;
00055
00056
#ifdef _GLIBCXX_USE_WCHAR_T
00057
extern stdio_sync_filebuf<wchar_t> buf_wcout_sync;
00058
extern stdio_sync_filebuf<wchar_t> buf_wcin_sync;
00059
extern stdio_sync_filebuf<wchar_t> buf_wcerr_sync;
00060
00061
extern stdio_filebuf<wchar_t> buf_wcout;
00062
extern stdio_filebuf<wchar_t> buf_wcin;
00063
extern stdio_filebuf<wchar_t> buf_wcerr;
00064
#endif
00065
}
00066
00067
namespace std
00068 {
00069
using namespace __gnu_internal;
00070
00071
extern istream cin;
00072
extern ostream cout;
00073
extern ostream cerr;
00074
extern ostream clog;
00075
00076
#ifdef _GLIBCXX_USE_WCHAR_T
00077
extern wistream wcin;
00078
extern wostream wcout;
00079
extern wostream wcerr;
00080
extern wostream wclog;
00081
#endif
00082
00083 ios_base::Init::Init()
00084 {
00085
if (__gnu_cxx::__exchange_and_add(&_S_refcount, 1) == 0)
00086 {
00087
00088 _S_synced_with_stdio =
true;
00089
00090
new (&buf_cout_sync) stdio_sync_filebuf<char>(stdout);
00091
new (&buf_cin_sync) stdio_sync_filebuf<char>(stdin);
00092
new (&buf_cerr_sync) stdio_sync_filebuf<char>(stderr);
00093
00094
00095
00096
new (&
cout)
ostream(&buf_cout_sync);
00097
new (&
cin)
istream(&buf_cin_sync);
00098
new (&
cerr)
ostream(&buf_cerr_sync);
00099
new (&
clog)
ostream(&buf_cerr_sync);
00100
cin.tie(&cout);
00101
cerr.flags(ios_base::unitbuf);
00102
00103
#ifdef _GLIBCXX_USE_WCHAR_T
00104
new (&buf_wcout_sync) stdio_sync_filebuf<wchar_t>(stdout);
00105
new (&buf_wcin_sync) stdio_sync_filebuf<wchar_t>(stdin);
00106
new (&buf_wcerr_sync) stdio_sync_filebuf<wchar_t>(stderr);
00107
00108
new (&wcout) wostream(&buf_wcout_sync);
00109
new (&wcin) wistream(&buf_wcin_sync);
00110
new (&wcerr) wostream(&buf_wcerr_sync);
00111
new (&wclog) wostream(&buf_wcerr_sync);
00112 wcin.tie(&wcout);
00113 wcerr.flags(ios_base::unitbuf);
00114
#endif
00115
00116
00117
00118
00119
00120 __gnu_cxx::__atomic_add(&_S_refcount, 1);
00121 }
00122 }
00123
00124 ios_base::Init::~Init()
00125 {
00126
if (__gnu_cxx::__exchange_and_add(&_S_refcount, -1) == 2)
00127 {
00128
00129
try
00130 {
00131
00132
cout.flush();
00133
cerr.flush();
00134
clog.flush();
00135
00136
#ifdef _GLIBCXX_USE_WCHAR_T
00137
wcout.flush();
00138 wcerr.flush();
00139 wclog.flush();
00140
#endif
00141
}
00142
catch (...)
00143 { }
00144 }
00145 }
00146
00147
bool
00148 ios_base::sync_with_stdio(
bool __sync)
00149 {
00150
00151
00152
bool __ret = ios_base::Init::_S_synced_with_stdio;
00153
00154
00155
00156
if (!__sync && __ret)
00157 {
00158 ios_base::Init::_S_synced_with_stdio = __sync;
00159
00160
00161
00162
00163 buf_cout_sync.~stdio_sync_filebuf<
char>();
00164 buf_cin_sync.~stdio_sync_filebuf<
char>();
00165 buf_cerr_sync.~stdio_sync_filebuf<
char>();
00166
00167
#ifdef _GLIBCXX_USE_WCHAR_T
00168
buf_wcout_sync.~stdio_sync_filebuf<
wchar_t>();
00169 buf_wcin_sync.~stdio_sync_filebuf<
wchar_t>();
00170 buf_wcerr_sync.~stdio_sync_filebuf<
wchar_t>();
00171
#endif
00172
00173
00174
00175
00176
new (&buf_cout)
stdio_filebuf<char>(stdout, ios_base::out);
00177
new (&buf_cin)
stdio_filebuf<char>(stdin, ios_base::in);
00178
new (&buf_cerr)
stdio_filebuf<char>(stderr, ios_base::out);
00179
cout.rdbuf(&buf_cout);
00180
cin.rdbuf(&buf_cin);
00181
cerr.rdbuf(&buf_cerr);
00182
clog.rdbuf(&buf_cerr);
00183
00184
#ifdef _GLIBCXX_USE_WCHAR_T
00185
new (&buf_wcout)
stdio_filebuf<wchar_t>(stdout, ios_base::out);
00186
new (&buf_wcin)
stdio_filebuf<wchar_t>(stdin, ios_base::in);
00187
new (&buf_wcerr)
stdio_filebuf<wchar_t>(stderr, ios_base::out);
00188 wcout.rdbuf(&buf_wcout);
00189 wcin.rdbuf(&buf_wcin);
00190 wcerr.rdbuf(&buf_wcerr);
00191 wclog.rdbuf(&buf_wcerr);
00192
#endif
00193
}
00194
return __ret;
00195 }
00196 }