00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef REPORTER_H
00011 #define REPORTER_H REPORTER_H
00012 #include "helper.h"
00013 #include "picgen.h"
00014 #include "typedefs.h"
00015 #include "i18n.h"
00016
00017 string InfoAppend(bool html = false, bool justname = false){
00018 string rv = tr("Report generated with") + " ";
00019 if(html) rv += "<a href='http://readesm.sourceforge.net/'>readESM</a>";
00020 else rv += "readESM (http://readesm.sourceforge.net/)";
00021 #ifdef VERSION
00022 rv += " " + tr("version") + " " + VERSION;
00023 #endif
00024 return rv + "\n";
00025 }
00026
00027 class reporter : public ostringstream{
00028 public:
00029 typedef shared_ptr<picgen> pgptr;
00030 reporter(const string& title_ = "ESM Data") : title(title_), verbose(false) {}
00031 class subblock{
00032 public:
00033 subblock(const string& description, int blockcount, reporter* nparent) : empty(blockcount == 0), entriestogo(blockcount), parent(nparent){
00034 if(!empty) parent->blockstart(description, blockcount);
00035 }
00036 ~subblock(){
00037 if(!empty) parent->blockend();
00038 }
00039 subblock& operator++(){
00040 --entriestogo;
00041 if(entriestogo) parent->blockbreak();
00042 return *this;
00043 }
00044 int operator()() {
00045 return entriestogo > 0;
00046 }
00047 private:
00048 bool empty;
00049 int entriestogo;
00050 reporter* parent;
00051 };
00052 subblock newsub(const string& description, int blockcount){
00053 return subblock(description, blockcount, this);
00054 }
00055 virtual string str(){ return ostringstream::str(); }
00056 virtual void blockstart(const string& description, int blockcount) = 0;
00057 virtual void blockend() = 0;
00058 virtual void blockbreak() = 0;
00059 virtual void single(const string& description, bool ishead = false) = 0;
00060 virtual void operator()(const string& description, const std::string& value) = 0;
00061 virtual void operator()(const string& description, int value) = 0;
00062 template <typename T>
00063 void reportray(const T& ray, const string& description){
00064 blockstart(description, ray.size());
00065 for(typename T::const_iterator i = ray.begin(); i < ray.end(); ++i){
00066 (*this) << *i;
00067 blockbreak();
00068 }
00069 blockend();
00070 }
00071 template <typename T>
00072 void reportraynosub(const T& ray){
00073 for(typename T::const_iterator i = ray.begin(); i < ray.end(); ++i){
00074 (*this) << *i;
00075 bigblockbreak();
00076 }
00077 }
00078 virtual void bigblockstart(const string& name) = 0;
00079 virtual void bigblockbreak(){ blockbreak(); };
00080 virtual void bigblockend() = 0;
00082 virtual bool hasBarGraph() const { return false; }
00084 virtual pgptr getBarGraph() const { return pgptr(new picgen); }
00085
00086 virtual bool hasPlotGraph() const { return false; }
00087 virtual pgptr getPlotGraph() const { return pgptr(new picgen); }
00088 string title;
00089 bool verbose;
00090 };
00091
00092 class txtreporter : public reporter{
00093 public:
00094 txtreporter(const string& title_ = "ESM Data") : reporter(title_) {}
00095 virtual string str(){ return title + reporter::str() + InfoAppend(); }
00096 virtual void blockstart(const string& description, int blockcount){
00097 (*this) << "***************" << tr(description) << " (" << blockcount << ") *********\n";
00098 }
00099 virtual void blockend(){
00100 (*this) << "*************************************\n";
00101 }
00102 virtual void blockbreak(){
00103 (*this) << " *** \n";
00104 }
00105 virtual void single(const string& description, bool ishead = false){
00106 string mark = "";
00107 if(ishead) mark = "**";
00108 (*this) << mark << " " << tr(description) << " " << mark << std::endl;
00109 }
00110 virtual void operator()(const string& description, const std::string& value){
00111 (*this) << tr(description) << ": \t" << value << std::endl;
00112 }
00113 virtual void operator()(const string& description, int value){
00114 (*this) << tr(description) << ": \t" << value << std::endl;
00115 }
00116 virtual void bigblockstart(const string& name){
00117 (*this) << "\n\n+++++++++++++++++ Block: " << name << " ++++++++++++++++++++++++++\n";
00118 }
00119 virtual void bigblockend(){
00120 (*this) << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
00121 }
00122
00123 };
00124
00126
00128 class htmlreporter : public reporter {
00129 protected:
00130 ostringstream links;
00131 int targetcount;
00132 public:
00133 htmlreporter(const string& title_ = "ESM Data") : reporter(title_), targetcount(0) {}
00134 virtual string str(){
00135 ostringstream o;
00136 o << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" dir=\"ltr\" lang=\"en-US\">\n<head><link rel='stylesheet' type='text/css' media='screen' href='style.css'/><title>" << title << "</title><meta http-equiv='Content-Type' content='text/html; charset=utf8'/></head><body><h1>" << title <<"</h1>" << links.str() << "<hr/>" << reporter::str() << "<hr/>" << InfoAppend(true) << "</body></html>\n";
00137 return o.str();
00138 }
00139 virtual void bigblockstart(const string& name){
00140 links << "<a href='#" << stringify(++targetcount) <<"'>" << tr(name) << "</a><br/>";
00141 (*this) << "<h2><a name='" << stringify(targetcount) << "'>" << tr(name) << "</a></h2><table>";
00142 }
00143 virtual void bigblockend(){
00144 (*this) << "</table>";
00145 }
00146 virtual void blockstart(const string& description, int blockcount){
00147 (*this) << "<tr><th>" << tr(description) << "</th><td><table>\n";
00148 }
00149 virtual void blockbreak(){
00150 (*this) << "<tr><th></th><td></td></tr>\n";
00151 }
00152 virtual void blockend(){
00153 (*this) << "</table></td></tr>\n";
00154 }
00155 virtual void single(const string& description, bool ishead = false){
00156 string mark = "td";
00157 if(ishead) mark = "th";
00158 (*this) << "<tr><" << mark << " colspan='2' class='center'>" << tr(description) << "</" << mark << "></tr>" << std::endl;
00159 }
00160 virtual void operator()(const string& description, const std::string& value){
00161 (*this) << "<tr><th>" << tr(description) << "</th><td>" << value << "</td></tr>\n";
00162 }
00163 virtual void operator()(const string& description, int value){
00164 (*this) << "<tr><th>" << tr(description) << "</th><td>" << value << "</td></tr>\n";
00165 }
00166 virtual bool hasBarGraph() const { return true; }
00167 virtual pgptr getBarGraph() const { return pgptr(new htmlBarGraph); }
00168 };
00169
00171
00173 class xmlreporter : public htmlreporter {
00174 public:
00175 virtual string str(){
00176 ostringstream o;
00177 o << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" \
00178 "<html xmlns=\"http://www.w3.org/1999/xhtml\" dir=\"ltr\" lang=\"en-US\">\n" \
00179 "<head><title>" << title << "</title>" \
00180 "<meta http-equiv='Content-Type' content='text/html; charset=utf8'/>" \
00181 "<style type=\"text/css\">" \
00182 "table { border-collapse:collapse; border-width:2px; border-style:solid; }" \
00183 "tr { border-top-width:1px; border-top-style:dashed; }" \
00184 "tr:hover {border-style:outset; background-color:#eeeeee; }" \
00185 ".center {text-align:center; }" \
00186 "th {text-align:left;vertical-align:top;}" \
00187 "td,th.max,th.avg, th.min{text-align:left;border-left: 1px dotted;}" \
00188 "caption {font-size:0.5em;}" \
00189 "small {font-size:0.8em;}</style>" \
00190 "</head><body>" \
00191 "<h1>" << title <<"</h1>" << links.str() << "<hr/>" \
00192 << reporter::str() << "<hr/>" << InfoAppend(true) \
00193 << "</body></html>\n";
00194 return o.str();
00195 }
00196 xmlreporter(const string& title_ = "ESM Data") : htmlreporter(title_) {}
00197 virtual pgptr getBarGraph() const { return pgptr(new svgBarGraph); }
00198 virtual bool hasPlotGraph() const { return true; }
00199 virtual pgptr getPlotGraph() const { return pgptr(new svgPlotGraph); }
00200 };
00201
00202 #endif