~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/include/db_cxx.h

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-
 
2
 * See the file LICENSE for redistribution information.
 
3
 *
 
4
 * Copyright (c) 1997-2001
 
5
 *      Sleepycat Software.  All rights reserved.
 
6
 *
 
7
 * $Id: db_cxx.h,v 11.65 2001/06/19 18:58:59 dda Exp $
 
8
 */
 
9
 
 
10
#ifndef _DB_CXX_H_
 
11
#define _DB_CXX_H_
 
12
//
 
13
// C++ assumptions:
 
14
//
 
15
// To ensure portability to many platforms, both new and old, we make
 
16
// few assumptions about the C++ compiler and library.  For example,
 
17
// we do not expect STL, templates or namespaces to be available.  The
 
18
// "newest" C++ feature used is exceptions, which are used liberally
 
19
// to transmit error information.  Even the use of exceptions can be
 
20
// disabled at runtime, to do so, use the DB_CXX_NO_EXCEPTIONS flags
 
21
// with the DbEnv or Db constructor.
 
22
//
 
23
// C++ naming conventions:
 
24
//
 
25
//  - All top level class names start with Db.
 
26
//  - All class members start with lower case letter.
 
27
//  - All private data members are suffixed with underscore.
 
28
//  - Use underscores to divide names into multiple words.
 
29
//  - Simple data accessors are named with get_ or set_ prefix.
 
30
//  - All method names are taken from names of functions in the C
 
31
//    layer of db (usually by dropping a prefix like "db_").
 
32
//    These methods have the same argument types and order,
 
33
//    other than dropping the explicit arg that acts as "this".
 
34
//
 
35
// As a rule, each DbFoo object has exactly one underlying DB_FOO struct
 
36
// (defined in db.h) associated with it.  In some cases, we inherit directly
 
37
// from the DB_FOO structure to make this relationship explicit.  Often,
 
38
// the underlying C layer allocates and deallocates these structures, so
 
39
// there is no easy way to add any data to the DbFoo class.  When you see
 
40
// a comment about whether data is permitted to be added, this is what
 
41
// is going on.  Of course, if we need to add data to such C++ classes
 
42
// in the future, we will arrange to have an indirect pointer to the
 
43
// DB_FOO struct (as some of the classes already have).
 
44
//
 
45
 
 
46
////////////////////////////////////////////////////////////////
 
47
////////////////////////////////////////////////////////////////
 
48
//
 
49
// Forward declarations
 
50
//
 
51
 
 
52
#include <iostream.h>
 
53
#include <stdarg.h>
 
54
#include "db.h"
 
55
#include "cxx_common.h"
 
56
#include "cxx_except.h"
 
57
 
 
58
class Db;                                        // forward
 
59
class Dbc;                                       // forward
 
60
class DbEnv;                                     // forward
 
61
class DbInfo;                                    // forward
 
62
class DbLock;                                    // forward
 
63
class DbLsn;                                     // forward
 
64
class DbMpoolFile;                               // forward
 
65
class Dbt;                                       // forward
 
66
class DbTxn;                                     // forward
 
67
 
 
68
// These classes are not defined here and should be invisible
 
69
// to the user, but some compilers require forward references.
 
70
// There is one for each use of the DEFINE_DB_CLASS macro.
 
71
 
 
72
class DbImp;
 
73
class DbEnvImp;
 
74
class DbMpoolFileImp;
 
75
class DbTxnImp;
 
76
 
 
77
// DEFINE_DB_CLASS defines an imp_ data member and imp() accessor.
 
78
// The underlying type is a pointer to an opaque *Imp class, that
 
79
// gets converted to the correct implementation class by the implementation.
 
80
//
 
81
// Since these defines use "private/public" labels, and leave the access
 
82
// being "private", we always use these by convention before any data
 
83
// members in the private section of a class.  Keeping them in the
 
84
// private section also emphasizes that they are off limits to user code.
 
85
//
 
86
#define DEFINE_DB_CLASS(name) \
 
87
        public: class name##Imp* imp() { return (imp_); } \
 
88
        public: const class name##Imp* constimp() const { return (imp_); } \
 
89
        private: class name##Imp* imp_
 
90
 
 
91
////////////////////////////////////////////////////////////////
 
92
////////////////////////////////////////////////////////////////
 
93
//
 
