1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 1997,2008 Oracle. All rights reserved. 5 * 6 * $Id: cxx_int.h,v 12.8 2008/01/08 20:58:17 bostic Exp $ 7 */ 8 9#ifndef _DB_CXX_INT_H_ 10#define _DB_CXX_INT_H_ 11 12// private data structures known to the implementation only 13 14// 15// Using FooImp classes will allow the implementation to change in the 16// future without any modification to user code or even to header files 17// that the user includes. FooImp * is just like void * except that it 18// provides a little extra protection, since you cannot randomly assign 19// any old pointer to a FooImp* as you can with void *. Currently, a 20// pointer to such an opaque class is always just a pointer to the 21// appropriate underlying implementation struct. These are converted 22// back and forth using the various overloaded wrap()/unwrap() methods. 23// This is essentially a use of the "Bridge" Design Pattern. 24// 25// WRAPPED_CLASS implements the appropriate wrap() and unwrap() methods 26// for a wrapper class that has an underlying pointer representation. 27// 28#define WRAPPED_CLASS(_WRAPPER_CLASS, _IMP_CLASS, _WRAPPED_TYPE) \ 29 class _IMP_CLASS {}; \ 30 \ 31 inline _WRAPPED_TYPE *unwrap(_WRAPPER_CLASS *val) \ 32 { \ 33 if (!val) return (0); \ 34 return (val->get_##_WRAPPED_TYPE()); \ 35 } \ 36 \ 37 inline const _WRAPPED_TYPE *unwrapConst(const _WRAPPER_CLASS *val) \ 38 { \ 39 if (!val) return (0); \ 40 return (val->get_const_##_WRAPPED_TYPE()); \ 41 } 42 43WRAPPED_CLASS(Db, DbImp, DB) 44WRAPPED_CLASS(DbEnv, DbEnvImp, DB_ENV) 45WRAPPED_CLASS(DbMpoolFile, DbMpoolFileImp, DB_MPOOLFILE) 46WRAPPED_CLASS(DbSequence, DbSequenceImp, DB_SEQUENCE) 47WRAPPED_CLASS(DbTxn, DbTxnImp, DB_TXN) 48 49// A tristate integer value used by the DB_ERROR macro below. 50// We chose not to make this an enumerated type so it can 51// be kept private, even though methods that return the 52// tristate int can be declared in db_cxx.h . 53// 54#define ON_ERROR_THROW 1 55#define ON_ERROR_RETURN 0 56#define ON_ERROR_UNKNOWN (-1) 57 58// Macros that handle detected errors, in case we want to 59// change the default behavior. The 'policy' is one of 60// the tristate values given above. If UNKNOWN is specified, 61// the behavior is taken from the last initialized DbEnv. 62// 63#define DB_ERROR(dbenv, caller, ecode, policy) \ 64 DbEnv::runtime_error(dbenv, caller, ecode, policy) 65 66#define DB_ERROR_DBT(dbenv, caller, dbt, policy) \ 67 DbEnv::runtime_error_dbt(dbenv, caller, dbt, policy) 68 69#define DB_OVERFLOWED_DBT(dbt) \ 70 (F_ISSET(dbt, DB_DBT_USERMEM) && dbt->size > dbt->ulen) 71 72/* values for Db::flags_ */ 73#define DB_CXX_PRIVATE_ENV 0x00000001 74 75#endif /* !_DB_CXX_INT_H_ */ 76