~ubuntu-branches/ubuntu/natty/evolution-data-server/natty

« back to all changes in this revision

Viewing changes to libdb/dist/db_cxx.h

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

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-2002
5
 
 *      Sleepycat Software.  All rights reserved.
6
 
 *
7
 
 * $Id$
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 <stdarg.h>
53
 
 
54
 
 
55
 
#ifdef HAVE_CXX_STDHEADERS
56
 
#include <iostream>
57
 
#define __DB_OSTREAMCLASS       std::ostream
58
 
#else
59
 
#include <iostream.h>
60
 
#define __DB_OSTREAMCLASS       ostream
61
 
#endif
62
 
 
63
 
#include "db.h"
64
 
#include "cxx_common.h"
65
 
#include "cxx_except.h"
66
 
 
67
 
class Db;                                        // forward
68
 
class Dbc;                                       // forward
69
 
class DbEnv;                                     // forward
70
 
class DbInfo;                                    // forward
71
 
class DbLock;                                    // forward
72
 
class DbLogc;                                    // forward
73
 
class DbLsn;                                     // forward
74
 
class DbMpoolFile;                               // forward
75
 
class DbPreplist;                                // forward
76
 
class Dbt;                                       // forward
77
 
class DbTxn;                                     // forward
78
 
 
79
 
// These classes are not defined here and should be invisible
80
 
// to the user, but some compilers require forward references.
81
 
// There is one for each use of the DEFINE_DB_CLASS macro.
82
 
 
83
 
class DbImp;
84
 
class DbEnvImp;
85
 
class DbMpoolFileImp;
86
 
class DbTxnImp;
87
 
 
88
 
// DEFINE_DB_CLASS defines an imp_ data member and imp() accessor.
89
 
// The underlying type is a pointer to an opaque *Imp class, that
90
 
// gets converted to the correct implementation class by the implementation.
91
 
//
92
 
// Since these defines use "private/public" labels, and leave the access
93
 
// being "private", we always use these by convention before any data
94
 
// members in the private section of a class.  Keeping them in the
95
 
// private section also emphasizes that they are off limits to user code.
96
 
//
97
 
#define DEFINE_DB_CLASS(name) \
98
 
        public: class name##Imp* imp() { return (imp_); } \
99
 
        public: const class name##Imp* constimp() const { return (imp_); } \
100
 
        private: class name##Imp* imp_
101
 
 
102
 
////////////////////////////////////////////////////////////////
103
 
////////////////////////////////////////////////////////////////
104
 
//
105
 
// Turn off inappropriate compiler warnings
106
 
//
107
 
 
108
 
#ifdef _MSC_VER
109
 
 
110
 
// These are level 4 warnings that are explicitly disabled.
111
 
// With Visual C++, by default you do not see above level 3 unless
112
 
// you use /W4.  But we like to compile with the highest level
113
 
// warnings to catch other errors.
114
 
//
115
 
// 4201: nameless struct/union
116
 
//       triggered by standard include file <winnt.h>
117
 
//
118
 
// 4514: unreferenced inline function has been removed
119
 
//       certain include files in MSVC define methods that are not called
120
 
//
121
 
#pragma warning(disable: 4201 4514)
122
 
 
123
 
#endif
124
 
 
125
 
// Some interfaces can be customized by allowing users to define
126
 
// callback functions.  For performance and logistical reasons, some
127
 
// callback functions must be declared in extern "C" blocks.  For others,
128
 
// we allow you to declare the callbacks in C++ or C (or an extern "C"
129
 
// block) as you wish.  See the set methods for the callbacks for
130
 
// the choices.
131
 
//
132
 
extern "C" {
133
 
        typedef void * (*db_malloc_fcn_type)
134
 
                (size_t);
135
 
        typedef void * (*db_realloc_fcn_type)
136
 
                (void *, size_t);
137
 
        typedef void (*db_free_fcn_type)
138
 
                (void *);
139
 
        typedef int (*bt_compare_fcn_type)          /*C++ version available*/
140
 
                (DB *, const DBT *, const DBT *);
141
 
        typedef size_t (*bt_prefix_fcn_type)        /*C++ version available*/
142
 
                (DB *, const DBT *, const DBT *);
143
 
        typedef int (*dup_compare_fcn_type)         /*C++ version available*/
144
 
                (DB *, const DBT *, const DBT *);
145
 
        typedef u_int32_t (*h_hash_fcn_type)        /*C++ version available*/
146
 
                (DB *, const void *, u_int32_t);
147
 
        typedef int (*pgin_fcn_type)
148
 
                (DB_ENV *dbenv, db_pgno_t pgno, void *pgaddr, DBT *pgcookie);
149
 
        typedef int (*pgout_fcn_type)
150
 
                (DB_ENV *dbenv, db_pgno_t pgno, void *pgaddr, DBT *pgcookie);
151
 
};
152
 
 
153
 