94
// Turn off inappropriate compiler warnings
 
95
//
 
96
 
 
97
#ifdef _MSC_VER
 
98
 
 
99
// These are level 4 warnings that are explicitly disabled.
 
100
// With Visual C++, by default you do not see above level 3 unless
 
101
// you use /W4.  But we like to compile with the highest level
 
102
// warnings to catch other errors.
 
103
//
 
104
// 4201: nameless struct/union
 
105
//       triggered by standard include file <winnt.h>
 
106
//
 
107
// 4514: unreferenced inline function has been removed
 
108
//       certain include files in MSVC define methods that are not called
 
109
//
 
110
#pragma warning(disable: 4201 4514)
 
111
 
 
112
#endif
 
113
 
 
114
// Some interfaces can be customized by allowing users to define
 
115
// callback functions.  For performance and logistical reasons, some
 
116
// callback functions must be declared in extern "C" blocks.  For others,
 
117
// we allow you to declare the callbacks in C++ or C (or an extern "C"
 
118
// block) as you wish.  See the set methods for the callbacks for
 
119
// the choices.
 
120
//
 
121
extern "C" {
 
122
        typedef void * (*db_malloc_fcn_type)
 
123
                (size_t);
 
124
        typedef void * (*db_realloc_fcn_type)
 
125
                (void *, size_t);
 
126
        typedef void (*db_free_fcn_type)
 
127
                (void *);
 
128
        typedef int (*bt_compare_fcn_type)          /*C++ version available*/
 
129
                (DB *, const DBT *, const DBT *);
 
130
        typedef size_t (*bt_prefix_fcn_type)        /*C++ version available*/
 
131
                (DB *, const DBT *, const DBT *);
 
132
        typedef int (*dup_compare_fcn_type)         /*C++ version available*/
 
133
                (DB *, const DBT *, const DBT *);
 
134
        typedef u_int32_t (*h_hash_fcn_type)        /*C++ version available*/
 
135
                (DB *, const void *, u_int32_t);
 
136
        typedef int (*pgin_fcn_type)
 
137
                (DB_ENV *dbenv, db_pgno_t pgno, void *pgaddr, DBT *pgcookie);
 
138
        typedef int (*pgout_fcn_type)
 
139
                (DB_ENV *dbenv, db_pgno_t pgno, void *pgaddr, DBT *pgcookie);
 
140
};
 
141
 
 
142
////////////////////////////////////////////////////////////////
 
143
////////////////////////////////////////////////////////////////
 
144
//
 
145
// Lock classes
 
146
//
 
147
 
 
148
class _exported DbLock
 
149
{
 
150
        friend class DbEnv;
 
151
 
 
152
public:
 
153
        DbLock();
 
154
 
 
155
        int put(DbEnv *env);
 
156
 
 
157
        DbLock(const DbLock &);
 
158
        DbLock &operator = (const DbLock &);
 
159
 
 
160
protected:
 
161
        // We can add data to this class if needed
 
162
        // since its contained class is not allocated by db.
 
163
        // (see comment at top)
 
164
 
 
165
        DbLock(DB_LOCK);
 
166
        DB_LOCK lock_;
 
167
};
 
168
 
 
169
////////////////////////////////////////////////////////////////
 
170
////////////////////////////////////////////////////////////////
 
171
//
 
172
// Log classes
 
173
//
 
174
 
 
175
class _exported DbLsn : protected DB_LSN
 
176
{
 
177
        friend class DbEnv;          // friendship needed to cast to base class
 
178
};
 
179
 
 
180
////////////////////////////////////////////////////////////////
 
181
////////////////////////////////////////////////////////////////
 
182
//
 
183
// Memory pool classes
 
184
//
 
185
 
 
186
class _exported DbMpoolFile
 
