Sophie

Sophie

distrib > Fedora > 14 > i386 > by-pkgid > abb2634846290d27f545cecded067e1f > files > 1823

barry-devel-docs-0.17.1-4.fc14.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Barry: restore.cc Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;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="classes.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_3e14c0bb4416cf979afc3165665fc916.html">src</a>
  </div>
</div>
<div class="contents">
<h1>restore.cc</h1><a href="restore_8cc.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"></span><span class="comment">/// \file       restore.cc</span>
<a name="l00003"></a>00003 <span class="comment"></span><span class="comment">///             Builder class for restoring from Barry Backup files</span>
<a name="l00004"></a>00004 <span class="comment"></span><span class="comment">///</span>
<a name="l00005"></a>00005 <span class="comment"></span>
<a name="l00006"></a>00006 <span class="comment">/*</span>
<a name="l00007"></a>00007 <span class="comment">    Copyright (C) 2010-2011, Net Direct Inc. (http://www.netdirect.ca/)</span>
<a name="l00008"></a>00008 <span class="comment"></span>
<a name="l00009"></a>00009 <span class="comment">    This program is free software; you can redistribute it and/or modify</span>
<a name="l00010"></a>00010 <span class="comment">    it under the terms of the GNU General Public License as published by</span>
<a name="l00011"></a>00011 <span class="comment">    the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00012"></a>00012 <span class="comment">    (at your option) any later version.</span>
<a name="l00013"></a>00013 <span class="comment"></span>
<a name="l00014"></a>00014 <span class="comment">    This program is distributed in the hope that it will be useful,</span>
<a name="l00015"></a>00015 <span class="comment">    but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00016"></a>00016 <span class="comment">    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</span>
<a name="l00017"></a>00017 <span class="comment"></span>
<a name="l00018"></a>00018 <span class="comment">    See the GNU General Public License in the COPYING file at the</span>
<a name="l00019"></a>00019 <span class="comment">    root directory of this project for more details.</span>
<a name="l00020"></a>00020 <span class="comment">*/</span>
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 <span class="preprocessor">#include "<a class="code" href="restore_8h.html" title="Builder class for restoring from Barry Backup files.">restore.h</a>"</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="tarfile_8h.html" title="API for reading and writing sequentially from compressed tar files.">tarfile.h</a>"</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="error_8h.html" title="Common exception classes for the Barry library.">error.h</a>"</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;sstream&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;iomanip&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;algorithm&gt;</span>
<a name="l00030"></a>00030 
<a name="l00031"></a>00031 <span class="keyword">using namespace </span>std;
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 <span class="keyword">namespace </span>Barry {
<a name="l00034"></a>00034 
<a name="l00035"></a>00035 <span class="keyword">namespace </span>{
<a name="l00036"></a>00036 
<a name="l00037"></a>00037         <span class="keywordtype">int</span> CountFiles(reuse::TarFile &amp;tar,
<a name="l00038"></a>00038                         <span class="keyword">const</span> Barry::Restore::DBListType &amp;restoreList,
<a name="l00039"></a>00039                         <span class="keywordtype">bool</span> default_all_db)
<a name="l00040"></a>00040         {
<a name="l00041"></a>00041                 <span class="keywordtype">int</span> count = 0;
<a name="l00042"></a>00042                 std::string name, last_name;
<a name="l00043"></a>00043                 <span class="keywordtype">bool</span> good = <span class="keyword">false</span>;
<a name="l00044"></a>00044 
<a name="l00045"></a>00045                 <span class="keywordflow">while</span>( tar.ReadNextFilenameOnly(name) ) {
<a name="l00046"></a>00046                         std::string::size_type pos = name.rfind(<span class="charliteral">'/'</span>);
<a name="l00047"></a>00047                         <span class="keywordflow">if</span>( pos == std::string::npos )
<a name="l00048"></a>00048                                 <span class="keywordflow">continue</span>;       <span class="comment">// bad name</span>
<a name="l00049"></a>00049                         std::string dbname = name.substr(0, pos);
<a name="l00050"></a>00050 
<a name="l00051"></a>00051                         <span class="keywordflow">if</span>( dbname != last_name ) {
<a name="l00052"></a>00052                                 last_name = dbname;
<a name="l00053"></a>00053                                 good = (default_all_db &amp;&amp; restoreList.size() == 0) ||
<a name="l00054"></a>00054                                         restoreList.IsSelected(dbname);
<a name="l00055"></a>00055                         }
<a name="l00056"></a>00056                         <span class="keywordflow">if</span>( good )
<a name="l00057"></a>00057                                 count++;
<a name="l00058"></a>00058                 }
<a name="l00059"></a>00059                 <span class="keywordflow">return</span> count;
<a name="l00060"></a>00060         }
<a name="l00061"></a>00061 
<a name="l00062"></a>00062 }
<a name="l00063"></a>00063 <span class="comment"></span>
<a name="l00064"></a>00064 <span class="comment">//////////////////////////////////////////////////////////////////////////////</span>
<a name="l00065"></a>00065 <span class="comment"></span><span class="comment">// Static Restore members</span>
<a name="l00066"></a>00066 <span class="comment"></span>
<a name="l00067"></a>00067 <span class="comment">/// Splits a tarpath of the form "DBName/DBID" into separate string values.</span>
<a name="l00068"></a>00068 <span class="comment">/// Returns true if successful, false if tarpath is a bad name.</span>
<a name="l00069"></a><a class="code" href="classBarry_1_1Restore.html#eed51b73f7d5125ae655af0a965a8113">00069</a> <span class="comment"></span><span class="keywordtype">bool</span> <a class="code" href="classBarry_1_1Restore.html#eed51b73f7d5125ae655af0a965a8113" title="Splits a tarpath of the form &amp;quot;DBName/DBID&amp;quot; into separate string values...">Restore::SplitTarPath</a>(<span class="keyword">const</span> std::string &amp;tarpath,
<a name="l00070"></a>00070                                    std::string &amp;dbname,
<a name="l00071"></a>00071                                    std::string &amp;dbid_text,
<a name="l00072"></a>00072                                    uint8_t &amp;dbrectype,
<a name="l00073"></a>00073                                    uint32_t &amp;dbid)
<a name="l00074"></a>00074 {
<a name="l00075"></a>00075         std::string::size_type pos = tarpath.rfind(<span class="charliteral">'/'</span>);
<a name="l00076"></a>00076         <span class="keywordflow">if</span>( pos == std::string::npos )
<a name="l00077"></a>00077                 <span class="keywordflow">return</span> <span class="keyword">false</span>;           <span class="comment">// bad name</span>
<a name="l00078"></a>00078 
<a name="l00079"></a>00079         dbname = tarpath.substr(0, pos);
<a name="l00080"></a>00080         dbid_text = tarpath.substr(pos + 1);
<a name="l00081"></a>00081         <span class="keywordflow">if</span>( dbname.size() == 0 || dbid_text.size() == 0 )
<a name="l00082"></a>00082                 <span class="keywordflow">return</span> <span class="keyword">false</span>;           <span class="comment">// bad name</span>
<a name="l00083"></a>00083 
<a name="l00084"></a>00084         std::istringstream iss(dbid_text);
<a name="l00085"></a>00085         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> temp;
<a name="l00086"></a>00086         iss &gt;&gt; std::hex &gt;&gt; dbid &gt;&gt; temp;
<a name="l00087"></a>00087         dbrectype = (uint8_t) temp;
<a name="l00088"></a>00088 
<a name="l00089"></a>00089         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00090"></a>00090 }
<a name="l00091"></a>00091 
<a name="l00092"></a>00092 <span class="comment"></span>
<a name="l00093"></a>00093 <span class="comment">//////////////////////////////////////////////////////////////////////////////</span>
<a name="l00094"></a>00094 <span class="comment"></span><span class="comment">// Restore - constructors</span>
<a name="l00095"></a>00095 
<a name="l00096"></a><a class="code" href="classBarry_1_1Restore.html#d23e005d6fadc20cde4c6f12e2bfa892">00096</a> Restore::Restore(<span class="keyword">const</span> std::string &amp;tarpath, <span class="keywordtype">bool</span> default_all_db)
<a name="l00097"></a>00097         : m_tarpath(tarpath)
<a name="l00098"></a>00098         , m_default_all_db(default_all_db)
<a name="l00099"></a>00099         , m_tar_record_state(RS_EMPTY)
<a name="l00100"></a>00100         , m_rec_type(0)
<a name="l00101"></a>00101         , m_unique_id(0)
<a name="l00102"></a>00102 {
<a name="l00103"></a>00103         <span class="keywordflow">try</span> {
<a name="l00104"></a>00104                 m_tar.reset( <span class="keyword">new</span> reuse::TarFile(tarpath.c_str(), <span class="keyword">false</span>,
<a name="l00105"></a>00105                                         &amp;reuse::gztar_ops_nonthread, <span class="keyword">true</span>) );
<a name="l00106"></a>00106         }
<a name="l00107"></a>00107         <span class="keywordflow">catch</span>( reuse::TarFile::TarError &amp;te ) {
<a name="l00108"></a>00108                 <span class="keywordflow">throw</span> <a class="code" href="classBarry_1_1RestoreError.html" title="Thrown by the Restore builder class when there is a problem with the low level file...">Barry::RestoreError</a>(te.what());
<a name="l00109"></a>00109         }
<a name="l00110"></a>00110 }
<a name="l00111"></a>00111 
<a name="l00112"></a>00112 Restore::~Restore()
<a name="l00113"></a>00113 {
<a name="l00114"></a>00114 }
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 <span class="comment"></span>
<a name="l00117"></a>00117 <span class="comment">//////////////////////////////////////////////////////////////////////////////</span>
<a name="l00118"></a>00118 <span class="comment"></span><span class="comment">// Restore - Protected helpers</span>
<a name="l00119"></a>00119 
<a name="l00120"></a>00120 <span class="keywordtype">bool</span> Restore::IsSelected(<span class="keyword">const</span> std::string &amp;dbName)<span class="keyword"> const</span>
<a name="l00121"></a>00121 <span class="keyword"></span>{
<a name="l00122"></a>00122         <span class="comment">// if nothing is in the list, use default</span>
<a name="l00123"></a>00123         <span class="keywordflow">if</span>( m_dbList.size() == 0 )
<a name="l00124"></a>00124                 <span class="keywordflow">return</span> m_default_all_db;
<a name="l00125"></a>00125         <span class="keywordflow">else</span>
<a name="l00126"></a>00126                 <span class="keywordflow">return</span> m_dbList.IsSelected(dbName);
<a name="l00127"></a>00127 }
<a name="l00128"></a>00128 
<a name="l00129"></a>00129 <span class="comment"></span>
<a name="l00130"></a>00130 <span class="comment">//////////////////////////////////////////////////////////////////////////////</span>
<a name="l00131"></a>00131 <span class="comment"></span><span class="comment">// Restore - Public API</span>
<a name="l00132"></a>00132 
<a name="l00133"></a><a class="code" href="classBarry_1_1Restore.html#e8d23b32bbbb26d4bd02961cd9b32262">00133</a> <span class="keywordtype">void</span> <a class="code" href="classBarry_1_1Restore.html#e8d23b32bbbb26d4bd02961cd9b32262" title="Add database name to the read filter.">Restore::AddDB</a>(<span class="keyword">const</span> std::string &amp;dbName)
<a name="l00134"></a>00134 {
<a name="l00135"></a>00135         <span class="keywordflow">if</span>( find(m_dbList.begin(), m_dbList.end(), dbName) == m_dbList.end() ) {
<a name="l00136"></a>00136                 <span class="comment">// only add it if it is not already in the list</span>
<a name="l00137"></a>00137                 m_dbList.push_back(dbName);
<a name="l00138"></a>00138         }
<a name="l00139"></a>00139 }
<a name="l00140"></a>00140 
<a name="l00141"></a><a class="code" href="classBarry_1_1Restore.html#210fba48d39754019bbbb893e404a849">00141</a> <span class="keywordtype">void</span> <a class="code" href="classBarry_1_1Restore.html#210fba48d39754019bbbb893e404a849" title="Add all database names in dblist to the read filter This function is additive.">Restore::Add</a>(<span class="keyword">const</span> DBListType &amp;dbList)
<a name="l00142"></a>00142 {
<a name="l00143"></a>00143         <span class="keywordflow">for</span>( DBListType::const_iterator i = dbList.begin();
<a name="l00144"></a>00144                 i != dbList.end();
<a name="l00145"></a>00145                 ++i )
<a name="l00146"></a>00146         {
<a name="l00147"></a>00147                 <a class="code" href="classBarry_1_1Restore.html#e8d23b32bbbb26d4bd02961cd9b32262" title="Add database name to the read filter.">AddDB</a>(*i);
<a name="l00148"></a>00148         }
<a name="l00149"></a>00149 }
<a name="l00150"></a>00150 
<a name="l00151"></a>00151 <span class="keywordtype">void</span> Restore::SkipCurrentDB()
<a name="l00152"></a>00152 {
<a name="l00153"></a>00153         <span class="comment">// skip all records until next DB</span>
<a name="l00154"></a>00154         <span class="keywordflow">try</span> {
<a name="l00155"></a>00155                 <span class="keywordflow">while</span>( Retrieve(m_record_data) == RS_NEXT ) {
<a name="l00156"></a>00156                         std::cerr &lt;&lt; <span class="stringliteral">"Skipping: "</span>
<a name="l00157"></a>00157                                 &lt;&lt; m_current_dbname &lt;&lt; <span class="stringliteral">"/"</span>
<a name="l00158"></a>00158                                 &lt;&lt; m_tar_id_text &lt;&lt; std::endl;
<a name="l00159"></a>00159                         m_tar_record_state = RS_EMPTY;
<a name="l00160"></a>00160                 }
<a name="l00161"></a>00161         }
<a name="l00162"></a>00162         <span class="keywordflow">catch</span>( reuse::TarFile::TarError &amp; ) {
<a name="l00163"></a>00163                 m_tar_record_state = RS_EOF;
<a name="l00164"></a>00164         }
<a name="l00165"></a>00165 }
<a name="l00166"></a>00166 
<a name="l00167"></a><a class="code" href="classBarry_1_1Restore.html#97e837397dbfe9e027bd5745a42011d5">00167</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classBarry_1_1Restore.html#97e837397dbfe9e027bd5745a42011d5" title="Loads the given file, and counts all records according to the current read filter...">Restore::GetRecordTotal</a>()<span class="keyword"> const</span>
<a name="l00168"></a>00168 <span class="keyword"></span>{
<a name="l00169"></a>00169         <span class="keywordflow">return</span> <a class="code" href="classBarry_1_1Restore.html#97e837397dbfe9e027bd5745a42011d5" title="Loads the given file, and counts all records according to the current read filter...">GetRecordTotal</a>(m_tarpath, m_dbList, m_default_all_db);
<a name="l00170"></a>00170 }
<a name="l00171"></a>00171 
<a name="l00172"></a><a class="code" href="classBarry_1_1Restore.html#2c57a7bbe16c2c37ff38ccb6f3d42a39">00172</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classBarry_1_1Restore.html#97e837397dbfe9e027bd5745a42011d5" title="Loads the given file, and counts all records according to the current read filter...">Restore::GetRecordTotal</a>(<span class="keyword">const</span> std::string &amp;tarpath,
<a name="l00173"></a>00173                                         <span class="keyword">const</span> DBListType &amp;dbList,
<a name="l00174"></a>00174                                         <span class="keywordtype">bool</span> default_all_db)
<a name="l00175"></a>00175 {
<a name="l00176"></a>00176         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> count = 0;
<a name="l00177"></a>00177 
<a name="l00178"></a>00178         std::auto_ptr&lt;reuse::TarFile&gt; tar;
<a name="l00179"></a>00179 
<a name="l00180"></a>00180         <span class="keywordflow">try</span> {
<a name="l00181"></a>00181                 <span class="comment">// do a scan through the tar file</span>
<a name="l00182"></a>00182                 tar.reset( <span class="keyword">new</span> reuse::TarFile(tarpath.c_str(), <span class="keyword">false</span>,
<a name="l00183"></a>00183                                 &amp;reuse::gztar_ops_nonthread, <span class="keyword">true</span>) );
<a name="l00184"></a>00184                 count = CountFiles(*tar, dbList, default_all_db);
<a name="l00185"></a>00185         }
<a name="l00186"></a>00186         <span class="keywordflow">catch</span>( reuse::TarFile::TarError &amp;te ) {
<a name="l00187"></a>00187                 <span class="keywordflow">throw</span> <a class="code" href="classBarry_1_1RestoreError.html" title="Thrown by the Restore builder class when there is a problem with the low level file...">Barry::RestoreError</a>(te.what());
<a name="l00188"></a>00188         }
<a name="l00189"></a>00189         <span class="keywordflow">return</span> count;
<a name="l00190"></a>00190 }
<a name="l00191"></a>00191 
<a name="l00192"></a><a class="code" href="classBarry_1_1Restore.html#ca46f9c51a68eb3872f98a73bdcd226c">00192</a> <span class="keywordtype">bool</span> <a class="code" href="classBarry_1_1Restore.html#ca46f9c51a68eb3872f98a73bdcd226c" title="If this function returns true, it fills data with the meta data that the next call...">Restore::GetNextMeta</a>(<a class="code" href="classBarry_1_1DBData.html" title="Database record data class.">DBData</a> &amp;data)
<a name="l00193"></a>00193 {
<a name="l00194"></a>00194         <span class="comment">// always use m_record_data here, so that we don't lose access</span>
<a name="l00195"></a>00195         <span class="comment">// to the actual record data for future calls to BuildRecord()</span>
<a name="l00196"></a>00196         <span class="comment">// and FetchRecord()</span>
<a name="l00197"></a>00197         <span class="keywordflow">if</span>( m_tar_record_state == RS_EMPTY ) {
<a name="l00198"></a>00198                 Retrieve(m_record_data);
<a name="l00199"></a>00199         }
<a name="l00200"></a>00200 
<a name="l00201"></a>00201         <span class="comment">// fill in the meta data that will be returned in the next call</span>
<a name="l00202"></a>00202         <span class="comment">// to BuildRecord() or FetchRecord()... this is only valid if</span>
<a name="l00203"></a>00203         <span class="comment">// the state is RS_NEXT</span>
<a name="l00204"></a>00204         <span class="keywordflow">switch</span>( m_tar_record_state )
<a name="l00205"></a>00205         {
<a name="l00206"></a>00206         <span class="keywordflow">case</span> RS_NEXT:
<a name="l00207"></a>00207                 data.<a class="code" href="classBarry_1_1DBData.html#d1a3e69cabea68e0a309459cd7c58e78">SetVersion</a>(Barry::DBData::REC_VERSION_1);
<a name="l00208"></a>00208                 data.<a class="code" href="classBarry_1_1DBData.html#55d6bde680fe0b48d07882ade96ef9c3">SetDBName</a>(m_current_dbname);
<a name="l00209"></a>00209                 data.<a class="code" href="classBarry_1_1DBData.html#a46147fced1b122cb6a0e6d1cee3cb07">SetIds</a>(m_rec_type, m_unique_id);
<a name="l00210"></a>00210                 data.<a class="code" href="classBarry_1_1DBData.html#cb569139ee2d44442d4709ccf2a4ab3c">SetOffset</a>(0);
<a name="l00211"></a>00211                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00212"></a>00212 
<a name="l00213"></a>00213         <span class="keywordflow">default</span>:
<a name="l00214"></a>00214                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00215"></a>00215         }
<a name="l00216"></a>00216 }
<a name="l00217"></a>00217 
<a name="l00218"></a>00218 <span class="comment"></span>
<a name="l00219"></a>00219 <span class="comment">//////////////////////////////////////////////////////////////////////////////</span>
<a name="l00220"></a>00220 <span class="comment"></span><span class="comment">// Barry::Builder overrides</span>
<a name="l00221"></a>00221 
<a name="l00222"></a>00222 Restore::RetrievalState Restore::Retrieve(Data &amp;record_data)
<a name="l00223"></a>00223 {
<a name="l00224"></a>00224         <span class="comment">// don't do anything unless we're empty</span>
<a name="l00225"></a>00225         <span class="keywordflow">if</span>( m_tar_record_state != RS_EMPTY )
<a name="l00226"></a>00226                 <span class="keywordflow">return</span> m_tar_record_state;
<a name="l00227"></a>00227 
<a name="l00228"></a>00228         <span class="comment">// search for a valid record</span>
<a name="l00229"></a>00229         <span class="keywordflow">for</span>(;;) {
<a name="l00230"></a>00230                 <span class="comment">// load record data from tar file</span>
<a name="l00231"></a>00231                 std::string filename;
<a name="l00232"></a>00232                 <span class="keywordflow">if</span>( !m_tar-&gt;ReadNextFile(filename, record_data) ) {
<a name="l00233"></a>00233                         <span class="comment">// assume end of file</span>
<a name="l00234"></a>00234                         <span class="keywordflow">return</span> m_tar_record_state = RS_EOF;
<a name="l00235"></a>00235                 }
<a name="l00236"></a>00236                 m_tar_record_state = RS_UNKNOWN;
<a name="l00237"></a>00237 
<a name="l00238"></a>00238                 <span class="comment">// split record filename into dbname and ID</span>
<a name="l00239"></a>00239                 std::string dbname;
<a name="l00240"></a>00240                 <span class="keywordflow">if</span>( !<a class="code" href="classBarry_1_1Restore.html#eed51b73f7d5125ae655af0a965a8113" title="Splits a tarpath of the form &amp;quot;DBName/DBID&amp;quot; into separate string values...">SplitTarPath</a>(filename, dbname, m_tar_id_text, m_rec_type, m_unique_id) ) {
<a name="l00241"></a>00241                         <span class="comment">// invalid filename, skip it</span>
<a name="l00242"></a>00242                         std::cerr &lt;&lt; <span class="stringliteral">"Skipping invalid tar record: "</span> &lt;&lt; filename &lt;&lt; std::endl;
<a name="l00243"></a>00243                         <span class="keywordflow">continue</span>;
<a name="l00244"></a>00244                 }
<a name="l00245"></a>00245 
<a name="l00246"></a>00246                 <span class="comment">// are we working on the same dbname as last time?</span>
<a name="l00247"></a>00247                 <span class="comment">// if so, go ahead!</span>
<a name="l00248"></a>00248                 <span class="keywordflow">if</span>( m_current_dbname == dbname ) {
<a name="l00249"></a>00249                         <span class="keywordflow">return</span> m_tar_record_state = RS_NEXT;
<a name="l00250"></a>00250                 }
<a name="l00251"></a>00251 
<a name="l00252"></a>00252                 <span class="comment">// DIFFERENT DBNAME from here on down!</span>
<a name="l00253"></a>00253                 m_tar_record_state = RS_DBEND;
<a name="l00254"></a>00254 
<a name="l00255"></a>00255                 <span class="comment">// does the filter allow this record?</span>
<a name="l00256"></a>00256                 <span class="comment">// if not, skip it and continue looking</span>
<a name="l00257"></a>00257                 <span class="keywordflow">if</span>( !IsSelected(dbname) ) {
<a name="l00258"></a>00258                         <span class="keywordflow">continue</span>;
<a name="l00259"></a>00259                 }
<a name="l00260"></a>00260 
<a name="l00261"></a>00261                 <span class="comment">// all checks pass, load the new dbname, and return DBEND</span>
<a name="l00262"></a>00262                 <span class="comment">// if we are on a dbname boundary</span>
<a name="l00263"></a>00263                 <span class="keywordflow">if</span>( m_current_dbname.size() == 0 ) {
<a name="l00264"></a>00264                         <span class="comment">// this is the first time through Retrieve, so ok</span>
<a name="l00265"></a>00265                         m_tar_record_state = RS_NEXT;
<a name="l00266"></a>00266                 }
<a name="l00267"></a>00267 
<a name="l00268"></a>00268                 m_current_dbname = dbname;
<a name="l00269"></a>00269                 <span class="keywordflow">return</span> m_tar_record_state;
<a name="l00270"></a>00270         }
<a name="l00271"></a>00271 }
<a name="l00272"></a>00272 
<a name="l00273"></a><a class="code" href="classBarry_1_1Restore.html#59f9e2d2e9dd3d7c40588416b27b5ee7">00273</a> <span class="keywordtype">bool</span> <a class="code" href="classBarry_1_1Restore.html#59f9e2d2e9dd3d7c40588416b27b5ee7" title="Called to build the record field data.">Restore::BuildRecord</a>(<a class="code" href="classBarry_1_1DBData.html" title="Database record data class.">Barry::DBData</a> &amp;data,
<a name="l00274"></a>00274                           <span class="keywordtype">size_t</span> &amp;offset,
<a name="l00275"></a>00275                           <span class="keyword">const</span> <a class="code" href="classBarry_1_1IConverter.html" title="Main charset conversion class, primarily focused on converting between the Blackberry...">Barry::IConverter</a> *ic)
<a name="l00276"></a>00276 {
<a name="l00277"></a>00277         <span class="comment">// in this case, we are loading into m_record_data anyway,</span>
<a name="l00278"></a>00278         <span class="comment">// so no special handling is needed, like FetchRecord() needs.</span>
<a name="l00279"></a>00279         <span class="keywordflow">switch</span>( Retrieve(m_record_data) )
<a name="l00280"></a>00280         {
<a name="l00281"></a>00281         <span class="keywordflow">case</span> RS_NEXT:
<a name="l00282"></a>00282                 {
<a name="l00283"></a>00283                         data.<a class="code" href="classBarry_1_1DBData.html#d1a3e69cabea68e0a309459cd7c58e78">SetVersion</a>(Barry::DBData::REC_VERSION_1);
<a name="l00284"></a>00284                         data.<a class="code" href="classBarry_1_1DBData.html#55d6bde680fe0b48d07882ade96ef9c3">SetDBName</a>(m_current_dbname);
<a name="l00285"></a>00285                         data.<a class="code" href="classBarry_1_1DBData.html#a46147fced1b122cb6a0e6d1cee3cb07">SetIds</a>(m_rec_type, m_unique_id);
<a name="l00286"></a>00286                         data.<a class="code" href="classBarry_1_1DBData.html#cb569139ee2d44442d4709ccf2a4ab3c">SetOffset</a>(offset);
<a name="l00287"></a>00287 
<a name="l00288"></a>00288                         <span class="keywordtype">int</span> packet_size = offset + m_record_data.GetSize();
<a name="l00289"></a>00289                         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *buf = data.<a class="code" href="classBarry_1_1DBData.html#3c1c4ad5ce85cef0ea85002a0fe07881">UseData</a>().GetBuffer(packet_size);
<a name="l00290"></a>00290                         memcpy(buf + offset, m_record_data.GetData(), m_record_data.GetSize());
<a name="l00291"></a>00291                         offset += m_record_data.GetSize();
<a name="l00292"></a>00292                         data.<a class="code" href="classBarry_1_1DBData.html#3c1c4ad5ce85cef0ea85002a0fe07881">UseData</a>().ReleaseBuffer(packet_size);
<a name="l00293"></a>00293 
<a name="l00294"></a>00294                         <span class="comment">// clear loaded flag, as it has now been used</span>
<a name="l00295"></a>00295                         m_tar_record_state = RS_EMPTY;
<a name="l00296"></a>00296                         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00297"></a>00297                 }
<a name="l00298"></a>00298 
<a name="l00299"></a>00299         <span class="keywordflow">case</span> RS_EMPTY:
<a name="l00300"></a>00300         <span class="keywordflow">case</span> RS_UNKNOWN:
<a name="l00301"></a>00301         <span class="keywordflow">default</span>:
<a name="l00302"></a>00302                 <span class="keywordflow">throw</span> std::logic_error(<span class="stringliteral">"Invalid state in Restore::BuildRecord()"</span>);
<a name="l00303"></a>00303 
<a name="l00304"></a>00304         <span class="keywordflow">case</span> RS_DBEND:
<a name="l00305"></a>00305                 <span class="comment">// process the end of database by returning false</span>
<a name="l00306"></a>00306                 <span class="comment">// the next round will be valid, so set to RS_NEXT</span>
<a name="l00307"></a>00307                 m_tar_record_state = RS_NEXT;
<a name="l00308"></a>00308                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00309"></a>00309 
<a name="l00310"></a>00310         <span class="keywordflow">case</span> RS_EOF:
<a name="l00311"></a>00311                 <span class="comment">// always return false at end of file</span>
<a name="l00312"></a>00312                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00313"></a>00313         }
<a name="l00314"></a>00314 }
<a name="l00315"></a>00315 
<a name="l00316"></a><a class="code" href="classBarry_1_1Restore.html#fc3e4162a0ae1c19d338126d920abb57">00316</a> <span class="keywordtype">bool</span> <a class="code" href="classBarry_1_1Restore.html#fc3e4162a0ae1c19d338126d920abb57" title="Same as BuildRecord, but does not care about any offsets.">Restore::FetchRecord</a>(<a class="code" href="classBarry_1_1DBData.html" title="Database record data class.">Barry::DBData</a> &amp;data, <span class="keyword">const</span> <a class="code" href="classBarry_1_1IConverter.html" title="Main charset conversion class, primarily focused on converting between the Blackberry...">Barry::IConverter</a> *ic)
<a name="l00317"></a>00317 {
<a name="l00318"></a>00318         <span class="comment">// if the record has not yet been loaded, we can optimize</span>
<a name="l00319"></a>00319         <span class="comment">// the buffer, and pass in our own... otherwise, just copy</span>
<a name="l00320"></a>00320         <span class="comment">// the current buffer from m_record_data</span>
<a name="l00321"></a>00321         <span class="comment">//</span>
<a name="l00322"></a>00322         <span class="comment">// it is assumed here that Builder users will not alternate</span>
<a name="l00323"></a>00323         <span class="comment">// between calls to BuildRecord() and FetchRecord()</span>
<a name="l00324"></a>00324         <span class="comment">//</span>
<a name="l00325"></a>00325         <span class="keywordflow">if</span>( m_tar_record_state == RS_EMPTY ) {
<a name="l00326"></a>00326                 <span class="comment">// BUT, if RS_DBEND is the next value, then we need</span>
<a name="l00327"></a>00327                 <span class="comment">// to save the data for the next round... this</span>
<a name="l00328"></a>00328                 <span class="comment">// optimization is almost more bother than it's worth :-)</span>
<a name="l00329"></a>00329                 <span class="keywordflow">if</span>( Retrieve(data.<a class="code" href="classBarry_1_1DBData.html#3c1c4ad5ce85cef0ea85002a0fe07881">UseData</a>()) == RS_DBEND ) {
<a name="l00330"></a>00330                         m_record_data = data.<a class="code" href="classBarry_1_1DBData.html#a7cacc9655376447ffbf3aa4d664a03b">GetData</a>();
<a name="l00331"></a>00331                         m_tar_record_state = RS_NEXT;
<a name="l00332"></a>00332                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00333"></a>00333                 }
<a name="l00334"></a>00334         }
<a name="l00335"></a>00335         <span class="keywordflow">else</span> {
<a name="l00336"></a>00336                 data.<a class="code" href="classBarry_1_1DBData.html#3c1c4ad5ce85cef0ea85002a0fe07881">UseData</a>() = m_record_data;
<a name="l00337"></a>00337         }
<a name="l00338"></a>00338 
<a name="l00339"></a>00339         <span class="keywordflow">switch</span>( m_tar_record_state )
<a name="l00340"></a>00340         {
<a name="l00341"></a>00341         <span class="keywordflow">case</span> RS_NEXT:
<a name="l00342"></a>00342                 data.<a class="code" href="classBarry_1_1DBData.html#d1a3e69cabea68e0a309459cd7c58e78">SetVersion</a>(Barry::DBData::REC_VERSION_1);
<a name="l00343"></a>00343                 data.<a class="code" href="classBarry_1_1DBData.html#55d6bde680fe0b48d07882ade96ef9c3">SetDBName</a>(m_current_dbname);
<a name="l00344"></a>00344                 data.<a class="code" href="classBarry_1_1DBData.html#a46147fced1b122cb6a0e6d1cee3cb07">SetIds</a>(m_rec_type, m_unique_id);
<a name="l00345"></a>00345                 data.<a class="code" href="classBarry_1_1DBData.html#cb569139ee2d44442d4709ccf2a4ab3c">SetOffset</a>(0);
<a name="l00346"></a>00346 
<a name="l00347"></a>00347                 <span class="comment">// clear loaded flag, as it has now been used</span>
<a name="l00348"></a>00348                 m_tar_record_state = RS_EMPTY;
<a name="l00349"></a>00349                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00350"></a>00350 
<a name="l00351"></a>00351         <span class="keywordflow">case</span> RS_EMPTY:
<a name="l00352"></a>00352         <span class="keywordflow">case</span> RS_UNKNOWN:
<a name="l00353"></a>00353         <span class="keywordflow">default</span>:
<a name="l00354"></a>00354                 <span class="keywordflow">throw</span> std::logic_error(<span class="stringliteral">"Invalid state in Restore::FetchRecord()"</span>);
<a name="l00355"></a>00355 
<a name="l00356"></a>00356         <span class="keywordflow">case</span> RS_DBEND:
<a name="l00357"></a>00357                 <span class="comment">// process the end of database by returning false</span>
<a name="l00358"></a>00358                 <span class="comment">// the next round will be valid, so set to RS_NEXT</span>
<a name="l00359"></a>00359                 m_tar_record_state = RS_NEXT;
<a name="l00360"></a>00360                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00361"></a>00361 
<a name="l00362"></a>00362         <span class="keywordflow">case</span> RS_EOF:
<a name="l00363"></a>00363                 <span class="comment">// always return false at end of file</span>
<a name="l00364"></a>00364                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00365"></a>00365         }
<a name="l00366"></a>00366 }
<a name="l00367"></a>00367 
<a name="l00368"></a><a class="code" href="classBarry_1_1Restore.html#4d8f64fce3b905a756185e1a9ca0c09e">00368</a> <span class="keywordtype">bool</span> <a class="code" href="classBarry_1_1Restore.html#4d8f64fce3b905a756185e1a9ca0c09e" title="Sometimes a builder can have multiple databases stored in it, so when Build/Fetch...">Restore::EndOfFile</a>()<span class="keyword"> const</span>
<a name="l00369"></a>00369 <span class="keyword"></span>{
<a name="l00370"></a>00370         <span class="keywordflow">return</span> m_tar_record_state == RS_EOF;
<a name="l00371"></a>00371 }
<a name="l00372"></a>00372 
<a name="l00373"></a>00373 } <span class="comment">// namespace Barry</span>
<a name="l00374"></a>00374 
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Tue Mar 1 17:50:16 2011 for Barry by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>