Update.
[glibc.git] / db2 / include / cxx_int.h
blobbf7a09602da65e20b0ff7df970d96248845c4949
1 /*-
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1997
5 * Sleepycat Software. All rights reserved.
7 * @(#)cxx_int.h 10.4 (Sleepycat) 8/22/97
8 */
10 #ifndef _CXX_INT_H_
11 #define _CXX_INT_H_
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) \
36 { \
37 if (!val) return 0; \
38 return (_WRAPPED_TYPE)(val->imp()); \
39 } \
41 inline const _WRAPPED_TYPE unwrapConst(const _WRAPPER_CLASS *val) \
42 { \
43 if (!val) return 0; \
44 return (const _WRAPPED_TYPE)(val->imp()); \
45 } \
47 inline _IMP_CLASS *wrap(_WRAPPED_TYPE val) \
48 { \
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
66 // detected errors.
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
82 // the _flags field.
84 #define DB_FLAG_METHODS(_class, _flags, _cxx_name, _flag_name) \
86 void _class::set##_cxx_name(int onOrOff) \
87 { \
88 if (onOrOff) \
89 _flags |= _flag_name; \
90 else \
91 _flags &= ~(_flag_name); \
92 } \
94 int _class::get##_cxx_name() const \
95 { \
96 return (_flags & _flag_name) ? 1 : 0; \
100 #define DB_RO_ACCESS(_class, _type, _cxx_name, _field) \
102 _type _class::get_##_cxx_name() const \
104 return _field; \
107 #define DB_WO_ACCESS(_class, _type, _cxx_name, _field) \
109 void _class::set_##_cxx_name(_type value) \
111 _field = 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_ */