Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > b3a1f4d91c26f535919e39e25606614a > files > 821

wt-doc-3.2.3-1.fc18.noarch.rpm

<!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/treeview-dragdrop/CsvUtil.h 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
   &#160;<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&#160;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&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="summary">
<a href="#namespaces">Namespaces</a> &#124;
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">/home/koen/project/wt/public-git/wt/examples/treeview-dragdrop/CsvUtil.h File Reference</div>  </div>
</div>
<div class="contents">
<div class="textblock"><code>#include &lt;iostream&gt;</code><br/>
</div>
<p><a href="treeview-dragdrop_2CsvUtil_8h_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="namespaces"></a>
Namespaces</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html">Wt</a></td></tr>
<tr><td colspan="2"><h2><a name="func-members"></a>
Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="treeview-dragdrop_2CsvUtil_8h.html#a1ce51cd14c57073cb7839d5e05b59c65">readFromCsv</a> (std::istream &amp;f, <a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html">Wt::WAbstractItemModel</a> *model, int numRows=-1, bool firstLineIsHeaders=true)</td></tr>
</table>
<hr/><h2>Function Documentation</h2>
<a class="anchor" id="a1ce51cd14c57073cb7839d5e05b59c65"></a><!-- doxytag: member="CsvUtil.h::readFromCsv" ref="a1ce51cd14c57073cb7839d5e05b59c65" args="(std::istream &amp;f, Wt::WAbstractItemModel *model, int numRows=&#45;1, bool firstLineIsHeaders=true)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void readFromCsv </td>
          <td>(</td>
          <td class="paramtype">std::istream &amp;&#160;</td>
          <td class="paramname"><em>f</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="elRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html">Wt::WAbstractItemModel</a> *&#160;</td>
          <td class="paramname"><em>model</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>numRows</em> = <code>-1</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>firstLineIsHeaders</em> = <code>true</code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Definition at line <a class="el" href="treeview-dragdrop_2CsvUtil_8C_source.html#l00009">9</a> of file <a class="el" href="treeview-dragdrop_2CsvUtil_8C_source.html">CsvUtil.C</a>.</p>
<div class="fragment"><pre class="fragment">{
  <span class="keywordtype">int</span> csvRow = 0;

  <span class="keywordflow">while</span> (f) {
    std::string line;
    getline(f, line);

    <span class="keywordflow">if</span> (f) {
      <span class="keyword">typedef</span> boost::tokenizer&lt;boost::escaped_list_separator&lt;char&gt; &gt;
        CsvTokenizer;
      CsvTokenizer tok(line);

      <span class="keywordtype">int</span> col = 0;
      <span class="keywordflow">for</span> (CsvTokenizer::iterator i = tok.begin();
           i != tok.end(); ++i, ++col) {

        <span class="keywordflow">if</span> (col &gt;= model-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html#abcf7912a95a0a60f8e9b1c37d30b8383">columnCount</a>())
          model-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html#a1eded9eb68b9247ae2ff371f74a5e5f2">insertColumns</a>(model-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html#abcf7912a95a0a60f8e9b1c37d30b8383">columnCount</a>(),
                               col + 1 - model-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html#abcf7912a95a0a60f8e9b1c37d30b8383">columnCount</a>());

        <span class="keywordflow">if</span> (firstLineIsHeaders &amp;&amp; csvRow == 0)
          model-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html#a57f5d417f933440db0d38ece7dd370f4">setHeaderData</a>(col, boost::any(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html#a17afc7c43b5b7a710047be4a2c639575">Wt::WString::fromUTF8</a>(*i)));
        <span class="keywordflow">else</span> {
          <span class="keywordtype">int</span> dataRow = firstLineIsHeaders ? csvRow - 1 : csvRow;

          <span class="keywordflow">if</span> (numRows != -1 &amp;&amp; dataRow &gt;= numRows)
            <span class="keywordflow">return</span>;

          <span class="keywordflow">if</span> (dataRow &gt;= model-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html#ab0709a8f71fd5df882f29bb29fd055f0">rowCount</a>())
            model-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html#abcafc38dc24fd9edf70eafe834ca411d">insertRows</a>(model-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html#ab0709a8f71fd5df882f29bb29fd055f0">rowCount</a>(),
                              dataRow + 1 - model-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html#ab0709a8f71fd5df882f29bb29fd055f0">rowCount</a>());

          std::string s = *i;

          boost::any data;

          <span class="keywordtype">char</span> *end;
          <span class="keywordtype">int</span> i = std::strtol(s.c_str(), &amp;end, 10);
          <span class="keywordflow">if</span> (*end == 0)
            data = boost::any(i);
          <span class="keywordflow">else</span> {
            <span class="keywordtype">double</span> d = std::strtod(s.c_str(), &amp;end);
            <span class="keywordflow">if</span> (*end == 0)
              data = boost::any(d);
            <span class="keywordflow">else</span>
              data = boost::any(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html#a17afc7c43b5b7a710047be4a2c639575">Wt::WString::fromUTF8</a>(s));
          }

          model-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html#a70856db8c322be8c7f397a932165a943">setData</a>(dataRow, col, data);
        }
      }
    }

    ++csvRow;
  }
}
</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&nbsp;<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>