00001 #ifndef RESULT_LOG_H 00002 #define RESULT_LOG_H 00003 00004 //-------------------------------------------------------------------- 00005 // 00006 // This file is part of PEACE. 00007 // 00008 // PEACE is free software: you can redistribute it and/or modify it 00009 // under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation, either version 3 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // PEACE is distributed in the hope that it will be useful, but 00014 // WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with PEACE. If not, see <http://www.gnu.org/licenses/>. 00020 // 00021 // Miami University makes no representations or warranties about the 00022 // suitability of the software, either express or implied, including 00023 // but not limited to the implied warranties of merchantability, 00024 // fitness for a particular purpose, or non-infringement. Miami 00025 // University shall not be liable for any damages suffered by licensee 00026 // as a result of using, result of using, modifying or distributing 00027 // this software or its derivatives. 00028 // 00029 // By using or copying this Software, Licensee agrees to abide by the 00030 // intellectual property laws, and all other applicable laws of the 00031 // U.S., and the terms of GNU General Public License (version 3). 00032 // 00033 // Authors: Dhananjai M. Rao raodm@muohio.edu 00034 // 00035 //--------------------------------------------------------------------- 00036 00037 #include <stdio.h> 00038 #include <string> 00039 00040 class ResultLog { 00041 public: 00042 /** Constructor. 00043 00044 The constructor establishes a ResultLog. The result outputs 00045 are written to standard output or a file in plain text or HTML 00046 format. 00047 00048 \param[in] fileName The output/destination file to which logs 00049 are to be cut. If this parameter is NULL then data is written 00050 to standard output. 00051 00052 \param[in] html If this parameter is \c true then logs are 00053 written in HTML format so that they can be easily viewed in 00054 via a browser. 00055 */ 00056 ResultLog(const std::string& fileName = std::string(""), 00057 const bool html = false); 00058 00059 /** Destructor. 00060 00061 Winds up the process of generating a log. If HTML logs are 00062 being generated then it generates trailers to wind up HTML 00063 formats. If a file was opened then the destructor closes the 00064 destination file. 00065 */ 00066 ~ResultLog(); 00067 00068 /** Dumps a line of result to the log. 00069 00070 This method provides a convenient mechanism to dump a line of 00071 output to the specified destination. If no destination is 00072 specified it dumps the line to standard output. This method 00073 also handles the task of including necessary html tags if HTML 00074 output is requested. 00075 00076 \param[in] line The line of text to be displayed. This line 00077 can take the standard format as the printf() method thereby 00078 facilitating dumping of complex output in a simple manner. 00079 */ 00080 void reportLine(const char *line, ...); 00081 00082 /** Dumps a line of result using a 3-column table format. 00083 00084 This method provides a convenient mechanism to dump a line of 00085 output in 3-column format to the specified destination. If no 00086 destination is specified it dumps the line to standard output. 00087 This method also handles the task of including necessary html 00088 tags if HTML output is requested. 00089 00090 \param[in] col1 The data to be displayed in the first column. 00091 This text can take the standard format as the printf() method 00092 thereby facilitating dumping of complex output in a simple 00093 manner. 00094 00095 \param[in] col2 The data to be displayed in the second 00096 column. This text can take the standard format as the printf() 00097 method thereby facilitating dumping of complex output in a 00098 simple manner. 00099 00100 \param[in] col3 The data to be displayed in the third 00101 column. This text can take the standard format as the printf() 00102 method thereby facilitating dumping of complex output in a 00103 simple manner. 00104 00105 \note This method accepts a variable number of arguments 00106 corresponding to the printf() style format specifiers in the 00107 three text entries. The order of arguments must match the 00108 order of format specifiers in col1, col2, and col3 00109 respectively. Here is an example: 00110 00111 \code 00112 00113 ResultLog log("test.html", true); 00114 log.report("%s", "%c %d", "%ld", "test", '*', 123, 3.142); 00115 00116 \endcode 00117 */ 00118 void report(const char* col1, const char*col2, const char *col3, ...); 00119 00120 /** Starts an HTML table if necessary. 00121 00122 This method generates HTML code to start a table. This method 00123 peforms all the checks for handling HTML mode and generates 00124 headers only if it is needed. Consequently, it is safe to 00125 call this method repeatedly without much performance penalty. 00126 00127 \param[in] titles The titles for the rows to be used when 00128 creating the table. If this parameter is NULL, then no titles 00129 are included for the table. 00130 00131 */ 00132 void startTable(const char* titles[] = NULL); 00133 00134 /** Ends an HTML table if necessary. 00135 00136 This method generates HTML code to end a HTML table. This 00137 method peforms all the checks for handling HTML mode and 00138 generates headers only if it is needed. Consequently, it is 00139 safe to call this method repeatedly without much performance 00140 penalty. 00141 */ 00142 void endTable(); 00143 00144 protected: 00145 /** Helper method to dump HTML headers. 00146 00147 This method is a helper method that is invoked from the 00148 constructor to dump HTML headers. 00149 */ 00150 void dumpHTMLHeaders(); 00151 00152 private: 00153 /** The file to which results are to be logged. 00154 00155 This member object holds the file to which results are to be 00156 logged. This pointer is initialized in the constructor to 00157 either point to a result file or standard output. 00158 */ 00159 FILE *output; 00160 00161 /** Flag to indicate if HTML format is being used. 00162 00163 This instance variable is used to determine if the logs are to 00164 be generated in HTML format or not. This value is set in the 00165 constructor and is never changed during the life time of this 00166 class. 00167 */ 00168 const bool html; 00169 00170 /** Flag to indicate if a HTML table is currently open. 00171 00172 This flag is initialized to false. It is set to true each 00173 time a HTML table is started. It is reset to false when the 00174 table is ended. This flag is used in the polymorphic report() 00175 methods in this class to appropriately handle HTML tables. 00176 */ 00177 bool insideTable; 00178 00179 /** A dummy operator= 00180 00181 The operator=() is supressed for this class as it has constant members 00182 whose value is set when the object is created. These values cannot be 00183 changed during the lifetime of this object. 00184 00185 \param[in] src The source object from where data is to be copied. 00186 Currently this value is ignored. 00187 00188 \return Reference to this. 00189 */ 00190 ResultLog& operator=(const ResultLog& src); 00191 00192 }; 00193 00194 #endif