////////////////////////////////////////////////////////////////
154
 
////////////////////////////////////////////////////////////////
155
 
//
156
 
// Lock classes
157
 
//
158
 
 
159
 
class _exported DbLock
160
 
{
161
 
        friend class DbEnv;
162
 
 
163
 
public:
164
 
        DbLock();
165
 
        DbLock(const DbLock &);
166
 
        DbLock &operator = (const DbLock &);
167
 
 
168
 
protected:
169
 
        // We can add data to this class if needed
170
 
        // since its contained class is not allocated by db.
171
 
        // (see comment at top)
172
 
 
173
 
        DbLock(DB_LOCK);
174
 
        DB_LOCK lock_;
175
 
};
176
 
 
177
 
////////////////////////////////////////////////////////////////
178
 
////////////////////////////////////////////////////////////////
179
 
//
180
 
// Log classes
181
 
//
182
 
 
183
 
class _exported DbLsn : protected DB_LSN
184
 
{
185
 
        friend class DbEnv;          // friendship needed to cast to base class
186
 
        friend class DbLogc;         // friendship needed to cast to base class
187
 
};
188
 
 
189
 
////////////////////////////////////////////////////////////////
190
 
////////////////////////////////////////////////////////////////
191
 
//
192
 
// Memory pool classes
193
 
//
194
 
 
195
 
class _exported DbMpoolFile
196
 
{
197
 
        friend class DbEnv;
198
 
 
199
 
private:
200
 
        // Put this first to allow inlining with some C++ compilers (g++-2.95)
201
 
        DEFINE_DB_CLASS(DbMpoolFile);
202
 
 
203
 
public:
204
 
        int close(u_int32_t flags);
205
 
        int get(db_pgno_t *pgnoaddr, u_int32_t flags, void *pagep);
206
 
        void last_pgno(db_pgno_t *pgnoaddr);
207
 
        int open(const char *file, u_int32_t flags, int mode, size_t pagesize);
208
 
        int put(void *pgaddr, u_int32_t flags);
209
 
        void refcnt(db_pgno_t *pgnoaddr);
210
 
        int set(void *pgaddr, u_int32_t flags);
211
 
        int set_clear_len(u_int32_t len);
212
 
        int set_fileid(u_int8_t *fileid);
213
 
        int set_ftype(int ftype);
214
 
        int set_lsn_offset(int32_t offset);
215
 
        int set_pgcookie(DBT *dbt);
216
 
        void set_unlink(int);
217
 
        int sync();
218
 
 
219
 
        virtual DB_MPOOLFILE *get_DB_MPOOLFILE()
220
 
        {
221
 
                return (DB_MPOOLFILE *)imp();
222
 
        }
223
 
 
224
 
        virtual const DB_MPOOLFILE *get_const_DB_MPOOLFILE() const
225
 
        {
226
 
                return (const DB_MPOOLFILE *)constimp();
227
 
        }
228
 
 
229
 
private:
230
 
        // We can add data to this class if needed
231
 
        // since it is implemented via a pointer.
232
 
        // (see comment at top)
233
 
 
234
 
        // Note: use DbEnv::memp_fcreate() to get pointers to a DbMpoolFile,
235
 
        // and call DbMpoolFile::close() rather than delete to release them.
236
 
        //
237
 
        DbMpoolFile();
238
 
 
239
 
        // Shut g++ up.
240
 
protected:
241
 
        virtual ~DbMpoolFile();
242
 
 
243
 
private:
244
 
        // no copying
245
 
        DbMpoolFile(const DbMpoolFile &);
246
 
        void operator = (const DbMpoolFile &);
247
 
};
248
 
 
249
 
////////////////////////////////////////////////////////////////
250
 
////////////////////////////////////////////////////////////////
251
 
//
252
 