187
{
 
188
        friend class DbEnv;
 
189
 
 
190
public:
 
191
        int close();
 
192
        int get(db_pgno_t *pgnoaddr, u_int32_t flags, void *pagep);
 
193
        int put(void *pgaddr, u_int32_t flags);
 
194
        int set(void *pgaddr, u_int32_t flags);
 
195
        int sync();
 
196
 
 
197
        static int open(DbEnv *envp, const char *file,
 
198
                        u_int32_t flags, int mode, size_t pagesize,
 
199
                        DB_MPOOL_FINFO *finfop, DbMpoolFile **mpf);
 
200
 
 
201
private:
 
202
        // We can add data to this class if needed
 
203
        // since it is implemented via a pointer.
 
204
        // (see comment at top)
 
205
 
 
206
        // Note: use DbMpoolFile::open()
 
207
        // to get pointers to a DbMpoolFile,
 
208
        // and call DbMpoolFile::close() rather than delete to release them.
 
209
        //
 
210
        DbMpoolFile();
 
211
 
 
212
        // Shut g++ up.
 
213
protected:
 
214
        ~DbMpoolFile();
 
215
 
 
216
private:
 
217
        // no copying
 
218
        DbMpoolFile(const DbMpoolFile &);
 
219
        void operator = (const DbMpoolFile &);
 
220
 
 
221
        DEFINE_DB_CLASS(DbMpoolFile);
 
222
};
 
223
 
 
224
////////////////////////////////////////////////////////////////
 
225
////////////////////////////////////////////////////////////////
 
226
//
 
227
// Transaction classes
 
228
//
 
229
 
 
230
class _exported DbTxn
 
231
{
 
232
        friend class DbEnv;
 
233
 
 
234
public:
 
235
        int abort();
 
236
        int commit(u_int32_t flags);
 
237
        u_int32_t id();
 
238
        int prepare(u_int8_t *gid);
 
239
 
 
240
private:
 
241
        // We can add data to this class if needed
 
242
        // since it is implemented via a pointer.
 
243
        // (see comment at top)
 
244
 
 
245
        // Note: use DbEnv::txn_begin() to get pointers to a DbTxn,
 
246
        // and call DbTxn::abort() or DbTxn::commit rather than
 
247
        // delete to release them.
 
248
        //
 
249
        DbTxn();
 
250
        ~DbTxn();
 
251
 
 
252
        // no copying
 
253
        DbTxn(const DbTxn &);
 
254
        void operator = (const DbTxn &);
 
255
 
 
256
        DEFINE_DB_CLASS(DbTxn);
 
257
};
 
258
 
 
259
//
 
260
// Berkeley DB environment class.  Provides functions for opening databases.
 
261
// User of this library can use this class as a starting point for
 
262
// developing a DB application - derive their application class from
 
263
// this one, add application control logic.
 
264
//
 
265
// Note that if you use the default constructor, you must explicitly
 
266
// call appinit() before any other db activity (e.g. opening files)
 
267
//
 
268
class _exported DbEnv
 
