00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __HTMLFILE_H
00033 #define __HTMLFILE_H
00034
00035 #include "Model.h"
00036 #include <string>
00037 #include <fstream>
00038 #include <stdexcept>
00039
00040 namespace Modelib {
00041
00047 class HTMLFile
00048 {
00049 std::string nom;
00050 std::ofstream html;
00051 bool openLater;
00052
00053 protected:
00054
00056 void BuildHeader()
00057 {
00058
00059 std::string __CSS[9] = {
00060 " body {background: #449; font: 13px \"Trebuchet MS\" verdana; border-left:2px solid #222;border-top: 2px solid #222;border-right: 8px solid #222;border-bottom: 8px solid #222;}",
00061 "#container {background: #efefef; padding: 2px 10px 2px 10px;}",
00062 "#container h1 {background: #ccc;border: 1px solid;font: 20px \"Trebuchet MS\" verdana;padding: 0px 5px 0px 5px;}",
00063 "#container h2 {border-right :15px solid #666;border-top : 1px solid #666;border-bottom: 1px solid #666;font: 16px \"Trebuchet MS\" verdana; padding: 0px 5px 0px 5px;}",
00064 "#container pre {position: relative;background: #fff;border: 1px dashed #669;border-left: 3px solid #669;font: 12px Courier, Tahoma;padding: 2px 10px 2px 10px;}",
00065 "#container a {color: #339; text-decoration: none;}",
00066 "#container a:hover {color: #000; text-decoration: none;}",
00067 "hr {border:1px solid;}",
00068 "#container h3 {background:#ddd; border:2px solid #f63;font: 20px \"Trebuchet MS\" verdana;padding: 0px 5px 0px 5px;text-align:center;}",
00069 };
00070
00071 html << "<html><head><title>"<<nom<<" - Linear program modeling</title><meta http-equiv=\"Content-type\" content=\"text/html; charset=iso-8859-1\"/><style type=\"text/css\">"<<std::endl;
00072
00073 for (unsigned i=0;i<9;i++)
00074 {
00075 html << __CSS[i] << std::endl;
00076 html.flush();
00077 }
00078
00079 html << "</style></head><body><div id='container'>" << std::endl;
00080 html.flush();
00081 }
00082
00084 void BuildFooter()
00085 {
00086 html << "</body></html>";
00087 html.flush();
00088 }
00089
00091 HTMLFile() {};
00092
00093 public:
00094
00100 HTMLFile(const std::string& _nom, bool _openLater=false) : nom(_nom),openLater(_openLater)
00101 {
00102 if (openLater==false)
00103 {
00104 html.open(nom.c_str());
00105 if( !html.is_open())
00106 throw runtime_error("HTMLFile::HTMLFile() : I/O Error");
00107 BuildHeader();
00108 }
00109 }
00111 ~HTMLFile() { html.close(); }
00112
00114 void Open()
00115 {
00116 html.open(nom.c_str());
00117 BuildHeader();
00118 html.flush();
00119 }
00120
00122 void Close()
00123 {
00124 BuildFooter();
00125 html.flush();
00126 html.close();
00127 }
00128
00129
00130
00131 HTMLFile& operator<<(const Model& _m);
00132 HTMLFile& operator<<(const std::string& _s);
00133 HTMLFile& operator<<(const float _f);
00134 HTMLFile& operator<<(const char _c);
00135 HTMLFile& operator<<(const int _i);
00136
00137
00139 void NewLine()
00140 {
00141 html << "<br />" << std::endl;
00142 html.flush();
00143 }
00144
00146 std::ostream & getStream() {return html;}
00147 };
00148
00149 }
00150
00151 #endif
00152