// This is filled in and returned by the DbEnv::txn_recover() method.
253
 
//
254
 
 
255
 
class _exported DbPreplist
256
 
{
257
 
public:
258
 
        DbTxn *txn;
259
 
        u_int8_t gid[DB_XIDDATASIZE];
260
 
};
261
 
 
262
 
////////////////////////////////////////////////////////////////
263
 
////////////////////////////////////////////////////////////////
264
 
//
265
 
// Transaction classes
266
 
//
267
 
 
268
 
class _exported DbTxn
269
 
{
270
 
        friend class DbEnv;
271
 
 
272
 
private:
273
 
        // Put this first to allow inlining with some C++ compilers (g++-2.95)
274
 
        DEFINE_DB_CLASS(DbTxn);
275
 
 
276
 
public:
277
 
        int abort();
278
 
        int commit(u_int32_t flags);
279
 
        int discard(u_int32_t flags);
280
 
        u_int32_t id();
281
 
        int prepare(u_int8_t *gid);
282
 
        int set_timeout(db_timeout_t timeout, u_int32_t flags);
283
 
 
284
 
        virtual DB_TXN *get_DB_TXN()
285
 
        {
286
 
                return (DB_TXN *)imp();
287
 
        }
288
 
 
289
 
        virtual const DB_TXN *get_const_DB_TXN() const
290
 
        {
291
 
                return (const DB_TXN *)constimp();
292
 
        }
293
 
 
294
 
        static DbTxn* get_DbTxn(DB_TXN *txn)
295
 
        {
296
 
                return (DbTxn *)txn->api_internal;
297
 
        }
298
 
 
299
 
        static const DbTxn* get_const_DbTxn(const DB_TXN *txn)
300
 
        {
301
 
                return (const DbTxn *)txn->api_internal;
302
 
        }
303
 
 
304
 
        // For internal use only.
305
 
        static DbTxn* wrap_DB_TXN(DB_TXN *txn);
306
 
 
307
 
private:
308
 
        // We can add data to this class if needed
309
 
        // since it is implemented via a pointer.
310
 
        // (see comment at top)
311
 
 
312
 
        // Note: use DbEnv::txn_begin() to get pointers to a DbTxn,
313
 
        // and call DbTxn::abort() or DbTxn::commit rather than
314
 
        // delete to release them.
315
 
        //
316
 
        DbTxn();
317
 
        // For internal use only.
318
 
        DbTxn(DB_TXN *txn);
319
 
        virtual ~DbTxn();
320
 
 
321
 
        // no copying
322
 
        DbTxn(const DbTxn &);
323
 
        void operator = (const DbTxn &);
324
 
};
325
 
 
326
 
//
327
 
// Berkeley DB environment class.  Provides functions for opening databases.
328
 
// User of this library can use this class as a starting point for
329
 
// developing a DB application - derive their application class from
330
 
// this one, add application control logic.
331
 
//
332
 
// Note that if you use the default constructor, you must explicitly
333
 
// call appinit() before any other db activity (e.g. opening files)
334
 
//
335
 
class _exported DbEnv
336
 
