• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/db-4.8.30/docs/programmer_reference/
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml">
4  <head>
5    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6    <title>Dbstl miscellaneous notes</title>
7    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9    <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" />
10    <link rel="up" href="stl.html" title="Chapter��7.��Standard Template Library API" />
11    <link rel="prev" href="stl_memory_mgmt.html" title="Dbstl memory management" />
12    <link rel="next" href="stl_known_issues.html" title="Dbstl known issues" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">Dbstl miscellaneous notes</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="stl_memory_mgmt.html">Prev</a>��</td>
22          <th width="60%" align="center">Chapter��7.��Standard Template Library API</th>
23          <td width="20%" align="right">��<a accesskey="n" href="stl_known_issues.html">Next</a></td>
24        </tr>
25      </table>
26      <hr />
27    </div>
28    <div class="sect1" lang="en" xml:lang="en">
29      <div class="titlepage">
30        <div>
31          <div>
32            <h2 class="title" style="clear: both"><a id="stl_misc"></a>Dbstl miscellaneous notes</h2>
33          </div>
34        </div>
35      </div>
36      <div class="toc">
37        <dl>
38          <dt>
39            <span class="sect2">
40              <a href="stl_misc.html#id1602620">Special notes about trivial methods</a>
41            </span>
42          </dt>
43          <dt>
44            <span class="sect2">
45              <a href="stl_misc.html#id1602670">Using correct container and iterator public types</a>
46            </span>
47          </dt>
48        </dl>
49      </div>
50      <div class="sect2" lang="en" xml:lang="en">
51        <div class="titlepage">
52          <div>
53            <div>
54              <h3 class="title"><a id="id1602620"></a>Special notes about trivial methods</h3>
55            </div>
56          </div>
57        </div>
58        <p>
59        There are some standard STL methods which are meaningless in dbstl, but they are kept in
60        dbstl as no-ops so as to stay consistent with the standard. These are:
61	</p>
62        <table class="simplelist" border="0" summary="Simple list">
63          <tr>
64            <td>
65              <code class="methodname">db_vecter::reserve();</code>
66            </td>
67          </tr>
68          <tr>
69            <td>
70              <code class="methodname">db_vector::max_size();</code>
71            </td>
72          </tr>
73          <tr>
74            <td>
75              <code class="methodname">db_vector::capacity();</code>
76            </td>
77          </tr>
78          <tr>
79            <td>
80              <code class="methodname">db_map::reserve();</code>
81            </td>
82          </tr>
83          <tr>
84            <td>
85              <code class="methodname">db_map::max_size();</code>
86            </td>
87          </tr>
88        </table>
89        <p>
90        <code class="methodname">db_vector&lt;&gt;::max_size()</code> and
91        <code class="methodname">db_map&lt;&gt;::max_size()</code> both return 2^30. This does not mean
92        that Berkeley DB can only hold that much data. This value is returned to conform to some
93        compilers' overflow rules ��� if we set bigger numbers like 2^32 or 2^31, some compilers
94        complain that the number has overflowed.
95	</p>
96        <p>
97        See the Berkeley DB documentation for information about limitations on how much data a
98        database can store.
99	</p>
100        <p>
101        There are also some read-only functions. You set the configuration
102        for these using the Berkeley DB API. You access them using the container's methods. Again,
103        this is to keep consistent with C++ standard STL containers, such as:
104	</p>
105        <table class="simplelist" border="0" summary="Simple list">
106          <tr>
107            <td>
108              <code class="methodname">db_map::key_comp();</code>
109            </td>
110          </tr>
111          <tr>
112            <td>
113              <code class="methodname">db_map::value_comp();</code>
114            </td>
115          </tr>
116          <tr>
117            <td>
118              <code class="methodname">db_map::hash_funct();</code>
119            </td>
120          </tr>
121          <tr>
122            <td>
123              <code class="methodname">db_map::key_eq();</code>
124            </td>
125          </tr>
126        </table>
127      </div>
128      <div class="sect2" lang="en" xml:lang="en">
129        <div class="titlepage">
130          <div>
131            <div>
132              <h3 class="title"><a id="id1602670"></a>Using correct container and iterator public types</h3>
133            </div>
134          </div>
135        </div>
136        <p>
137        All public types defined by the C++ STL specification are present in dbstl. One thing to
138        note is the <span class="bold"><strong>value_type</strong></span>. dbstl defines the <span class="bold"><strong>value_type</strong></span> for each iterator and container class to be the raw
139        type without the <code class="classname">ElementRef</code>/<code class="classname">ElementHolder</code>
140        wrapper, so this type of variable can not be used to store data in a database.  There is a
141        <span class="bold"><strong>value_type_wrap</strong></span> type for each container and iterator type,
142        with the raw type wrapped by the
143        <code class="classname">ElementRef</code>/<code class="classname">ElementHolder</code>.
144	</p>
145        <p>
146        For example, when type <code class="literal">int_vector_t</code> is defined as
147    </p>
148        <pre class="programlisting">db_vector&lt;int, ElementHolder&lt;int&gt; &gt;</pre>
149        <p>
150        its <span class="bold"><strong>value_type</strong></span> is <code class="literal">int</code>, its 
151        <span class="bold"><strong>value_type_wrap</strong></span> is <code class="literal">ElementHolder&lt;int&gt;</code>,
152        and its reference and pointer types are <code class="literal">ElementHolder&lt;int&gt;&amp;</code> and
153        <code class="literal">ElementHolder&lt;int&gt;*</code> respectively.  If you need to store data, use
154        <span class="bold"><strong>value_type_wrap</strong></span> to make use of the wrapper to store data
155        into database.
156	</p>
157        <p>
158        The reason we leave <span class="bold"><strong>value_type</strong></span> as the raw type is that we
159        want the existing algorithms in the STL library to work with dbstl because we have seen that
160        without doing so, a few tests will fail.
161	</p>
162        <p>
163        You need to use the same type as the return type of the data element retrieval functions to
164        hold a value in order to properly manipulate the data element. For example, when calling
165    </p>
166        <pre class="programlisting">db_vector&lt;T&gt;::operator[]</pre>
167        <p>
168        check that the return type for this function is 
169    </p>
170        <pre class="programlisting">db_vector&lt;T&gt;::datatype_wrap</pre>
171        <p>
172        Then,  hold the return value using an object of the same type:
173    </p>
174        <pre class="programlisting">db_vector&lt;T&gt;::datatype_wrap refelem = vctr[3];</pre>
175      </div>
176    </div>
177    <div class="navfooter">
178      <hr />
179      <table width="100%" summary="Navigation footer">
180        <tr>
181          <td width="40%" align="left"><a accesskey="p" href="stl_memory_mgmt.html">Prev</a>��</td>
182          <td width="20%" align="center">
183            <a accesskey="u" href="stl.html">Up</a>
184          </td>
185          <td width="40%" align="right">��<a accesskey="n" href="stl_known_issues.html">Next</a></td>
186        </tr>
187        <tr>
188          <td width="40%" align="left" valign="top">Dbstl memory management��</td>
189          <td width="20%" align="center">
190            <a accesskey="h" href="index.html">Home</a>
191          </td>
192          <td width="40%" align="right" valign="top">��Dbstl known issues</td>
193        </tr>
194      </table>
195    </div>
196  </body>
197</html>
198