00001 #ifndef __HTMLFILE_H
00002 #define __HTMLFILE_H
00003
00004 #include "Model.h"
00005 #include <string>
00006 #include <fstream>
00007 #include <stdexcept>
00008
00014 class HTMLFile
00015 {
00016 std::string nom;
00017 std::ofstream html;
00018 bool openLater;
00019
00020 protected:
00021
00023 void BuildHeader()
00024 {
00025
00026 std::string __CSS[9] = {
00027 " 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;}",
00028 "#container {background: #efefef; padding: 2px 10px 2px 10px;}",
00029 "#container h1 {background: #ccc;border: 1px solid;font: 20px \"Trebuchet MS\" verdana;padding: 0px 5px 0px 5px;}",
00030 "#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;}",
00031 "#container pre {position: relative;background: #fff;border: 1px dashed #669;border-left: 3px solid #669;font: 12px Courier, Tahoma;padding: 2px 10px 2px 10px;}",
00032 "#container a {color: #339; text-decoration: none;}",
00033 "#container a:hover {color: #000; text-decoration: none;}",
00034 "hr {border:1px solid;}",
00035 "#container h3 {background:#ddd; border:2px solid #f63;font: 20px \"Trebuchet MS\" verdana;padding: 0px 5px 0px 5px;text-align:center;}",
00036 };
00037
00038 html << "<html><head><title>"<<nom<<" - Linear program modeling</title><style type=\"text/css\">"<<std::endl;
00039
00040 for (unsigned i=0;i<9;i++)
00041 {
00042 html << __CSS[i] << std::endl;
00043 html.flush();
00044 }
00045
00046 html << "</style></head><body><div id='container'>" << std::endl;
00047 html.flush();
00048 }
00049
00051 void BuildFooter()
00052 {
00053 html << "</body></html>";
00054 html.flush();
00055 }
00056
00058 HTMLFile() {};
00059
00060 public:
00061
00067 HTMLFile(const std::string& _nom, bool _openLater=false) : nom(_nom),openLater(_openLater)
00068 {
00069 if (openLater==false)
00070 {
00071 html.open(nom.c_str());
00072 if( !html.is_open())
00073 throw runtime_error("HTMLFile::HTMLFile() : I/O Error");
00074 BuildHeader();
00075 }
00076 }
00078 ~HTMLFile() { html.close(); }
00079
00081 void Open()
00082 {
00083 html.open(nom.c_str());
00084 BuildHeader();
00085 html.flush();
00086 }
00087
00089 void Close()
00090 {
00091 BuildFooter();
00092 html.flush();
00093 html.close();
00094 }
00095
00096
00097
00098 HTMLFile& operator<<(const Model& _m);
00099 HTMLFile& operator<<(const std::string& _s);
00100 HTMLFile& operator<<(const float _f);
00101 HTMLFile& operator<<(const char _c);
00102 HTMLFile& operator<<(const int _i);
00103
00104
00106 void NewLine()
00107 {
00108 html << "<br />" << std::endl;
00109 html.flush();
00110 }
00111
00113 std::ostream & getStream() {return html;}
00114 };
00115
00116 #endif
00117