{
337
 
        friend class Db;
338
 
        friend class DbLock;
339
 
        friend class DbMpoolFile;
340
 
 
341
 
private:
342
 
        // Put this first to allow inlining with some C++ compilers (g++-2.95)
343
 
        DEFINE_DB_CLASS(DbEnv);
344
 
 
345
 
public:
346
 
        // After using this constructor, you can set any needed
347
 
        // parameters for the environment using the set_* methods.
348
 
        // Then call open() to finish initializing the environment
349
 
        // and attaching it to underlying files.
350
 
        //
351
 
        DbEnv(u_int32_t flags);
352
 
 
353
 
        virtual ~DbEnv();
354
 
 
355
 
        // These methods match those in the C interface.
356
 
        //
357
 
        virtual int close(u_int32_t);
358
 
        virtual int dbremove(DbTxn *txn, const char *name, const char *subdb,
359
 
            u_int32_t flags);
360
 
        virtual int dbrename(DbTxn *txn, const char *name, const char *subdb,
361
 
            const char *newname, u_int32_t flags);
362
 
        virtual void err(int, const char *, ...);
363
 
        virtual void errx(const char *, ...);
364
 
        virtual void *get_app_private() const;
365
 
        virtual int open(const char *, u_int32_t, int);
366
 
        virtual int remove(const char *, u_int32_t);
367
 
        virtual int set_alloc(db_malloc_fcn_type, db_realloc_fcn_type,
368
 
                      db_free_fcn_type);
369
 
        virtual void set_app_private(void *);
370
 
        virtual int set_cachesize(u_int32_t, u_int32_t, int);
371
 
        virtual int set_data_dir(const char *);
372
 
        virtual int set_encrypt(const char *, int);
373
 
        virtual void set_errcall(void (*)(const char *, char *));
374
 
        virtual void set_errfile(FILE *);
375
 
        virtual void set_errpfx(const char *);
376
 
        virtual int set_flags(u_int32_t, int);
377
 
        virtual int set_feedback(void (*)(DbEnv *, int, int));
378
 
        virtual int set_lg_bsize(u_int32_t);
379
 
        virtual int set_lg_dir(const char *);
380
 
        virtual int set_lg_max(u_int32_t);
381
 
        virtual int set_lg_regionmax(u_int32_t);
382
 
        virtual int set_lk_conflicts(u_int8_t *, int);
383
 
        virtual int set_lk_detect(u_int32_t);
384
 
        virtual int set_lk_max(u_int32_t);
385
 
        virtual int set_lk_max_lockers(u_int32_t);
386
 
        virtual int set_lk_max_locks(u_int32_t);
387
 
        virtual int set_lk_max_objects(u_int32_t);
388
 
        virtual int set_mp_mmapsize(size_t);
389
 
        virtual int set_paniccall(void (*)(DbEnv *, int));
390
 
        virtual int set_rpc_server(void *, char *, long, long, u_int32_t);
391
 
        virtual int set_shm_key(long);
392
 
        virtual int set_timeout(db_timeout_t timeout, u_int32_t flags);
393
 
        virtual int set_tmp_dir(const char *);
394
 
        virtual int set_tas_spins(u_int32_t);
395
 
        virtual int set_tx_max(u_int32_t);
396
 
        virtual int set_app_dispatch(int (*)(DbEnv *,
397
 
            Dbt *, DbLsn *, db_recops));
398
 
        virtual int set_tx_timestamp(time_t *);
399
 
        virtual int set_verbose(u_int32_t which, int onoff);
400
 
 
401
 
        // Version information.  A static method so it can be obtained anytime.
402
 
        //
403
 
        static char *version(int *major, int *minor, int *patch);
404
 
 
405
 
        // Convert DB errors to strings
406
 
        static char *strerror(int);
407
 
 
408
 
        // If an error is detected and the error call function
409
 
        // or stream is set, a message is dispatched or printed.
410
 
        // If a prefix is set, each message is prefixed.
411
 
        //
412
 
        // You can use set_errcall() or set_errfile() above to control
413
 
        // error functionality.  Alternatively, you can call
414
 
        // set_error_stream() to force all errors to a C++ stream.
415
 
        // It is unwise to mix these approaches.
416
 
        //
417
 
        virtual void set_error_stream(__DB_OSTREAMCLASS *);
418
 
 
419
 
        // used internally
420
 
        static void runtime_error(const char *caller, int err,
421
 
                                  int error_policy);
422
 
        static void runtime_error_dbt(const char *caller, Dbt *dbt,
423
 
                                  int error_policy);
424
 
        static void runtime_error_lock_get(const char *caller, int err,
425
 
                                  db_lockop_t op, db_lockmode_t mode,
426
 
                                  const Dbt *obj, DbLock lock, int index,
427
 
                                  int error_policy);
428
 
 
429
 
        // Lock functions
430
 
        //
431
 
        virtual int lock_detect(u_int32_t flags, u_int32_t atype, int *aborted);
432
 
        virtual int lock_get(u_int32_t locker, u_int32_t flags, const Dbt *obj,
433
 
                     db_lockmode_t lock_mode, DbLock *lock);
434
 
        virtual int lock_id(u_int32_t *idp);
435
 
        virtual int lock_id_free(u_int32_t id);
436
 
        virtual int lock_put(DbLock *lock);
437
 
        virtual int lock_stat(DB_LOCK_STAT **statp, u_int32_t flags);
438
 
        virtual int lock_vec(u_int32_t locker, u_int32_t flags, DB_LOCKREQ list[],
439
 
                     int nlist, DB_LOCKREQ **elistp);
440
 
 
441
 
        // Log functions
442
 
        //
443
 
        virtual int log_archive(char **list[], u_int32_t flags);
444
 
        static int log_compare(const DbLsn *lsn0, const DbLsn *lsn1);
445
 
        virtual int log_cursor(DbLogc **cursorp, u_int32_t flags);
446
 
        virtual int log_file(DbLsn *lsn, char *namep, size_t len);
447
 
        virtual int log_flush(const DbLsn *lsn);
448
 
        virtual int log_put(DbLsn *lsn, const Dbt *data, u_int32_t flags);
449
 
 
450
 
        virtual int log_stat(DB_LOG_STAT **spp, u_int32_t flags);
451
 
 
452
 
        // Mpool functions
453
 
        //
454
 
        virtual int memp_fcreate(DbMpoolFile **dbmfp, u_int32_t flags);
455
 
        virtual int memp_register(int ftype,
456
 
                          pgin_fcn_type pgin_fcn,
457
 
                          pgout_fcn_type pgout_fcn);
458
 
        virtual int memp_stat(DB_MPOOL_STAT
459
 
                      **gsp, DB_MPOOL_FSTAT ***fsp, u_int32_t flags);
460
 
        virtual int memp_sync(DbLsn *lsn);
461
 
        virtual int memp_trickle(int pct, int *nwrotep);
462
 
 
463
 
        // Transaction functions
464
 
        //
465
 
        virtual int txn_begin(DbTxn *pid, DbTxn **tid, u_int32_t flags);
466
 
        virtual int txn_checkpoint(u_int32_t kbyte, u_int32_t min, u_int32_t flags);
467
 
        virtual int txn_recover(DbPreplist *preplist, long count,
468
 
                        long *retp, u_int32_t flags);
469
 
        virtual int txn_stat(DB_TXN_STAT **statp, u_int32_t flags);
470
 
 
471
 
        // Replication functions
472
 
        //
473
 
        virtual int rep_elect(int, int, u_int32_t, int *);
474
 
        virtual int rep_process_message(Dbt *, Dbt *, int *);
475
 
        virtual int rep_start(Dbt *, u_int32_t);
476
 
        virtual int rep_stat(DB_REP_STAT **statp, u_int32_t flags);
477
 
        virtual int set_rep_limit(u_int32_t, u_int32_t);
478
 
        virtual int set_rep_transport(u_int32_t,
479
 
            int (*)(DbEnv *, const Dbt *, const Dbt *, int, u_int32_t));
480
 
 
481
 
        // Conversion functions
482
 
        //
483
 
        virtual DB_ENV *get_DB_ENV()
484
 
        {
485
 
                return (DB_ENV *)imp();
486
 
        }
487
 
 
488
 
        virtual const DB_ENV *get_const_DB_ENV() const
489
 
        {
490
 
                return (const DB_ENV *)constimp();
491
 
        }
492
 
 
493
 
        static DbEnv* get_DbEnv(DB_ENV *dbenv)
494
 
        {
495
 
                return (DbEnv *)dbenv->api1_internal;
496
 
        }
497
 
 
498
 
        static const DbEnv* get_const_DbEnv(const DB_ENV *dbenv)
499
 
        {
500
 
                return (const DbEnv *)dbenv->api1_internal;
501
 
        }
502
 
 
503
 
        // For internal use only.
504
 
        static DbEnv* wrap_DB_ENV(DB_ENV *dbenv);
505
 
 
506
 
        // These are public only because they need to be called
507
 
        // via C functions.  They should never be called by users
508
 
        // of this class.
509
 
        //
510
 
        static void _stream_error_function(const char *, char *);
511
 
        static int _app_dispatch_intercept(DB_ENV *env, DBT *dbt, DB_LSN *lsn,
512
 
                                        db_recops op);
513
 
        static void _paniccall_intercept(DB_ENV *env, int errval);
514
 
        static void _feedback_intercept(DB_ENV *env, int opcode, int pct);
515
 
        static int _rep_send_intercept(DB_ENV *env,
516
 
                                       const DBT *cntrl, const DBT *data,
517
 
                                       int id, u_int32_t flags);
518
 
 
519
 
private:
520
 
        void cleanup();
521
 
        int initialize(DB_ENV *env);
522
 
        int error_policy();
523
 
 
524
 
        // For internal use only.
525
 
        DbEnv(DB_ENV *, u_int32_t flags);
526
 
 
527
 
        // no copying
528
 
        DbEnv(const DbEnv &);
529
 
        void operator = (const DbEnv &);
530
 
 
531
 
        // instance data
532
 
        int construct_error_;
533
 
        u_int32_t construct_flags_;
534
 
        int (*app_dispatch_callback_)(DbEnv *, Dbt *, DbLsn *, db_recops);
535
 
        void (*feedback_callback_)(DbEnv *, int, int);
536
 
        void (*paniccall_callback_)(DbEnv *, int);
537
 
        int (*pgin_callback_)(DbEnv *dbenv, db_pgno_t pgno,
538
 
                              void *pgaddr, Dbt *pgcookie);
539
 
        int (*pgout_callback_)(DbEnv *dbenv, db_pgno_t pgno,
540
 
                               void *pgaddr, Dbt *pgcookie);
541
 
        int (*rep_send_callback_)(DbEnv *,
542
 
            const Dbt *, const Dbt *, int, u_int32_t);
543
 
 
544
 
        // class data
545
 
        static __DB_OSTREAMCLASS *error_stream_;
546
 
};
547
 
 
548
 
