| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
| 2 |
|
| 3 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 4 |
|
| 5 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 6 |
|
| 7 |
<head> |
| 8 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 9 |
<meta http-equiv="Content-Style-Type" content="text/css" /> |
| 10 |
<meta name="author" content="Mikio Hirabayashi" /> |
| 11 |
<meta name="keywords" content="QDBM, C++, Depot, Curia, Villa" /> |
| 12 |
<meta name="description" content="specifications of C++ API of QDBM" /> |
| 13 |
<link rel="contents" href="./" /> |
| 14 |
<link rel="alternate" href="xspex-ja.html" hreflang="ja" title="the Japanese version" /> |
| 15 |
<link rev="made" href="mailto:[email protected]" /> |
| 16 |
<title>Specifications of QDBM for C++</title> |
| 17 |
<style type="text/css">html { margin: 0em 0em; padding: 0em 0em; background: #eeeeee none; } |
| 18 |
body { margin: 2em 2em; padding: 0em 0em; |
| 19 |
background: #eeeeee none; color: #111111; |
| 20 |
font-style: normal; font-weight: normal; } |
| 21 |
h1 { margin-top: 1.8em; margin-bottom: 1.3em; font-weight: bold; } |
| 22 |
h2 { margin-top: 1.8em; margin-bottom: 1.1em; font-weight: bold; |
| 23 |
border-left: solid 0.6em #445555; border-bottom: solid 1pt #bbbbbb; |
| 24 |
padding: 0.5em 0.5em; width: 60%; } |
| 25 |
h3 { margin-top: 1.8em; margin-bottom: 0.8em; font-weight: bold; } |
| 26 |
hr { margin-top: 2.5em; margin-bottom: 1.5em; height: 1pt; |
| 27 |
color: #999999; background-color: #999999; border: none; } |
| 28 |
div.note,div.navi { text-align: right; } |
| 29 |
div.logo { text-align: center; margin: 3em 0em; } |
| 30 |
div.logo img { border: inset 2pt #ccccdd; } |
| 31 |
p { margin: 0.8em 0em; line-height: 140%; } |
| 32 |
p,dd { text-indent: 0.8em; } |
| 33 |
div,pre { margin-left: 1.7em; margin-right: 1.7em; } |
| 34 |
pre { background-color: #ddddee; padding: 0.2em; border: 1pt solid #bbbbcc; font-size: smaller; } |
| 35 |
kbd { color: #111111; font-style: normal; font-weight: bold; } |
| 36 |
a { color: #0022aa; text-decoration: none; } |
| 37 |
a:hover,a:focus { color: #0033ee; text-decoration: underline; } |
| 38 |
a.head { color: #111111; text-decoration: none; } |
| 39 |
table { padding: 1pt 2pt 1pt 2pt; border: none; margin-left: 1.7em; border-collapse: collapse; } |
| 40 |
th { padding: 1pt 4pt 1pt 4pt; border-style: none; |
| 41 |
text-align: left; vertical-align: bottom; } |
| 42 |
td { padding: 1pt 4pt 1pt 4pt; border: 1pt solid #333333; |
| 43 |
text-align: left; vertical-align: top; } |
| 44 |
ul,ol,dl { line-height: 140%; } |
| 45 |
dt { margin-left: 1.2em; } |
| 46 |
dd { margin-left: 2.0em; } |
| 47 |
ul.lines { list-style-type: none; } |
| 48 |
@media print { |
| 49 |
html,body { margin: 0em 0em; background-color: #ffffff; color: #000000; } |
| 50 |
h1 { padding: 8em 0em 0.5em 0em; text-align: center; } |
| 51 |
h2 { page-break-before: always; } |
| 52 |
div.navi,div.logo { display: none } |
| 53 |
div.navi { display: none } |
| 54 |
hr { display: none; } |
| 55 |
pre { margin: 0.8em 0.8em; background-color: #ffffff; |
| 56 |
border: 1pt solid #aaaaaa; font-size: smaller; } |
| 57 |
a,kbd { color: #000000; text-decoration: none; } |
| 58 |
h1,h2,h3 { font-family: sans-serif; } |
| 59 |
p,div,li,dt,dd { font-family: serif; } |
| 60 |
pre,kbd { font-family: monospace; } |
| 61 |
dd { font-size: smaller; } |
| 62 |
} |
| 63 |
</style> |
| 64 |
</head> |
| 65 |
|
| 66 |
<body> |
| 67 |
|
| 68 |
<h1>Specifications of QDBM for C++</h1> |
| 69 |
|
| 70 |
<div class="note">Copyright (C) 2000-2006 Mikio Hirabayashi</div> |
| 71 |
<div class="note">Last Update: Thu, 26 Oct 2006 15:00:20 +0900</div> |
| 72 |
<div class="navi">[<a href="xapidoc/index.html">API</a>] [<a href="xspex-ja.html" hreflang="ja">Japanese</a>]</div> |
| 73 |
|
| 74 |
<hr /> |
| 75 |
|
| 76 |
<h2>Table of Contents</h2> |
| 77 |
|
| 78 |
<ol> |
| 79 |
<li><a href="#overview">Overview</a></li> |
| 80 |
<li><a href="#installation">Installation</a></li> |
| 81 |
<li><a href="#examples">Examples</a></li> |
| 82 |
<li><a href="#bugs">Bugs</a></li> |
| 83 |
</ol> |
| 84 |
|
| 85 |
<hr /> |
| 86 |
|
| 87 |
<h2><a name="overview" id="overview" class="head">Overview</a></h2> |
| 88 |
|
| 89 |
<p>QDBM provides API for C++. This encapsulates the basic API, the extended API and the advanced API of QDBM, and make them thread-safe.</p> |
| 90 |
|
| 91 |
<p>The basic API for C++ realizes a hash database with a file. Constructors of the class `Depot' open a database file. The member function `close' is used in order to close the database. If the instance is destroyed without closing the database explicitly, the destructor closes the database. The member function `put' is used in order to store a record. The member function `out' is used in order to delete a record. The member function `get' is used in order to retrieve a record. Besides, most operations like ones of the basic API for C are available. Each member functions throws an instance of the class `Depot_error' if an error occurs.</p> |
| 92 |
|
| 93 |
<p>The extended API for C++ realizes a hash database with a directory and multiple files. Constructors of the class `Curia' open a database directory. The member function `close' is used in order to close the database. If the instance is destroyed without closing the database explicitly, the destructor closes the database. The member function `put' is used in order to store a record. The member function `out' is used in order to delete a record. The member function `get' is used in order to retrieve a record. Operations for managing large objects are also provided. Besides, most operations like ones of the extended API for C are available. Each member functions throws an instance of the class `Curia_error' if an error occurs.</p> |
| 94 |
|
| 95 |
<p>The advanced API for C++ realizes a B+ tree database with a file. Constructors of the class `Villa' open a database file. The member function `close' is used in order to close the database. If the instance is destroyed without closing the database explicitly, the destructor closes the database. The member function `put' is used in order to store a record. The member function `out' is used in order to delete a record. The member function `get' is used in order to retrieve a record. Besides, most operations like ones of the advanced API for C are available. Each member functions throws an instance of the class `Villa_error' if an error occurs.</p> |
| 96 |
|
| 97 |
<p>`Depot', `Curia', and `Villa' are derived classes of the class `ADBM'. This class is an interface for abstraction of database managers compatible with DBM of UNIX standard. This class does only declare pure virtual functions. Each member functions throws an instance of the class `DBM_error'. In this framework, a key and a value of each record are expressed by the class `Datum'. An instance of `Datum' has the pointer to the region of data and its size. When you choose the one of four APIs, `Depot' is suggested if performance is weighted, `Curia' is suggested if scalability is weighted, `Villa' is suggested if ordering access is required, `ADBM' is suggested if elegance and maintenance are weighted. Besides, a database file is not compatible with each API.</p> |
| 98 |
|
| 99 |
<p>You should include the following header files in source files of applications: `xdepot.h' for `Depot', `xcuria.h' for `Curia', `xvilla.h' for `Villa', and `xadbm.h' for `ADBM'. Besides, each class is packaged in the name space `qdbm'.</p> |
| 100 |
|
| 101 |
<p>While APIs for C are thread-safe unless plural threads do not share a database handle, APIs for C++ are thread-safe even if plural threads share a handle. This API is implemented depending on the POSIX thread package. If you use another thread package, you should write your own C++ wrapper.</p> |
| 102 |
|
| 103 |
<p>When `put' overwriting an existing record is cancelled or `get' retrieving a missing record, failure of the operation is noticed by exception. If you dislike such behavior, set the `silent' flag to be true. Then, failure of the operation is noticed by the return value.</p> |
| 104 |
|
| 105 |
<p>For more information about the APIs, read documents in the sub directory `<a href="xapidoc/">xapidoc</a>' and each header file.</p> |
| 106 |
|
| 107 |
<hr /> |
| 108 |
|
| 109 |
<h2><a name="installation" id="installation" class="head">Installation</a></h2> |
| 110 |
|
| 111 |
<h3>Preparation</h3> |
| 112 |
|
| 113 |
<p>Make sure that GCC 3.3 or later version is installed. And make sure that QDBM is installed under `/usr/local'.</p> |
| 114 |
|
| 115 |
<p>Change the current working directory to the sub directory named `plus'.</p> |
| 116 |
|
| 117 |
<pre>cd plus |
| 118 |
</pre> |
| 119 |
|
| 120 |
<h3>Usual Steps</h3> |
| 121 |
|
| 122 |
<p>Run the configuration script.</p> |
| 123 |
|
| 124 |
<pre>./configure |
| 125 |
</pre> |
| 126 |
|
| 127 |
<p>Build programs.</p> |
| 128 |
|
| 129 |
<pre>make |
| 130 |
</pre> |
| 131 |
|
| 132 |
<p>Perform self-diagnostic test.</p> |
| 133 |
|
| 134 |
<pre>make check |
| 135 |
</pre> |
| 136 |
|
| 137 |
<p>Install programs. This operation must be carried out by the root user.</p> |
| 138 |
|
| 139 |
<pre>make install |
| 140 |
</pre> |
| 141 |
|
| 142 |
<p>When a series of work finishes, header files, `xdepot.h', `xcuria.h', `xvilla.h', and `xadbm.h' will be installed in `/usr/local/include', a library `libxqdbm.so' and so on will be installed in `/usr/local/lib', executable commands `xdptest', `xcrtest', and `xvltest' will be installed in `/usr/local/bin'.</p> |
| 143 |
|
| 144 |
<p>To uninstall them, execute the following command after `./configure'. This operation must be carried out by the root user.</p> |
| 145 |
|
| 146 |
<pre>make uninstall |
| 147 |
</pre> |
| 148 |
|
| 149 |
<h3>For Windows</h3> |
| 150 |
|
| 151 |
<p>On Windows (Cygwin), you should follow the procedures below for installation.</p> |
| 152 |
|
| 153 |
<p>Run the configuration script.</p> |
| 154 |
|
| 155 |
<pre>./configure |
| 156 |
</pre> |
| 157 |
|
| 158 |
<p>Build programs.</p> |
| 159 |
|
| 160 |
<pre>make win |
| 161 |
</pre> |
| 162 |
|
| 163 |
<p>Perform self-diagnostic test.</p> |
| 164 |
|
| 165 |
<pre>make check-win |
| 166 |
</pre> |
| 167 |
|
| 168 |
<p>Install programs. As well, perform `make uninstall-win' to uninstall them.</p> |
| 169 |
|
| 170 |
<pre>make install-win |
| 171 |
</pre> |
| 172 |
|
| 173 |
<p>On Windows, an import library `libxqdbm.dll.a' is created, and a dynamic linking library `jqdbm.dll' is created. `xqdbm.dll' is installed into `/usr/local/bin'.</p> |
| 174 |
|
| 175 |
<p>Build of the C++ API using MinGW is not supported.</p> |
| 176 |
|
| 177 |
<h3>For Mac OS X</h3> |
| 178 |
|
| 179 |
<p>On Mac OS X (Darwin), you should follow the procedures below for installation.</p> |
| 180 |
|
| 181 |
<p>Run the configuration script.</p> |
| 182 |
|
| 183 |
<pre>./configure |
| 184 |
</pre> |
| 185 |
|
| 186 |
<p>Build programs.</p> |
| 187 |
|
| 188 |
<pre>make mac |
| 189 |
</pre> |
| 190 |
|
| 191 |
<p>Perform self-diagnostic test.</p> |
| 192 |
|
| 193 |
<pre>make check-mac |
| 194 |
</pre> |
| 195 |
|
| 196 |
<p>Install programs. As well, perform `make uninstall-mac' to uninstall them.</p> |
| 197 |
|
| 198 |
<pre>make install-mac |
| 199 |
</pre> |
| 200 |
|
| 201 |
<p>On Mac OS X, `libxqdbm.dylib' and so on are created instead of `libxqdbm.so' and so on.</p> |
| 202 |
|
| 203 |
<h3>For HP-UX</h3> |
| 204 |
|
| 205 |
<p>On HP-UX, you should follow the procedures below for installation.</p> |
| 206 |
|
| 207 |
<p>Run the configuration script.</p> |
| 208 |
|
| 209 |
<pre>./configure |
| 210 |
</pre> |
| 211 |
|
| 212 |
<p>Build programs.</p> |
| 213 |
|
| 214 |
<pre>make hpux |
| 215 |
</pre> |
| 216 |
|
| 217 |
<p>Perform self-diagnostic test.</p> |
| 218 |
|
| 219 |
<pre>make check-hpux |
| 220 |
</pre> |
| 221 |
|
| 222 |
<p>Install programs. As well, perform `make uninstall-hpux' to uninstall them.</p> |
| 223 |
|
| 224 |
<pre>make install-hpux |
| 225 |
</pre> |
| 226 |
|
| 227 |
<p>On HP-UX, `libxqdbm.sl' is created instead of `libxqdbm.so' and so on.</p> |
| 228 |
|
| 229 |
<hr /> |
| 230 |
|
| 231 |
<h2><a name="examples" id="examples" class="head">Examples</a></h2> |
| 232 |
|
| 233 |
<p>The following example stores and retrieves a phone number, using the name as the key.</p> |
| 234 |
|
| 235 |
<pre>#include <xdepot.h> |
| 236 |
#include <cstdlib> |
| 237 |
#include <iostream> |
| 238 |
|
| 239 |
using namespace std; |
| 240 |
using namespace qdbm; |
| 241 |
|
| 242 |
const char* NAME = "mikio"; |
| 243 |
const char* NUMBER = "000-1234-5678"; |
| 244 |
const char* DBNAME = "book"; |
| 245 |
|
| 246 |
int main(int argc, char** argv){ |
| 247 |
try { |
| 248 |
|
| 249 |
// open the database |
| 250 |
Depot depot(DBNAME, Depot::OWRITER | Depot::OCREAT); |
| 251 |
|
| 252 |
// store the record |
| 253 |
depot.put(NAME, -1, NUMBER, -1); |
| 254 |
|
| 255 |
// retrieve the record |
| 256 |
char* val = depot.get(NAME, -1); |
| 257 |
cout << "Name: " << NAME << endl; |
| 258 |
cout << "Number: " << val << endl; |
| 259 |
free(val); |
| 260 |
|
| 261 |
// close the database |
| 262 |
depot.close(); |
| 263 |
|
| 264 |
} catch(Depot_error& e){ |
| 265 |
cerr << e << endl; |
| 266 |
return 1; |
| 267 |
} |
| 268 |
return 0; |
| 269 |
} |
| 270 |
</pre> |
| 271 |
|
| 272 |
<p>The following example is a transcription of the one above, using the class `ADBM'.</p> |
| 273 |
|
| 274 |
<pre>#include <xadbm.h> |
| 275 |
#include <xdepot.h> |
| 276 |
#include <iostream> |
| 277 |
|
| 278 |
using namespace std; |
| 279 |
using namespace qdbm; |
| 280 |
|
| 281 |
const char* NAME = "mikio"; |
| 282 |
const char* NUMBER = "000-1234-5678"; |
| 283 |
const char* DBNAME = "book"; |
| 284 |
|
| 285 |
int main(int argc, char** argv){ |
| 286 |
try { |
| 287 |
|
| 288 |
// open the database |
| 289 |
Depot depot(DBNAME, Depot::OWRITER | Depot::OCREAT); |
| 290 |
ADBM& dbm = depot; |
| 291 |
|
| 292 |
// prepare the record |
| 293 |
Datum key(NAME); |
| 294 |
Datum val(NUMBER); |
| 295 |
|
| 296 |
// store the record |
| 297 |
dbm.storerec(key, val); |
| 298 |
|
| 299 |
// retrieve the record |
| 300 |
const Datum& res = dbm.fetchrec(key); |
| 301 |
cout << "Name: " << NAME << endl; |
| 302 |
cout << "Number: " << res << endl; |
| 303 |
|
| 304 |
// close the database |
| 305 |
dbm.close(); |
| 306 |
|
| 307 |
} catch(DBM_error& e){ |
| 308 |
cerr << e << endl; |
| 309 |
return 1; |
| 310 |
} |
| 311 |
return 0; |
| 312 |
} |
| 313 |
</pre> |
| 314 |
|
| 315 |
<p>The following example performs forward matching search for strings, using the class `Villa'.</p> |
| 316 |
|
| 317 |
<pre>#include <xvilla.h> |
| 318 |
#include <cstdlib> |
| 319 |
#include <cstring> |
| 320 |
#include <iostream> |
| 321 |
|
| 322 |
using namespace std; |
| 323 |
using namespace qdbm; |
| 324 |
|
| 325 |
const char* DBNAME = "words"; |
| 326 |
const char* PREFIX = "apple"; |
| 327 |
|
| 328 |
int main(int argc, char** argv){ |
| 329 |
try { |
| 330 |
|
| 331 |
// open the database |
| 332 |
Villa villa(DBNAME, Villa::OWRITER | Villa::OCREAT); |
| 333 |
|
| 334 |
// store records |
| 335 |
villa.put("applet", -1, "little application", -1, Villa::DDUP); |
| 336 |
villa.put("aurora", -1, "polar wonderwork", -1, Villa::DDUP); |
| 337 |
villa.put("apple", -1, "delicious fruit", -1, Villa::DDUP); |
| 338 |
villa.put("amigo", -1, "good friend", -1, Villa::DDUP); |
| 339 |
villa.put("apple", -1, "big city", -1, Villa::DDUP); |
| 340 |
|
| 341 |
try { |
| 342 |
|
| 343 |
// set the cursor at the top of candidates |
| 344 |
villa.curjump(PREFIX, -1); |
| 345 |
|
| 346 |
// scan with the cursor |
| 347 |
for(;;){ |
| 348 |
char* key = villa.curkey(); |
| 349 |
if(strstr(key, PREFIX) != key){ |
| 350 |
free(key); |
| 351 |
break; |
| 352 |
} |
| 353 |
char* val = villa.curval(); |
| 354 |
cout << key << ": " << val << endl; |
| 355 |
free(key); |
| 356 |
free(val); |
| 357 |
villa.curnext(); |
| 358 |
} |
| 359 |
|
| 360 |
} catch(Villa_error& e){ |
| 361 |
if(e.code() != Villa::ENOITEM) throw e; |
| 362 |
} |
| 363 |
|
| 364 |
// close the database |
| 365 |
villa.close(); |
| 366 |
|
| 367 |
} catch(Villa_error& e){ |
| 368 |
cerr << e << endl; |
| 369 |
return 1; |
| 370 |
} |
| 371 |
return 0; |
| 372 |
} |
| 373 |
</pre> |
| 374 |
|
| 375 |
<p>For building a program using C++ API of QDBM, the program should be linked with the libraries: `xqdbm' and `qdbm'. For example, the following command is executed to build `sample' from `sample.cc'.</p> |
| 376 |
|
| 377 |
<pre>g++ -I/usr/local/include -o sample sample.cc -L/usr/local/lib -lxqdbm -lqdbm |
| 378 |
</pre> |
| 379 |
|
| 380 |
<hr /> |
| 381 |
|
| 382 |
<h2><a name="bugs" id="bugs" class="head">Bugs</a></h2> |
| 383 |
|
| 384 |
<p>QDBM has restrictions that two or more handles of the same database file should not be used by a process at the same time. So, when a database is used by two or more threads, open the database in the main thread and pass the handle to each thread.</p> |
| 385 |
|
| 386 |
<p>Because QDBM does not provide mechanism that serialize generic objects and store them into a database, if you want it, you should extend the class `ADBM'. Besides, if the comparing function of `Villa' compares deserialized objects, the database can be used as an object-oriented database.</p> |
| 387 |
|
| 388 |
<hr /> |
| 389 |
|
| 390 |
</body> |
| 391 |
|
| 392 |
</html> |
| 393 |
|
| 394 |
|