ARB
arbdb.h
Go to the documentation of this file.
1 // ================================================================ //
2 // //
3 // File : arbdb.h //
4 // Purpose : external ARB DB interface //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // ================================================================ //
10 
11 #ifndef ARBDB_H
12 #define ARBDB_H
13 
14 #ifndef ARBTOOLS_H
15 #include <arbtools.h>
16 #endif
17 #ifndef ARBDB_BASE_H
18 #include <arbdb_base.h>
19 #endif
20 #ifndef ARB_ERROR_H
21 #include <arb_error.h>
22 #endif
23 #ifndef _STDINT_H
24 #include <stdint.h>
25 #endif
26 
27 #define GB_SYSTEM_FOLDER "__SYSTEM__"
28 #define GB_SYSTEM_KEY_DATA "@key_data"
29 
30 #define GB_DEFAULT_ALIGNMENT "presets/use" // has to match ../WINDOW/aw_awar_defs.hxx@AWAR_DEFAULT_ALIGNMENT
31 
32 // ---------------------
33 // simple types
34 
35 typedef int GB_COMPRESSION_MASK;
36 
37 // ------------------------------
38 // forward declare types
39 
40 struct GB_NUMHASH;
41 
42 struct GBS_regex;
43 struct GBS_string_matcher;
44 struct GBS_strstruct;
45 struct GEN_position;
46 struct DictData;
47 struct CharPtrArray;
48 struct StrArray;
49 struct ConstStrArray;
50 
51 // -------------------
52 // constants
53 
54 #define GB_USERFLAG_ANY 127 // maximum for gb_flag_types2::usr_ref
55 #define GB_USERFLAG_QUERY 1 // bit used for search&query (used on species, genes, experiments)
56 #define GB_USERFLAG_WASMARKED 2 // bit used to temp. store marks
57 #define GB_USERFLAG_GHOSTNODE 1 // bit used by gbt_write_tree (only used on tree-nodes; so it does not clash with GB_USERFLAG_QUERY)
58 
59 // --------------
60 // enums
61 
62 enum GB_TYPES { // supported DB entry types
63  GB_NONE = 0,
64  GB_BIT = 1,
65  GB_BYTE = 2,
66  GB_INT = 3,
67  GB_FLOAT = 4,
68  GB_POINTER = 5, // not savable! only allowed in temporary entries
69  GB_BITS = 6,
70  // 7 is unused
71  GB_BYTES = 8,
72  GB_INTS = 9,
73  GB_FLOATS = 10,
74  GB_OBSOLETE = 11, // former GB_LINK (stay backward compatible until arb 6.2 or later)
75  GB_STRING = 12,
76  GB_STRING_SHRT = 13, // used automatically during save
77  // 14 is unused
78  GB_DB = 15,
79 
80  // keep GB_TYPES consistent with AW_VARIABLE_TYPE
81  // see ../WINDOW/aw_base.hxx@sync_GB_TYPES_AW_VARIABLE_TYPE
82 
84 
87 
88 };
89 
96  return type == GB_STRING || type == GB_BYTE || type == GB_INT || type == GB_FLOAT || type == GB_BITS;
97 }
98 
100  SEARCH_BROTHER = 1, // [was: this_level]
101  SEARCH_CHILD = 2, // [was: down_level]
102  SEARCH_GRANDCHILD = 4, // [was: down_2_level]
103  SEARCH_NEXT_BROTHER = SEARCH_BROTHER+8, // [was: this_level|search_next]
104  SEARCH_CHILD_OF_NEXT = SEARCH_CHILD+8, // [was: down_level|search_next]
105 };
106 
108  GB_UNDO_NONE, // no undo
109  GB_UNDO_KILL, // no undo and delete all old undos
110  GB_UNDO_UNDO, // normal undo -> deleted all redoes
111  GB_UNDO_REDO, // moves to UNDO_REDO
112  GB_UNDO_UNDO_REDO // internal makes undo redoable
113 };
114 
115 enum XCMD_TYPE {
116  // internal (use public values below):
117  _XCMD__ASYNC = 1, // run asynchronous (otherwise wait for finish)
118  _XCMD__WAITKEY = 2, // always wait for keypress (otherwise only in case of error!)
119 
120  // public:
125 };
126 
127 // -----------------------
128 // callback types
129 
130 typedef long (*gb_hash_loop_type)(const char *key, long val, void *client_data);
131 typedef void (*gb_hash_const_loop_type)(const char *key, long val, void *client_data);
132 typedef int (*gbs_hash_compare_function) (const char *key0, long val0, const char *key1, long val1);
133 
134 typedef const char* (*gb_export_sequence_cb)(GBDATA *gb_species, size_t *seq_len, GB_ERROR *error);
135 
136 typedef GBDATA* (*GB_Link_Follower)(GBDATA *GB_root, GBDATA *GB_elem, const char *link);
137 
138 typedef const char *(*gb_getenv_hook)(const char *varname);
139 
140 // -----------------------
141 // GB_transaction
142 
143 class GB_transaction : virtual Noncopyable {
144  GBDATA *ta_main;
145  bool ta_open; // is transaction open ?
146  GB_ERROR ta_err;
147 
148 #if defined(ASSERTION_USED)
149  mutable int checked_for_error; // true when ok() or close() was used while ta_err
150  void CFE(int flag) const { if (ta_err) checked_for_error = checked_for_error|flag; }
151 #else
152  void CFE(int) const {}
153 #endif
154 
155  void init(GBDATA *gb_main, bool initial);
156 protected:
157  GB_transaction(GBDATA *gb_main, bool) { init(gb_main, true); }
158 public:
159  GB_transaction(GBDATA *gb_main) { init(gb_main, false); }
160  ~GB_transaction();
161 
162  bool ok() const { CFE(1); return ta_open && !ta_err; } // ready to work on DB?
163  GB_ERROR close(GB_ERROR error); // abort transaction if error (e.g.: 'return ta.close(error);')
164  ARB_ERROR close(ARB_ERROR& error); // abort transaction if error (e.g.: 'return ta.close(error);')
165 };
166 
169 };
170 
171 class GB_shell {
172  // initialize and cleanup module ARBDB
173  // No database usage is possible when no GB_shell exists!
174 public:
175  GB_shell();
176  ~GB_shell();
177 
178  static void ensure_inside();
179  static bool in_shell();
180 };
181 
182 // --------------------------
183 // GB_securityLevel
184 
185 class GB_securityLevel : virtual Noncopyable {
186  // changes global security level until destruction of this.
187  // intended to be used as auto-variable.
188 
189  GBDATA *gbdata;
190  int previous_level;
191 
192  int whats_my_security() const;
193  void change_my_security(int level);
194 
195 public:
196  GBDATA *get_gbd() const { return gbdata; } // internal use only
197 
198  int previous() const { return previous_level; }
199  int current() const { return whats_my_security(); }
200 
201  GB_securityLevel(GBDATA *gbd, int level) :
202  gbdata(gbd),
203  previous_level(current())
204  {
205  change_my_security(level);
206  }
208  change_my_security(previous());
209  }
210 
211 };
212 struct GB_topSecurityLevel : public GB_securityLevel { // derived from Noncopyable
213  // raise security level to top (allow everything).
214  // Note: the highest user-level is 6
216  GB_securityLevel(gbd, 7)
217  {}
218 };
219 struct GB_previousSecurityLevel : public GB_securityLevel { // derived from Noncopyable
220  // temporarily lower security again (while another GB_securityLevel is active).
222  GB_securityLevel(active.get_gbd(), active.previous())
223  {}
224 };
225 
226 // --------------------------------------------
227 
228 #if defined(DEBUG)
229 struct GB_SizeInfo {
230  long containers; // no of containers
231  long terminals; // no of terminals
232  long structure; // structure size
233  long data; // data size
234  long mem; // data memory size (compressed)
235 
236  GB_SizeInfo() : containers(0), terminals(0), structure(0), data(0), mem(0) {}
237 
238  void collect(GBDATA *gbd);
239 };
240 #endif
241 
242 // --------------------------------------------
243 // include generated public prototypes
244 
245 #include <ad_prot.h>
246 
247 // to avoid arb-wide changes atm include some headers from CORE lib
248 #ifndef ARB_MEM_H
249 #include <arb_mem.h>
250 #endif
251 #ifndef ARB_MSG_H
252 #include <arb_msg.h>
253 #endif
254 #ifndef ARB_STRING_H
255 #include <arb_string.h>
256 #endif
257 
258 // ----------------------------------------------------
259 // const wrappers for functions from ad_prot.h
260 
261 inline char *GBS_find_string(char *content, GB_CSTR key, int match_mode) {
262  return const_cast<char*>(GBS_find_string(const_cast<GB_CSTR>(content), key, match_mode));
263 }
264 
265 // ---------------------------------
266 // error delivery functions
267 
268 inline void GB_end_transaction_show_error(GBDATA *gbd, ARB_ERROR& error, void (*error_handler)(GB_ERROR)) {
269  GB_end_transaction_show_error(gbd, error.deliver(), error_handler);
270 }
272  return GB_end_transaction(gbd, error.deliver());
273 }
274 
275 
276 #else
277 #error arbdb.h included twice
278 #endif // ARBDB_H
const char * GB_ERROR
Definition: arb_core.h:25
GB_TYPES type
bool GB_TYPE_readable_as_string(GB_TYPES type)
Definition: arbdb.h:90
Definition: arbdb.h:65
Definition: arbdb.h:69
~GB_securityLevel()
Definition: arbdb.h:207
long
Definition: AW_awar.cxx:152
int(* gbs_hash_compare_function)(const char *key0, long val0, const char *key1, long val1)
Definition: arbdb.h:132
bool ok() const
Definition: arbdb.h:162
int current() const
Definition: arbdb.h:199
XCMD_TYPE
Definition: arbdb.h:115
GB_topSecurityLevel(GBDATA *gbd)
Definition: arbdb.h:215
long(* gb_hash_loop_type)(const char *key, long val, void *client_data)
Definition: arbdb.h:130
char * GBS_find_string(char *content, GB_CSTR key, int match_mode)
Definition: arbdb.h:261
GB_UNDO_TYPE
Definition: arbdb.h:107
GB_initial_transaction(GBDATA *gb_main)
Definition: arbdb.h:168
GB_transaction(GBDATA *gb_main, bool)
Definition: arbdb.h:157
Definition: arbdb.h:67
Definition: arbdb.h:78
GB_ERROR deliver() const
Definition: arb_error.h:116
#define true
Definition: ureadseq.h:14
~GB_shell()
Definition: arbdb.cxx:458
Definition: arbdb.h:64
GB_shell()
Definition: arbdb.cxx:454
static void ensure_inside()
Definition: arbdb.cxx:463
static void error(const char *msg)
Definition: mkptypes.cxx:96
int previous() const
Definition: arbdb.h:198
ARB_ERROR GB_end_transaction(GBDATA *gbd, ARB_ERROR &error)
Definition: arbdb.h:271
GB_previousSecurityLevel(const GB_securityLevel &active)
Definition: arbdb.h:221
GB_securityLevel(GBDATA *gbd, int level)
Definition: arbdb.h:201
GB_SEARCH_TYPE
Definition: arbdb.h:99
Definition: arbdb.h:86
static bool in_shell()
Definition: arbdb.cxx:465
void(* gb_hash_const_loop_type)(const char *key, long val, void *client_data)
Definition: arbdb.h:131
long int flag
Definition: f2c.h:39
Definition: arbdb.h:72
Definition: arbdb.h:63
GB_ERROR close(GB_ERROR error)
Definition: arbdbpp.cxx:35
aisc_com * link
GB_transaction(GBDATA *gb_main)
Definition: arbdb.h:159
int GB_COMPRESSION_MASK
Definition: arbdb.h:35
GB_TYPES
Definition: arbdb.h:62
GBDATA * get_gbd() const
Definition: arbdb.h:196
GBDATA * gb_main
Definition: adname.cxx:32
Definition: arbdb.h:71
void GB_end_transaction_show_error(GBDATA *gbd, ARB_ERROR &error, void(*error_handler)(GB_ERROR))
Definition: arbdb.h:268
const char * GB_CSTR
Definition: arbdb_base.h:25
Definition: arbdb.h:66