////////////////////////////////////////////////////////////////
549
 
////////////////////////////////////////////////////////////////
550
 
//
551
 
// Table access classes
552
 
//
553
 
 
554
 
//
555
 
// Represents a database table = a set of keys with associated values.
556
 
//
557
 
class _exported Db
558
 
{
559
 
        friend class DbEnv;
560
 
 
561
 
private:
562
 
        // Put this first to allow inlining with some C++ compilers (g++-2.95)
563
 
        DEFINE_DB_CLASS(Db);
564
 
 
565
 
public:
566
 
        Db(DbEnv*, u_int32_t);      // create a Db object, then call open()
567
 
        virtual ~Db();              // does *not* call close.
568
 
 
569
 
        // These methods exactly match those in the C interface.
570
 
        //
571
 
        virtual int associate(DbTxn *txn, Db *secondary,
572
 
            int (*callback)(Db *, const Dbt *, const Dbt *, Dbt *),
573
 
            u_int32_t flags);
574
 
        virtual int close(u_int32_t flags);
575
 
        virtual int cursor(DbTxn *txnid, Dbc **cursorp, u_int32_t flags);
576
 
        virtual int del(DbTxn *txnid, Dbt *key, u_int32_t flags);
577
 
        virtual void err(int, const char *, ...);
578
 
        virtual void errx(const char *, ...);
579
 
        virtual int fd(int *fdp);
580
 
        virtual int get(DbTxn *txnid, Dbt *key, Dbt *data, u_int32_t flags);
581
 
        virtual void *get_app_private() const;
582
 
        virtual int get_byteswapped(int *);
583
 
        virtual int get_type(DBTYPE *);
584
 
        virtual int join(Dbc **curslist, Dbc **dbcp, u_int32_t flags);
585
 
        virtual int key_range(DbTxn *, Dbt *, DB_KEY_RANGE *, u_int32_t);
586
 
        virtual int open(DbTxn *txnid,
587
 
            const char *, const char *subname, DBTYPE, u_int32_t, int);
588
 
        virtual int pget(DbTxn *txnid, Dbt *key, Dbt *pkey, Dbt *data,
589
 
                 u_int32_t flags);
590
 
        virtual int put(DbTxn *, Dbt *, Dbt *, u_int32_t);
591
 
        virtual int remove(const char *, const char *, u_int32_t);
592
 
        virtual int rename(const char *, const char *, const char *, u_int32_t);
593
 
        virtual int set_alloc(db_malloc_fcn_type, db_realloc_fcn_type,
594
 
                      db_free_fcn_type);
595
 
        virtual void set_app_private(void *);
596
 
        virtual int set_append_recno(int (*)(Db *, Dbt *, db_recno_t));
597
 
        virtual int set_bt_compare(bt_compare_fcn_type); /*deprecated*/
598
 
        virtual int set_bt_compare(int (*)(Db *, const Dbt *, const Dbt *));
599
 
        virtual int set_bt_maxkey(u_int32_t);
600
 
        virtual int set_bt_minkey(u_int32_t);
601
 
        virtual int set_bt_prefix(bt_prefix_fcn_type); /*deprecated*/
602
 
        virtual int set_bt_prefix(size_t (*)(Db *, const Dbt *, const Dbt *));
603
 
        virtual int set_cachesize(u_int32_t, u_int32_t, int);
604
 
        virtual int set_cache_priority(DB_CACHE_PRIORITY);
605
 
        virtual int set_dup_compare(dup_compare_fcn_type); /*deprecated*/
606
 
        virtual int set_dup_compare(int (*)(Db *, const Dbt *, const Dbt *));
607
 
        virtual int set_encrypt(const char *, int);
608
 
        virtual void set_errcall(void (*)(const char *, char *));
609
 
        virtual void set_errfile(FILE *);
610
 
        virtual void set_errpfx(const char *);
611
 
        virtual int set_feedback(void (*)(Db *, int, int));
612
 
        virtual int set_flags(u_int32_t);
613
 
        virtual int set_h_ffactor(u_int32_t);
614
 
        virtual int set_h_hash(h_hash_fcn_type); /*deprecated*/
615
 
        virtual int set_h_hash(u_int32_t (*)(Db *, const void *, u_int32_t));
616
 
        virtual int set_h_nelem(u_int32_t);
617
 
        virtual int set_lorder(int);
618
 
        virtual int set_pagesize(u_int32_t);
619
 
        virtual int set_paniccall(void (*)(DbEnv *, int));
620
 
        virtual int set_re_delim(int);
621
 
        virtual int set_re_len(u_int32_t);
622
 
        virtual int set_re_pad(int);
623
 
        virtual int set_re_source(char *);
624
 
        virtual int set_q_extentsize(u_int32_t);
625
 
        virtual int stat(void *sp, u_int32_t flags);
626
 
        virtual int sync(u_int32_t flags);
627
 
        virtual int truncate(DbTxn *, u_int32_t *, u_int32_t);
628
 
        virtual int upgrade(const char *name, u_int32_t flags);
629
 
        virtual int verify(const char *, const char *, __DB_OSTREAMCLASS *, u_int32_t);
630
 
 
631
 
        // These additional methods are not in the C interface, and
632
 
        // are only available for C++.
633
 
        //
634
 
        virtual void set_error_stream(__DB_OSTREAMCLASS *);
635
 
 
636
 
        virtual DB *get_DB()
637
 
        {
638
 
                return (DB *)imp();
639
 
        }
640
 
 
641
 
        virtual const DB *get_const_DB() const
642
 
        {
643
 
                return (const DB *)constimp();
644
 
        }
645
 
 
646
 
        static Db* get_Db(DB *db)
647
 
        {
648
 
                return (Db *)db->api_internal;
649
 
        }
650
 
 
651
 
        static const Db* get_const_Db(const DB *db)
652
 
        {
653
 
                return (const Db *)db->api_internal;
654
 
        }
655
 
 
656
 
private:
657
 
        // no copying
658
 
        Db(const Db &);
659
 
        Db &operator = (const Db &);
660
 
 
661
 
        void cleanup();
662
 
        int initialize();
663
 
        int error_policy();
664
 
 
665
 
        // instance data
666
 
        DbEnv *env_;
667
 
        int construct_error_;
668
 
        u_int32_t flags_;
669
 
        u_int32_t construct_flags_;
670
 
 
671
 
public:
672
 
        // These are public only because they need to be called
673
 
        // via C callback functions.  They should never be used by
674
 
        // external users of this class.
675
 
        //
676
 
        int (*append_recno_callback_)(Db *, Dbt *, db_recno_t);
677
 
        int (*associate_callback_)(Db *, const Dbt *, const Dbt *, Dbt *);
678
 
        int (*bt_compare_callback_)(Db *, const Dbt *, const Dbt *);
679
 
        size_t (*bt_prefix_callback_)(Db *, const Dbt *, const Dbt *);
680
 
        int (*dup_compare_callback_)(Db *, const Dbt *, const Dbt *);
681
 
        void (*feedback_callback_)(Db *, int, int);
682
 
        u_int32_t (*h_hash_callback_)(Db *, const void *, u_int32_t);
683
 
};
684
 
 
685
 
