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_GHOSTNODE 1 // bit used by gbt_write_tree (only used on tree-nodes; so it does not clash with GB_USERFLAG_QUERY) |
---|
57 | |
---|
58 | // -------------- |
---|
59 | // enums |
---|
60 | |
---|
61 | enum GB_TYPES { // supported DB entry types |
---|
62 | GB_NONE = 0, |
---|
63 | GB_BIT = 1, |
---|
64 | GB_BYTE = 2, |
---|
65 | GB_INT = 3, |
---|
66 | GB_FLOAT = 4, |
---|
67 | GB_POINTER = 5, // not savable! only allowed in temporary entries |
---|
68 | GB_BITS = 6, |
---|
69 | // 7 is unused |
---|
70 | GB_BYTES = 8, |
---|
71 | GB_INTS = 9, |
---|
72 | GB_FLOATS = 10, |
---|
73 | GB_LINK = 11, |
---|
74 | GB_STRING = 12, |
---|
75 | GB_STRING_SHRT = 13, // used automatically during save |
---|
76 | // 14 is unused |
---|
77 | GB_DB = 15, |
---|
78 | |
---|
79 | // keep GB_TYPES consistent with AW_VARIABLE_TYPE |
---|
80 | // see ../WINDOW/aw_base.hxx@sync_GB_TYPES_AW_VARIABLE_TYPE |
---|
81 | |
---|
82 | GB_TYPE_MAX = 16, |
---|
83 | |
---|
84 | GB_CREATE_CONTAINER = GB_DB, |
---|
85 | GB_FIND = GB_NONE, |
---|
86 | |
---|
87 | }; |
---|
88 | |
---|
89 | enum GB_SEARCH_TYPE { |
---|
90 | SEARCH_BROTHER = 1, // [was: this_level] |
---|
91 | SEARCH_CHILD = 2, // [was: down_level] |
---|
92 | SEARCH_GRANDCHILD = 4, // [was: down_2_level] |
---|
93 | SEARCH_NEXT_BROTHER = SEARCH_BROTHER+8, // [was: this_level|search_next] |
---|
94 | SEARCH_CHILD_OF_NEXT = SEARCH_CHILD+8, // [was: down_level|search_next] |
---|
95 | }; |
---|
96 | |
---|
97 | enum GB_UNDO_TYPE { |
---|
98 | GB_UNDO_NONE, // no undo |
---|
99 | GB_UNDO_KILL, // no undo and delete all old undos |
---|
100 | GB_UNDO_UNDO, // normal undo -> deleted all redoes |
---|
101 | GB_UNDO_REDO, // moves to UNDO_REDO |
---|
102 | GB_UNDO_UNDO_REDO // internal makes undo redoable |
---|
103 | }; |
---|
104 | |
---|
105 | |
---|
106 | // ----------------------- |
---|
107 | // callback types |
---|
108 | |
---|
109 | typedef long (*gb_hash_loop_type)(const char *key, long val, void *client_data); |
---|
110 | typedef void (*gb_hash_const_loop_type)(const char *key, long val, void *client_data); |
---|
111 | typedef int (*gbs_hash_compare_function) (const char *key0, long val0, const char *key1, long val1); |
---|
112 | |
---|
113 | typedef const char* (*gb_export_sequence_cb)(GBDATA *gb_species, size_t *seq_len, GB_ERROR *error); |
---|
114 | |
---|
115 | typedef GBDATA* (*GB_Link_Follower)(GBDATA *GB_root, GBDATA *GB_elem, const char *link); |
---|
116 | |
---|
117 | typedef const char *(*gb_getenv_hook)(const char *varname); |
---|
118 | |
---|
119 | // ----------------------- |
---|
120 | // GB_transaction |
---|
121 | |
---|
122 | class GB_transaction : virtual Noncopyable { |
---|
123 | GBDATA *ta_main; |
---|
124 | bool ta_open; // is transaction open ? |
---|
125 | GB_ERROR ta_err; |
---|
126 | |
---|
127 | void init(GBDATA *gb_main, bool initial); |
---|
128 | protected: |
---|
129 | GB_transaction(GBDATA *gb_main, bool) { init(gb_main, true); } |
---|
130 | public: |
---|
131 | GB_transaction(GBDATA *gb_main) { init(gb_main, false); } |
---|
132 | ~GB_transaction(); |
---|
133 | |
---|
134 | bool ok() const { return ta_open && !ta_err; } // ready to work on DB? |
---|
135 | GB_ERROR close(GB_ERROR error); // abort transaction if error (e.g.: 'return ta.close(error);') |
---|
136 | ARB_ERROR close(ARB_ERROR& error); // abort transaction if error (e.g.: 'return ta.close(error);') |
---|
137 | }; |
---|
138 | |
---|
139 | struct GB_initial_transaction : public GB_transaction { |
---|
140 | GB_initial_transaction(GBDATA *gb_main) : GB_transaction(gb_main, true) {} |
---|
141 | }; |
---|
142 | |
---|
143 | class GB_shell { |
---|
144 | // initialize and cleanup module ARBDB |
---|
145 | // No database usage is possible when no GB_shell exists! |
---|
146 | public: |
---|
147 | GB_shell(); |
---|
148 | ~GB_shell(); |
---|
149 | |
---|
150 | static void ensure_inside(); |
---|
151 | static bool in_shell(); |
---|
152 | }; |
---|
153 | |
---|
154 | // -------------------------------------------- |
---|
155 | |
---|
156 | #if defined(DEBUG) |
---|
157 | struct GB_SizeInfo { |
---|
158 | long containers; // no of containers |
---|
159 | long terminals; // no of terminals |
---|
160 | long structure; // structure size |
---|
161 | long data; // data size |
---|
162 | long mem; // data memory size (compressed) |
---|
163 | |
---|
164 | GB_SizeInfo() : containers(0), terminals(0), structure(0), data(0), mem(0) {} |
---|
165 | |
---|
166 | void collect(GBDATA *gbd); |
---|
167 | }; |
---|
168 | #endif |
---|
169 | |
---|
170 | // -------------------------------------------- |
---|
171 | // include generated public prototypes |
---|
172 | |
---|
173 | #include <ad_prot.h> |
---|
174 | |
---|
175 | // to avoid arb-wide changes atm include some headers from CORE lib |
---|
176 | #ifndef ARB_MSG_H |
---|
177 | #include <arb_msg.h> |
---|
178 | #endif |
---|
179 | #ifndef ARB_STRING_H |
---|
180 | #include <arb_string.h> |
---|
181 | #endif |
---|
182 | |
---|
183 | // ---------------------------------------------------- |
---|
184 | // const wrappers for functions from ad_prot.h |
---|
185 | |
---|
186 | inline char *GBS_find_string(char *content, GB_CSTR key, int match_mode) { |
---|
187 | return const_cast<char*>(GBS_find_string(const_cast<GB_CSTR>(content), key, match_mode)); |
---|
188 | } |
---|
189 | |
---|
190 | // --------------------------------- |
---|
191 | // error delivery functions |
---|
192 | |
---|
193 | inline void GB_end_transaction_show_error(GBDATA *gbd, ARB_ERROR& error, void (*error_handler)(GB_ERROR)) { |
---|
194 | GB_end_transaction_show_error(gbd, error.deliver(), error_handler); |
---|
195 | } |
---|
196 | inline ARB_ERROR GB_end_transaction(GBDATA *gbd, ARB_ERROR& error) { |
---|
197 | return GB_end_transaction(gbd, error.deliver()); |
---|
198 | } |
---|
199 | |
---|
200 | |
---|
201 | #else |
---|
202 | #error arbdb.h included twice |
---|
203 | #endif // ARBDB_H |
---|