📄 db_cxx.in
字号:
/*- * See the file LICENSE for redistribution information. * * Copyright (c) 1997-2002 * Sleepycat Software. All rights reserved. * * $Id: db_cxx.in,v 11.113 2002/08/23 13:02:27 mjc Exp $ */#ifndef _DB_CXX_H_#define _DB_CXX_H_//// C++ assumptions://// To ensure portability to many platforms, both new and old, we make// few assumptions about the C++ compiler and library. For example,// we do not expect STL, templates or namespaces to be available. The// "newest" C++ feature used is exceptions, which are used liberally// to transmit error information. Even the use of exceptions can be// disabled at runtime, to do so, use the DB_CXX_NO_EXCEPTIONS flags// with the DbEnv or Db constructor.//// C++ naming conventions://// - All top level class names start with Db.// - All class members start with lower case letter.// - All private data members are suffixed with underscore.// - Use underscores to divide names into multiple words.// - Simple data accessors are named with get_ or set_ prefix.// - All method names are taken from names of functions in the C// layer of db (usually by dropping a prefix like "db_").// These methods have the same argument types and order,// other than dropping the explicit arg that acts as "this".//// As a rule, each DbFoo object has exactly one underlying DB_FOO struct// (defined in db.h) associated with it. In some cases, we inherit directly// from the DB_FOO structure to make this relationship explicit. Often,// the underlying C layer allocates and deallocates these structures, so// there is no easy way to add any data to the DbFoo class. When you see// a comment about whether data is permitted to be added, this is what// is going on. Of course, if we need to add data to such C++ classes// in the future, we will arrange to have an indirect pointer to the// DB_FOO struct (as some of the classes already have).////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Forward declarations//#include <stdarg.h>@cxx_have_stdheaders@#ifdef HAVE_CXX_STDHEADERS#include <iostream>#define __DB_OSTREAMCLASS std::ostream#else#include <iostream.h>#define __DB_OSTREAMCLASS ostream#endif#include "db.h"#include "cxx_common.h"#include "cxx_except.h"class Db; // forwardclass Dbc; // forwardclass DbEnv; // forwardclass DbInfo; // forwardclass DbLock; // forwardclass DbLogc; // forwardclass DbLsn; // forwardclass DbMpoolFile; // forwardclass DbPreplist; // forwardclass Dbt; // forwardclass DbTxn; // forward// These classes are not defined here and should be invisible// to the user, but some compilers require forward references.// There is one for each use of the DEFINE_DB_CLASS macro.class DbImp;class DbEnvImp;class DbMpoolFileImp;class DbTxnImp;// DEFINE_DB_CLASS defines an imp_ data member and imp() accessor.// The underlying type is a pointer to an opaque *Imp class, that// gets converted to the correct implementation class by the implementation.//// Since these defines use "private/public" labels, and leave the access// being "private", we always use these by convention before any data// members in the private section of a class. Keeping them in the// private section also emphasizes that they are off limits to user code.//#define DEFINE_DB_CLASS(name) \ public: class name##Imp* imp() { return (imp_); } \ public: const class name##Imp* constimp() const { return (imp_); } \ private: class name##Imp* imp_//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Turn off inappropriate compiler warnings//#ifdef _MSC_VER// These are level 4 warnings that are explicitly disabled.// With Visual C++, by default you do not see above level 3 unless// you use /W4. But we like to compile with the highest level// warnings to catch other errors.//// 4201: nameless struct/union// triggered by standard include file <winnt.h>//// 4514: unreferenced inline function has been removed// certain include files in MSVC define methods that are not called//#pragma warning(disable: 4201 4514)#endif// Some interfaces can be customized by allowing users to define// callback functions. For performance and logistical reasons, some// callback functions must be declared in extern "C" blocks. For others,// we allow you to declare the callbacks in C++ or C (or an extern "C"// block) as you wish. See the set methods for the callbacks for// the choices.//extern "C" { typedef void * (*db_malloc_fcn_type) (size_t); typedef void * (*db_realloc_fcn_type) (void *, size_t); typedef void (*db_free_fcn_type) (void *); typedef int (*bt_compare_fcn_type) /*C++ version available*/ (DB *, const DBT *, const DBT *); typedef size_t (*bt_prefix_fcn_type) /*C++ version available*/ (DB *, const DBT *, const DBT *); typedef int (*dup_compare_fcn_type) /*C++ version available*/ (DB *, const DBT *, const DBT *); typedef u_int32_t (*h_hash_fcn_type) /*C++ version available*/ (DB *, const void *, u_int32_t); typedef int (*pgin_fcn_type) (DB_ENV *dbenv, db_pgno_t pgno, void *pgaddr, DBT *pgcookie); typedef int (*pgout_fcn_type) (DB_ENV *dbenv, db_pgno_t pgno, void *pgaddr, DBT *pgcookie);};//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Lock classes//class _exported DbLock{ friend class DbEnv;public: DbLock(); DbLock(const DbLock &); DbLock &operator = (const DbLock &);protected: // We can add data to this class if needed // since its contained class is not allocated by db. // (see comment at top) DbLock(DB_LOCK); DB_LOCK lock_;};//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Log classes//class _exported DbLsn : protected DB_LSN{ friend class DbEnv; // friendship needed to cast to base class friend class DbLogc; // friendship needed to cast to base class};//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Memory pool classes//class _exported DbMpoolFile{ friend class DbEnv;private: // Put this first to allow inlining with some C++ compilers (g++-2.95) DEFINE_DB_CLASS(DbMpoolFile);public: int close(u_int32_t flags); int get(db_pgno_t *pgnoaddr, u_int32_t flags, void *pagep); void last_pgno(db_pgno_t *pgnoaddr); int open(const char *file, u_int32_t flags, int mode, size_t pagesize); int put(void *pgaddr, u_int32_t flags); void refcnt(db_pgno_t *pgnoaddr); int set(void *pgaddr, u_int32_t flags); int set_clear_len(u_int32_t len); int set_fileid(u_int8_t *fileid); int set_ftype(int ftype); int set_lsn_offset(int32_t offset); int set_pgcookie(DBT *dbt); void set_unlink(int); int sync(); virtual DB_MPOOLFILE *get_DB_MPOOLFILE() { return (DB_MPOOLFILE *)imp(); } virtual const DB_MPOOLFILE *get_const_DB_MPOOLFILE() const { return (const DB_MPOOLFILE *)constimp(); }private: // We can add data to this class if needed // since it is implemented via a pointer. // (see comment at top) // Note: use DbEnv::memp_fcreate() to get pointers to a DbMpoolFile, // and call DbMpoolFile::close() rather than delete to release them. // DbMpoolFile(); // Shut g++ up.protected: virtual ~DbMpoolFile();private: // no copying DbMpoolFile(const DbMpoolFile &); void operator = (const DbMpoolFile &);};//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// This is filled in and returned by the DbEnv::txn_recover() method.//class _exported DbPreplist{public: DbTxn *txn; u_int8_t gid[DB_XIDDATASIZE];};//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Transaction classes//class _exported DbTxn{ friend class DbEnv;private: // Put this first to allow inlining with some C++ compilers (g++-2.95) DEFINE_DB_CLASS(DbTxn);public: int abort(); int commit(u_int32_t flags); int discard(u_int32_t flags); u_int32_t id(); int prepare(u_int8_t *gid); int set_timeout(db_timeout_t timeout, u_int32_t flags); virtual DB_TXN *get_DB_TXN() { return (DB_TXN *)imp(); } virtual const DB_TXN *get_const_DB_TXN() const { return (const DB_TXN *)constimp(); } static DbTxn* get_DbTxn(DB_TXN *txn) { return (DbTxn *)txn->api_internal; } static const DbTxn* get_const_DbTxn(const DB_TXN *txn) { return (const DbTxn *)txn->api_internal; } // For internal use only. static DbTxn* wrap_DB_TXN(DB_TXN *txn);private: // We can add data to this class if needed // since it is implemented via a pointer. // (see comment at top) // Note: use DbEnv::txn_begin() to get pointers to a DbTxn, // and call DbTxn::abort() or DbTxn::commit rather than // delete to release them. // DbTxn(); // For internal use only. DbTxn(DB_TXN *txn); virtual ~DbTxn(); // no copying DbTxn(const DbTxn &); void operator = (const DbTxn &);};//// Berkeley DB environment class. Provides functions for opening databases.// User of this library can use this class as a starting point for// developing a DB application - derive their application class from// this one, add application control logic.//// Note that if you use the default constructor, you must explicitly// call appinit() before any other db activity (e.g. opening files)//class _exported DbEnv{ friend class Db; friend class DbLock; friend class DbMpoolFile;private: // Put this first to allow inlining with some C++ compilers (g++-2.95) DEFINE_DB_CLASS(DbEnv);public: // After using this constructor, you can set any needed // parameters for the environment using the set_* methods. // Then call open() to finish initializing the environment // and attaching it to underlying files. // DbEnv(u_int32_t flags); virtual ~DbEnv(); // These methods match those in the C interface. // virtual int close(u_int32_t); virtual int dbremove(DbTxn *txn, const char *name, const char *subdb, u_int32_t flags); virtual int dbrename(DbTxn *txn, const char *name, const char *subdb, const char *newname, u_int32_t flags); virtual void err(int, const char *, ...); virtual void errx(const char *, ...); virtual void *get_app_private() const; virtual int open(const char *, u_int32_t, int); virtual int remove(const char *, u_int32_t); virtual int set_alloc(db_malloc_fcn_type, db_realloc_fcn_type, db_free_fcn_type); virtual void set_app_private(void *); virtual int set_cachesize(u_int32_t, u_int32_t, int); virtual int set_data_dir(const char *); virtual int set_encrypt(const char *, int); virtual void set_errcall(void (*)(const char *, char *)); virtual void set_errfile(FILE *); virtual void set_errpfx(const char *); virtual int set_flags(u_int32_t, int); virtual int set_feedback(void (*)(DbEnv *, int, int)); virtual int set_lg_bsize(u_int32_t); virtual int set_lg_dir(const char *); virtual int set_lg_max(u_int32_t); virtual int set_lg_regionmax(u_int32_t); virtual int set_lk_conflicts(u_int8_t *, int); virtual int set_lk_detect(u_int32_t); virtual int set_lk_max(u_int32_t); virtual int set_lk_max_lockers(u_int32_t); virtual int set_lk_max_locks(u_int32_t); virtual int set_lk_max_objects(u_int32_t); virtual int set_mp_mmapsize(size_t); virtual int set_paniccall(void (*)(DbEnv *, int)); virtual int set_rpc_server(void *, char *, long, long, u_int32_t); virtual int set_shm_key(long); virtual int set_timeout(db_timeout_t timeout, u_int32_t flags); virtual int set_tmp_dir(const char *); virtual int set_tas_spins(u_int32_t); virtual int set_tx_max(u_int32_t); virtual int set_app_dispatch(int (*)(DbEnv *, Dbt *, DbLsn *, db_recops)); virtual int set_tx_timestamp(time_t *);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -