source: tags/ms_r16q3/ARBDB/arbdb.h

Last change on this file was 15268, checked in by westram, 8 years ago
  • GB_xcmd
    • remove from perl interface
    • replace bool-flag-couple by enum
    • guard unused case XCMD_SYNC_WAITKEY
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
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
35typedef int GB_COMPRESSION_MASK;
36
37// ------------------------------
38//      forward declare types
39
40struct GB_NUMHASH;
41
42struct GBS_regex;
43struct GBS_string_matcher;
44struct GBS_strstruct;
45struct GEN_position;
46struct DictData;
47struct CharPtrArray;
48struct StrArray;
49struct 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
62enum 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_LINK        = 11,
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
83    GB_TYPE_MAX = 16,
84
85    GB_CREATE_CONTAINER = GB_DB,
86    GB_FIND             = GB_NONE,
87
88};
89
90enum GB_SEARCH_TYPE {
91    SEARCH_BROTHER       = 1,                       // [was: this_level]
92    SEARCH_CHILD         = 2,                       // [was: down_level]
93    SEARCH_GRANDCHILD    = 4,                       // [was: down_2_level]
94    SEARCH_NEXT_BROTHER  = SEARCH_BROTHER+8,        // [was: this_level|search_next]
95    SEARCH_CHILD_OF_NEXT = SEARCH_CHILD+8,          // [was: down_level|search_next]
96};
97
98enum GB_UNDO_TYPE {
99    GB_UNDO_NONE,                                   // no undo
100    GB_UNDO_KILL,                                   // no undo and delete all old undos
101    GB_UNDO_UNDO,                                   // normal undo -> deleted all redoes
102    GB_UNDO_REDO,                                   // moves to UNDO_REDO
103    GB_UNDO_UNDO_REDO                               // internal makes undo redoable
104};
105
106enum XCMD_TYPE {
107    // internal (use public values below):
108    _XCMD__ASYNC   = 1, // run asynchronous (otherwise wait for finish)
109    _XCMD__WAITKEY = 2, // always wait for keypress (otherwise only in case of error!)
110
111    // public:
112    XCMD_ASYNC_WAITKEY       = _XCMD__ASYNC|_XCMD__WAITKEY,
113    XCMD_ASYNC_WAIT_ON_ERROR = _XCMD__ASYNC,
114    XCMD_SYNC_WAITKEY        = _XCMD__WAITKEY,
115    XCMD_SYNC_WAIT_ON_ERROR  = 0,
116};
117
118// -----------------------
119//      callback types
120
121typedef long (*gb_hash_loop_type)(const char *key, long val, void *client_data);
122typedef void (*gb_hash_const_loop_type)(const char *key, long val, void *client_data);
123typedef int (*gbs_hash_compare_function) (const char *key0, long val0, const char *key1, long val1);
124
125typedef const char* (*gb_export_sequence_cb)(GBDATA *gb_species, size_t *seq_len, GB_ERROR *error);
126
127typedef GBDATA* (*GB_Link_Follower)(GBDATA *GB_root, GBDATA *GB_elem, const char *link);
128
129typedef const char *(*gb_getenv_hook)(const char *varname);
130
131// -----------------------
132//      GB_transaction
133
134class GB_transaction : virtual Noncopyable {
135    GBDATA   *ta_main;
136    bool      ta_open;          // is transaction open ?
137    GB_ERROR  ta_err;
138
139    void init(GBDATA *gb_main, bool initial);
140protected:
141    GB_transaction(GBDATA *gb_main, bool) { init(gb_main, true); }
142public:
143    GB_transaction(GBDATA *gb_main) { init(gb_main, false); }
144    ~GB_transaction();
145
146    bool ok() const { return ta_open && !ta_err; }  // ready to work on DB?
147    GB_ERROR close(GB_ERROR error);                 // abort transaction if error (e.g.: 'return ta.close(error);')
148    ARB_ERROR close(ARB_ERROR& error);              // abort transaction if error (e.g.: 'return ta.close(error);')
149};
150
151struct GB_initial_transaction : public GB_transaction {
152    GB_initial_transaction(GBDATA *gb_main) : GB_transaction(gb_main, true) {}
153};
154
155class GB_shell {
156    // initialize and cleanup module ARBDB
157    // No database usage is possible when no GB_shell exists!
158public: 
159    GB_shell();
160    ~GB_shell();
161
162    static void ensure_inside();
163    static bool in_shell();
164};
165
166// --------------------------------------------
167
168#if defined(DEBUG)
169struct GB_SizeInfo {
170    long containers; // no of containers
171    long terminals;  // no of terminals
172    long structure;  // structure size
173    long data;       // data size
174    long mem;        // data memory size (compressed)
175
176    GB_SizeInfo() : containers(0), terminals(0), structure(0), data(0), mem(0) {}
177
178    void collect(GBDATA *gbd);
179};
180#endif
181
182// --------------------------------------------
183//      include generated public prototypes
184
185#include <ad_prot.h>
186
187// to avoid arb-wide changes atm include some headers from CORE lib
188#ifndef ARB_MEM_H
189#include <arb_mem.h>
190#endif
191#ifndef ARB_MSG_H
192#include <arb_msg.h>
193#endif
194#ifndef ARB_STRING_H
195#include <arb_string.h>
196#endif
197
198// ----------------------------------------------------
199//      const wrappers for functions from ad_prot.h
200
201inline char *GBS_find_string(char *content, GB_CSTR key, int match_mode) {
202    return const_cast<char*>(GBS_find_string(const_cast<GB_CSTR>(content), key, match_mode));
203}
204
205// ---------------------------------
206//      error delivery functions
207
208inline void GB_end_transaction_show_error(GBDATA *gbd, ARB_ERROR& error, void (*error_handler)(GB_ERROR)) {
209    GB_end_transaction_show_error(gbd, error.deliver(), error_handler);
210}
211inline ARB_ERROR GB_end_transaction(GBDATA *gbd, ARB_ERROR& error) {
212    return GB_end_transaction(gbd, error.deliver());
213}
214
215
216#else
217#error arbdb.h included twice
218#endif // ARBDB_H
Note: See TracBrowser for help on using the repository browser.