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

Last change on this file was 2, checked in by oldcode, 24 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.5 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
9        beginn 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_KEY_CODES_INCLUDED
25#include <aw_keysym.hxx>
26#endif
27
28
29#ifndef ARBDBPP_INCLUDED
30#define ARBDBPP_INCLUDED
31
32#ifndef GB_INCLUDED
33        typedef struct gb_data_base_type GBDATA;
34#endif
35
36#define ADPP_CORE *(int *)0=0;
37#define AD_ERR_WARNING  1
38        // Punktzeichen fuer sequenz     
39#define SEQ_POINT '.'   
40#define ALIGN_STRING ".-~?"     // characters allowed to change in align_mod
41#define ADPP_IS_ALIGN_CHARACTER(chr) (strchr (ALIGN_STRING,chr))
42
43const int MINCACH = 1;
44const int MAXCACH = 0;  // schaltet cach ein bei open Funktionen
45const int CORE = 1;
46
47typedef enum ad_edit_modus {
48        AD_allign       = 0,    // add & remove of . possible (default)
49        AD_nowrite      = 1,    // no edits allowed
50        AD_replace      = 2,    // all edits
51        AD_insert       = 3     //
52        } AD_EDITMODI;
53
54typedef enum ad_types {
55        ad_none         = 0,
56        ad_bit          = 1,
57        ad_byte         = 2,
58        ad_int          = 3,
59        ad_float        = 4,
60        ad_bits         = 6,
61        ad_bytes        = 8,
62        ad_ints         = 9,
63        ad_floats       = 10,
64        ad_string       = 12,
65        ad_db           = 15,
66        ad_type_max     = 16
67        } AD_TYPES;     // equal GBDATA types
68/*******************************
69class AD_ERR
70 *******************************/
71
72class AD_ERR
73        {
74        int modus;      // Mode  0 = Errors, 1 = Warnings
75        int  anzahl;    // Number of errors
76        char *text;     // error text
77       
78        public:
79        AD_ERR();               // create error
80        AD_ERR(const char *errorstring); // create error
81        AD_ERR(const char *,const int core); // setzt den Fehler und bricht mit core ab falls core == CORE
82        ~AD_ERR();
83        char *show();   // returns the error text
84        };
85
86
87class AD_READWRITE {
88        // Klasse, die es den anderen AD_Klassen ermoeglicht
89        // Eintraege zu lesen und zu schreiben.
90        public:
91        GBDATA *gbdataptr;      // jeweiliger Zeiger auf GBDATA eintrag
92                                // am Besten in initpntr bzw init auf jeweiligen
93                                // Eintrag setzen.
94        char    *readstring(char *feld);
95        int     readint(char *feld);
96        float   readfloat(char *feld);
97        AD_ERR  *writestring(char *feld,char *eintrag);
98        AD_ERR  *writeint(char *feld,int eintrag);
99        AD_ERR  *writefloat(char *feld,float eintrag);
100        AD_ERR  *create_entry(char *key, AD_TYPES type);
101        AD_TYPES read_type(char *key);
102        GBDATA  *get_GBDATA(void) { return gbdataptr; };
103        };
104
105/*************************
106class: AD_MAIN
107
108***************************/
109 
110
111class AD_MAIN : public AD_READWRITE
112        {
113        friend class AD_SPECIES; // fuer den zugriff auf gbd
114        friend class AD_SAI;
115        friend class AD_ALI;
116        friend class AD_SEQ;
117       
118        GBDATA *gbd;            // Zeiger auf container der DB
119        GBDATA *species_data;   //
120        GBDATA *extended_data;  //
121        GBDATA *presets;
122        int     AD_fast;        // Flag fuer schnelen Zugriff
123        AD_EDITMODI      mode;  // for seq modes
124       
125        public:
126
127
128        AD_MAIN();
129        ~AD_MAIN();
130       
131        AD_ERR *        open(const char *);
132        AD_ERR *        open(const char *,int );       
133        AD_ERR *        close();
134        AD_ERR *        save(const char *modus);
135        AD_ERR *        save_as(const char *modus);
136        AD_ERR *        save_home(const char *modus);
137        AD_ERR *        push_transaction();
138        AD_ERR *        pop_transaction();
139        AD_ERR *        begin_transaction();
140        AD_ERR *        commit_transaction();
141        AD_ERR *        abort_transaction();
142        AD_ERR *        change_security_level(int level);
143        int     time_stamp(void);
144
145         int get_cach_flag();   
146};
147
148/*******************************
149class AD_ALI
150container alignment
151*******************************/
152
153class AD_ALI : public AD_READWRITE
154        {
155        friend class AD_CONT;
156        AD_MAIN *ad_main;       
157        GBDATA *gb_ali;
158        GBDATA *gb_aligned;
159        GBDATA *gb_name;       
160        GBDATA *gb_len; 
161        GBDATA  *gb_type;
162        char *ad_name;
163        long  ad_len;
164        char *ad_type;
165        long  ad_aligned;
166
167       
168        int     count;         
169        int     last;
170        AD_ERR * initpntr();   
171        AD_ERR * release();
172        public:
173        AD_ALI();
174        ~AD_ALI();
175       
176        AD_ERR * init(AD_MAIN *gbptr);
177        AD_ERR * exit();
178        AD_ERR * find(char* name);
179        AD_ERR * first();
180        AD_ERR * ddefault();
181        AD_ERR * next();
182        //      AD_ERR * default();
183
184        AD_MAIN *get_ad_main() { return ad_main; };
185        int     eof();          // 1 ,falls letztes alignment
186        int     aligned();     
187        int     len();
188        char*   type();
189        char*   name();
190        int time_stamp();
191
192        void    operator = (AD_ALI& );
193
194        };
195
196
197/**********************************************
198AD_SPECIES
199***********************************************/
200class CONTLIST;
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       
230        public:
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
261        public:
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               
303        public:
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 AD_CONT::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
332        public:
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   // Sequenzklasse in der die Sequenz und ihre
347        // markierung gespeichert ist
348        {
349        class AD_CONT *ad_cont;
350       
351        friend int AD_STAT_updatecall(GBDATA * ,AD_STAT* ); 
352        AD_TYPES  marktype;
353        char    * markkey;
354        char    * markdata;     // Markierungsdaten String
355        float   * markdatafloat;
356        GB_UINT4        * markdataint;
357        long    nmark;          // anzahl der floats`
358       
359        char    c_0,c_1;        // Zeichen fuer die markierung
360        int last;
361
362        int     updated;        // flag fuer aufgetretenen update
363        int     inited_object;  // fuer init/exit ueberpruefung
364        GBDATA  *gb_mark;       // Zeiger auf ali_xxx container
365        GBDATA  *gb_char_mark;
366        GBDATA  *GB_FLOAT_mark;
367        GBDATA  *GB_INT_mark;
368        GBDATA  *gb_markdata;   // aktuelle markierung (aller 3 typen)
369       
370        AD_ERR  *initpntr();
371        AD_ERR  *release();     
372        public:
373        AD_STAT();
374        ~AD_STAT();
375       
376        AD_ERR * init(AD_CONT *);
377        AD_ERR * exit();
378       
379        AD_ERR * first();
380        AD_ERR * first(AD_TYPES type);
381
382        AD_ERR * next();
383        AD_ERR * next(AD_TYPES type);
384
385        int * eof();
386        AD_TYPES type();
387        GB_UINT4        * getint();
388       
389        char    * getbits();
390        float   * getfloat();
391        AD_ERR  * put();
392        AD_ERR  * put(char *markings, int len);
393        AD_ERR  * put(float *markings, int len);
394        AD_ERR  * put(GB_UINT4 *markings, int len);
395        int time_stamp();
396        };
397
398
399/**********************************
400        AD SEQ
401*********************************/
402class AD_SEQ: public AD_READWRITE
403        // Sequenzklasse in der die Sequenz und ihre
404        // markierung gespeichert ist
405        {       
406        friend int AD_SEQ_updatecall(GBDATA * ,AD_SEQ  * ); 
407        GBDATA *gb_seq;         // zeiger auf ali_xxx container
408       
409protected:
410        int     updated;        // flag fuer aufgetretenen update
411        int     nseq_but_filter; // show filter, no sequence
412        long    seq_len;        // hier steht die max laenge der sequenz
413       
414        char    * seq;          // Sequenzdata
415        long    timestamp;      // Zeit des letzten zugriffs auf DB
416        class AD_CONT   *ad_cont;       
417        AD_ERR *check_base(char chr,long position, int direction);
418        AD_ERR *push(long position, int direction);
419        AD_ERR *jump(long position, int direction);
420        AD_ERR *fetch(long position, int direction);
421        long    get_next_base(long position, int direction);
422        long    get_next_gap(long position, int direction);
423
424public:
425        AD_SEQ();
426        ~AD_SEQ();
427       
428        AD_ERR * init(AD_CONT *);
429        AD_ERR * exit();
430
431        AD_ERR *update();       // reread data froam database   
432
433        char    * get(); // read the sequence
434        AD_ERR  *put(); // write the internal cash to the database
435        AD_ERR  *create(void);
436        AD_ERR  *changemode(AD_EDITMODI mod);
437        AD_EDITMODI     mode();
438        AD_MAIN *get_ad_main() { return ad_cont->get_ad_main(); };
439
440        int     s_inited();
441        int     time_stamp(void);
442        int     len();
443        // EDITIERFUNKTINEN
444        // position ab 0 bis strlen(seq)
445        //
446        AD_ERR  *insert(char *,long position, int direction);
447        AD_ERR  *remove(int len,long position, int direction);
448        AD_ERR  *replace(char *text,long position, int direction);
449        AD_ERR  *swap_gaps(long position, char ch);
450        AD_ERR  *command( AW_key_mod keymod, AW_key_code keycode, char key, int direction, long &cursorpos, int & changed_flag);
451        };
452
453#endif
454
455
456#endif
Note: See TracBrowser for help on using the repository browser.