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