269
{
 
270
        friend class Db;
 
271
        friend class DbLock;
 
272
        friend class DbMpoolFile;
 
273
 
 
274
public:
 
275
 
 
276
        ~DbEnv();
 
277
 
 
278
        // After using this constructor, you can set any needed
 
279
        // parameters for the environment using the set_* methods.
 
280
        // Then call open() to finish initializing the environment
 
281
        // and attaching it to underlying files.
 
282
        //
 
283
        DbEnv(u_int32_t flags);
 
284
 
 
285
        // These methods match those in the C interface.
 
286
        //
 
287
        int close(u_int32_t);
 
288
        void err(int, const char *, ...);
 
289
        void errx(const char *, ...);
 
290
        void *get_app_private() const;
 
291
        int open(const char *, u_int32_t, int);
 
292
        int remove(const char *, u_int32_t);
 
293
        int set_alloc(db_malloc_fcn_type, db_realloc_fcn_type,
 
294
                      db_free_fcn_type);
 
295
        void set_app_private(void *);
 
296
        int set_cachesize(u_int32_t, u_int32_t, int);
 
297
        int set_data_dir(const char *);
 
298
        void set_errcall(void (*)(const char *, char *));
 
299
        void set_errfile(FILE *);
 
300
        void set_errpfx(const char *);
 
301
        int set_flags(u_int32_t, int);
 
302
        int set_feedback(void (*)(DbEnv *, int, int));
 
303
        int set_recovery_init(int (*)(DbEnv *));
 
304
        int set_lg_bsize(u_int32_t);
 
305
        int set_lg_dir(const char *);
 
306
        int set_lg_max(u_int32_t);
 
307
        int set_lg_regionmax(u_int32_t);
 
308
        int set_lk_conflicts(u_int8_t *, int);
 
309
        int set_lk_detect(u_int32_t);
 
310
        int set_lk_max(u_int32_t);
 
311
        int set_lk_max_lockers(u_int32_t);
 
312
        int set_lk_max_locks(u_int32_t);
 
313
        int set_lk_max_objects(u_int32_t);
 
314
        int set_mp_mmapsize(size_t);
 
315
        int set_mutexlocks(int);
 
316
        static int set_pageyield(int);
 
317
        int set_paniccall(void (*)(DbEnv *, int));
 
318
        static int set_panicstate(int);
 
319
        static int set_region_init(int);
 
320
        int set_rpc_server(void *, char *, long, long, u_int32_t);
 
321
        int set_shm_key(long);
 
322
        int set_tmp_dir(const char *);
 
323
        static int set_tas_spins(u_int32_t);
 
324
        int set_tx_max(u_int32_t);
 
325
        int set_tx_recover(int (*)(DbEnv *, Dbt *, DbLsn *, db_recops));
 
326
        int set_tx_timestamp(time_t *);
 
327
        int set_verbose(u_int32_t which, int onoff);
 
328
 
 
329
        // Version information.  A static method so it can be obtained anytime.
 
330
        //
 
331
        static char *version(int *major, int *minor, int *patch);
 
332
 
 
333
        // Convert DB errors to strings
 
334
        static char *strerror(int);
 
335
 
 
336
        // If an error is detected and the error call function
 
337
        // or stream is set, a message is dispatched or printed.
 
338
        // If a prefix is set, each message is prefixed.
 
339
        //
 
340
        // You can use set_errcall() or set_errfile() above to control
 
341
        // error functionality.  Alternatively, you can call
 
342
        // set_error_stream() to force all errors to a C++ stream.
 
343
        // It is unwise to mix these approaches.
 
344
        //
 
345
        void set_error_stream(ostream *);
 
346
 
 
347
        // used internally
 
348
        static void runtime_error(const char *caller, int err,
 
349
                                  int error_policy);
 
350
        static void runtime_error_dbt(const char *caller, Dbt *dbt,
 
351
                                  int error_policy);
 
352
 
 
353
        // Lock functions
 
354
        //
 
355
        int lock_detect(u_int32_t flags, u_int32_t atype, int *aborted);
 
356
        int lock_get(u_int32_t locker, u_int32_t flags, const Dbt *obj,
 
357
                     db_lockmode_t lock_mode, DbLock *lock);
 
358
        int lock_id(u_int32_t *idp);
 
359
        int lock_stat(DB_LOCK_STAT **statp);
 
360
        int lock_vec(u_int32_t locker, u_int32_t flags, DB_LOCKREQ list[],
 
361
                     int nlist, DB_LOCKREQ **elistp);
 
362
 
 
363
        // Log functions
 
364
        //
 
365
        int log_archive(char **list[], u_int32_t flags);
 
366
        static int log_compare(const DbLsn *lsn0, const DbLsn *lsn1);
 
367
        int log_file(DbLsn *lsn, char *namep, size_t len);
 
368
        int log_flush(const DbLsn *lsn);
 
369
        int log_get(DbLsn *lsn, Dbt *data, u_int32_t flags);
 
370
        int log_put(DbLsn *lsn, const Dbt *data, u_int32_t flags);
 
371
 
 
372
        int log_register(Db *dbp, const char *name);
 
373
        int log_stat(DB_LOG_STAT **spp);
 
374
        int log_unregister(Db *dbp);
 
375
 
 
376
        // Mpool functions
 
377
        //
 
378
        int memp_register(int ftype,
 
379
                          pgin_fcn_type pgin_fcn,
 
380
                          pgout_fcn_type pgout_fcn);
 
381
        int memp_stat(DB_MPOOL_STAT **gsp, DB_MPOOL_FSTAT ***fsp);
 
382
        int memp_sync(DbLsn *lsn);
 
383
        int memp_trickle(int pct, int *nwrotep);
 
384
 
 
385
        // Transaction functions
 
386
        //
 
387
        int txn_begin(DbTxn *pid, DbTxn **tid, u_int32_t flags);
 
388
        int txn_checkpoint(u_int32_t kbyte, u_int32_t min, u_int32_t flags);
 
389
        int txn_recover(DB_PREPLIST *preplist, long count,
 
390
                        long *retp, u_int32_t flags);
 
391
        int txn_stat(DB_TXN_STAT **statp);
 
392
 
 
393
        // Conversion functions
 
394
        //
 
395
        DB_ENV *get_DB_ENV()
 
396
        {
 
397
                return (DB_ENV *)imp();
 
398
        }
 
399
 
 
400
        const DB_ENV *get_const_DB_ENV() const
 
401
        {
 
402
                return (const DB_ENV *)constimp();
 
403
        }
 
404
 
 
405
        static DbEnv* get_DbEnv(DB_ENV *dbenv)
 
406
        {
 
407
                return (DbEnv *)dbenv->cj_internal;
 
408
        }
 
409
 
 
410
        static const DbEnv* get_const_DbEnv(const DB_ENV *dbenv)
 
411
        {
 
412
                return (const DbEnv *)dbenv->cj_internal;
 
413
        }
 
414
 
 
415
        // These are public only because they need to be called
 
416
        // via C functions.  They should never be called by users
 
417
        // of this class.
 
418
        //
 
419
        static void _stream_error_function(const char *, char *);
 
420
        static int _tx_recover_intercept(DB_ENV *env, DBT *dbt, DB_LSN *lsn,
 
421
                                        db_recops op);
 
422
        static void _paniccall_intercept(DB_ENV *env, int errval);
 
423
        static int _recovery_init_intercept(DB_ENV *env);
 
424
        static void _feedback_intercept(DB_ENV *env, int opcode, int pct);
 
425
        static void _destroy_check(const char *str, int isDbEnv);
 
426
 
 
427
private:
 
428
        void cleanup();
 
429
        int initialize(DB_ENV *env);
 
430
        int error_policy();
 
431
 
 
432
        // Used internally
 
433
        DbEnv(DB_ENV *, u_int32_t flags);
 
434
 
 
435
        // no copying
 
436
        DbEnv(const DbEnv &);
 
437
        void operator = (const DbEnv &);
 
438
 
 
439
        DEFINE_DB_CLASS(DbEnv);
 
440
 
 
441
        // instance data
 
442
        int construct_error_;
 
443
        u_int32_t construct_flags_;
 
444
        int (*tx_recover_callback_)(DbEnv *, Dbt *, DbLsn *, db_recops);
 
445
        int (*recovery_init_callback_)(DbEnv *);
 
446
        void (*paniccall_callback_)(DbEnv *, int);
 
447
        void (*feedback_callback_)(DbEnv *, int, int);
 
448
        int (*pgin_callback_)(DbEnv *dbenv, db_pgno_t pgno,
 
449
                              void *pgaddr, Dbt *pgcookie);
 
450
        int (*pgout_callback_)(DbEnv *dbenv, db_pgno_t pgno,
 
451
                               void *pgaddr, Dbt *pgcookie);
 
452
 
 
453
        // class data
 
454
        static ostream *error_stream_;
 
455
};
 
