source: tags/cvs_2_svn/ARBDBPP/arbdb++.hxx

Last change on this file was 4030, checked in by westram, 18 years ago
  • gcc 4.1.1 fixes
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.9 KB
Line 
1#ifndef arbdbpp_hxx_included
2#define arbdbpp_hxx_included
3
4/* KLASSENDEFINITIONEN fuer die Datenbankschnittstelle
5
6AD_ERR  Fehlerklasse, oft Rueckgabewert von Funktionen
7       
8AD_MAIN Hauptklasse, oeffnen und schliessen der Datenbank, sowie
9beginn und Ende von Transaktionen
10
11folgende Klassen entsprechen im wesentlichen den Containern der
12ARB Database. Nach der Deklaration eines Objekts muss vor einem
13Funktionsaufruf init(), vor der Deallokierung ein exit()
14mit den entsprechenden Parametern aufgerufen werden.
15
16AD_SPECIES                 
17AD_ALI          ->alignment
18AD_CONT
19AD_SEQ
20AD_MARK
21
22***********************************************************/
23
24#ifndef AW_KEYSYM_HXX
25#include <aw_keysym.hxx>
26#endif
27
28#ifndef ARBDBPP_INCLUDED
29#define ARBDBPP_INCLUDED
30
31#define ADPP_CORE *(int *)0=0;
32#define AD_ERR_WARNING  1
33// Punktzeichen fuer sequenz     
34#define SEQ_POINT '.'   
35#define ALIGN_STRING ".-~?"     // characters allowed to change in align_mod
36#define ADPP_IS_ALIGN_CHARACTER(chr) (strchr (ALIGN_STRING,chr))
37
38const int MINCACH = 1;
39const int MAXCACH = 0;  // schaltet cach ein bei open Funktionen
40const int CORE = 1;
41
42typedef enum ad_edit_modus {
43    AD_allign       = 0,    // add & remove of . possible (default)
44    AD_nowrite      = 1,    // no edits allowed
45    AD_replace      = 2,    // all edits
46    AD_insert       = 3     //
47} AD_EDITMODI;
48
49typedef enum ad_types {
50    ad_none         = 0,
51    ad_bit          = 1,
52    ad_byte         = 2,
53    ad_int          = 3,
54    ad_float        = 4,
55    ad_bits         = 6,
56    ad_bytes        = 8,
57    ad_ints         = 9,
58    ad_floats       = 10,
59    ad_string       = 12,
60    ad_db           = 15,
61    ad_type_max     = 16
62} AD_TYPES;     // equal GBDATA types
63/*******************************
64class AD_ERR
65*******************************/
66
67class AD_ERR
68{
69    int modus;      // Mode  0 = Errors, 1 = Warnings
70    int  anzahl;    // Number of errors
71    char *text;     // error text
72       
73public:
74    AD_ERR();               // create error
75    AD_ERR(const char *errorstring); // create error
76    AD_ERR(const char *,const int core); // setzt den Fehler und bricht mit core ab falls core == CORE
77    ~AD_ERR();
78    char *show();   // returns the error text
79};
80
81
82class AD_READWRITE {
83    // Klasse, die es den anderen AD_Klassen ermoeglicht
84    // Eintraege zu lesen und zu schreiben.
85public:
86    GBDATA *gbdataptr;      // jeweiliger Zeiger auf GBDATA eintrag
87    // am Besten in initpntr bzw init auf jeweiligen
88    // Eintrag setzen.
89    char    *readstring(char *feld);
90    int     readint(char *feld);
91    float   readfloat(char *feld);
92    AD_ERR  *writestring(char *feld,char *eintrag);
93    AD_ERR  *writeint(char *feld,int eintrag);
94    AD_ERR  *writefloat(char *feld,float eintrag);
95    AD_ERR  *create_entry(char *key, AD_TYPES type);
96    AD_TYPES read_type(char *key);
97    GBDATA  *get_GBDATA(void) { return gbdataptr; };
98};
99
100/*************************
101class: AD_MAIN
102
103***************************/
104 
105
106class AD_MAIN : public AD_READWRITE
107{
108    friend class AD_SPECIES; // fuer den zugriff auf gbd
109    friend class AD_SAI;
110    friend class AD_ALI;
111    friend class AD_SEQ;
112       
113    GBDATA *gbd;            // Zeiger auf container der DB
114    GBDATA *species_data;   //
115    GBDATA *extended_data;  //
116    GBDATA *presets;
117    int     AD_fast;        // Flag fuer schnelen Zugriff
118    AD_EDITMODI      mode;  // for seq modes
119       
120public:
121
122
123    AD_MAIN();
124    ~AD_MAIN();
125       
126    AD_ERR *open(const char *);
127    AD_ERR *open(const char *,int );
128    AD_ERR *close();
129    AD_ERR *save(const char *modus);
130    AD_ERR *save_as(const char *modus);
131    AD_ERR *save_home(const char *modus);
132    AD_ERR *push_transaction();
133    AD_ERR *pop_transaction();
134    AD_ERR *begin_transaction();
135    AD_ERR *commit_transaction();
136    AD_ERR *abort_transaction();
137    AD_ERR *change_security_level(int level);
138    int     time_stamp(void);
139
140    int get_cach_flag();
141};
142
143/*******************************
144class AD_ALI
145container alignment
146*******************************/
147
148class AD_ALI : public AD_READWRITE
149{
150    friend class AD_CONT;
151   
152    AD_MAIN *ad_main;
153    GBDATA  *gb_ali;
154    GBDATA  *gb_aligned;
155    GBDATA  *gb_name;
156    GBDATA  *gb_len;
157    GBDATA  *gb_type;
158    char    *ad_name;
159    long     ad_len;
160    char    *ad_type;
161    long     ad_aligned;
162
163
164    int     count;
165    int     last;
166    AD_ERR *initpntr();
167    AD_ERR *release();
168public:
169    AD_ALI();
170    ~AD_ALI();
171
172    AD_ERR *init(AD_MAIN *gbptr);
173    AD_ERR *exit();
174    AD_ERR *find(char*name);
175    AD_ERR *first();
176    AD_ERR *ddefault();
177    AD_ERR *next();
178    //      AD_ERR *default();
179
180    AD_MAIN *get_ad_main() { return ad_main; };
181    int     eof();          // 1 ,falls letztes alignment
182    int     aligned();
183    int     len();
184    char *type();
185    char *name();
186    int time_stamp();
187
188    void    operator = (AD_ALI& );
189
190};
191
192
193/**********************************************
194AD_SPECIES
195***********************************************/
196class CONTLIST;
197class AD_SPECIES;
198
199int AD_SPECIES_destroy(GBDATA *,AD_SPECIES *);
200int AD_SPECIES_name_change(GBDATA *,AD_SPECIES *);
201
202class AD_SPECIES : public AD_READWRITE
203{
204    GBDATA  *gb_spdata;     // um lange Zeigerzugriffe zu vermeiden
205    // kopie von AD_MAIN.speciesdata
206protected:
207    AD_MAIN *ad_main;       // fuer DB zugriff
208    GBDATA *gb_species;     // zeiger auf species
209    GBDATA *gb_name;
210
211    char *spname;           // enthaelt kopie des namens
212
213    int last;               // 1 -> EOF
214    int count;              // zaehler fuer die daranhaengenden
215    // container
216
217    AD_ERR *error();
218    AD_ERR *ddefault();
219    class CONTLIST *container;
220
221    friend class AD_CONT;
222    friend int AD_SPECIES_destroy(GBDATA *,AD_SPECIES *);
223    friend int AD_SPECIES_name_change(GBDATA *,AD_SPECIES *);
224    // Funktion die callback behandelt
225
226    void initpntr();        // internes Aufbereiten der Klasse
227    void release();         // behandelt speicherverwaltung
228
229
230public:
231    AD_SPECIES();
232    ~AD_SPECIES();
233
234    AD_ERR *init(AD_MAIN *);
235    AD_ERR *exit();
236    AD_ERR *first();
237    AD_ERR *next();
238    AD_ERR *firstmarked();
239    AD_ERR *nextmarked();
240    AD_ERR *find(const char *name);
241    AD_ERR *create(const char *name);
242
243    void    operator = (const AD_SPECIES&); // zum kopieren
244
245    int time_stamp();
246
247    const char      *name();
248    int     flag();
249    const char      *fullname();
250    int     eof();
251};
252
253
254/**********************************************
255AD_SAI
256***********************************************/
257class AD_SAI : public AD_SPECIES
258{
259    GBDATA  *gb_main;       // um lange Zeigerzugriffe zu vermeiden
260    // kopie von AD_MAIN.speciesdata
261public:
262    AD_SAI();
263    ~AD_SAI();
264
265    int     flag();
266    AD_ERR *init(AD_MAIN *);
267    AD_ERR *exit();
268    AD_ERR *first();
269    AD_ERR *next();
270    AD_ERR *firstmarked();
271    AD_ERR *nextmarked();
272    AD_ERR *find(char *);
273    AD_ERR *create(char *name);
274
275    char    *fullname();
276    void    operator = (const AD_SAI&);     // zum kopieren
277    char    *name();        // liefert name zurueck
278
279};
280/*************************************
281 *AD_CONT
282 ************************************/
283class AD_CONT : public AD_READWRITE
284                // Containerklasse in der die Sequenzinformationen fuer
285                // ein Spezies gehalten und verwaltet wird
286                // muss ein spezies und ein alignment objekt
287                // beim initialisieren bekommen
288{
289    AD_SPECIES      *ad_species;
290    AD_ALI          *ad_ali;
291
292    GBDATA *gb_species; // wird 0, wenn species deleted
293    GBDATA *gb_ali;         // pointer to ali_xxx container
294
295    friend class AD_SEQ;
296    friend class AD_STAT;
297    // funktionen zum einfuegen in die AD_SPECIES Containerliste
298    int con_insert(AD_SPECIES *,AD_ALI *);
299    void con_remove(AD_SPECIES *,AD_ALI *);
300    // gibt cach flag zurueck (implementiert um mehrfachzeiger
301    int get_cach_flag();
302
303public:
304    AD_CONT();
305    ~AD_CONT();
306
307    AD_MAIN *get_ad_main() { return ad_ali->get_ad_main(); };
308    AD_ERR *init(AD_SPECIES *,AD_ALI *);
309    AD_ERR *create(AD_SPECIES *,AD_ALI *);
310    int     eof(void);
311    AD_ERR *exit();
312};
313
314
315// einfach verkettete Liste CONTLIST
316
317struct CLISTENTRY {
318    AD_SPECIES *entry;      // werden zum vergleich verwendet
319    AD_ALI  *entry2;
320    CLISTENTRY *next;
321    CLISTENTRY();
322};
323
324class CONTLIST {
325    // einfach verkettete liste mit AD_CONT eintraegen
326    // mit der nachgeprueft werden soll welche container
327    // enthalten sind.
328    CLISTENTRY *first;
329    int anzahl;
330
331
332public:
333    CONTLIST();
334    ~CONTLIST();
335
336    int insert(AD_SPECIES *,AD_ALI *);
337    int element(AD_SPECIES *,AD_ALI *);
338    void remove(AD_SPECIES *,AD_ALI *);
339};
340
341
342/*****************************
343        AD_STAT
344****************************/
345
346class AD_STAT;
347int   AD_STAT_updatecall(GBDATA *,AD_STAT*);
348
349class AD_STAT                   // Sequenzklasse in der die Sequenz und ihre
350// markierung gespeichert ist
351{
352    class AD_CONT *ad_cont;
353
354    friend int AD_STAT_updatecall(GBDATA *,AD_STAT*);
355   
356    AD_TYPES  marktype;
357    char     *markkey;
358    char     *markdata;         // Markierungsdaten String
359    float    *markdatafloat;
360    GB_UINT4 *markdataint;
361    long      nmark;            // anzahl der floats`
362
363    char c_0, c_1;              // Zeichen fuer die markierung
364    int  last;
365
366    int     updated;            // flag fuer aufgetretenen update
367    int     inited_object;      // fuer init/exit ueberpruefung
368    GBDATA *gb_mark;            // Zeiger auf ali_xxx container
369    GBDATA *gb_char_mark;
370    GBDATA *GB_FLOAT_mark;
371    GBDATA *GB_INT_mark;
372    GBDATA *gb_markdata;        // aktuelle markierung (aller 3 typen)
373
374    AD_ERR *initpntr();
375    AD_ERR *release();
376public:
377    AD_STAT();
378    ~AD_STAT();
379
380    AD_ERR *init(AD_CONT *);
381    AD_ERR *exit();
382
383    AD_ERR *first();
384    AD_ERR *first(AD_TYPES type);
385
386    AD_ERR *next();
387    AD_ERR *next(AD_TYPES type);
388
389    int      *eof();
390    AD_TYPES  type();
391    GB_UINT4 *getint();
392
393    char   *getbits();
394    float  *getfloat();
395    AD_ERR *put();
396    AD_ERR *put(char *markings, int len);
397    AD_ERR *put(float *markings, int len);
398    AD_ERR *put(GB_UINT4 *markings, int len);
399    int     time_stamp();
400};
401
402
403/**********************************
404        AD SEQ
405*********************************/
406class AD_SEQ: public AD_READWRITE
407              // Sequenzklasse in der die Sequenz und ihre
408              // markierung gespeichert ist
409{
410    friend int AD_SEQ_updatecall(GBDATA *,AD_SEQ  *);
411    GBDATA *gb_seq;         // zeiger auf ali_xxx container
412
413protected:
414    int     updated;        // flag fuer aufgetretenen update
415    int     nseq_but_filter; // show filter, no sequence
416    long    seq_len;        // hier steht die max laenge der sequenz
417
418    char    *seq;               // Sequenzdata
419    long     timestamp;         // Zeit des letzten zugriffs auf DB
420    AD_CONT *ad_cont;
421
422    AD_ERR *check_base(char chr,long position, int direction);
423    AD_ERR *push(long position, int direction);
424    AD_ERR *jump(long position, int direction);
425    AD_ERR *fetch(long position, int direction);
426    long    get_next_base(long position, int direction);
427    long    get_next_gap(long position, int direction);
428
429public:
430    AD_SEQ();
431    ~AD_SEQ();
432
433    AD_ERR *init(AD_CONT *);
434    AD_ERR *exit();
435
436    AD_ERR *update();       // reread data froam database
437
438    char        *get();         // read the sequence
439    AD_ERR      *put();         // write the internal cash to the database
440    AD_ERR      *create(void);
441    AD_ERR      *changemode(AD_EDITMODI mod);
442    AD_EDITMODI  mode();
443    AD_MAIN *get_ad_main() { return ad_cont->get_ad_main(); };
444
445    int     s_inited();
446    int     time_stamp(void);
447    int     len();
448    // EDITIERFUNKTINEN
449    // position ab 0 bis strlen(seq)
450    //
451    AD_ERR *insert(char *,long position, int direction);
452    AD_ERR *remove(int len,long position, int direction);
453    AD_ERR *replace(char *text,long position, int direction);
454    AD_ERR *swap_gaps(long position, char ch);
455    AD_ERR *command( AW_key_mod keymod, AW_key_code keycode, char key, int direction, long &cursorpos, int & changed_flag);
456};
457
458#endif
459
460
461#endif
Note: See TracBrowser for help on using the repository browser.