📄 iohandler.htm
字号:
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 << "Reading element #" << read_it.GetLastCount() << endl;
cout << "read_it->exampleInt = " << read_it->exampleInt << endl;
cout << "read_it->exampleStr = " << read_it->exampleStr << endl;
results.push_back(*read_it);
}
catch (RootException &ex)
{
cout << "Caught Exception!!!!" << endl;
cout << ex.what() << endl;
}
}
LoggingHandler<Example> handler =
read_it.get_io_handler((LoggingHandler<Example> *) NULL);
typedef LoggingHandler<Example>::LoggedTriple LoggedTriple;
vector<LoggedTriple> errors = handler.GetLog();
for (vector<LoggedTriple>::iterator log_it = errors.begin(); log_it != errors.end();
log_it++)
{
LoggedTriple error = *log_it;
cout << "Error msg = " << error.errmsg << endl;
cout << "Example = " << error.dataObj << 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<class DataObj, class ParamObj = DefaultParamObj<DataObj> > class OurHeroicHandler
{
private:
<span class="codeComment">// ... some state data, but assume handler is default constructible</span>
public:
dtl_ios_base::MeansOfRecovery
operator()(RootException &ex, dtl_ios_base &base,
DataObj &data, ParamObj &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"> </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<DataObj></font>
</td>
</tr>
</TBODY></table>
<p> </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"> </td>
<td valign="top">Construct the function object.</td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top">Copy constructor </td>
<td valign="top"><pre>X a(constX &b)</pre>
</td>
<td valign="top"> </td>
<td valign="top">Copy construct the <font size="2"
face="Courier New">IOHandler</font>.</td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top"><font size="2" face="Courier New">UserHandler</font>
constructor</td>
<td valign="top"><pre>template<class UserHandler> a(const UserHandler hb)</pre>
</td>
<td valign="top"> </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"> </td>
</tr>
<tr>
<td>Assignment Operator</td>
<td><font size="2" face="Courier New">X operator=(const X
&b)</font></td>
<td> </td>
<td>Assign the <font size="2" face="Courier New">IOHandler</font>.</td>
<td> </td>
</tr>
<tr>
<td valign="top">Handle exception operator</td>
<td valign="top"><pre>dtl_ios_base::MeansOfRecovery operator()(RootException &ex, dtl_ios_base &base, DataObj &data, ParamObj &params)</pre>
</td>
<td valign="top"> </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"> </td>
</tr>
<tr>
<td valign="top">Get <font size="2" face="Courier New">UserHandler</font></td>
<td valign="top"><pre>template<class UserHandler> const UserHandler &
get(const UserHandler *dummy) const</pre>
</td>
<td valign="top"> </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"> </td>
</tr>
</table>
<p> </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 + -