456
 
 
457
////////////////////////////////////////////////////////////////
 
458
////////////////////////////////////////////////////////////////
 
459
//
 
460
// Table access classes
 
461
//
 
462
 
 
463
//
 
464
// Represents a database table = a set of keys with associated values.
 
465
//
 
466
class _exported Db
 
467
{
 
468
        friend class DbEnv;
 
469
 
 
470
public:
 
471
        Db(DbEnv*, u_int32_t);      // create a Db object, then call open()
 
472
        ~Db();                      // does *not* call close.
 
473
 
 
474
        // These methods exactly match those in the C interface.
 
475
        //
 
476
        int associate(Db *secondary, int (*callback)(Db *, const Dbt *,
 
477
                const Dbt *, Dbt *), u_int32_t flags);
 
478
        int close(u_int32_t flags);
 
479
        int cursor(DbTxn *txnid, Dbc **cursorp, u_int32_t flags);
 
480
        int del(DbTxn *txnid, Dbt *key, u_int32_t flags);
 
481
        void err(int, const char *, ...);
 
482
        void errx(const char *, ...);
 
483
        int fd(int *fdp);
 
484
        int get(DbTxn *txnid, Dbt *key, Dbt *data, u_int32_t flags);
 
485
        void *get_app_private() const;
 
486
        int get_byteswapped(int *);
 
487
        int get_type(DBTYPE *);
 
488
        int join(Dbc **curslist, Dbc **dbcp, u_int32_t flags);
 
489
        int key_range(DbTxn *, Dbt *, DB_KEY_RANGE *, u_int32_t);
 
490
        int open(const char *, const char *subname, DBTYPE, u_int32_t, int);
 
491
        int pget(DbTxn *txnid, Dbt *key, Dbt *pkey, Dbt *data,
 
492
                 u_int32_t flags);
 
493
        int put(DbTxn *, Dbt *, Dbt *, u_int32_t);
 
494
        int remove(const char *, const char *, u_int32_t);
 
495
        int rename(const char *, const char *, const char *, u_int32_t);
 
496
        int set_alloc(db_malloc_fcn_type, db_realloc_fcn_type,
 
497
                      db_free_fcn_type);
 
498
        void set_app_private(void *);
 
499
        int set_append_recno(int (*)(Db *, Dbt *, db_recno_t));
 
500
        int set_bt_compare(bt_compare_fcn_type); /*deprecated*/
 
501
        int set_bt_compare(int (*)(Db *, const Dbt *, const Dbt *));
 
502
        int set_bt_maxkey(u_int32_t);
 
503
        int set_bt_minkey(u_int32_t);
 
504
        int set_bt_prefix(bt_prefix_fcn_type); /*deprecated*/
 
505
        int set_bt_prefix(size_t (*)(Db *, const Dbt *, const Dbt *));
 
506
        int set_cachesize(u_int32_t, u_int32_t, int);
 
507
        int set_dup_compare(dup_compare_fcn_type); /*deprecated*/
 
508
        int set_dup_compare(int (*)(Db *, const Dbt *, const Dbt *));
 
509
        void set_errcall(void (*)(const char *, char *));
 
510
        void set_errfile(FILE *);
 
511
        void set_errpfx(const char *);
 
512
        int set_feedback(void (*)(Db *, int, int));
 
513
        int set_flags(u_int32_t);
 
514
        int set_h_ffactor(u_int32_t);
 
515
        int set_h_hash(h_hash_fcn_type); /*deprecated*/
 
516
        int set_h_hash(u_int32_t (*)(Db *, const void *, u_int32_t));
 
517
        int set_h_nelem(u_int32_t);
 
518
        int set_lorder(int);
 
519
        int set_pagesize(u_int32_t);
 
520
        int set_paniccall(void (*)(DbEnv *, int));
 
521
        int set_re_delim(int);
 
522
        int set_re_len(u_int32_t);
 
523
        int set_re_pad(int);
 
524
        int set_re_source(char *);
 
525
        int set_q_extentsize(u_int32_t);
 
526
        int stat(void *sp, u_int32_t flags);
 
527
        int sync(u_int32_t flags);
 
528
        int truncate(DbTxn *, u_int32_t *, u_int32_t);
 
529
        int upgrade(const char *name, u_int32_t flags);
 
530
        int verify(const char *, const char *, ostream *, u_int32_t);
 
531
 
 
532
        // These additional methods are not in the C interface, and
 
533
        // are only available for C++.
 
534
        //
 
535
        void set_error_stream(ostream *);
 
536
 
 
537
        DB *get_DB()
 
538
        {
 
539
                return (DB *)imp();
 
540
        }
 
541
 
 
542
        const DB *get_const_DB() const
 
543
        {
 
544
                return (const DB *)constimp();
 
545
        }
 
546
 
 
547
        static Db* get_Db(DB *db)
 
548
        {
 
549
                return (Db *)db->cj_internal;
 
550
        }
 
551
 
 
552
        static const Db* get_const_Db(const DB *db)
 
553
        {
 
554
                return (const Db *)db->cj_internal;
 
555
        }
 
556
 
 
557
        // These are public only because they need to be called
 
558
        // via C callback functions.  They should never be used by
 
559
        // external users of this class.
 
560
        //
 
561
        void (*feedback_callback_)(Db *, int, int);
 
562
        int (*append_recno_callback_)(Db *, Dbt *, db_recno_t);
 
563
        int (*bt_compare_callback_)(Db *, const Dbt *, const Dbt *);
 
564
        size_t (*bt_prefix_callback_)(Db *, const Dbt *, const Dbt *);
 
565
        int (*dup_compare_callback_)(Db *, const Dbt *, const Dbt *);
 
566
        u_int32_t (*h_hash_callback_)(Db *, const void *, u_int32_t);
 
567
        int (*associate_callback_)(Db *, const Dbt *, const Dbt *, Dbt *);
 
568
private:
 
569
 
 
570
        // no copying
 
571
        Db(const Db &);
 
572
        Db &operator = (const Db &);
 
573
 
 
574
        DEFINE_DB_CLASS(Db);
 
575
 
 
576
        void cleanup();
 
577
        int initialize();
 
578
        int error_policy();
 
579
 
 
580
        // instance data
 
581
        DbEnv *env_;
 
582
        int construct_error_;
 
583
        u_int32_t flags_;
 
584
        u_int32_t construct_flags_;
 
585
};
 
