Modelib: Fichier source de htmlFile.h

Page principale | Liste des namespaces | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de namespace | Membres de classe | Membres de fichier

# htmlFile.h

Aller à la documentation de ce fichier.

    00001 /*
    00002     Copyright (c) 2005, Quentin Lequy and Romain Gaucher
    00003     All rights reserved.
    00004
    00005     Redistribution and use in source and binary forms, with or
    00006     without modification, are permitted provided that the following
    00007     conditions are met:
    00008
    00009         * Redistributions of source code must retain the above copyright
    00010           notice, this list of conditions and the following disclaimer.
    00011
    00012         * Redistributions in binary form must reproduce the above copyright
    00013           notice, this list of conditions and the following disclaimer in the
    00014           documentation and/or other materials provided with the distribution.
    00015
    00016         * Neither the name of Quentin Lequy or Romain Gaucher nor the names
    00017           of its contributors may be used to endorse or promote products
    00018           derived from this software without specific prior written permission.
    00019
    00020     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    00021     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00022     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    00023     ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    00024     LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    00025     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    00026     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
    00027     AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00028     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00029     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    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         // Diverses surcharges d'operateur pour faciliter l'ecriture
    00130
    00131         HTMLFile& operator<<(const Model& _m);              //< using <pre> keyword for html rendering
    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