| 1 | /* -------------------- adlmacros.h -------------------- */ |
|---|
| 2 | |
|---|
| 3 | #define A_TO_I(c) if(c>'9') c-='A'-10; else c-='0'; |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | #if defined(DIGITAL) || defined(DARWIN) |
|---|
| 7 | # define GB_MEMALIGN(a,b) malloc(b) |
|---|
| 8 | #else |
|---|
| 9 | # define GB_MEMALIGN(a,b) memalign(a,b) |
|---|
| 10 | #endif |
|---|
| 11 | |
|---|
| 12 | #define GB_MIN(a,b) ( (a)>(b) ? (b):(a) ) |
|---|
| 13 | #define GB_MAX(a,b) ( (a)<(b) ? (b):(a) ) |
|---|
| 14 | |
|---|
| 15 | /********************* SECURITY ******************/ |
|---|
| 16 | |
|---|
| 17 | # define GB_GET_SECURITY_READ(gb) ((gb)->flags.security_read) |
|---|
| 18 | # define GB_GET_SECURITY_WRITE(gb) ((gb)->flags.security_write) |
|---|
| 19 | # define GB_GET_SECURITY_DELETE(gb) ((gb)->flags.security_delete) |
|---|
| 20 | |
|---|
| 21 | # define GB_PUT_SECURITY_READ(gb,i) ((gb)->flags.security_read = (i)) |
|---|
| 22 | # define GB_PUT_SECURITY_WRITE(gb,i) ((gb)->flags.security_write = (i)) |
|---|
| 23 | # define GB_PUT_SECURITY_DELETE(gb,i) ((gb)->flags.security_delete = (i)) |
|---|
| 24 | |
|---|
| 25 | /********************* RELATIVE ADRESSING **********/ |
|---|
| 26 | |
|---|
| 27 | #if (MEMORY_TEST==1) |
|---|
| 28 | |
|---|
| 29 | # define GB_RESOLVE(typ,struct_add,member_name) ( (typ)(struct_add->member_name) ) |
|---|
| 30 | # define GB_SETREL(struct_add,member_name,creator) ( struct_add)->member_name = creator |
|---|
| 31 | # define GB_ENTRIES_ENTRY(entries,idx) (entries)[idx] |
|---|
| 32 | # define SET_GB_ENTRIES_ENTRY(entries,idx,ie) entries[idx] = ie; |
|---|
| 33 | |
|---|
| 34 | #else /* !(MEMORY_TEST==1) */ |
|---|
| 35 | |
|---|
| 36 | # define GB_RESOLVE(typ,struct_add,member_name) \ |
|---|
| 37 | ((typ) (((struct_add)->member_name) \ |
|---|
| 38 | ? (typ) (((char*)(struct_add))+((struct_add)->member_name)) \ |
|---|
| 39 | : NULL )) |
|---|
| 40 | |
|---|
| 41 | # define GB_SETREL(struct_add,member_name,creator) \ |
|---|
| 42 | do { \ |
|---|
| 43 | char *pntr = (char *)(creator); \ |
|---|
| 44 | if (pntr) \ |
|---|
| 45 | { \ |
|---|
| 46 | (struct_add)->member_name = (char*)(pntr)-(char*)(struct_add); \ |
|---|
| 47 | } \ |
|---|
| 48 | else { \ |
|---|
| 49 | (struct_add)->member_name = 0; \ |
|---|
| 50 | } \ |
|---|
| 51 | } while(0) |
|---|
| 52 | |
|---|
| 53 | # define GB_ENTRIES_ENTRY(entries,idx) ((struct gb_if_entries *) ((entries)[idx] ? ((char*)entries)+(entries[idx]) : NULL)) |
|---|
| 54 | |
|---|
| 55 | # define SET_GB_ENTRIES_ENTRY(entries,idx,ie) \ |
|---|
| 56 | do { \ |
|---|
| 57 | if (ie) { \ |
|---|
| 58 | (entries)[idx] = (char*)(ie)-(char*)(entries); \ |
|---|
| 59 | } \ |
|---|
| 60 | else { \ |
|---|
| 61 | (entries)[idx] = 0; \ |
|---|
| 62 | } \ |
|---|
| 63 | } while(0) |
|---|
| 64 | |
|---|
| 65 | #endif /* !(MEMORY_TEST==1) */ |
|---|
| 66 | |
|---|
| 67 | /* Please keep care that all 'member_name's of the following macros have different names |
|---|
| 68 | Otherwise there will be NO WARNINGS from the compiler |
|---|
| 69 | |
|---|
| 70 | The parameter types for the following macros are: |
|---|
| 71 | |
|---|
| 72 | hl struct gb_header_list_struct * |
|---|
| 73 | dl struct gb_data_list |
|---|
| 74 | ie struct gb_if_entries * |
|---|
| 75 | if struct gb_index_files_struct * |
|---|
| 76 | gbc GBCONTAINER * |
|---|
| 77 | ex struct gb_extern_data * |
|---|
| 78 | gbd GBDATA* or GBCONTAINER* |
|---|
| 79 | */ |
|---|
| 80 | |
|---|
| 81 | /* -------------------------------------------------------------------------------- */ |
|---|
| 82 | |
|---|
| 83 | #ifdef __cplusplus |
|---|
| 84 | |
|---|
| 85 | inline GBDATA * GB_HEADER_LIST_GBD(struct gb_header_list_struct& hl) { return GB_RESOLVE(struct gb_data_base_type *,(&(hl)),rel_hl_gbd); } |
|---|
| 86 | inline struct gb_header_list_struct * GB_DATA_LIST_HEADER(struct gb_data_list& dl) { return GB_RESOLVE(struct gb_header_list_struct *,(&(dl)),rel_header); } |
|---|
| 87 | inline struct gb_if_entries * GB_IF_ENTRIES_NEXT(struct gb_if_entries *ie) { return GB_RESOLVE(struct gb_if_entries *,ie,rel_ie_next); } |
|---|
| 88 | inline GBDATA * GB_IF_ENTRIES_GBD(struct gb_if_entries *ie) { return GB_RESOLVE(struct gb_data_base_type *,ie,rel_ie_gbd); } |
|---|
| 89 | inline struct gb_index_files_struct * GB_INDEX_FILES_NEXT(struct gb_index_files_struct *ixf) { return GB_RESOLVE(struct gb_index_files_struct *,ixf,rel_if_next); } |
|---|
| 90 | inline GB_REL_IFES * GB_INDEX_FILES_ENTRIES(struct gb_index_files_struct *ifs) { return GB_RESOLVE(GB_REL_IFES *,ifs,rel_entries); } |
|---|
| 91 | inline struct gb_index_files_struct * GBCONTAINER_IFS(GBCONTAINER *gbc) { return GB_RESOLVE(struct gb_index_files_struct *,gbc,rel_ifs); } |
|---|
| 92 | inline char * GB_EXTERN_DATA_DATA(struct gb_extern_data& ex) { return GB_RESOLVE(char*,(&(ex)),rel_data); } |
|---|
| 93 | |
|---|
| 94 | #else |
|---|
| 95 | |
|---|
| 96 | #define GB_HEADER_LIST_GBD(hl) GB_RESOLVE(struct gb_data_base_type *,(&(hl)),rel_hl_gbd) |
|---|
| 97 | #define GB_DATA_LIST_HEADER(dl) GB_RESOLVE(struct gb_header_list_struct *,(&(dl)),rel_header) |
|---|
| 98 | #define GB_IF_ENTRIES_NEXT(ie) GB_RESOLVE(struct gb_if_entries *,ie,rel_ie_next) |
|---|
| 99 | #define GB_IF_ENTRIES_GBD(ie) GB_RESOLVE(struct gb_data_base_type *,ie,rel_ie_gbd) |
|---|
| 100 | #define GB_INDEX_FILES_NEXT(ixf) GB_RESOLVE(struct gb_index_files_struct *,ixf,rel_if_next) |
|---|
| 101 | #define GB_INDEX_FILES_ENTRIES(if) GB_RESOLVE(GB_REL_IFES *,if,rel_entries) |
|---|
| 102 | #define GBCONTAINER_IFS(gbc) GB_RESOLVE(struct gb_index_files_struct *,gbc,rel_ifs) |
|---|
| 103 | #define GB_EXTERN_DATA_DATA(ex) GB_RESOLVE(char*,(&(ex)),rel_data) |
|---|
| 104 | |
|---|
| 105 | #endif |
|---|
| 106 | |
|---|
| 107 | /* -------------------------------------------------------------------------------- */ |
|---|
| 108 | |
|---|
| 109 | #ifdef __cplusplus |
|---|
| 110 | |
|---|
| 111 | inline void SET_GB_HEADER_LIST_GBD(struct gb_header_list_struct& hl, GBDATA *gbd) { GB_SETREL(&hl, rel_hl_gbd, gbd); } |
|---|
| 112 | inline void SET_GB_DATA_LIST_HEADER(struct gb_data_list& dl, struct gb_header_list_struct *head) { GB_SETREL(&dl, rel_header, head); } |
|---|
| 113 | inline void SET_GB_IF_ENTRIES_NEXT(struct gb_if_entries *ie, struct gb_if_entries *next) { GB_SETREL(ie, rel_ie_next, next); } |
|---|
| 114 | inline void SET_GB_IF_ENTRIES_GBD(struct gb_if_entries *ie, GBDATA *gbd) { GB_SETREL(ie, rel_ie_gbd, gbd); } |
|---|
| 115 | inline void SET_GB_INDEX_FILES_NEXT(struct gb_index_files_struct *ixf, struct gb_index_files_struct *next) { GB_SETREL(ixf, rel_if_next, next); } |
|---|
| 116 | inline void SET_GB_INDEX_FILES_ENTRIES(struct gb_index_files_struct *ixf, struct gb_if_entries **entries) { GB_SETREL(ixf, rel_entries, entries); } |
|---|
| 117 | inline void SET_GBCONTAINER_IFS(GBCONTAINER *gbc, struct gb_index_files_struct *ifs) { GB_SETREL(gbc, rel_ifs, ifs); } |
|---|
| 118 | inline void SET_GB_EXTERN_DATA_DATA(struct gb_extern_data& ex, char *data) { GB_SETREL(&ex, rel_data, data); } |
|---|
| 119 | |
|---|
| 120 | #else |
|---|
| 121 | |
|---|
| 122 | # define SET_GB_HEADER_LIST_GBD(hl,gbd) GB_SETREL((&(hl)),rel_hl_gbd,gbd) |
|---|
| 123 | # define SET_GB_DATA_LIST_HEADER(dl,head) GB_SETREL((&(dl)),rel_header,head) |
|---|
| 124 | # define SET_GB_IF_ENTRIES_NEXT(ie,next) GB_SETREL(ie,rel_ie_next,next) |
|---|
| 125 | # define SET_GB_IF_ENTRIES_GBD(ie,gbd) GB_SETREL(ie,rel_ie_gbd,gbd) |
|---|
| 126 | # define SET_GB_INDEX_FILES_NEXT(if,next) GB_SETREL(if,rel_if_next,next) |
|---|
| 127 | # define SET_GB_INDEX_FILES_ENTRIES(if,entries) GB_SETREL(if,rel_entries,entries) |
|---|
| 128 | # define SET_GBCONTAINER_IFS(gbc,ifs) GB_SETREL(gbc,rel_ifs,ifs) |
|---|
| 129 | # define SET_GB_EXTERN_DATA_DATA(ex,data) GB_SETREL((&(ex)),rel_data,data) |
|---|
| 130 | |
|---|
| 131 | #endif |
|---|
| 132 | |
|---|
| 133 | /* -------------------------------------------------------------------------------- */ |
|---|
| 134 | |
|---|
| 135 | #define HAS_FATHER(gbd) ((gbd)->rel_father != NULL) |
|---|
| 136 | |
|---|
| 137 | #ifdef __cplusplus |
|---|
| 138 | |
|---|
| 139 | inline GBCONTAINER* GB_FATHER(GBDATA *gbd) { return GB_RESOLVE(struct gb_data_base_type2 *,gbd,rel_father); } |
|---|
| 140 | inline GBCONTAINER* GB_FATHER(GBCONTAINER *gbc) { return GB_RESOLVE(struct gb_data_base_type2 *,gbc,rel_father); } |
|---|
| 141 | inline void SET_GB_FATHER(GBDATA *gbd, GBCONTAINER *father) { GB_SETREL(gbd, rel_father, father); } |
|---|
| 142 | inline void SET_GB_FATHER(GBCONTAINER *gbc, GBCONTAINER *father) { GB_SETREL(gbc, rel_father, father); } |
|---|
| 143 | |
|---|
| 144 | inline GBCONTAINER* GB_GRANDPA(GBDATA *gbd) { return GB_FATHER(GB_FATHER(gbd)); } |
|---|
| 145 | |
|---|
| 146 | inline GBDATA *EXISTING_GBCONTAINER_ELEM(GBCONTAINER *gbc,int idx) { return GB_HEADER_LIST_GBD(GB_DATA_LIST_HEADER((gbc)->d)[idx]); } |
|---|
| 147 | inline GBDATA *GBCONTAINER_ELEM(GBCONTAINER *gbc,int idx) { if (idx<gbc->d.nheader) return EXISTING_GBCONTAINER_ELEM(gbc, idx); return (GBDATA*)0; } |
|---|
| 148 | inline void SET_GBCONTAINER_ELEM(GBCONTAINER *gbc, int idx, GBDATA *gbd) { SET_GB_HEADER_LIST_GBD(GB_DATA_LIST_HEADER(gbc->d)[idx], gbd); } |
|---|
| 149 | |
|---|
| 150 | // inline GB_MAIN_TYPE *GBCONTAINER_MAIN(GBCONTAINER *gbc) { return gb_main_array[(gbc->main_idx) % GB_MAIN_ARRAY_SIZE]; } |
|---|
| 151 | inline GB_MAIN_TYPE *GBCONTAINER_MAIN(GBCONTAINER *gbc) { return gb_main_array[gbc->main_idx]; } |
|---|
| 152 | inline GB_MAIN_TYPE *GB_MAIN(GBDATA *gbd) { return GBCONTAINER_MAIN(GB_FATHER(gbd)); } |
|---|
| 153 | inline GB_MAIN_TYPE *GB_MAIN(GBCONTAINER *gbc) { return GBCONTAINER_MAIN(gbc); } |
|---|
| 154 | |
|---|
| 155 | #else |
|---|
| 156 | |
|---|
| 157 | # define GB_FATHER(gbd) GB_RESOLVE(struct gb_data_base_type2 *,gbd,rel_father) |
|---|
| 158 | # define SET_GB_FATHER(gbd,father) GB_SETREL(gbd,rel_father,father) |
|---|
| 159 | |
|---|
| 160 | # define GB_GRANDPA(gbd) GB_FATHER(GB_FATHER(gbd)) |
|---|
| 161 | |
|---|
| 162 | # define EXISTING_GBCONTAINER_ELEM(gbc,idx) (GB_HEADER_LIST_GBD(GB_DATA_LIST_HEADER((gbc)->d)[idx])) |
|---|
| 163 | # define GBCONTAINER_ELEM(gbc,idx) ((struct gb_data_base_type *)((idx)<(gbc)->d.nheader ? EXISTING_GBCONTAINER_ELEM(gbc, idx) : NULL)) |
|---|
| 164 | # define SET_GBCONTAINER_ELEM(gbc,idx,gbd) SET_GB_HEADER_LIST_GBD(GB_DATA_LIST_HEADER((gbc)->d)[idx],gbd) |
|---|
| 165 | |
|---|
| 166 | // # define GBCONTAINER_MAIN(gbc) gb_main_array[((gbc)->main_idx) % GB_MAIN_ARRAY_SIZE] |
|---|
| 167 | # define GBCONTAINER_MAIN(gbc) gb_main_array[(gbc)->main_idx] |
|---|
| 168 | # define GB_MAIN(gbd) GBCONTAINER_MAIN(GB_FATHER(gbd)) |
|---|
| 169 | |
|---|
| 170 | #endif |
|---|
| 171 | |
|---|
| 172 | /********************* SOME FLAGS ******************/ |
|---|
| 173 | |
|---|
| 174 | #ifdef __cplusplus |
|---|
| 175 | |
|---|
| 176 | inline int GB_KEY_QUARK(GBDATA *gbd) { return GB_DATA_LIST_HEADER(GB_FATHER(gbd)->d)[gbd->index].flags.key_quark; } |
|---|
| 177 | inline char *GB_KEY(GBDATA *gbd) { return GB_MAIN(gbd)->keys[GB_KEY_QUARK(gbd)].key; } |
|---|
| 178 | inline GB_TYPES GB_TYPE(GBDATA *gbd) { return GB_TYPES(gbd->flags.type); } |
|---|
| 179 | inline GB_TYPES GB_TYPE(GBCONTAINER *gbd) { return GB_TYPES(gbd->flags.type); } |
|---|
| 180 | inline GB_TYPES GB_TYPE_TS(struct gb_transaction_save *ts) { return GB_TYPES(ts->flags.type); } |
|---|
| 181 | |
|---|
| 182 | inline gb_header_flags& GB_ARRAY_FLAGS(GBDATA *gbd) { return GB_DATA_LIST_HEADER(GB_FATHER(gbd)->d)[gbd->index].flags; } |
|---|
| 183 | inline gb_header_flags& GB_ARRAY_FLAGS(GBCONTAINER *gbc) { return GB_DATA_LIST_HEADER(GB_FATHER(gbc)->d)[gbc->index].flags; } |
|---|
| 184 | |
|---|
| 185 | #else |
|---|
| 186 | |
|---|
| 187 | #define GB_KEY_QUARK(gbd) (GB_DATA_LIST_HEADER(GB_FATHER(gbd)->d)[(gbd)->index].flags.key_quark) |
|---|
| 188 | #define GB_KEY(gbd) (GB_MAIN(gbd)->keys[GB_KEY_QUARK(gbd)].key) |
|---|
| 189 | #define GB_TYPE(gbd) ((GB_TYPES)(gbd)->flags.type) // return type was 'int', changed 11.Mai.07 hopefully w/o harm --ralf |
|---|
| 190 | #define GB_TYPE_TS(ts) ((GB_TYPES)(ts)->flags.type) |
|---|
| 191 | |
|---|
| 192 | #define GB_ARRAY_FLAGS(gbd) (GB_DATA_LIST_HEADER(GB_FATHER(gbd)->d)[(gbd)->index].flags) |
|---|
| 193 | |
|---|
| 194 | #endif |
|---|
| 195 | |
|---|
| 196 | /********************* INDEX ******************/ |
|---|
| 197 | |
|---|
| 198 | # define GB_GBM_INDEX(gbd) ((gbd)->flags2.gbm_index) |
|---|
| 199 | |
|---|
| 200 | #ifdef __cplusplus |
|---|
| 201 | |
|---|
| 202 | inline long GB_QUARK_2_GBMINDEX(GB_MAIN_TYPE *Main, int key_quark) { return (Main->keys[key_quark].nref<GBM_MAX_UNINDEXED_ENTRIES) ? 0 : key_quark; } |
|---|
| 203 | inline long GB_GBD_2_GBMINDEX(GBDATA *gbd) { return GB_QUARK_2_GBMINDEX(GB_MAIN(gbd), GB_KEY_QUARK(gbd)); } |
|---|
| 204 | |
|---|
| 205 | #else |
|---|
| 206 | |
|---|
| 207 | # define GB_QUARK_2_GBMINDEX(Main,key_quark) (((Main)->keys[key_quark].nref<GBM_MAX_UNINDEXED_ENTRIES) ? 0 : (key_quark)) |
|---|
| 208 | # define GB_GBD_2_GBMINDEX(gbd) GB_QUARK_2_GBMINDEX(GB_MAIN(gbd), GB_KEY_QUARK(gbd)) |
|---|
| 209 | |
|---|
| 210 | #endif |
|---|
| 211 | |
|---|
| 212 | /********************* READ and WRITE ******************/ |
|---|
| 213 | |
|---|
| 214 | #ifdef __cplusplus |
|---|
| 215 | |
|---|
| 216 | inline GB_BOOL GB_COMPRESSION_ENABLED(GBDATA *gbd, long size) { return (!GB_MAIN(gbd)->compression_mask) && size>=GBTUM_SHORT_STRING_SIZE; } |
|---|
| 217 | |
|---|
| 218 | inline void GB_TEST_TRANSACTION(GBDATA *gbd) { |
|---|
| 219 | if (!GB_MAIN(gbd)->transaction) { |
|---|
| 220 | GBK_terminate("No running transaction"); |
|---|
| 221 | } |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | #else |
|---|
| 225 | |
|---|
| 226 | #define GB_COMPRESSION_ENABLED(gbd,size) ((!GB_MAIN(gbd)->compression_mask) && (size)>=GBTUM_SHORT_STRING_SIZE) |
|---|
| 227 | |
|---|
| 228 | #define GB_TEST_TRANSACTION(gbd) \ |
|---|
| 229 | do { \ |
|---|
| 230 | if (!GB_MAIN(gbd)->transaction) { \ |
|---|
| 231 | GBK_terminate("No running transaction"); \ |
|---|
| 232 | } \ |
|---|
| 233 | } while(0) |
|---|
| 234 | |
|---|
| 235 | #endif // __cplusplus |
|---|
| 236 | |
|---|
| 237 | #define GB_TEST_READ(gbd,ty,error) \ |
|---|
| 238 | do { \ |
|---|
| 239 | GB_TEST_TRANSACTION(gbd); \ |
|---|
| 240 | if (GB_ARRAY_FLAGS(gbd).changed == gb_deleted) { \ |
|---|
| 241 | GB_internal_errorf("%s: %s",error,"Entry is deleted !!"); \ |
|---|
| 242 | return 0;} \ |
|---|
| 243 | if ( GB_TYPE(gbd) != ty && (ty != GB_STRING || GB_TYPE(gbd) == GB_LINK)) { \ |
|---|
| 244 | GB_internal_errorf("%s: %s",error,"wrong type"); \ |
|---|
| 245 | return 0;} \ |
|---|
| 246 | } while(0) |
|---|
| 247 | |
|---|
| 248 | #define GB_TEST_WRITE(gbd,ty,gerror) \ |
|---|
| 249 | do { \ |
|---|
| 250 | GB_TEST_TRANSACTION(gbd); \ |
|---|
| 251 | if ( GB_ARRAY_FLAGS(gbd).changed == gb_deleted) { \ |
|---|
| 252 | GB_internal_errorf("%s: %s",gerror,"Entry is deleted !!"); \ |
|---|
| 253 | return 0;} \ |
|---|
| 254 | if ( GB_TYPE(gbd) != ty && (ty != GB_STRING || GB_TYPE(gbd) != GB_LINK)) { \ |
|---|
| 255 | GB_internal_errorf("%s: %s",gerror,"type conflict !!"); \ |
|---|
| 256 | return 0;} \ |
|---|
| 257 | if (GB_GET_SECURITY_WRITE(gbd)>GB_MAIN(gbd)->security_level) \ |
|---|
| 258 | return gb_security_error(gbd); \ |
|---|
| 259 | } while(0) |
|---|
| 260 | |
|---|
| 261 | #define GB_TEST_NON_BUFFER(x,gerror) \ |
|---|
| 262 | do { \ |
|---|
| 263 | if (GB_is_in_buffer(x)) { \ |
|---|
| 264 | GBK_terminatef("%s: you are not allowed to write any data, which you get by pntr", gerror); \ |
|---|
| 265 | } \ |
|---|
| 266 | } while(0) |
|---|
| 267 | |
|---|
| 268 | /********************* INDEX CHECK ******************/ |
|---|
| 269 | |
|---|
| 270 | #ifdef __cplusplus |
|---|
| 271 | |
|---|
| 272 | inline void GB_INDEX_CHECK_IN(GBDATA *gbd) { if (gbd->flags2.tisa_index) gb_index_check_in(gbd); } |
|---|
| 273 | inline void GB_INDEX_CHECK_OUT(GBDATA *gbd) { if ((gbd)->flags2.is_indexed) gb_index_check_out(gbd); } |
|---|
| 274 | |
|---|
| 275 | #else |
|---|
| 276 | |
|---|
| 277 | #define GB_INDEX_CHECK_IN(gbd) do { if ((gbd)->flags2.tisa_index) gb_index_check_in(gbd); } while(0) |
|---|
| 278 | #define GB_INDEX_CHECK_OUT(gbd) do { if ((gbd)->flags2.is_indexed) gb_index_check_out(gbd); } while(0) |
|---|
| 279 | |
|---|
| 280 | #endif // __cplusplus |
|---|
| 281 | |
|---|
| 282 | /********************* EXTENDED DATA ******************/ |
|---|
| 283 | |
|---|
| 284 | #ifdef __cplusplus |
|---|
| 285 | |
|---|
| 286 | inline struct gb_callback *GB_GET_EXT_CALLBACKS(GBDATA *gbd) { return gbd->ext ? gbd->ext->callback : 0; } |
|---|
| 287 | inline long GB_GET_EXT_CREATION_DATE(GBDATA *gbd) { return gbd->ext ? gbd->ext->creation_date : 0; } |
|---|
| 288 | inline long GB_GET_EXT_UPDATE_DATE(GBDATA *gbd) { return gbd->ext ? gbd->ext->update_date : 0; } |
|---|
| 289 | inline struct gb_transaction_save *GB_GET_EXT_OLD_DATA(GBDATA *gbd) { return gbd->ext ? gbd->ext->old : 0; } |
|---|
| 290 | |
|---|
| 291 | inline struct gb_cache_struct& GB_GET_CACHE(GB_MAIN_TYPE *gbmain) { return gbmain->cache; } |
|---|
| 292 | inline void GB_SET_CACHE(GB_MAIN_TYPE *gbmain, struct gb_cache_struct& val) { gbmain->cache = val; } |
|---|
| 293 | |
|---|
| 294 | inline void GB_CREATE_EXT(GBDATA *gbd) { if (!gbd->ext) gb_create_extended(gbd); } |
|---|
| 295 | inline void _GB_DELETE_EXT(GBDATA *gbd, long gbm_index) { |
|---|
| 296 | if (gbd->ext) { |
|---|
| 297 | gbm_free_mem((char *) gbd->ext, sizeof(struct gb_db_extended), gbm_index); |
|---|
| 298 | gbd->ext = 0; |
|---|
| 299 | } |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | #else |
|---|
| 303 | |
|---|
| 304 | #define GB_GET_EXT_CALLBACKS(gbd) (((gbd)->ext)?(gbd)->ext->callback:0) |
|---|
| 305 | #define GB_GET_EXT_CREATION_DATE(gbd) (((gbd)->ext)?(gbd)->ext->creation_date:0) |
|---|
| 306 | #define GB_GET_EXT_UPDATE_DATE(gbd) (((gbd)->ext)?(gbd)->ext->update_date:0) |
|---|
| 307 | #define GB_GET_EXT_OLD_DATA(gbd) (((gbd)->ext)?(gbd)->ext->old:0) |
|---|
| 308 | #define GB_GET_CACHE(gbd) ((gbd)->cache) |
|---|
| 309 | #define GB_SET_CACHE(gbd,val) do { (gbd)->cache = (val); } while(0) |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | #define GB_CREATE_EXT(gbd) do { if (!(gbd)->ext) gb_create_extended(gbd); } while(0) |
|---|
| 313 | |
|---|
| 314 | #define _GB_DELETE_EXT(gbd, gbm_index) \ |
|---|
| 315 | do { \ |
|---|
| 316 | if ((gbd)->ext) { \ |
|---|
| 317 | gbm_free_mem((char *) (gbd)->ext, sizeof(struct gb_db_extended), gbm_index); \ |
|---|
| 318 | (gbd)->ext = 0; \ |
|---|
| 319 | } \ |
|---|
| 320 | } while(0) |
|---|
| 321 | |
|---|
| 322 | #endif |
|---|
| 323 | |
|---|
| 324 | /********************* DATA ACCESS ******************/ |
|---|
| 325 | |
|---|
| 326 | #ifdef __cplusplus |
|---|
| 327 | |
|---|
| 328 | inline long GB_GETSIZE(const GBDATA *gbd) { return gbd->flags2.extern_data ? gbd->info.ex.size : gbd->info.istr.size; } |
|---|
| 329 | inline long GB_GETMEMSIZE(const GBDATA *gbd) { return gbd->flags2.extern_data ? gbd->info.ex.memsize : gbd->info.istr.memsize; } |
|---|
| 330 | inline char *GB_GETDATA(GBDATA *gbd) { return gbd->flags2.extern_data ? GB_EXTERN_DATA_DATA(gbd->info.ex) : &((gbd)->info.istr.data[0]); } |
|---|
| 331 | |
|---|
| 332 | inline long GB_GETSIZE_TS(struct gb_transaction_save *ts) { return ts->flags2.extern_data ? ts->info.ex.size : ts->info.istr.size; } |
|---|
| 333 | inline long GB_GETMEMSIZE_TS(struct gb_transaction_save *ts) { return ts->flags2.extern_data ? ts->info.ex.memsize : ts->info.istr.memsize; } |
|---|
| 334 | inline char *GB_GETDATA_TS(struct gb_transaction_save *ts) { return ts->flags2.extern_data ? ts->info.ex.data : &(ts->info.istr.data[0]); } |
|---|
| 335 | |
|---|
| 336 | #else |
|---|
| 337 | |
|---|
| 338 | #define GB_GETSIZE(gbd) (((gbd)->flags2.extern_data) ? (gbd)->info.ex.size : (gbd)->info.istr.size) |
|---|
| 339 | #define GB_GETMEMSIZE(gbd) (((gbd)->flags2.extern_data) ? (gbd)->info.ex.memsize : (gbd)->info.istr.memsize) |
|---|
| 340 | #define GB_GETDATA(gbd) (((gbd)->flags2.extern_data) ? GB_EXTERN_DATA_DATA((gbd)->info.ex) : &((gbd)->info.istr.data[0])) |
|---|
| 341 | |
|---|
| 342 | #define GB_GETSIZE_TS(ts) GB_GETSIZE(ts) |
|---|
| 343 | #define GB_GETMEMSIZE_TS(ts) GB_GETMEMSIZE(ts) |
|---|
| 344 | #define GB_GETDATA_TS(ts) (((ts)->flags2.extern_data) ? ts->info.ex.data : & ((ts)->info.istr.data[0])) |
|---|
| 345 | |
|---|
| 346 | #endif |
|---|
| 347 | |
|---|
| 348 | /********************* DATA MODIFY ******************/ |
|---|
| 349 | |
|---|
| 350 | #ifdef __cplusplus |
|---|
| 351 | |
|---|
| 352 | inline void GB_FREE_TRANSACTION_SAVE(GBDATA *gbd) { |
|---|
| 353 | if (gbd->ext && gbd->ext->old) { |
|---|
| 354 | gb_del_ref_gb_transaction_save(gbd->ext->old); |
|---|
| 355 | gbd->ext->old = NULL; |
|---|
| 356 | } |
|---|
| 357 | } |
|---|
| 358 | |
|---|
| 359 | /* frees local data */ |
|---|
| 360 | inline void GB_FREEDATA(GBDATA *gbd) { |
|---|
| 361 | GB_INDEX_CHECK_OUT(gbd); |
|---|
| 362 | if (gbd->flags2.extern_data && GB_EXTERN_DATA_DATA(gbd->info.ex)) { |
|---|
| 363 | gbm_free_mem(GB_EXTERN_DATA_DATA(gbd->info.ex), (size_t)(gbd->info.ex.memsize), GB_GBM_INDEX(gbd)); |
|---|
| 364 | SET_GB_EXTERN_DATA_DATA(gbd->info.ex,0); |
|---|
| 365 | } |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | #else |
|---|
| 369 | |
|---|
| 370 | #define GB_FREE_TRANSACTION_SAVE(gbd) \ |
|---|
| 371 | do { \ |
|---|
| 372 | if ((gbd)->ext && (gbd)->ext->old) { \ |
|---|
| 373 | gb_del_ref_gb_transaction_save((gbd)->ext->old); \ |
|---|
| 374 | (gbd)->ext->old = NULL; \ |
|---|
| 375 | } \ |
|---|
| 376 | } while(0) |
|---|
| 377 | |
|---|
| 378 | /* frees local data */ |
|---|
| 379 | #define GB_FREEDATA(gbd) \ |
|---|
| 380 | do { \ |
|---|
| 381 | GB_INDEX_CHECK_OUT(gbd); \ |
|---|
| 382 | if ((gbd)->flags2.extern_data && GB_EXTERN_DATA_DATA((gbd)->info.ex)) { \ |
|---|
| 383 | gbm_free_mem(GB_EXTERN_DATA_DATA((gbd)->info.ex), (size_t)((gbd)->info.ex.memsize), GB_GBM_INDEX(gbd)); \ |
|---|
| 384 | SET_GB_EXTERN_DATA_DATA((gbd)->info.ex,0); \ |
|---|
| 385 | } \ |
|---|
| 386 | } while(0) |
|---|
| 387 | |
|---|
| 388 | #endif |
|---|
| 389 | |
|---|
| 390 | #ifdef __cplusplus |
|---|
| 391 | |
|---|
| 392 | inline GB_BOOL GB_CHECKINTERN(int size, int memsize) { return size<256 && memsize<SIZOFINTERN; } |
|---|
| 393 | inline void GB_SETINTERN(GBDATA *gbd) { gbd->flags2.extern_data = 0; } |
|---|
| 394 | inline void GB_SETEXTERN(GBDATA *gbd) { gbd->flags2.extern_data = 1; } |
|---|
| 395 | |
|---|
| 396 | #else |
|---|
| 397 | |
|---|
| 398 | #define GB_CHECKINTERN(size,memsize) (((int)(size) < 256) && ((int)(memsize) < SIZOFINTERN)) |
|---|
| 399 | #define GB_SETINTERN(gbd) (gbd)->flags2.extern_data = 0 |
|---|
| 400 | #define GB_SETEXTERN(gbd) (gbd)->flags2.extern_data = 1 |
|---|
| 401 | |
|---|
| 402 | #endif |
|---|
| 403 | |
|---|
| 404 | /** insert external data into any db. field |
|---|
| 405 | Warning: this function has a lot of side effects: |
|---|
| 406 | 1. extern_data must be set by the user before calling this |
|---|
| 407 | 2. if !extern_data the data is not set |
|---|
| 408 | -> better use GB_SETSMDMALLOC |
|---|
| 409 | */ |
|---|
| 410 | |
|---|
| 411 | #ifdef __cplusplus |
|---|
| 412 | |
|---|
| 413 | inline void GB_SETSMD(GBDATA *gbd, long siz, long memsiz, char *dat) { |
|---|
| 414 | if (gbd->flags2.extern_data) { |
|---|
| 415 | gbd->info.ex.size = siz; |
|---|
| 416 | gbd->info.ex.memsize = memsiz; |
|---|
| 417 | SET_GB_EXTERN_DATA_DATA(gbd->info.ex,dat); |
|---|
| 418 | }else{ |
|---|
| 419 | gbd->info.istr.size = (unsigned char)siz; |
|---|
| 420 | gbd->info.istr.memsize = (unsigned char)memsiz; |
|---|
| 421 | } |
|---|
| 422 | GB_INDEX_CHECK_IN(gbd); |
|---|
| 423 | } |
|---|
| 424 | |
|---|
| 425 | inline void GB_SETSMDMALLOC(GBDATA *gbd, long siz, long memsiz, char *dat) { |
|---|
| 426 | gb_assert(dat); |
|---|
| 427 | if (GB_CHECKINTERN(siz,memsiz)) { |
|---|
| 428 | GB_SETINTERN(gbd); |
|---|
| 429 | gbd->info.istr.size = (unsigned char)siz; |
|---|
| 430 | gbd->info.istr.memsize = (unsigned char)memsiz; |
|---|
| 431 | if (dat) memcpy(&(gbd->info.istr.data[0]), (char *)dat, (size_t)(memsiz)); |
|---|
| 432 | }else{ |
|---|
| 433 | char *exData; |
|---|
| 434 | GB_SETEXTERN(gbd); |
|---|
| 435 | gbd->info.ex.size = siz; |
|---|
| 436 | gbd->info.ex.memsize = memsiz; |
|---|
| 437 | exData = gbm_get_mem((size_t)memsiz,GB_GBM_INDEX(gbd)); |
|---|
| 438 | SET_GB_EXTERN_DATA_DATA(gbd->info.ex,exData); |
|---|
| 439 | if (dat) memcpy(exData, (char *)dat, (size_t)(memsiz)); |
|---|
| 440 | } |
|---|
| 441 | GB_INDEX_CHECK_IN(gbd); |
|---|
| 442 | } |
|---|
| 443 | |
|---|
| 444 | inline void GB_SETSMDMALLOC_UNINITIALIZED(GBDATA *gbd, long siz, long memsiz) { |
|---|
| 445 | if (GB_CHECKINTERN(siz,memsiz)) { |
|---|
| 446 | GB_SETINTERN(gbd); |
|---|
| 447 | gbd->info.istr.size = (unsigned char)siz; |
|---|
| 448 | gbd->info.istr.memsize = (unsigned char)memsiz; |
|---|
| 449 | }else{ |
|---|
| 450 | char *exData; |
|---|
| 451 | GB_SETEXTERN(gbd); |
|---|
| 452 | gbd->info.ex.size = siz; |
|---|
| 453 | gbd->info.ex.memsize = memsiz; |
|---|
| 454 | exData = gbm_get_mem((size_t)memsiz,GB_GBM_INDEX(gbd)); |
|---|
| 455 | SET_GB_EXTERN_DATA_DATA(gbd->info.ex,exData); |
|---|
| 456 | } |
|---|
| 457 | GB_INDEX_CHECK_IN(gbd); |
|---|
| 458 | } |
|---|
| 459 | |
|---|
| 460 | #else |
|---|
| 461 | |
|---|
| 462 | #define GB_SETSMD(gbd,siz,memsiz,dat) \ |
|---|
| 463 | do { \ |
|---|
| 464 | if ((gbd)->flags2.extern_data) { \ |
|---|
| 465 | (gbd)->info.ex.size = (siz); \ |
|---|
| 466 | (gbd)->info.ex.memsize = (memsiz); \ |
|---|
| 467 | SET_GB_EXTERN_DATA_DATA((gbd)->info.ex,(dat)); \ |
|---|
| 468 | }else{ \ |
|---|
| 469 | (gbd)->info.istr.size = (unsigned char)(siz); \ |
|---|
| 470 | (gbd)->info.istr.memsize = (unsigned char)(memsiz); \ |
|---|
| 471 | } \ |
|---|
| 472 | GB_INDEX_CHECK_IN(gbd); \ |
|---|
| 473 | } while(0) |
|---|
| 474 | |
|---|
| 475 | /** copies any data into any db field */ |
|---|
| 476 | #define GB_SETSMDMALLOC(gbd,siz,memsiz,dat) \ |
|---|
| 477 | do { \ |
|---|
| 478 | gb_assert(dat); \ |
|---|
| 479 | if (GB_CHECKINTERN(siz,memsiz)) { \ |
|---|
| 480 | GB_SETINTERN(gbd); \ |
|---|
| 481 | (gbd)->info.istr.size = (unsigned char)(siz); \ |
|---|
| 482 | (gbd)->info.istr.memsize = (unsigned char)(memsiz); \ |
|---|
| 483 | if (dat) memcpy(&((gbd)->info.istr.data[0]), (char *)(dat), (size_t)(memsiz)); \ |
|---|
| 484 | }else{ \ |
|---|
| 485 | char *exData; \ |
|---|
| 486 | GB_SETEXTERN(gbd); \ |
|---|
| 487 | (gbd)->info.ex.size = (siz); \ |
|---|
| 488 | (gbd)->info.ex.memsize = (memsiz); \ |
|---|
| 489 | exData = gbm_get_mem((size_t)(memsiz),GB_GBM_INDEX(gbd)); \ |
|---|
| 490 | SET_GB_EXTERN_DATA_DATA((gbd)->info.ex,exData); \ |
|---|
| 491 | if (dat) memcpy(exData, (char *)(dat), (size_t)(memsiz)); \ |
|---|
| 492 | } \ |
|---|
| 493 | GB_INDEX_CHECK_IN(gbd); \ |
|---|
| 494 | }while(0) |
|---|
| 495 | |
|---|
| 496 | /** allocate data */ |
|---|
| 497 | #define GB_SETSMDMALLOC_UNINITIALIZED(gbd,siz,memsiz) \ |
|---|
| 498 | do { \ |
|---|
| 499 | if (GB_CHECKINTERN(siz,memsiz)) { \ |
|---|
| 500 | GB_SETINTERN(gbd); \ |
|---|
| 501 | (gbd)->info.istr.size = (unsigned char)(siz); \ |
|---|
| 502 | (gbd)->info.istr.memsize = (unsigned char)(memsiz); \ |
|---|
| 503 | }else{ \ |
|---|
| 504 | char *exData; \ |
|---|
| 505 | GB_SETEXTERN(gbd); \ |
|---|
| 506 | (gbd)->info.ex.size = (siz); \ |
|---|
| 507 | (gbd)->info.ex.memsize = (memsiz); \ |
|---|
| 508 | exData = gbm_get_mem((size_t)(memsiz),GB_GBM_INDEX(gbd)); \ |
|---|
| 509 | SET_GB_EXTERN_DATA_DATA((gbd)->info.ex,exData); \ |
|---|
| 510 | } \ |
|---|
| 511 | GB_INDEX_CHECK_IN(gbd); \ |
|---|
| 512 | }while(0) |
|---|
| 513 | |
|---|
| 514 | |
|---|
| 515 | |
|---|
| 516 | #endif |
|---|
| 517 | |
|---|
| 518 | /********************* UNDO ******************/ |
|---|
| 519 | /** copy all info + external data mem |
|---|
| 520 | to an one step undo buffer (to abort a transaction */ |
|---|
| 521 | |
|---|
| 522 | #ifdef __cplusplus |
|---|
| 523 | |
|---|
| 524 | inline void _GB_CHECK_IN_UNDO_DELETE(GB_MAIN_TYPE *Main, GBDATA *gbd) { |
|---|
| 525 | if (Main->undo_type) gb_check_in_undo_delete(Main,gbd,0); |
|---|
| 526 | else gb_delete_entry(gbd); |
|---|
| 527 | } |
|---|
| 528 | inline void _GB_CHECK_IN_UNDO_CREATE(GB_MAIN_TYPE *Main, GBDATA *gbd) { |
|---|
| 529 | if (Main->undo_type) gb_check_in_undo_create(Main,gbd); |
|---|
| 530 | } |
|---|
| 531 | inline void _GB_CHECK_IN_UNDO_MODIFY(GB_MAIN_TYPE *Main, GBDATA *gbd) { |
|---|
| 532 | if (Main->undo_type) gb_check_in_undo_modify(Main,gbd); |
|---|
| 533 | } |
|---|
| 534 | inline void STATIC_BUFFER(char*& strvar, int minlen) { |
|---|
| 535 | ad_assert(minlen > 0); |
|---|
| 536 | if (strvar && (strlen(strvar) < (size_t)(minlen-1))) { freeset(strvar, NULL); } |
|---|
| 537 | if (!strvar) strvar=(char*)GB_calloc(minlen,1); |
|---|
| 538 | } |
|---|
| 539 | |
|---|
| 540 | #else |
|---|
| 541 | |
|---|
| 542 | #define _GB_CHECK_IN_UNDO_DELETE(Main,gbd) \ |
|---|
| 543 | do { \ |
|---|
| 544 | if ((Main)->undo_type) gb_check_in_undo_delete(Main,gbd,0); \ |
|---|
| 545 | else gb_delete_entry(&(gbd)); \ |
|---|
| 546 | } while(0) |
|---|
| 547 | |
|---|
| 548 | #define _GB_CHECK_IN_UNDO_CREATE(Main,gbd) \ |
|---|
| 549 | do { \ |
|---|
| 550 | if ((Main)->undo_type) gb_check_in_undo_create(Main,gbd); \ |
|---|
| 551 | } while(0) |
|---|
| 552 | |
|---|
| 553 | #define _GB_CHECK_IN_UNDO_MODIFY(Main,gbd) \ |
|---|
| 554 | do { \ |
|---|
| 555 | if ((Main)->undo_type) gb_check_in_undo_modify(Main,gbd); \ |
|---|
| 556 | } while(0) |
|---|
| 557 | |
|---|
| 558 | #define STATIC_BUFFER(strvar,static_buffer_minlen) \ |
|---|
| 559 | do { \ |
|---|
| 560 | ad_assert(static_buffer_minlen > 0); \ |
|---|
| 561 | size_t static_buffer_len = (static_buffer_minlen); \ |
|---|
| 562 | if ((strvar) && (strlen(strvar) < (static_buffer_len-1))) { \ |
|---|
| 563 | freeset(strvar, NULL); \ |
|---|
| 564 | } \ |
|---|
| 565 | if (!(strvar)) (strvar)=(char*)GB_calloc(static_buffer_len,1); \ |
|---|
| 566 | } while(0) |
|---|
| 567 | |
|---|
| 568 | #endif |
|---|