⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iohandler.htm

📁 The goal of this library is to make ODBC recordsets look just like an STL container. As a user, you
💻 HTM
📖 第 1 页 / 共 2 页
字号:
	TIMESTAMP_STRUCT paramDate = {2000, 1, 1, 0, 0, 0, 0};
	read_it.Params().dateValue = paramDate;

	for ( ; read_it != view.end(); read_it++)
	{
	try
		{
		  <span class="codeComment">// note that the read_iterator::GetLastCount()  is incremented in operator++()
		  // remember that the record is fetched and thus the count incremented
		  // before operator*() is applied to the read_iterator</span>

		  cout &lt;&lt; &quot;Reading element #&quot; &lt;&lt; read_it.GetLastCount() &lt;&lt; endl;
		  
		  cout &lt;&lt; &quot;read_it-&gt;exampleInt = &quot; &lt;&lt; read_it-&gt;exampleInt &lt;&lt; endl;
		  cout &lt;&lt; &quot;read_it-&gt;exampleStr = &quot; &lt;&lt; read_it-&gt;exampleStr &lt;&lt; endl;
		  
		  results.push_back(*read_it);
		}
		catch (RootException &amp;ex)
		{
		  cout &lt;&lt; &quot;Caught Exception!!!!&quot; &lt;&lt; endl;
		  cout &lt;&lt; ex.what() &lt;&lt; endl;
		}
	}

	LoggingHandler&lt;Example&gt; handler = 
		read_it.get_io_handler((LoggingHandler&lt;Example&gt; *) NULL);

	typedef LoggingHandler&lt;Example&gt;::LoggedTriple LoggedTriple;

	vector&lt;LoggedTriple&gt; errors = handler.GetLog();

	for (vector&lt;LoggedTriple&gt;::iterator log_it = errors.begin(); log_it != errors.end();
			log_it++)
	{
		LoggedTriple error = *log_it;

		cout &lt;&lt; &quot;Error msg = &quot; &lt;&lt; error.errmsg &lt;&lt; endl;
		cout &lt;&lt; &quot;Example = &quot; &lt;&lt; error.dataObj &lt;&lt; endl;
	}

}
</code></pre>


 </p>

<h3>Example 2: A Heroic Error Handler</h3>

<p><pre><code><span class="codeComment">// Let's Use our X-Ray Vision to Look at the Innards of our Hero</span>


template&lt;class DataObj, class ParamObj = DefaultParamObj&lt;DataObj&gt; &gt; class OurHeroicHandler
{
private:
	<span class="codeComment">// ... some state data, but assume handler is default constructible</span>
public:

	dtl_ios_base::MeansOfRecovery
		operator()(RootException &amp;ex, dtl_ios_base &amp;base,
		   DataObj &amp;data, ParamObj &amp;params)
	{
		<span class="codeComment">// example of what you might do in a handler</span>
		if (bad())
		{
			LogErrorToFile(ex);
			return dtl_ios_base::THROW_EXCEPTION;
		}
		else if (fail())
		{
			<span class="codeComment">// tries to make the DataObj valid and then reapplies previous operation
			// to base on the good object ... may still fail</span>
			bool failed = WorkMagicOnDataObjAndTryAgain(...);

			if (failed)
			{
				LogErrorToFile(ex);
				return dtl_ios_base::THROW_EXCEPTION;
			}
			else
				return dtl_ios_base::SUPPRESS_ERROR; <span class="codeComment">// success ... our superhero
								     // has saved the day!</span>
		}
	}
};
</code></pre>

 </p>

<h3>Public Base Classes</h3>

<p>None.</p>

<h3>Template parameters</h3>

<table border="1">
<TBODY>    <tr>
        <th>Parameter </th>
        <th>Description </th>
        <th>Default </th>
    </tr>
    <tr>
        <td valign="top"><tt>DataObj</tt> </td>
        <td valign="top">The value type of objects in a <font
        size="2" face="Courier New">DBView</font>. </td>
        <td valign="top">&nbsp; </td>
    </tr>
    <tr>
        <td valign="top"><tt>ParamObj</tt> </td>
        <td valign="top">The type of object used to specify the
        postfix parameters to the <font size="2"
        face="Courier New">DBView</font>.</td>
        <td valign="top"><font size="2" face="Courier New">DefaultParamObj&lt;DataObj&gt;</font>&nbsp;
        </td>
    </tr>
</TBODY></table>

<p>&nbsp;</p>

<h3>Notation</h3>

