diff options
| author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2015-02-17 17:25:57 +0000 |
|---|---|---|
| committer | <> | 2015-03-17 16:26:24 +0000 |
| commit | 780b92ada9afcf1d58085a83a0b9e6bc982203d1 (patch) | |
| tree | 598f8b9fa431b228d29897e798de4ac0c1d3d970 /docs/programmer_reference/stl_examples.html | |
| parent | 7a2660ba9cc2dc03a69ddfcfd95369395cc87444 (diff) | |
| download | berkeleydb-master.tar.gz | |
Diffstat (limited to 'docs/programmer_reference/stl_examples.html')
| -rw-r--r-- | docs/programmer_reference/stl_examples.html | 179 |
1 files changed, 95 insertions, 84 deletions
diff --git a/docs/programmer_reference/stl_examples.html b/docs/programmer_reference/stl_examples.html index f029dadf..0918c31d 100644 --- a/docs/programmer_reference/stl_examples.html +++ b/docs/programmer_reference/stl_examples.html @@ -14,7 +14,7 @@ <body> <div xmlns="" class="navheader"> <div class="libver"> - <p>Library Version 11.2.5.3</p> + <p>Library Version 12.1.6.1</p> </div> <table width="100%" summary="Navigation header"> <tr> @@ -36,83 +36,91 @@ </div> </div> </div> - <p> - Because dbstl is so much like C++ STL, its usage exactly mirrors that - of C++ STL, with the exception of a few optional Berkeley DB specific - configurations. In fact, the only difference between a program using - dbstl and one using C++ STL is the class names. That is, - <code class="classname">vector</code> becomes <code class="classname">db_vector</code>, - and <code class="classname">map</code> becomes <code class="classname">db_map</code>. -</p> - <p> - The typical procedure for using dbstl is: -</p> + <p> + Because dbstl is so much like C++ STL, its usage exactly + mirrors that of C++ STL, with the exception of a few optional + Berkeley DB specific configurations. In fact, the only + difference between a program using dbstl and one using C++ STL + is the class names. That is, <code class="classname">vector</code> + becomes <code class="classname">db_vector</code>, and + <code class="classname">map</code> becomes + <code class="classname">db_map</code>. + </p> + <p> + The typical procedure for using dbstl is: + </p> <div class="orderedlist"> <ol type="1"> <li> <p> - Optionally create and open your own Berkeley DB environment and - database handles using the DB C++ API. If you perform these opens - using the C++ API, make sure to perform necessary - environment and database configurations at that time. - </p> + Optionally create and open your own Berkeley DB + environment and database handles using the DB C++ API. + If you perform these opens using the C++ API, make + sure to perform necessary environment and database + configurations at that time. + </p> </li> <li> - <p> - Optionally pass environment and database handles to dbstl container - constructors when you create dbstl container objects. Note that you - can create a dbstl container without passing it an environment and - database object. When you do this, an internal anonymous database - is created for you. In this situation, dbstl provides no data - persistence guarantees. - </p> + <p> + Optionally pass environment and database handles to + dbstl container constructors when you create dbstl + container objects. Note that you can create a dbstl + container without passing it an environment and + database object. When you do this, an internal + anonymous database is created for you. In this + situation, dbstl provides no data persistence + guarantees. + </p> </li> <li> - <p> - Perform dbstl-specific configurations. For example, you can - configure cursor open flags, as well as database - access for autocommit. You can also configure callback functions. - </p> + <p> + Perform dbstl-specific configurations. For example, + you can configure cursor open flags, as well as + database access for autocommit. You can also configure + callback functions. + </p> </li> <li> - <p> - Interact with the data contained in your Berkeley DB databases using - dbstl containers and iterators. This usage of dbstl is identical to - C++ STL container and iterator usage. - </p> + <p> + Interact with the data contained in your Berkeley + DB databases using dbstl containers and iterators. + This usage of dbstl is identical to C++ STL container + and iterator usage. + </p> </li> <li> <p> - At this time, you can also use dbstl calls that are specific to Berkeley DB. - For example, you can use Berkeley DB specific calls that manage transaction - begin/commit/abort, handle registration, and so forth. While these - calls are part of dbstl, they have no equivalence in the C++ STL - APIs. - </p> + At this time, you can also use dbstl calls that are + specific to Berkeley DB. For example, you can use + Berkeley DB specific calls that manage transaction + begin/commit/abort, handle registration, and so forth. + While these calls are part of dbstl, they have no + equivalence in the C++ STL APIs. + </p> </li> <li> - <p> - When your application is done using Berkeley DB, you do not need to - explicitly close any Berkeley DB handles (environments, database, - cursors, and so forth). Dbstl automatically closes all such handles - for you. - </p> + <p> When your application is done using Berkeley DB, + you do not need to explicitly close any Berkeley DB + handles (environments, database, cursors, and so + forth). Dbstl automatically closes all such handles + for you. </p> </li> </ol> </div> <p> - For examples of dbstl usage, see the example programs in the - <code class="filename">$db/examples_stl</code> directory. -</p> - <p> - The following program listing provides two code fragments. You can - find more example code in the <code class="filename">dbstl/examples/</code> - and <code class="filename">dbstl/test</code> directories. -</p> + For examples of dbstl usage, see the example programs in + the <code class="filename">$db/examples/stl</code> directory. + </p> + <p> + The following program listing provides two code fragments. + You can find more example code in the + <code class="filename">dbstl/examples/</code> and + <code class="filename">dbstl/test</code> directories. + </p> <pre class="programlisting">//////////////// Code Snippet 1 //////////////// db_vector<int, ElementHolder<int> > vctr(100); for (int i = 0; i < 100; i++) - vctr[i] = i; + vctr[i] = i; for (int i = 0; i < 100; i++) { cout<<"\nvctr["<<i<<"] : "<<vctr[i]; @@ -127,12 +135,12 @@ strmap_t2 strmap; char str[2], str2[2]; str[1] = str2[1] = '\0'; for (char c = 0; c < 26; c++) { - str[0] = c + 'a'; - str2[0] = 'z' - c; - strmap[str] = str2; + str[0] = c + 'a'; + str2[0] = 'z' - c; + strmap[str] = str2; } for (strmap_t2::iterator itr = strmap.begin(); itr != strmap.end(); ++itr) - cout<<endl<<itr->first<<" : "<<itr->second; + cout<<endl<<itr->first<<" : "<<itr->second; using namespace dbstl; dbstl::db_map<char, int> v; @@ -156,33 +164,36 @@ vi.push_back(obj); // More person storage. for (int I = 0; I < vi.size(); I++) cout<<vi[I]; </pre> <p> - The first snippet initializes a db_vector container of 100 elements, - with an in-memory anonymous database internally created by dbstl. The - only difference between this and C++ STL is dbstl requires one more - <code class="literal">type</code> parameter: - <em class="parameter"><code>ElementHolder<int></code></em>. The - <code class="classname">ElementHolder</code> class template should be used for - every type of dbstl container that will store C++ primitive data types, - such as <code class="literal">int</code>, <code class="literal">float</code>, - <code class="literal">char *</code>, <code class="literal">wchar_t *</code>, and so forth. But these - class templates should not be used for class types for reasons that we - explain in the following chapters. -</p> - <p> - In the second code snippet, the assignment: -</p> + The first snippet initializes a db_vector container of 100 + elements, with an in-memory anonymous database internally + created by dbstl. The only difference between this and C++ STL + is dbstl requires one more <code class="literal">type</code> parameter: + <em class="parameter"><code>ElementHolder<int></code></em>. The + <code class="classname">ElementHolder</code> class template should + be used for every type of dbstl container that will store C++ + primitive data types, such as <code class="literal">int</code>, + <code class="literal">float</code>, <code class="literal">char *</code>, + <code class="literal">wchar_t *</code>, and so forth. But these + class templates should not be used for class types for reasons + that we explain in the following chapters. + </p> + <p> + In the second code snippet, the assignment: + </p> <pre class="programlisting">strmap[str] = str2;</pre> <p> - is used to store a string pair (<code class="literal">(str, str2)</code>) instead - of pointers to the underlying database. -</p> + is used to store a string pair (<code class="literal">(str, + str2)</code>) instead of pointers to the underlying + database. + </p> <p> - The rest of the code used in these snippets is identical to the code - you would use for C++ STL containers. However, by using dbstl, you are - storing data into a Berkeley DB database. If you create your own - database with backing files on disk, your data or objects can persist - and be restored when the program runs again. -</p> + The rest of the code used in these snippets is identical to + the code you would use for C++ STL containers. However, by + using dbstl, you are storing data into a Berkeley DB database. + If you create your own database with backing files on disk, + your data or objects can persist and be restored when the + program runs again. + </p> </div> <div class="navfooter"> <hr /> |
