root/branches/stable_5.0/ARBDB/arbdb_base.h

Revision 6143, 3.3 KB (checked in by westram, 3 years ago)
  • backport [6141] (parts changing code, but only strings and comments)
Line 
1// ================================================================ //
2//                                                                  //
3//   File      : arbdb_base.h                                       //
4//   Purpose   : most minimal ARBDB interface                       //
5//               provide functions/types needed for arb_assert.h    //
6//                                                                  //
7//   Coded by Ralf Westram (coder@reallysoft.de) in December 2008   //
8//   Institute of Microbiology (Technical University Munich)        //
9//   http://www.arb-home.de/                                        //
10//                                                                  //
11// ================================================================ //
12
13#ifndef ARBDB_BASE_H
14#define ARBDB_BASE_H
15
16#ifndef _STDIO_H
17#include <stdio.h>
18#endif
19#ifndef ATTRIBUTES_H
20#include <attributes.h>
21#endif
22
23typedef const char *GB_CSTR;    /* this is read-only! */
24typedef const char *GB_ERROR;   /* memory management is controlled by the ARBDB lib */
25typedef char       *GB_BUFFER;  /* points to a piece of mem (writeable, but don't free!)*/
26typedef const char *GB_CBUFFER; /* points to a piece of mem (readable only)*/
27
28typedef struct gb_data_base_type GBDATA;
29
30typedef enum { GB_FALSE = 0 , GB_TRUE = 1 } GB_BOOL;
31
32typedef enum gb_call_back_type {
33    GB_CB_NONE        = 0,
34    GB_CB_DELETE      = 1,
35    GB_CB_CHANGED     = 2, // element or son of element changed
36    GB_CB_SON_CREATED = 4, // new son created
37    GB_CB_ALL         = 7
38} GB_CB_TYPE;
39
40/* --------------------------------------------------------------------------------
41 * The following function handle char*'s, which either own a heap copy or are NULL.
42 *
43 * freeset:  assigns a heap-copy to a variable (variable is automatically freed)
44 * freedup:  similar to freeset, but strdup's the rhs-expression
45 * reassign: similar to freeset, but rhs must be variable and will be set to NULL
46 * nulldup:  like strdup, but pass-through NULL
47 *
48 * Note: freeset, freedup and reassign may safely use the changed variable in the rhs-expression!
49 *
50 * @@@ the complete section could go into a separate header,
51 * but it makes no sense atm, cause we need GB_strdup for C compilation
52 * (using a macro would evaluate 'str' in nulldup twice - which is not ok)
53 *
54 */
55
56#define freeset(var,str) do { typeof(var) freesetvar = (str); free(var); (var) = freesetvar; } while(0)
57
58#ifdef __cplusplus
59
60#ifndef _CPP_CSTRING
61#include <cstring>
62#endif
63#ifndef _CPP_CSTDLIB
64#include <cstdlib>
65#endif
66
67inline char *nulldup(const char *str)                           { return str ? strdup(str) : NULL; } // this does the same as GB_strdup
68inline void freedup(char *& strvar, const char *no_heapcopy)    { char *tmp_copy = nulldup(no_heapcopy); free(strvar); strvar = tmp_copy; }
69inline void reassign(char *& dstvar, char *& srcvar)            { freeset(dstvar, srcvar); srcvar = NULL; }
70
71#else
72
73#define nulldup(str)        GB_strdup(str)
74#define freedup(var,str)    freeset(var, nulldup(str))
75#define reassign(dvar,svar) do { freeset(dvar, svar); (svar) = NULL; } while(0)
76
77#endif
78/* -------------------------------------------------------------------------------- */
79
80
81#ifndef P_
82#define P_(s) s
83#endif
84
85#ifndef AD_K_PROT_H
86#include <ad_k_prot.h>
87#endif
88
89#else
90#error arbdb_base.h included twice
91#endif // ARBDB_BASE_H
Note: See TracBrowser for help on using the browser.