<table border="0">
    <tr>
        <td valign="top"><tt>X</tt> </td>
        <td valign="top">A type that is a model of <font size="2"
        face="Courier New">IOHandler</font></td>
    </tr>
    <tr>
        <td valign="top"><tt>a</tt> </td>
        <td valign="top">Object of type <tt>X</tt> </td>
    </tr>
</table>

<h3>Expression semantics</h3>

<table border="1">
    <tr>
        <th>Name </th>
        <th>Expression </th>
        <th>Precondition </th>
        <th>Semantics </th>
        <th>Postcondition </th>
    </tr>
    <tr>
        <td valign="top">Default constructor </td>
        <td valign="top"><pre>X a()</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Construct the function object.</td>
        <td valign="top">&nbsp;</td>
    </tr>
    <tr>
        <td valign="top">Copy constructor </td>
        <td valign="top"><pre>X a(constX &amp;b)</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Copy construct the <font size="2"
        face="Courier New">IOHandler</font>.</td>
        <td valign="top">&nbsp;</td>
    </tr>
    <tr>
        <td valign="top"><font size="2" face="Courier New">UserHandler</font>
        constructor</td>
        <td valign="top"><pre>template&lt;class UserHandler&gt; a(const UserHandler hb)</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Construct the <font size="2"
        face="Courier New">IOHandler</font> using the user-defined
        handler ( it's type is bound to the <font size="2"
        face="Courier New">UserHandler </font>template parameter)
        passed in (the example classes above declare such
        handlers)..</td>
        <td valign="top">&nbsp;</td>
    </tr>
    <tr>
        <td>Assignment Operator</td>
        <td><font size="2" face="Courier New">X operator=(const X
        &amp;b)</font></td>
        <td>&nbsp;</td>
        <td>Assign the <font size="2" face="Courier New">IOHandler</font>.</td>
        <td>&nbsp;</td>
    </tr>
    <tr>
        <td valign="top">Handle exception operator</td>
        <td valign="top"><pre>dtl_ios_base::MeansOfRecovery operator()(RootException &amp;ex, dtl_ios_base &amp;base, DataObj &amp;data, ParamObj &amp;params)</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">This operator takes references to the
        thrown <font size="2" face="Courier New">RootException</font>
        object, the <font size="2" face="Courier New">dtl_ios_base</font>
        (iterator) which threw, and the <font size="2"
        face="Courier New">DataObj </font>and <font size="2"
        face="Courier New">ParamObj </font>relevant to the
        exception. Handles the exception and then returns whether
        the iterator should suppress the error (<font size="2"
        face="Courier New">dtl_ios_base::SUPPRESS_ERROR</font>)
        or whether to still throw the exception (<font size="2"
        face="Courier New">dtl_ios_base::THROW_EXCEPTION</font>).
        </td>
        <td valign="top">&nbsp;</td>
    </tr>
    <tr>
        <td valign="top">Get <font size="2" face="Courier New">UserHandler</font></td>
        <td valign="top"><pre>template&lt;class UserHandler&gt; const UserHandler &amp;
   get(const UserHandler *dummy) const</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Returns the user-defined handler ( it's
        type is bound to the <font size="2" face="Courier New">UserHandler
        </font>template parameter). You must pass in a pointer to
        your user-defined handler's type so the compiler knows
        what type <font size="2" face="Courier New">UserHandler </font><font
        size="3">should be as in:</font><p><font size="2"
        face="Courier New">MyHandler my_handler = io_handler.get((MyHandler
        *) NULL);</font></p>
        </td>
        <td valign="top">&nbsp;</td>
    </tr>
</table>

<p>&nbsp;</p>

<h3>Notes</h3>


<h3>See also</h3>

<p><a href="AlwaysThrowsHandler.htm"><font size="2"
face="Courier New">AlwaysThrowsHandler</font></a><font size="2"
face="Courier New">, </font><a href="LoggingHandler.htm"><font
size="2" face="Courier New">LoggingHandler</font></a><font
size="2" face="Courier New">, </font><a href="DBView.htm"><font
size="2" face="Courier New">DBView</font></a><font size="2"
face="Courier New">, </font><a href="IndexedDBView.htm"><font
size="2" face="Courier New">IndexedDBView</font><font size="2"><!--start footer--></font></a></p>

<p>
<hr>

<p><a href="index.htm"><img src="dtl_home.gif" alt="[DTL Home]"
width="54" height="54"></a> <br>
</p>

<p>Copyright 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -