2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1997, 1998
5 * Sleepycat Software. All rights reserved.
7 * @(#)cxx_int.h 10.5 (Sleepycat) 4/10/98
13 // private data structures known to the implementation only
15 #include <assert.h> // used by defines below
18 // Using FooImp classes will allow the implementation to change in the
19 // future without any modification to user code or even to header files
20 // that the user includes. FooImp * is just like void * except that it
21 // provides a little extra protection, since you cannot randomly assign
22 // any old pointer to a FooImp* as you can with void *. Currently, a
23 // pointer to such an opaque class is always just a pointer to the
24 // appropriate underlying implementation struct. These are converted
25 // back and forth using the various overloaded wrap()/unwrap() methods.
26 // This is essentially a use of the "Bridge" Design Pattern.
28 // WRAPPED_CLASS implements the appropriate wrap() and unwrap() methods
29 // for a wrapper class that has an underlying pointer representation.
31 #define WRAPPED_CLASS(_WRAPPER_CLASS, _IMP_CLASS, _WRAPPED_TYPE) \
33 class _IMP_CLASS {}; \
35 inline _WRAPPED_TYPE unwrap(_WRAPPER_CLASS *val) \
38 return (_WRAPPED_TYPE)(val->imp()); \
41 inline const _WRAPPED_TYPE unwrapConst(const _WRAPPER_CLASS *val) \
44 return (const _WRAPPED_TYPE)(val->imp()); \
47 inline _IMP_CLASS *wrap(_WRAPPED_TYPE val) \
49 return (_IMP_CLASS*)val; \
52 WRAPPED_CLASS(DbLockTab
, DbLockTabImp
, DB_LOCKTAB
*)
53 WRAPPED_CLASS(DbLog
, DbLogImp
, DB_LOG
*)
54 WRAPPED_CLASS(DbMpool
, DbMpoolImp
, DB_MPOOL
*)
55 WRAPPED_CLASS(DbMpoolFile
, DbMpoolFileImp
, DB_MPOOLFILE
*)
56 WRAPPED_CLASS(Db
, DbImp
, DB
*)
57 WRAPPED_CLASS(DbTxn
, DbTxnImp
, DB_TXN
*)
58 WRAPPED_CLASS(DbTxnMgr
, DbTxnMgrImp
, DB_TXNMGR
*)
60 // Macros that handle detected errors, in case we want to
61 // change the default behavior. runtime_error() throws an
62 // exception by default.
64 // Since it's unusual to throw an exception in a destructor,
65 // we have a separate macro. For now, we silently ignore such
68 #define DB_ERROR(caller, ecode) \
69 DbEnv::runtime_error(caller, ecode)
71 #define DB_DESTRUCTOR_ERROR(caller, ecode) \
72 DbEnv::runtime_error(caller, ecode, 1)
75 ////////////////////////////////////////////////////////////////
76 ////////////////////////////////////////////////////////////////
78 // These defines are for tedious flag or field set/get access methods.
81 // Define setName() and getName() methods that twiddle
84 #define DB_FLAG_METHODS(_class, _flags, _cxx_name, _flag_name) \
86 void _class::set##_cxx_name(int onOrOff) \
89 _flags |= _flag_name; \
91 _flags &= ~(_flag_name); \
94 int _class::get##_cxx_name() const \
96 return (_flags & _flag_name) ? 1 : 0; \
100 #define DB_RO_ACCESS(_class, _type, _cxx_name, _field) \
102 _type _class::get_##_cxx_name() const \
107 #define DB_WO_ACCESS(_class, _type, _cxx_name, _field) \
109 void _class::set_##_cxx_name(_type value) \
114 #define DB_RW_ACCESS(_class, _type, _cxx_name, _field) \
115 DB_RO_ACCESS(_class, _type, _cxx_name, _field) \
116 DB_WO_ACCESS(_class, _type, _cxx_name, _field)
118 #endif /* !_CXX_INT_H_ */