586
 
 
587
//
 
588
// A chunk of data, maybe a key or value.
 
589
//
 
590
class _exported Dbt : private DBT
 
591
{
 
592
        friend class Dbc;
 
593
        friend class Db;
 
594
        friend class DbEnv;
 
595
 
 
596
public:
 
597
 
 
598
        // key/data
 
599
        void *get_data() const                 { return data; }
 
600
        void set_data(void *value)             { data = value; }
 
601
 
 
602
        // key/data length
 
603
        u_int32_t get_size() const             { return size; }
 
604
        void set_size(u_int32_t value)         { size = value; }
 
605
 
 
606
        // RO: length of user buffer.
 
607
        u_int32_t get_ulen() const             { return ulen; }
 
608
        void set_ulen(u_int32_t value)         { ulen = value; }
 
609
 
 
610
        // RO: get/put record length.
 
611
        u_int32_t get_dlen() const             { return dlen; }
 
612
        void set_dlen(u_int32_t value)         { dlen = value; }
 
613
 
 
614
        // RO: get/put record offset.
 
615
        u_int32_t get_doff() const             { return doff; }
 
616
        void set_doff(u_int32_t value)         { doff = value; }
 
617
 
 
618
        // flags
 
619
        u_int32_t get_flags() const            { return flags; }
 
620
        void set_flags(u_int32_t value)        { flags = value; }
 
621
 
 
622
        // Conversion functions
 
623
        DBT *get_DBT()                         { return (DBT *)this; }
 
624
        const DBT *get_const_DBT() const       { return (const DBT *)this; }
 
625
 
 
626
        static Dbt* get_Dbt(DBT *dbt)          { return (Dbt *)dbt; }
 
627
        static const Dbt* get_const_Dbt(const DBT *dbt)
 
628
                                               { return (const Dbt *)dbt; }
 
629
 
 
630
        Dbt(void *data, size_t size);
 
631
        Dbt();
 
632
        ~Dbt();
 
633
        Dbt(const Dbt &);
 
634
        Dbt &operator = (const Dbt &);
 
635
 
 
636
private:
 
637
        // Note: no extra data appears in this class (other than
 
638
        // inherited from DBT) since we need DBT and Dbt objects
 
639
        // to have interchangable pointers.
 
640
        //
 
641
        // When subclassing this class, remember that callback
 
642
        // methods like bt_compare, bt_prefix, dup_compare may
 
643
        // internally manufacture DBT objects (which later are
 
644
        // cast to Dbt), so such callbacks might receive objects
 
645
        // not of your subclassed type.
 
646
};
 
647
 
 
648
class _exported Dbc : protected DBC
 
649
{
 
650
        friend class Db;
 
651
 
 
652
public:
 
653
        int close();
 
654
        int count(db_recno_t *countp, u_int32_t flags);
 
655
        int del(u_int32_t flags);
 
656
        int dup(Dbc** cursorp, u_int32_t flags);
 
657
        int get(Dbt* key, Dbt *data, u_int32_t flags);
 
658
        int pget(Dbt* key, Dbt* pkey, Dbt *data, u_int32_t flags);
 
659
        int put(Dbt* key, Dbt *data, u_int32_t flags);
 
660
 
 
661
private:
 
662
        // No data is permitted in this class (see comment at top)
 
663
 
 
664
        // Note: use Db::cursor() to get pointers to a Dbc,
 
665
        // and call Dbc::close() rather than delete to release them.
 
666
        //
 
667
        Dbc();
 
668
        ~Dbc();
 
669
 
 
670
        // no copying
 
671
        Dbc(const Dbc &);
 
672
        Dbc &operator = (const Dbc &);
 
673
};
 
674
#endif /* !_DB_CXX_H_ */