![]() |
Gowdy solver
|
00001 /** 00002 * @file slog.h 00003 * @brief Writing both to cerr and cout simultaneously. 00004 * @author Mikica Kocic 00005 * @copyright GNU General Public License (GPLv3). 00006 */ 00007 00008 #include <sys/types.h> 00009 #include <sys/stat.h> 00010 00011 /** SLog enables writing both to cerr and cout simultaneously. 00012 */ 00013 struct SLog 00014 { 00015 bool tty; 00016 00017 SLog () { 00018 struct stat buf; 00019 tty = fstat( _fileno( stderr ), &buf ) >= 0 00020 && (buf.st_mode & S_IFMT) == S_IFCHR; 00021 } 00022 00023 SLog& operator<< ( std::ostream& (*pfun)(std::ostream&) ) 00024 { 00025 pfun( std::cerr ); 00026 if ( ! tty ) pfun( std::cout ); 00027 return *this; 00028 } 00029 }; 00030 00031 template <class T> 00032 SLog& operator<< ( SLog& st, T val ) 00033 { 00034 std::cerr << val; 00035 if ( ! st.tty ) std::cout << val; 00036 return st; 00037 }; 00038 00039 static SLog slog;