//
686
 
// A chunk of data, maybe a key or value.
687
 
//
688
 
class _exported Dbt : private DBT
689
 
{
690
 
        friend class Dbc;
691
 
        friend class Db;
692
 
        friend class DbEnv;
693
 
        friend class DbLogc;
694
 
 
695
 
public:
696
 
 
697
 
        // key/data
698
 
        void *get_data() const                 { return data; }
699
 
        void set_data(void *value)             { data = value; }
700
 
 
701
 
        // key/data length
702
 
        u_int32_t get_size() const             { return size; }
703
 
        void set_size(u_int32_t value)         { size = value; }
704
 
 
705
 
        // RO: length of user buffer.
706
 
        u_int32_t get_ulen() const             { return ulen; }
707
 
        void set_ulen(u_int32_t value)         { ulen = value; }
708
 
 
709
 
        // RO: get/put record length.
710
 
        u_int32_t get_dlen() const             { return dlen; }
711
 
        void set_dlen(u_int32_t value)         { dlen = value; }
712
 
 
713
 
        // RO: get/put record offset.
714
 
        u_int32_t get_doff() const             { return doff; }
715
 
        void set_doff(u_int32_t value)         { doff = value; }
716
 
 
717
 
        // flags
718
 
        u_int32_t get_flags() const            { return flags; }
719
 
        void set_flags(u_int32_t value)        { flags = value; }
720
 
 
721
 
        // Conversion functions
722
 
        DBT *get_DBT()                         { return (DBT *)this; }
723
 
        const DBT *get_const_DBT() const       { return (const DBT *)this; }
724
 
 
725
 
        static Dbt* get_Dbt(DBT *dbt)          { return (Dbt *)dbt; }
726
 
        static const Dbt* get_const_Dbt(const DBT *dbt)
727
 
                                               { return (const Dbt *)dbt; }
728
 
 
729
 
        Dbt(void *data, u_int32_t size);
730
 
        Dbt();
731
 
        ~Dbt();
732
 
        Dbt(const Dbt &);
733
 
        Dbt &operator = (const Dbt &);
734
 
 
735
 
private:
736
 
        // Note: no extra data appears in this class (other than
737
 
        // inherited from DBT) since we need DBT and Dbt objects
738
 
        // to have interchangable pointers.
739
 
        //
740
 
        // When subclassing this class, remember that callback
741
 
        // methods like bt_compare, bt_prefix, dup_compare may
742
 
        // internally manufacture DBT objects (which later are
743
 
        // cast to Dbt), so such callbacks might receive objects
744
 
        // not of your subclassed type.
745
 
};
746
 
 
747
 
