00001 #if !defined(_VALIDATIONREPORT_H_) 00002 #define _VALIDATIONREPORT_H_ 00003 00004 #include <iostream> 00005 #include <fstream> 00006 #include <vector> 00007 #include <strstream> 00008 #include <sstream> 00009 #include <string> 00010 #include <qtextbrowser.h> 00011 using namespace std; 00012 00038 class ValidationReport { 00039 protected: 00040 fstream reportFile ; 00041 string filename ; 00042 std::vector<string> messages ; 00043 00044 public: 00045 ValidationReport() { 00046 openReport () ; 00047 } 00048 00049 ValidationReport(string newFilename) { 00050 filename = newFilename ; 00051 openReport () ; 00052 } 00053 00054 ~ValidationReport() { 00055 writeReport () ; 00056 } 00057 00058 /* ************************************************** 00059 * Unformatted messages 00060 * **************************************************/ 00061 00066 void report (char * msg) { 00067 std::stringstream msgstream ; 00068 msgstream << msg ; 00069 messages.push_back (msgstream.str()) ; 00070 } 00071 00076 void report (string msg) { 00077 std::stringstream msgstream ; 00078 msgstream << msg ; 00079 messages.push_back (msgstream.str()) ; 00080 } 00081 00082 /* ************************************************** 00083 * Formatted messages 00084 * **************************************************/ 00085 00092 void reportOkay (string msg) { 00093 std::stringstream msgstream ; 00094 msgstream << "<p><i>Okay: " 00095 << msg << "</i></p>" ; 00096 messages.push_back (msgstream.str()) ; 00097 } 00098 00105 void reportWarning (string msg) { 00106 std::stringstream msgstream ; 00107 msgstream << "<p><strong><font color=\"#CC6600\">Warning: " 00108 << msg << "</font></strong></p>" ; 00109 messages.push_back (msgstream.str()) ; 00110 } 00111 00118 void reportError (string msg) { 00119 std::stringstream msgstream ; 00120 msgstream << "<p><strong><font color=\"red\">Error: " 00121 << msg << "</font></strong></p>" ; 00122 messages.push_back (msgstream.str()) ; 00123 } 00124 00130 void breakBegin (string subTitle = "") { 00131 std::stringstream msgstream ; 00132 msgstream << "<hr noshade=\"noshade\" size=\"1\"/>" ; 00133 if (subTitle.size() > 0) { 00134 msgstream << "<h2>" << subTitle << "</h2>" ; 00135 } 00136 messages.push_back (msgstream.str()) ; 00137 } 00138 00144 void breakEnd (string endMessage = "") { 00145 std::stringstream msgstream ; 00146 if (endMessage.size() > 0) { 00147 msgstream << "<p><strong>" << endMessage << "</strong></p>" ; 00148 } 00149 messages.push_back (msgstream.str()) ; 00150 } 00151 00157 void subsectionBegin (string subTitle = "") { 00158 std::stringstream msgstream ; 00159 if (subTitle.size() > 0) { 00160 msgstream << "<h3>" << subTitle << "</h3>" ; 00161 } 00162 messages.push_back (msgstream.str()) ; 00163 } 00164 00170 void subsectionEnd (string endMessage = "") { 00171 std::stringstream msgstream ; 00172 if (endMessage.size() > 0) { 00173 msgstream << "<p><em>" << endMessage << "</em></p>" ; 00174 } 00175 messages.push_back (msgstream.str()) ; 00176 } 00177 00178 00179 00180 /* ************************************************** 00181 * Reporting functions 00182 * **************************************************/ 00183 00187 string getReport () { 00188 std::stringstream reportstream ; 00189 reportstream << "<qt>" << endl ; 00190 reportstream << "<h1>GLIMSView Project Validation Report</h1>" << endl ; 00191 00192 for (int i = 0 ; i < (int)messages.size() ; i++ ) { 00193 reportstream << messages[i] << endl ; 00194 } 00195 reportstream << "<p>[END REPORT]</p>" << endl ; 00196 reportstream << "</qt>" << endl ; 00197 return reportstream.str() ; 00198 } 00199 00204 void writeReport () { 00205 if (reportFile.is_open()) { 00206 reportFile << "<html><head><title>GLIMSView Validation Report</title></head><body>" << endl ; 00207 reportFile << "GLIMSView Validation Report" << endl ; 00208 for (int i = 0 ; i < (int)messages.size() ; i++ ) { 00209 reportFile << messages[i] << endl ; 00210 } 00211 messages.clear() ; 00212 reportFile.close() ; 00213 reportFile << "</body></html>" << endl ; 00214 } 00215 } 00216 00220 void clearReport () { 00221 messages.clear() ; 00222 if (reportFile.is_open()) { 00223 reportFile.close() ; 00224 } 00225 openReport () ; 00226 } 00227 00228 00229 void openReport () { 00230 if (filename.size() > 0) { 00231 reportFile.open (filename.c_str(), fstream::out) ; 00232 } 00233 } 00234 00235 }; 00236 00237 #endif // !defined(_VALIDATIONREPORT_H_) 00238 00239 00240
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |