|
|
- <!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>WORM: src/orm/wormclassgenerator.cpp Source File</title>
- <link href="tabs.css" rel="stylesheet" type="text/css"/>
- <link href="search/search.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="search/search.js"></script>
- <link href="doxygen.css" rel="stylesheet" type="text/css"/>
- </head>
- <body onload='searchBox.OnSelectItem(0);'>
- <!-- Generated by Doxygen 1.7.3 -->
- <script type="text/javascript"><!--
- var searchBox = new SearchBox("searchBox", "search",false,'Search');
- --></script>
- <script type="text/javascript">
- function hasClass(ele,cls) {
- return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
- }
-
- function addClass(ele,cls) {
- if (!this.hasClass(ele,cls)) ele.className += " "+cls;
- }
-
- function removeClass(ele,cls) {
- if (hasClass(ele,cls)) {
- var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
- ele.className=ele.className.replace(reg,' ');
- }
- }
-
- function toggleVisibility(linkObj) {
- var base = linkObj.getAttribute('id');
- var summary = document.getElementById(base + '-summary');
- var content = document.getElementById(base + '-content');
- var trigger = document.getElementById(base + '-trigger');
- if ( hasClass(linkObj,'closed') ) {
- summary.style.display = 'none';
- content.style.display = 'block';
- trigger.src = 'open.png';
- removeClass(linkObj,'closed');
- addClass(linkObj,'opened');
- } else if ( hasClass(linkObj,'opened') ) {
- summary.style.display = 'block';
- content.style.display = 'none';
- trigger.src = 'closed.png';
- removeClass(linkObj,'opened');
- addClass(linkObj,'closed');
- }
- return false;
- }
- </script>
- <div id="top">
- <div id="titlearea">
- <table cellspacing="0" cellpadding="0">
- <tbody>
- <tr style="height: 56px;">
- <td id="projectlogo"><img alt="Logo" src="worm_sm.png"></td>
- <td style="padding-left: 0.5em;">
- <div id="projectname">WORM <span id="projectnumber">0.2</span></div>
- <div id="projectbrief">A C++ DAL/ORM code generation framework</div>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <div id="navrow1" class="tabs">
- <ul class="tablist">
- <li><a href="index.html"><span>Main Page</span></a></li>
- <li><a href="pages.html"><span>Related Pages</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>
- <li id="searchli">
- <div id="MSearchBox" class="MSearchBoxInactive">
- <span class="left">
- <img id="MSearchSelect" src="search/mag_sel.png"
- onmouseover="return searchBox.OnSearchSelectShow()"
- onmouseout="return searchBox.OnSearchSelectHide()"
- alt=""/>
- <input type="text" id="MSearchField" value="Search" accesskey="S"
- onfocus="searchBox.OnSearchFieldFocus(true)"
- onblur="searchBox.OnSearchFieldFocus(false)"
- onkeyup="searchBox.OnSearchFieldChange(event)"/>
- </span><span class="right">
- <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
- </span>
- </div>
- </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 class="header">
- <div class="headertitle">
- <h1>src/orm/wormclassgenerator.cpp</h1> </div>
- </div>
- <div class="contents">
- <a href="wormclassgenerator_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
- <a name="l00002"></a>00002 <span class="comment"> WORM - a DAL/ORM code generation framework</span>
- <a name="l00003"></a>00003 <span class="comment"> Copyright (C) 2011 Erik Winn <sidewalksoftware@gmail.com></span>
- <a name="l00004"></a>00004 <span class="comment"></span>
- <a name="l00005"></a>00005 <span class="comment"> This program is free software: you can redistribute it and/or modify</span>
- <a name="l00006"></a>00006 <span class="comment"> it under the terms of the GNU General Public License as published by</span>
- <a name="l00007"></a>00007 <span class="comment"> the Free Software Foundation, either version 3 of the License, or</span>
- <a name="l00008"></a>00008 <span class="comment"> (at your option) any later version.</span>
- <a name="l00009"></a>00009 <span class="comment"></span>
- <a name="l00010"></a>00010 <span class="comment"> This program is distributed in the hope that it will be useful,</span>
- <a name="l00011"></a>00011 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
- <a name="l00012"></a>00012 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
- <a name="l00013"></a>00013 <span class="comment"> GNU General Public License for more details.</span>
- <a name="l00014"></a>00014 <span class="comment"></span>
- <a name="l00015"></a>00015 <span class="comment"> You should have received a copy of the GNU General Public License</span>
- <a name="l00016"></a>00016 <span class="comment"> along with this program. If not, see <http://www.gnu.org/licenses/>.</span>
- <a name="l00017"></a>00017 <span class="comment">*/</span>
- <a name="l00018"></a>00018
- <a name="l00019"></a>00019 <span class="comment">//class_definition.tpl is currently the shortest ..</span>
- <a name="l00020"></a><a class="code" href="wormclassgenerator_8cpp.html#a7da7455c29f8520e0ae3a9237c7aafce">00020</a> <span class="preprocessor">#define MIN_TPL_FILENAME_SIZE 20 </span>
- <a name="l00021"></a>00021 <span class="preprocessor"></span>
- <a name="l00022"></a>00022 <span class="preprocessor">#include "<a class="code" href="wormclassgenerator_8h.html">wormclassgenerator.h</a>"</span>
- <a name="l00023"></a>00023 <span class="preprocessor">#include <ctemplate/template.h></span>
- <a name="l00024"></a>00024 <span class="preprocessor">#include <dirent.h></span>
- <a name="l00025"></a>00025 <span class="preprocessor">#include <errno.h></span>
- <a name="l00026"></a>00026 <span class="preprocessor">#include <fstream></span>
- <a name="l00027"></a>00027
- <a name="l00028"></a>00028 <span class="keyword">using namespace </span>ctemplate;
- <a name="l00029"></a>00029
- <a name="l00030"></a><a class="code" href="namespace_w_sql.html">00030</a> <span class="keyword">namespace </span>WSql {
- <a name="l00035"></a><a class="code" href="namespace_w_sql.html#a32f959e9da78600affe97c38b84f2729">00035</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#abb14e5cd3eefa6ec1349041dd8553c82">kcd_INCLUDES</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#abb14e5cd3eefa6ec1349041dd8553c82">kcd_INCLUDES</a>, <span class="stringliteral">"INCLUDES"</span>, 7699670683738647257LLU);
- <a name="l00036"></a><a class="code" href="namespace_w_sql.html#a22fbfb35e7c9977f5bcd002b12e2adf5">00036</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#a5432edb409c732d3b75224d02a111614">kcd_INCLUDE</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#a5432edb409c732d3b75224d02a111614">kcd_INCLUDE</a>, <span class="stringliteral">"INCLUDE"</span>, 434435386609578605LLU);
- <a name="l00037"></a><a class="code" href="namespace_w_sql.html#a9e0d5eba9b94c663778a10ee004262bc">00037</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#acc678e189c024b59c4c7dbf3336a5d0c">kcd_FORWARD_DECLARATIONS</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#acc678e189c024b59c4c7dbf3336a5d0c">kcd_FORWARD_DECLARATIONS</a>, <span class="stringliteral">"FORWARD_DECLARATIONS"</span>, 15273852411010322531LLU);
- <a name="l00038"></a><a class="code" href="namespace_w_sql.html#a36c399903f8b1e9055def9422c088221">00038</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#ab6d30229a7121ede6b2c22010aecd171">kcd_REFERENCED_CLASSNAME</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#ab6d30229a7121ede6b2c22010aecd171">kcd_REFERENCED_CLASSNAME</a>, <span class="stringliteral">"REFERENCED_CLASSNAME"</span>, 5376938313052943395LLU);
- <a name="l00039"></a><a class="code" href="namespace_w_sql.html#a624c8aa68c1a9811bea34266f4b7f6bf">00039</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#a7942a7f5a2746621846598ab85572a49">kcd_CLASS_NAME</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#a7942a7f5a2746621846598ab85572a49">kcd_CLASS_NAME</a>, <span class="stringliteral">"CLASS_NAME"</span>, 13981977283673860485LLU);
- <a name="l00040"></a><a class="code" href="namespace_w_sql.html#a5018cd77220a19bf12455531e7e3eaf3">00040</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#a85df8fbf85bb1e837f0a0c0e15571595">kcd_BELONGS_TO</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#a85df8fbf85bb1e837f0a0c0e15571595">kcd_BELONGS_TO</a>, <span class="stringliteral">"BELONGS_TO"</span>, 15166195752158467517LLU);
- <a name="l00041"></a><a class="code" href="namespace_w_sql.html#a27f6478e0c83b69b2615229abace414e">00041</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#acc0fa525608d855426f75f13806c7402">kcd_HAS_MANY</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#acc0fa525608d855426f75f13806c7402">kcd_HAS_MANY</a>, <span class="stringliteral">"HAS_MANY"</span>, 12417993436827992317LLU);
- <a name="l00042"></a><a class="code" href="namespace_w_sql.html#af8672a60f75250a618fe9745b560a8ef">00042</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#ae9c91a1a67b3fe99e3e9db8dbdb793c5">kcd_FOREIGNKEY_CLASSNAME</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#ae9c91a1a67b3fe99e3e9db8dbdb793c5">kcd_FOREIGNKEY_CLASSNAME</a>, <span class="stringliteral">"FOREIGNKEY_CLASSNAME"</span>, 14113744978891695861LLU);
- <a name="l00043"></a><a class="code" href="namespace_w_sql.html#aa0d121588c9416d5c2602415218c126e">00043</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#af5763371207db409fa5f708c3d7b47d8">kcd_FOREIGNKEY_CLASS_PLURAL</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#af5763371207db409fa5f708c3d7b47d8">kcd_FOREIGNKEY_CLASS_PLURAL</a>, <span class="stringliteral">"FOREIGNKEY_CLASS_PLURAL"</span>, 13464148753922874173LLU);
- <a name="l00044"></a><a class="code" href="namespace_w_sql.html#ac5d782825cae6dc3208602e02f5ff38d">00044</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#a53225bf3ca7db82674e4754297aea205">kcd_COLUMNS</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#a53225bf3ca7db82674e4754297aea205">kcd_COLUMNS</a>, <span class="stringliteral">"COLUMNS"</span>, 15302874640052016969LLU);
- <a name="l00045"></a><a class="code" href="namespace_w_sql.html#a4d6f3f293d868bf467778eb03dda047c">00045</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#a2dde8c3267ab8d8d8287c0fe0eeaa433">kcd_UNSUPPORTED</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#a2dde8c3267ab8d8d8287c0fe0eeaa433">kcd_UNSUPPORTED</a>, <span class="stringliteral">"UNSUPPORTED"</span>, 8112833089436120679LLU);
- <a name="l00046"></a><a class="code" href="namespace_w_sql.html#aee4fb8709c5d533895b7f302b0064fba">00046</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#a7ee30b9baae76963a7bbb01930d1624a">kcd_UNSIGNED</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#a7ee30b9baae76963a7bbb01930d1624a">kcd_UNSIGNED</a>, <span class="stringliteral">"UNSIGNED"</span>, 10867561526856517727LLU);
- <a name="l00047"></a><a class="code" href="namespace_w_sql.html#a5e717f1d92272bbc2debf78eed72d1c6">00047</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#af3143da9b91f92aaae2c1807c0ef947f">kcd_DATATYPE</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#af3143da9b91f92aaae2c1807c0ef947f">kcd_DATATYPE</a>, <span class="stringliteral">"DATATYPE"</span>, 6518949878326190781LLU);
- <a name="l00048"></a><a class="code" href="namespace_w_sql.html#a56003b4c3badb9192aa77a29745a1c38">00048</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#a1e1cb63c9dce87ec05ecdf8d5e4340b2">kcd_VARIABLE_GETTOR</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#a1e1cb63c9dce87ec05ecdf8d5e4340b2">kcd_VARIABLE_GETTOR</a>, <span class="stringliteral">"VARIABLE_GETTOR"</span>, 4376112485907229951LLU);
- <a name="l00049"></a><a class="code" href="namespace_w_sql.html#aa398174c2c459c998bec894e45941360">00049</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#a4a26c6bfb0faee44e91066987f5f68b2">kcd_VARIABLE_NAME</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#a4a26c6bfb0faee44e91066987f5f68b2">kcd_VARIABLE_NAME</a>, <span class="stringliteral">"VARIABLE_NAME"</span>, 5051229879184672055LLU);
- <a name="l00050"></a><a class="code" href="namespace_w_sql.html#a51157cf76ce296aa46162b4ec55ef0a0">00050</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#a2682bf4433565d3c850f1d4895668a85">kcd_VARIABLE_SETTOR</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#a2682bf4433565d3c850f1d4895668a85">kcd_VARIABLE_SETTOR</a>, <span class="stringliteral">"VARIABLE_SETTOR"</span>, 18309610407346123363LLU);
- <a name="l00051"></a><a class="code" href="namespace_w_sql.html#aa2e687b7b6d092dd73ec19da1a8d8255">00051</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#a521b0e113f64c97e7a1b96b804243178">kcd_COLUMN_NAME</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#a521b0e113f64c97e7a1b96b804243178">kcd_COLUMN_NAME</a>, <span class="stringliteral">"COLUMN_NAME"</span>, 16524890828269290931LLU);
- <a name="l00052"></a><a class="code" href="namespace_w_sql.html#a56fb57dd4ab04e11aed4f93c34e1b758">00052</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#a7f065525a1da390502ebfa2a0762c324">kcd_REFERENCED_TABLENAME</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#a7f065525a1da390502ebfa2a0762c324">kcd_REFERENCED_TABLENAME</a>, <span class="stringliteral">"REFERENCED_TABLENAME"</span>, 14486319327059551333LLU);
- <a name="l00053"></a><a class="code" href="namespace_w_sql.html#ad2fb8b6751a7eaa954e284534cb68593">00053</a> <span class="keyword">static</span> const ::ctemplate::StaticTemplateString <a class="code" href="class__declaration_8tpl_8varnames_8h.html#ae61adac3784bd271abcc50bf2a2325ba">kcd_TABLE_NAME</a> = STS_INIT_WITH_HASH(<a class="code" href="class__declaration_8tpl_8varnames_8h.html#ae61adac3784bd271abcc50bf2a2325ba">kcd_TABLE_NAME</a>, <span class="stringliteral">"TABLE_NAME"</span>, 3760310134096538793LLU);
- <a name="l00088"></a><a class="code" href="class_w_sql_1_1_worm_class_generator.html#a03e364c4e63187824777694ccde7c45f">00088</a> WormClassGenerator::WormClassGenerator(<a class="code" href="class_w_sql_1_1_w_sql_database.html" title="The WSqlDatabase class represents a single database.">WSqlDatabase</a>& db):_db(db)
- <a name="l00089"></a>00089 {
- <a name="l00090"></a>00090 }
- <a name="l00101"></a><a class="code" href="class_w_sql_1_1_worm_class_generator.html#a3a753e5b47f8d8ccdfb21ec9022bfa69">00101</a> <span class="keywordtype">bool</span> <a class="code" href="class_w_sql_1_1_worm_class_generator.html#a3a753e5b47f8d8ccdfb21ec9022bfa69" title="Initialize templates and metadata.">WormClassGenerator::init</a>()
- <a name="l00102"></a>00102 {
- <a name="l00103"></a>00103 <span class="comment">//load available templates</span>
- <a name="l00104"></a>00104 DIR *dir;
- <a name="l00105"></a>00105 <span class="keyword">struct </span>dirent *ent;
- <a name="l00106"></a>00106
- <a name="l00107"></a>00107 dir = opendir (_templateDirectory.c_str());
- <a name="l00108"></a>00108 <span class="keywordflow">if</span> (dir != NULL)
- <a name="l00109"></a>00109 {
- <a name="l00110"></a>00110 <a class="code" href="class_w_sql_1_1_worm_code_template.html">WormCodeTemplate</a> tpl;
- <a name="l00111"></a>00111 <span class="keywordflow">while</span> ((ent = readdir (dir)) != NULL)
- <a name="l00112"></a>00112 {
- <a name="l00113"></a>00113 <span class="keywordflow">if</span>(ent->d_type != DT_REG)
- <a name="l00114"></a>00114 <span class="keywordflow">continue</span>;
- <a name="l00115"></a>00115 std::string entry = ent->d_name;
- <a name="l00116"></a>00116 <span class="keywordtype">size_t</span> sz = entry.size();
- <a name="l00117"></a>00117 <span class="keywordflow">if</span>(sz < <a class="code" href="wormclassgenerator_8cpp.html#a7da7455c29f8520e0ae3a9237c7aafce">MIN_TPL_FILENAME_SIZE</a> )
- <a name="l00118"></a>00118 <span class="keywordflow">continue</span>;
- <a name="l00119"></a>00119 <span class="comment">//only accept .tpl files</span>
- <a name="l00120"></a>00120 std::string ext = entry.substr(sz - 4);
- <a name="l00121"></a>00121 <span class="keywordflow">if</span>( ext.compare(<span class="stringliteral">".tpl"</span>))
- <a name="l00122"></a>00122 <span class="keywordflow">continue</span>;
- <a name="l00123"></a>00123 tpl.<a class="code" href="class_w_sql_1_1_worm_code_template.html#a777365c4f3a57595c2a7e350a2ed3061" title="Set the URI or filename containing the template.">setUri</a>(entry);
- <a name="l00124"></a>00124 _templates.push_back(tpl);
- <a name="l00125"></a>00125
- <a name="l00126"></a>00126 <span class="comment">/* maybe use, pass a string to ctemplate: std::string tmp;</span>
- <a name="l00127"></a>00127 <span class="comment"> fs.open(entry.c_str());</span>
- <a name="l00128"></a>00128 <span class="comment"> while(fs)</span>
- <a name="l00129"></a>00129 <span class="comment"> std::getline(fs,tmp);</span>
- <a name="l00130"></a>00130 <span class="comment"> tpl.setContent(tmp);</span>
- <a name="l00131"></a>00131 <span class="comment"> */</span>
- <a name="l00132"></a>00132 }
- <a name="l00133"></a>00133 closedir (dir);
- <a name="l00134"></a>00134 } <span class="keywordflow">else</span> {
- <a name="l00135"></a>00135 std::string msg = <span class="stringliteral">"Cannot open directory: "</span> + _templateDirectory;
- <a name="l00136"></a>00136 <span class="keywordflow">if</span>(errno == EACCES )
- <a name="l00137"></a>00137 msg.append(<span class="stringliteral">" - Access denied."</span>);
- <a name="l00138"></a>00138 _db.<a class="code" href="class_w_sql_1_1_w_sql_database.html#a7770c27b068eb51aa856c0ae37d726de">addError</a>(<a class="code" href="class_w_sql_1_1_w_sql_error.html" title="The WSqlError class provides SQL database and driver error information.">WSqlError</a>(msg, errno,<a class="code" href="class_w_sql_1_1_w_sql_error.html#a8bcabd8bf1016ca27304a717ef3d78dbaacc793148eebd48878f5e1b7bb4dfc70">WSql::WSqlError::SYSTEM</a>, <a class="code" href="class_w_sql_1_1_w_sql_error.html#a63b2672eb5c68164c4ff43443037f6d9ac6ac27cbc8f55f680a218784311e15a3">WSql::WSqlError::FATAL</a>));
- <a name="l00139"></a>00139 <span class="keywordflow">return</span> <span class="keyword">false</span>;
- <a name="l00140"></a>00140 }
- <a name="l00141"></a>00141 _db.<a class="code" href="class_w_sql_1_1_w_sql_database.html#a9bd1765f14443afbb875981321d4c529" title="Initializes the metadata for all tables in the database.">initMetaData</a>();
- <a name="l00142"></a>00142 <span class="keywordflow">return</span> <span class="keyword">true</span>;
- <a name="l00143"></a>00143 }
- <a name="l00155"></a><a class="code" href="class_w_sql_1_1_worm_class_generator.html#a99918905652f92668ded30d579830cbb">00155</a> <span class="keywordtype">void</span> <a class="code" href="class_w_sql_1_1_worm_class_generator.html#a99918905652f92668ded30d579830cbb" title="Run the generator.">WormClassGenerator::run</a>()
- <a name="l00156"></a>00156 {
- <a name="l00157"></a>00157 <span class="keywordflow">if</span>(_tablesToGenerate.empty())
- <a name="l00158"></a>00158 {
- <a name="l00159"></a>00159 std::cerr << <span class="stringliteral">"No tables specified - assuming all tables .."</span> << std::endl;
- <a name="l00160"></a>00160 _tablesToGenerate = _db.<a class="code" href="class_w_sql_1_1_w_sql_database.html#a86df7db5900c3a2d1483375195c7b025" title="Returns a vector of the database&#39;s table names.">tableNames</a>();
- <a name="l00161"></a>00161 }
- <a name="l00162"></a>00162
- <a name="l00163"></a>00163 std::string outbuffer;
- <a name="l00164"></a>00164 std::string outfilename;
- <a name="l00165"></a>00165 std::vector<WormCodeTemplate>::iterator tpl_it;
- <a name="l00166"></a>00166 std::vector<std::string>::const_iterator tbl_it = _tablesToGenerate.begin();
- <a name="l00167"></a>00167 <span class="comment">//each table translates to a class object ..</span>
- <a name="l00168"></a>00168 <span class="keywordflow">for</span>(; tbl_it != _tablesToGenerate.end();++tbl_it)
- <a name="l00169"></a>00169 {
- <a name="l00170"></a>00170 <a class="code" href="class_w_sql_1_1_w_sql_table.html" title="WSqlTable is an abstraction for a single table, collection or view in a database.">WSqlTable</a> table = _db.<a class="code" href="class_w_sql_1_1_w_sql_database.html#a2f068c8103068f0b4cab897b824144b9" title="Fetch metadata for table tableName.">tableMetaData</a>(*tbl_it);
- <a name="l00171"></a>00171 <span class="comment">//foreach template, expand for this table</span>
- <a name="l00172"></a>00172 <span class="keywordflow">for</span>(tpl_it = _templates.begin(); tpl_it != _templates.end();++ tpl_it)
- <a name="l00173"></a>00173 {
- <a name="l00174"></a>00174 <span class="keyword">const</span> std::string tplfilename = _templateDirectory + tpl_it->uri();
- <a name="l00175"></a>00175 outbuffer = expand(tplfilename, table);
- <a name="l00176"></a>00176 outfilename = createOutFileName(tpl_it->type(), table);
- <a name="l00177"></a>00177 <span class="keywordflow">if</span>(!writeFile(outbuffer, outfilename))
- <a name="l00178"></a>00178 std::cerr << <span class="stringliteral">"Warning: failed to write File "</span> << outfilename << std::endl;
- <a name="l00179"></a>00179 }
- <a name="l00180"></a>00180 }
- <a name="l00181"></a>00181 }
- <a name="l00182"></a>00182
- <a name="l00194"></a>00194 std::string WormClassGenerator::expand( <span class="keyword">const</span> std::string& filename, <span class="keyword">const</span> <a class="code" href="class_w_sql_1_1_w_sql_table.html" title="WSqlTable is an abstraction for a single table, collection or view in a database.">WSqlTable</a>& table)
- <a name="l00195"></a>00195 {
- <a name="l00196"></a>00196 <span class="comment">// std::cerr << "============= Processing table " << table.name() << std::endl;</span>
- <a name="l00197"></a>00197 std::string strToReturn;
- <a name="l00198"></a>00198 <span class="keywordtype">bool</span> has_string=<span class="keyword">false</span>;
- <a name="l00199"></a>00199 std::string type_declaration;
- <a name="l00200"></a>00200 std::string variable_name;
- <a name="l00201"></a>00201 std::string variable_settor;
- <a name="l00202"></a>00202 std::string variable_gettor;
- <a name="l00203"></a>00203 std::vector<std::string> forward_declarations;
- <a name="l00204"></a>00204
- <a name="l00205"></a>00205 TemplateDictionary *topdict = <span class="keyword">new</span> TemplateDictionary(filename);
- <a name="l00206"></a>00206 TemplateDictionary *forwarddecls_dict;
- <a name="l00207"></a>00207 TemplateDictionary *belongsto_dict;
- <a name="l00208"></a>00208 TemplateDictionary *hasmany_dict;
- <a name="l00209"></a>00209 TemplateDictionary *coldict;
- <a name="l00210"></a>00210 topdict->SetValue(<a class="code" href="namespace_w_sql.html#a624c8aa68c1a9811bea34266f4b7f6bf">kcd_CLASS_NAME</a>, table.<a class="code" href="class_w_sql_1_1_w_sql_table.html#ac9a982900d31ae351ff89b576f43388b">className</a>());
- <a name="l00211"></a>00211 topdict->SetValue(<a class="code" href="namespace_w_sql.html#ad2fb8b6751a7eaa954e284534cb68593">kcd_TABLE_NAME</a>, table.<a class="code" href="class_w_sql_1_1_w_sql_table.html#a27a8e1e92061bebb56b1d3a79e216ff4">name</a>());
- <a name="l00212"></a>00212
- <a name="l00213"></a>00213 <span class="keyword">const</span> std::vector<WSqlColumn>& columns = table.<a class="code" href="class_w_sql_1_1_w_sql_table.html#acfdf1961dd9401c8c6946a03d1da5651">columns</a>();
- <a name="l00214"></a>00214 std::vector<WSqlColumn>::const_iterator col_it = columns.begin();
- <a name="l00215"></a>00215
- <a name="l00216"></a>00216 <span class="keywordflow">if</span>(table.<a class="code" href="class_w_sql_1_1_w_sql_table.html#a9fd4f99e267750bafe697523e7dbc09a">hasForeignKeys</a>())
- <a name="l00217"></a>00217 {
- <a name="l00218"></a>00218 std::vector< WSqlForeignKey >fks = table.<a class="code" href="class_w_sql_1_1_w_sql_table.html#a6376a1c1783991391d0ae0224e4e7279">foreignKeys</a>();
- <a name="l00219"></a>00219 std::vector< WSqlForeignKey >::const_iterator fks_it = fks.begin();
- <a name="l00220"></a>00220 <span class="keywordflow">for</span>(;fks_it != fks.end();++fks_it)
- <a name="l00221"></a>00221 {
- <a name="l00222"></a>00222 <span class="comment">//fks_it->dump();</span>
- <a name="l00223"></a>00223 std::vector<std::string>::const_iterator it = std::find(forward_declarations.begin(), forward_declarations.end(), fks_it->referencedClassName());
- <a name="l00224"></a>00224 <span class="keywordflow">if</span> (it== forward_declarations.end())
- <a name="l00225"></a>00225 {
- <a name="l00226"></a>00226 forwarddecls_dict = topdict->AddSectionDictionary(<a class="code" href="namespace_w_sql.html#a9e0d5eba9b94c663778a10ee004262bc">kcd_FORWARD_DECLARATIONS</a>);
- <a name="l00227"></a>00227 forwarddecls_dict->SetValue(<a class="code" href="namespace_w_sql.html#a36c399903f8b1e9055def9422c088221">kcd_REFERENCED_CLASSNAME</a>, fks_it->referencedClassName());
- <a name="l00228"></a>00228 forward_declarations.push_back(fks_it->referencedClassName());
- <a name="l00229"></a>00229 }
- <a name="l00230"></a>00230 belongsto_dict = topdict->AddSectionDictionary(<a class="code" href="namespace_w_sql.html#a5018cd77220a19bf12455531e7e3eaf3">kcd_BELONGS_TO</a>);
- <a name="l00231"></a>00231 belongsto_dict->SetValue(<a class="code" href="namespace_w_sql.html#a36c399903f8b1e9055def9422c088221">kcd_REFERENCED_CLASSNAME</a>, fks_it->referencedClassName());
- <a name="l00232"></a>00232 belongsto_dict->SetValue(<a class="code" href="namespace_w_sql.html#a56fb57dd4ab04e11aed4f93c34e1b758">kcd_REFERENCED_TABLENAME</a>, fks_it->referencedTableName());
- <a name="l00233"></a>00233 }
- <a name="l00234"></a>00234 }
- <a name="l00235"></a>00235 <span class="keywordflow">if</span>(table.<a class="code" href="class_w_sql_1_1_w_sql_table.html#a1c04777c5f9393415fb62668dc902eb9">hasReferencedKeys</a>())
- <a name="l00236"></a>00236 {
- <a name="l00237"></a>00237 std::vector< WSqlReferencedKey >rks = table.<a class="code" href="class_w_sql_1_1_w_sql_table.html#aeb424ef06d4e5978e861be12f3689fa5">referencedKeys</a>();
- <a name="l00238"></a>00238 std::vector< WSqlReferencedKey >::const_iterator rks_it = rks.begin();
- <a name="l00239"></a>00239 <span class="keywordflow">for</span>(;rks_it != rks.end();++rks_it)
- <a name="l00240"></a>00240 {
- <a name="l00241"></a>00241 <span class="comment">//rks_it->dump();</span>
- <a name="l00242"></a>00242 std::vector<std::string>::const_iterator it = std::find(forward_declarations.begin(), forward_declarations.end(), rks_it->referingClassName());
- <a name="l00243"></a>00243 <span class="keywordflow">if</span> (it == forward_declarations.end())
- <a name="l00244"></a>00244 {
- <a name="l00245"></a>00245 forwarddecls_dict = topdict->AddSectionDictionary(<a class="code" href="namespace_w_sql.html#a9e0d5eba9b94c663778a10ee004262bc">kcd_FORWARD_DECLARATIONS</a>);
- <a name="l00246"></a>00246 forwarddecls_dict->SetValue(<a class="code" href="namespace_w_sql.html#a36c399903f8b1e9055def9422c088221">kcd_REFERENCED_CLASSNAME</a>, rks_it->referingClassName());
- <a name="l00247"></a>00247 forward_declarations.push_back(rks_it->referingClassName());
- <a name="l00248"></a>00248 }
- <a name="l00249"></a>00249 hasmany_dict = topdict->AddSectionDictionary(<a class="code" href="namespace_w_sql.html#a27f6478e0c83b69b2615229abace414e">kcd_HAS_MANY</a>);
- <a name="l00250"></a>00250 hasmany_dict->SetValue(<a class="code" href="namespace_w_sql.html#af8672a60f75250a618fe9745b560a8ef">kcd_FOREIGNKEY_CLASSNAME</a>, rks_it->referingClassName());
- <a name="l00251"></a>00251 hasmany_dict->SetValue(<a class="code" href="namespace_w_sql.html#aa0d121588c9416d5c2602415218c126e">kcd_FOREIGNKEY_CLASS_PLURAL</a>, rks_it->referingClassNamePlural());
- <a name="l00252"></a>00252 }
- <a name="l00253"></a>00253 }
- <a name="l00254"></a>00254 <span class="keywordflow">for</span>(;col_it != columns.end();++col_it)
- <a name="l00255"></a>00255 {
- <a name="l00256"></a>00256 coldict = topdict->AddSectionDictionary(<a class="code" href="namespace_w_sql.html#ac5d782825cae6dc3208602e02f5ff38d">kcd_COLUMNS</a>);
- <a name="l00257"></a>00257 type_declaration = col_it->typeDeclaration();
- <a name="l00258"></a>00258 variable_name = col_it->variableName();
- <a name="l00259"></a>00259 std::string tmp = variable_name;
- <a name="l00260"></a>00260 tmp[0] = toupper(tmp[0]);
- <a name="l00261"></a>00261 variable_settor = <span class="stringliteral">"set"</span> + tmp;
- <a name="l00262"></a>00262 variable_gettor = <span class="stringliteral">"get"</span> + tmp;
- <a name="l00263"></a>00263 <span class="keywordflow">if</span>(type_declaration.compare(<span class="stringliteral">"std::string"</span>) == 0)
- <a name="l00264"></a>00264 has_string=<span class="keyword">true</span>;
- <a name="l00265"></a>00265 <span class="keywordflow">if</span>(! col_it->typeIsSupported())
- <a name="l00266"></a>00266 coldict->ShowSection(<a class="code" href="namespace_w_sql.html#a4d6f3f293d868bf467778eb03dda047c">kcd_UNSUPPORTED</a>);
- <a name="l00267"></a>00267 coldict->SetValue(<a class="code" href="namespace_w_sql.html#aa2e687b7b6d092dd73ec19da1a8d8255">kcd_COLUMN_NAME</a>, col_it->columnName());
- <a name="l00268"></a>00268 coldict->SetValue(<a class="code" href="namespace_w_sql.html#a5e717f1d92272bbc2debf78eed72d1c6">kcd_DATATYPE</a>, type_declaration);
- <a name="l00269"></a>00269 coldict->SetValue(<a class="code" href="namespace_w_sql.html#aa398174c2c459c998bec894e45941360">kcd_VARIABLE_NAME</a>, variable_name );
- <a name="l00270"></a>00270 coldict->SetValue(<a class="code" href="namespace_w_sql.html#a51157cf76ce296aa46162b4ec55ef0a0">kcd_VARIABLE_SETTOR</a>, variable_settor);
- <a name="l00271"></a>00271 coldict->SetValue(<a class="code" href="namespace_w_sql.html#a56003b4c3badb9192aa77a29745a1c38">kcd_VARIABLE_GETTOR</a>, variable_gettor);
- <a name="l00272"></a>00272
- <a name="l00273"></a>00273 <span class="comment">//FIXME always unsigned .. deep strangeness .. </span>
- <a name="l00274"></a>00274 <span class="comment">/* if(col_it->isUnsigned())</span>
- <a name="l00275"></a>00275 <span class="comment"> {</span>
- <a name="l00276"></a>00276 <span class="comment"> coldict->ShowSection(kcd_UNSIGNED);</span>
- <a name="l00277"></a>00277 <span class="comment"> std::cerr << "in table " << tbl.className() << " " << col_it->columnName() << "is unsigned .." << std::endl</span>
- <a name="l00278"></a>00278 <span class="comment"> << " type: " << WSqlDataType::toString(col_it->type()) << std::endl; </span>
- <a name="l00279"></a>00279 <span class="comment"> } */</span>
- <a name="l00280"></a>00280 }
- <a name="l00281"></a>00281
- <a name="l00283"></a>00283 <span class="keywordflow">if</span>(has_string)
- <a name="l00284"></a>00284 topdict->SetValueAndShowSection(<span class="stringliteral">"INCLUDE"</span>,<span class="stringliteral">"#include <string>"</span>, <a class="code" href="namespace_w_sql.html#a32f959e9da78600affe97c38b84f2729">kcd_INCLUDES</a>);
- <a name="l00285"></a>00285
- <a name="l00286"></a>00286 ExpandTemplate(filename, DO_NOT_STRIP, topdict, &strToReturn);
- <a name="l00287"></a>00287 <span class="keyword">delete</span> topdict;
- <a name="l00288"></a>00288 <span class="keywordflow">return</span> strToReturn;
- <a name="l00289"></a>00289 }
- <a name="l00290"></a>00290
- <a name="l00301"></a>00301 std::string WormClassGenerator::createOutFileName(<span class="keyword">const</span> <a class="code" href="class_w_sql_1_1_worm_code_template.html#a6c3faf9576eb86f71e7e1270f02cda1b">WormCodeTemplate::Type</a> type, <span class="keyword">const</span> WSqlTable& table)
- <a name="l00302"></a>00302 {
- <a name="l00303"></a>00303 std::string strToReturn;
- <a name="l00304"></a>00304 <span class="keywordflow">switch</span>(type){
- <a name="l00305"></a>00305 <span class="keywordflow">case</span> <a class="code" href="class_w_sql_1_1_worm_code_template.html#a6c3faf9576eb86f71e7e1270f02cda1ba12a930ae6aa6b1c82f14cca0de4a95bf">WormCodeTemplate::ClassDeclarationBase</a>:
- <a name="l00306"></a>00306 strToReturn = table.className() + <span class="stringliteral">"Base.h"</span>;
- <a name="l00307"></a>00307 <span class="keywordflow">break</span>;
- <a name="l00308"></a>00308 <span class="keywordflow">case</span> <a class="code" href="class_w_sql_1_1_worm_code_template.html#a6c3faf9576eb86f71e7e1270f02cda1babd60733af048e610900651ce3bb88462">WormCodeTemplate::ClassDefinitionBase</a>:
- <a name="l00309"></a>00309 strToReturn = table.className() + <span class="stringliteral">"Base.cpp"</span>;
- <a name="l00310"></a>00310 <span class="keywordflow">break</span>;
- <a name="l00311"></a>00311 <span class="keywordflow">case</span> <a class="code" href="class_w_sql_1_1_worm_code_template.html#a6c3faf9576eb86f71e7e1270f02cda1bade0a459ad25b7d10f96b91b2518a07d8">WormCodeTemplate::ClassDeclaration</a>:
- <a name="l00312"></a>00312 strToReturn = table.className() + <span class="stringliteral">".h"</span>;
- <a name="l00313"></a>00313 <span class="keywordflow">break</span>;
- <a name="l00314"></a>00314 <span class="keywordflow">case</span> <a class="code" href="class_w_sql_1_1_worm_code_template.html#a6c3faf9576eb86f71e7e1270f02cda1badacce5fdfa6887f72abd87a863b82208">WormCodeTemplate::ClassDefinition</a>:
- <a name="l00315"></a>00315 strToReturn = table.className() + <span class="stringliteral">".cpp"</span>;
- <a name="l00316"></a>00316 <span class="keywordflow">break</span>;
- <a name="l00317"></a>00317 <span class="keywordflow">default</span>:
- <a name="l00318"></a>00318 std::cerr << <span class="stringliteral">"WormClassGenerator: WARNING: template type unsupported!"</span>;
- <a name="l00319"></a>00319 ;
- <a name="l00320"></a>00320 }
- <a name="l00321"></a>00321 <span class="keywordflow">return</span> strToReturn;
- <a name="l00322"></a>00322 }
- <a name="l00323"></a>00323
- <a name="l00328"></a>00328 <span class="keywordtype">bool</span> WormClassGenerator::writeFile( <span class="keyword">const</span> std::string content, <span class="keyword">const</span> std::string filename )
- <a name="l00329"></a>00329 {
- <a name="l00330"></a>00330 std::ofstream fs;
- <a name="l00331"></a>00331 std::string target = _outputDirectory + <span class="stringliteral">"/"</span> + filename;
- <a name="l00332"></a>00332 fs.open(target.c_str());
- <a name="l00333"></a>00333 <span class="keywordflow">if</span>(!fs)
- <a name="l00334"></a>00334 <span class="keywordflow">return</span> <span class="keyword">false</span>;
- <a name="l00335"></a>00335 fs << content;
- <a name="l00336"></a>00336 fs.close();
- <a name="l00337"></a>00337 <span class="keywordflow">return</span> <span class="keyword">true</span>;
- <a name="l00338"></a>00338 }
- <a name="l00339"></a>00339
- <a name="l00345"></a><a class="code" href="class_w_sql_1_1_worm_class_generator.html#ae18b5f7c5d9015a1b675cdb2a6c9264c">00345</a> <span class="keywordtype">void</span> <a class="code" href="class_w_sql_1_1_worm_class_generator.html#ae18b5f7c5d9015a1b675cdb2a6c9264c">WormClassGenerator::setOutputDirectory</a>( <span class="keyword">const</span> std::string dir )
- <a name="l00346"></a>00346 {
- <a name="l00347"></a>00347 _outputDirectory = dir;
- <a name="l00348"></a>00348 <span class="keywordflow">if</span>(<span class="charliteral">'/'</span> != _outputDirectory[ _outputDirectory.size()-1])
- <a name="l00349"></a>00349 _outputDirectory.append(<span class="stringliteral">"/"</span>);
- <a name="l00350"></a>00350 }
- <a name="l00356"></a><a class="code" href="class_w_sql_1_1_worm_class_generator.html#ae33fa044cc6eca45643217603f78ead2">00356</a> <span class="keywordtype">void</span> <a class="code" href="class_w_sql_1_1_worm_class_generator.html#ae33fa044cc6eca45643217603f78ead2">WormClassGenerator::setTemplateDirectory</a>( <span class="keyword">const</span> std::string dir )
- <a name="l00357"></a>00357 {
- <a name="l00358"></a>00358 _templateDirectory = dir;
- <a name="l00359"></a>00359 <span class="keywordflow">if</span>(<span class="charliteral">'/'</span> != _templateDirectory[ _templateDirectory.size()-1])
- <a name="l00360"></a>00360 _templateDirectory.append(<span class="stringliteral">"/"</span>);
- <a name="l00361"></a>00361 }
- <a name="l00362"></a>00362
- <a name="l00363"></a>00363
- <a name="l00364"></a>00364 } <span class="comment">//namespace WSql</span>
- </pre></div></div>
- </div>
- <!--- window showing the filter options -->
- <div id="MSearchSelectWindow"
- onmouseover="return searchBox.OnSearchSelectShow()"
- onmouseout="return searchBox.OnSearchSelectHide()"
- onkeydown="return searchBox.OnSearchSelectKey(event)">
- <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Defines</a></div>
-
- <!-- iframe showing the search results (closed by default) -->
- <div id="MSearchResultsWindow">
- <iframe src="" frameborder="0"
- name="MSearchResults" id="MSearchResults">
- </iframe>
- </div>
-
- <hr class="footer"/><address class="footer"><small>Generated on Fri Nov 18 2011 21:01:45 for WORM by 
- <a href="http://www.doxygen.org/index.html">
- <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address>
- </body>
- </html>
|