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