📄 cb_ptr_fun.htm
字号:
<html>
<head>
<style>
CODE {COLOR: #990000;}
.code{COLOR: #990000}
.codeComment{COLOR: #008000}
.codeHighlight{BACKGROUND-COLOR: #FFFF00}
.codeFileName{FONT-WEIGHT: bold;}
</style>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="Author" content="Mike Gradman">
<meta name="KeyWords"
content="DTL, Oracle, ODBC, database API, C++, Template Library">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<!--
-- Copyright 2000
-- Michael Gradman & Corwin Joy
--
-- Permission to use, copy, modify, distribute and sell this software
-- and its documentation for any purpose is hereby granted without fee,
-- provided that the above copyright notice appears in all copies and
-- that both that copyright notice and this permission notice appear
-- in supporting documentation. Corwin Joy & Michael Gradman make no
-- representations about the suitability of this software for any
-- purpose. It is provided "as is" without express or implied warranty.
--
--
-- Copyright (c) 1996-1999
-- Silicon Graphics Computer Systems, Inc.
--
-- Permission to use, copy, modify, distribute and sell this software
-- and its documentation for any purpose is hereby granted without fee,
-- provided that the above copyright notice appears in all copies and
-- that both that copyright notice and this permission notice appear
-- in supporting documentation. Silicon Graphics makes no
-- representations about the suitability of this software for any
-- purpose. It is provided "as is" without express or implied warranty.
--
-- Copyright (c) 1994
-- Hewlett-Packard Company
--
-- Permission to use, copy, modify, distribute and sell this software
-- and its documentation for any purpose is hereby granted without fee,
-- provided that the above copyright notice appears in all copies and
-- that both that copyright notice and this permission notice appear
-- in supporting documentation. Hewlett-Packard Company makes no
-- representations about the suitability of this software for any
-- purpose. It is provided "as is" without express or implied warranty.
--
-->
<!-- Generated by htmldoc -->
<title>cb_ptr_fun() and cb_ptr_fun_w_ret()</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000EE"
vlink="#551A8B" alink="#FF0000">
<p><font size="6" face="Bookman Old Style"><em><strong><u>dtl</u></strong></em></font></p>
<p><img src="stat.gif" width="6" height="6"> <!--end header--> <br>
</p>
<h1>cb_ptr_fun() and cb_ptr_fun_w_ret()</h1>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td><img src="utilities.gif" width="194" height="38"></td>
<td align="right"><img src="concept.gif" width="194"
height="39"></td>
</tr>
<tr>
<td valign="top"><b>Category</b>: utilities</td>
<td align="right" valign="top"><b>Component type</b>:
concept</td>
</tr>
</table>
<h3>Description</h3>
<p>Use the <font size="2" face="Courier New">cb_ptr_fun() </font><font
size="3">and</font><font size="2" face="Courier New">
cb_ptr_fun_w_ret() </font>template helper functions to wrap a raw
function pointer into a function object. This mechanism allows
you write regular C++ functions for use as a <a href="BCA.htm"><font
size="2" face="Courier New">BCA</font></a> , <a href="BPA.htm"><font
size="2" face="Courier New">BPA</font></a>, <a href="InsVal.htm"><font
size="2" face="Courier New">InsVal</font></a>, <a
href="SelVal.htm"><font size="2" face="Courier New">SelVal</font></a>,
<a href="IOHandler.htm"><font size="2" face="Courier New">IOHandler</font></a>,
or <font size="2" face="Courier New">SetParamsFn</font> in an <a href="IndexedDBView.htm"><font
size="2" face="Courier New">IndexedDBView</font></a><font size="3">. Both </font><font
size="2" face="Courier New">cb_ptr_fun() </font><font size="3">and</font><font
size="2" face="Courier New"> cb_ptr_fun_w_ret() </font>take a raw
function pointer as their only argument. Use <font size="2"
face="Courier New">cb_ptr_fun() </font><font size="3">for
functions that do not return a value (return</font><font size="2">
</font><font size="2" face="Courier New">void</font><font
size="3">) and </font><font size="2" face="Courier New">cb_ptr_fun_w_ret()
</font><font size="3">for functions that do return a value. You
may wrap any C++ function that contains up to and including 4
arguments.</font></p>
<h3>Definition</h3>
<p>Defined in the <font size="2" face="Courier New">variant_cc.h </font><font
size="3">header file. </font></p>
<h3>Refinement of</h3>
<p>None.</p>
<h3>Associated types</h3>
<p><a href="BPA.htm"><font size="2" face="Courier New">BPA</font></a><font
size="2" face="Courier New">, </font><a href="BCA.htm"><font
size="2" face="Courier New">BCA</font></a><font size="2"
face="Courier New">, </font><a href="InsVal.htm"><font size="2"
face="Courier New">InsVal</font></a><font size="2"
face="Courier New">, </font><a href="SelVal.htm"><font size="2"
face="Courier New">SelVal</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></a>, <font size="2"
face="Courier New">, </font><a href="IOHandler.htm"><font
size="2" face="Courier New">IOHandler</font></a></p>
<h3>Example 1:</h3>
<p><pre><code><span class="codeComment">//Simple use of cb_ptr_fun() with a BCA
// a BCA written as a simple function </span>
void BCAExample(BoundIOs &cols, Example &row)
{
cols["INT_VALUE"] == row.exampleInt;
cols["STRING_VALUE"] == row.exampleStr;
cols["DOUBLE_VALUE"] == row.exampleDouble;
cols["EXAMPLE_LONG"] == row.exampleLong;
cols["EXAMPLE_DATE"] == row.exampleDate;
}
<span class="codeComment">// Read the contents of the DB_EXAMPLE table and return a vector of the
// resulting rows</span>
vector<Example> ReadData()
{
vector<Example> results;
<span class="codeComment">// the call to cb_ptr_fun() wraps BCAExample in a function object
// so DTL may use it as the BCA for the DBView</span>
DBView<Example> view("DB_EXAMPLE", cb_ptr_fun(BCAExample));
DBView<Example>::select_iterator read_it = view.begin();
for ( ; read_it != view.end(); ++read_it)
{
results.push_back(*read_it);
}
return results;
}
</code></pre> </p>
<p> </p>
<h3>Example 2:</h3>
<p><pre><code><span class="codeComment">//Simple use of cb_ptr_fun_w_ret() as a SelVal</span>
<span class="codeComment">// a typical SelVal function that we want to use in DTL
// an Example object is valid if all columns have a value</span>
bool ExampleSelValidate(boundIOs &boundIOs, Example &rowbuf)
{
for (BoundIOs::iterator b_it = boundIOs.begin();
b_it != boundIOs.end(); b_it++)
{
BoundIO &boundIO = (*b_it).second;
if (boundIO.IsColumn() && boundIO.IsNull())
return false; <span class="codeComment">// found null column ... data is invalid</span>
}
return true; <span class="codeComment">// no nulls found ... data is OK</span>
}
<span class="codeComment">// Read the contents of the DB_EXAMPLE table and return a vector of the
// resulting rows</span>
vector<Example> ReadData()
{
vector<Example> results;
<span class="codeComment">// the call to cb_ptr_fun_w_ret() wraps ExampleSelValidate in a function object
// so DTL may use it as the SelVal for the DBView</span>
DBView<Example> view("DB_EXAMPLE", DefaultBCA<Example>(),
"", DefaultBPA<Example>(), cb_ptr_fun_w_ret(ExampleSelValidate));
DBView<Example>::select_iterator read_it = view.begin();
for ( ; read_it != view.end(); ++read_it)
{
results.push_back(*read_it);
}
return results;
}
</code></pre> </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">BoundIO</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">Wrap function ptr. for functions
returning <font size="2" face="Courier New">void </font></td>
<td valign="top"><pre>cb_ptr_fun(func_ptr)</pre>
</td>
<td valign="top"> </td>
<td valign="top">Wraps the raw function pointer <font
size="2" face="Courier New">func_ptr </font>into a
function object in the <a href="#foot1"><font size="2"
face="Courier New">CBFunctor</font></a> family. See Note <a
href="#foot1">[1]</a>.</td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top">Wrap function ptr. for functions
returning a value<font size="2" face="Courier New"> </font></td>
<td valign="top"><pre>cb_ptr_fun_w_ret(func_ptr)</pre>
</td>
<td valign="top"> </td>
<td valign="top">Wraps the raw function pointer <font
size="2" face="Courier New">func_ptr</font> into a
function object in the <a href="#foot1"><font size="2"
face="Courier New">CBFunctor</font></a> family.See Note <a
href="#foot1">[1]</a>.</td>
<td valign="top"> </td>
<td valign="top"> </td>
</tr>
</table>
<h3>Notes</h3>
<p><a name="foot1">[1] </a>The CBFunctor family of functions is
defined in the C++ Callback Library created by Rich Hickey. For
information, go to <a href="http://www.bestweb.net/~rhickey/">http://www.bestweb.net/~rhickey/</a>.
Much of the DTL implementation uses a modified and extended form
of this library wherever function objects are required.</p>
<h3>See also</h3>
<p><a href="BPA.htm"><font size="2" face="Courier New">BPA</font></a><font
size="2" face="Courier New">, </font><a href="BCA.htm"><font
size="2" face="Courier New">BCA</font></a><font size="2"
face="Courier New">, </font><a href="InsVal.htm"><font size="2"
face="Courier New">InsVal</font></a><font size="2"
face="Courier New">, </font><a href="SelVal.htm"><font size="2"
face="Courier New">SelVal</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></a>, <font size="2"
face="Courier New">, </font><a href="IOHandler.htm"><font
size="2" face="Courier New">IOHandler</font></a></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 + -