<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>Wt examples: /home/koen/project/wt/public-git/wt/examples/wt-homepage/SourceView.C File Reference</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">Wt examples  <span id="projectnumber">3.2.3</span> </div> </td> </tr> </tbody> </table> </div> <!-- Generated by Doxygen 1.7.5.1 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> </div> <div class="header"> <div class="summary"> <a href="#func-members">Functions</a> </div> <div class="headertitle"> <div class="title">/home/koen/project/wt/public-git/wt/examples/wt-homepage/SourceView.C File Reference</div> </div> </div> <div class="contents"> <div class="textblock"><code>#include "<a class="el" href="SourceView_8h_source.html">SourceView.h</a>"</code><br/> <code>#include <iostream></code><br/> <code>#include <fstream></code><br/> <code>#include <sstream></code><br/> <code>#include <stdlib.h></code><br/> <code>#include <boost/algorithm/string.hpp></code><br/> <code>#include <boost/filesystem/operations.hpp></code><br/> <code>#include <boost/filesystem/convenience.hpp></code><br/> <code>#include <Wt/WApplication></code><br/> <code>#include <Wt/WText></code><br/> <code>#include <Wt/WImage></code><br/> </div> <p><a href="SourceView_8C_source.html">Go to the source code of this file.</a></p> <table class="memberdecls"> <tr><td colspan="2"><h2><a name="func-members"></a> Functions</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top">std::string </td><td class="memItemRight" valign="bottom"><a class="el" href="SourceView_8C.html#ae50d5388ee0cfd7d80f931509dc435cc">tempFileName</a> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">std::string </td><td class="memItemRight" valign="bottom"><a class="el" href="SourceView_8C.html#a8fe8775b5b65da2de2254166ecdcc74e">getLanguageFromFileExtension</a> (const std::string &fileName)</td></tr> <tr><td class="memItemLeft" align="right" valign="top">std::string </td><td class="memItemRight" valign="bottom"><a class="el" href="SourceView_8C.html#a5df67bacd4ae6a5fd90b7bfd5a16f263">readFileToString</a> (const std::string &fileName)</td></tr> </table> <hr/><h2>Function Documentation</h2> <a class="anchor" id="a8fe8775b5b65da2de2254166ecdcc74e"></a><!-- doxytag: member="SourceView.C::getLanguageFromFileExtension" ref="a8fe8775b5b65da2de2254166ecdcc74e" args="(const std::string &fileName)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">std::string getLanguageFromFileExtension </td> <td>(</td> <td class="paramtype">const std::string & </td> <td class="paramname"><em>fileName</em></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="SourceView_8C_source.html#l00063">63</a> of file <a class="el" href="SourceView_8C_source.html">SourceView.C</a>.</p> <div class="fragment"><pre class="fragment">{ <span class="keywordflow">if</span> (boost::iends_with(fileName, <span class="stringliteral">".h"</span>) || boost::iends_with(fileName, <span class="stringliteral">".C"</span>) || boost::iends_with(fileName, <span class="stringliteral">".cpp"</span>)) <span class="keywordflow">return</span> <span class="stringliteral">"cpp"</span>; <span class="keywordflow">else</span> <span class="keywordflow">if</span> (boost::iends_with(fileName, <span class="stringliteral">".xml"</span>)) <span class="keywordflow">return</span> <span class="stringliteral">"xml"</span>; <span class="keywordflow">else</span> <span class="keywordflow">if</span> (boost::iends_with(fileName, <span class="stringliteral">".html"</span>)) <span class="keywordflow">return</span> <span class="stringliteral">"html"</span>; <span class="keywordflow">else</span> <span class="keywordflow">if</span> (boost::iends_with(fileName, <span class="stringliteral">".java"</span>)) <span class="keywordflow">return</span> <span class="stringliteral">"java"</span>; <span class="keywordflow">else</span> <span class="keywordflow">if</span> (boost::iends_with(fileName, <span class="stringliteral">".js"</span>)) <span class="keywordflow">return</span> <span class="stringliteral">"javascript"</span>; <span class="keywordflow">else</span> <span class="keywordflow">if</span> (boost::iends_with(fileName, <span class="stringliteral">".css"</span>)) <span class="keywordflow">return</span> <span class="stringliteral">"css"</span>; <span class="keywordflow">else</span> <span class="keywordflow">return</span> std::string(); } </pre></div> </div> </div> <a class="anchor" id="a5df67bacd4ae6a5fd90b7bfd5a16f263"></a><!-- doxytag: member="SourceView.C::readFileToString" ref="a5df67bacd4ae6a5fd90b7bfd5a16f263" args="(const std::string &fileName)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">std::string readFileToString </td> <td>(</td> <td class="paramtype">const std::string & </td> <td class="paramname"><em>fileName</em></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="SourceView_8C_source.html#l00083">83</a> of file <a class="el" href="SourceView_8C_source.html">SourceView.C</a>.</p> <div class="fragment"><pre class="fragment">{ std::size_t outputFileSize = (std::size_t)fs::file_size(fileName); std::fstream file (fileName.c_str(), std::ios::in | std::ios::binary); <span class="keywordtype">char</span>* memblock = <span class="keyword">new</span> <span class="keywordtype">char</span> [outputFileSize]; file.read(memblock, (std::streamsize)outputFileSize); file.close(); std::string data = std::string(memblock, outputFileSize); <span class="keyword">delete</span> [] memblock; <span class="keywordflow">return</span> data; } </pre></div> </div> </div> <a class="anchor" id="ae50d5388ee0cfd7d80f931509dc435cc"></a><!-- doxytag: member="SourceView.C::tempFileName" ref="ae50d5388ee0cfd7d80f931509dc435cc" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">std::string tempFileName </td> <td>(</td> <td class="paramname"></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="SourceView_8C_source.html#l00048">48</a> of file <a class="el" href="SourceView_8C_source.html">SourceView.C</a>.</p> <div class="fragment"><pre class="fragment">{ <span class="preprocessor">#ifndef WIN32</span> <span class="preprocessor"></span> <span class="keywordtype">char</span> spool[20]; strcpy(spool, <span class="stringliteral">"/tmp/wtXXXXXX"</span>); <span class="keywordtype">int</span> i = mkstemp(spool); close(i); <span class="preprocessor">#else</span> <span class="preprocessor"></span> <span class="keywordtype">char</span> spool[2 * L_tmpnam]; tmpnam(spool); <span class="preprocessor">#endif</span> <span class="preprocessor"></span> <span class="keywordflow">return</span> std::string(spool); } </pre></div> </div> </div> </div> <hr size="1"><address style="text-align: right; margin: 3px"><small> Generated on Thu Nov 1 2012 for <a href="http://www.webtoolkit.eu/wt">the C++ Web Toolkit (Wt)</a> by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" border="0" style="vertical-align: middle; display: inline-block; height: 2em"></a> 1.7.5.1</small></address> </body> </html>