Line data Source code
1 : #include "Log/ProgressLoggerTableOStream.hpp" 2 : 3 : #include <stdexcept> 4 : 5 : using namespace std; 6 : using namespace Log; 7 : 8 3 : ProgressLoggerTableOStream::ProgressLoggerTableOStream(ostream &os_): 9 3 : os(os_) {} 10 : 11 14 : ProgressLoggerTableOStream &ProgressLoggerTableOStream::operator<<(const StartMessage &) { 12 14 : if(s != NO_MESSAGE) 13 0 : throw logic_error("Cannot start message if state is not NO_MESSAGE"); 14 : 15 14 : s = MESSAGE; 16 14 : return *this; 17 : } 18 : 19 14 : ProgressLoggerTableOStream &ProgressLoggerTableOStream::operator<<(const EndMessage &) { 20 14 : if(s == TEXT) 21 14 : *this << EndText(); 22 : 23 14 : if(s != MESSAGE) 24 0 : throw logic_error("Cannot end message if state is not MESSAGE"); 25 : 26 14 : os << endl; 27 14 : s = NO_MESSAGE; 28 14 : firstField = true; 29 : 30 14 : return *this; 31 : } 32 : 33 14 : ProgressLoggerTableOStream &ProgressLoggerTableOStream::operator<<(const Progress &progress) { 34 14 : if(s == NO_MESSAGE) 35 0 : *this << StartMessage(); 36 : 37 14 : if(s != MESSAGE) 38 0 : throw logic_error("Cannot send Progress if state is not MESSAGE"); 39 : 40 14 : if(!firstField) { 41 14 : os << "\t"; 42 : } 43 14 : firstField = false; 44 : 45 14 : os << progress.p; 46 : 47 14 : return *this; 48 : } 49 : 50 14 : ProgressLoggerTableOStream &ProgressLoggerTableOStream::operator<<(const Elapsed &elapsed) { 51 14 : if(s == NO_MESSAGE) 52 14 : *this << StartMessage(); 53 : 54 14 : if(s != MESSAGE) 55 0 : throw logic_error("Cannot send Progress if state is not MESSAGE"); 56 : 57 14 : if(!firstField) { 58 0 : os << "\t"; 59 : } 60 14 : firstField = false; 61 : 62 14 : os << elapsed.t; 63 : 64 14 : return *this; 65 : } 66 : 67 14 : ProgressLoggerTableOStream &ProgressLoggerTableOStream::operator<<(const ETA &eta) { 68 14 : if(s == NO_MESSAGE) 69 0 : *this << StartMessage(); 70 : 71 14 : if(s != MESSAGE) 72 0 : throw logic_error("Cannot send ETA if state is not MESSAGE"); 73 : 74 14 : if(!firstField) { 75 14 : os << "\t"; 76 : } 77 14 : firstField = false; 78 : 79 14 : os << eta.t; 80 : 81 14 : return *this; 82 : } 83 : 84 14 : ProgressLoggerTableOStream &ProgressLoggerTableOStream::operator<<(const StartText &) { 85 14 : if(s == NO_MESSAGE) 86 0 : *this << StartMessage(); 87 14 : if(s != MESSAGE) 88 0 : throw logic_error("Cannot start text if state is not MESSAGE"); 89 : 90 14 : if(!firstField) { 91 14 : os << "\t"; 92 : } 93 14 : firstField = false; 94 : 95 14 : s = TEXT; 96 : 97 14 : return *this; 98 : } 99 : 100 14 : ProgressLoggerTableOStream &ProgressLoggerTableOStream::operator<<(const EndText &) { 101 14 : if(s != TEXT) 102 0 : throw logic_error("Cannot end text if state is not TEXT"); 103 14 : s = MESSAGE; 104 14 : return *this; 105 : } 106 : 107 : // clang-format off 108 0 : ProgressLoggerTableOStream &ProgressLoggerTableOStream::operator<<(const int &t) { send(t); return *this; } 109 8 : ProgressLoggerTableOStream &ProgressLoggerTableOStream::operator<<(const unsigned long &t) { send(t); return *this; } 110 64 : ProgressLoggerTableOStream &ProgressLoggerTableOStream::operator<<(const double &t) { send(t); return *this; } 111 70 : ProgressLoggerTableOStream &ProgressLoggerTableOStream::operator<<(const char *t) { send(t); return *this; } 112 : 113 3 : ProgressLoggerTableOStream &ProgressLoggerTableOStream::operator<<(std::_Setprecision t) { os << t; return *this; } 114 : // clang-format on 115 : 116 0 : ProgressLogger &ProgressLoggerTableOStream::operator<<(ProgressLogger &(*pf)(ProgressLogger &)) { 117 0 : return pf(*this); 118 : } 119 : 120 3 : ProgressLoggerTableOStream &ProgressLoggerTableOStream::fixed() { 121 3 : os << std::fixed; 122 3 : return *this; 123 : }