class _exported Dbc : protected DBC
748
 
{
749
 
        friend class Db;
750
 
 
751
 
public:
752
 
        int close();
753
 
        int count(db_recno_t *countp, u_int32_t flags);
754
 
        int del(u_int32_t flags);
755
 
        int dup(Dbc** cursorp, u_int32_t flags);
756
 
        int get(Dbt* key, Dbt *data, u_int32_t flags);
757
 
        int pget(Dbt* key, Dbt* pkey, Dbt *data, u_int32_t flags);
758
 
        int put(Dbt* key, Dbt *data, u_int32_t flags);
759
 
 
760
 
private:
761
 
        // No data is permitted in this class (see comment at top)
762
 
 
763
 
        // Note: use Db::cursor() to get pointers to a Dbc,
764
 
        // and call Dbc::close() rather than delete to release them.
765
 
        //
766
 
        Dbc();
767
 
        ~Dbc();
768
 
 
769
 
        // no copying
770
 
        Dbc(const Dbc &);
771
 
        Dbc &operator = (const Dbc &);
772
 
};
773
 
 
774
 
class _exported DbLogc : protected DB_LOGC
775
 
{
776
 
        friend class DbEnv;
777
 
 
778
 
public:
779
 
        int close(u_int32_t _flags);
780
 
        int get(DbLsn *lsn, Dbt *data, u_int32_t _flags);
781
 
 
782
 
private:
783
 
        // No data is permitted in this class (see comment at top)
784
 
 
785
 
        // Note: use Db::cursor() to get pointers to a Dbc,
786
 
        // and call Dbc::close() rather than delete to release them.
787
 
        //
788
 
        DbLogc();
789
 
        ~DbLogc();
790
 
 
791
 
        // no copying
792
 
        DbLogc(const Dbc &);
793
 
        DbLogc &operator = (const Dbc &);
794
 
};
795
 
#endif /* !_DB_CXX_H_ */