source: tags/arb_5.2/ARBDBPP/adali.cxx

Last change on this file was 5309, checked in by westram, 16 years ago
  • replaced calls to GB_find with new find-functions
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1#include <cstdio>
2#include <cstring>
3#include <memory.h>
4
5#include <iostream>
6
7#include <arbdb.h>
8#include <arbdbt.h>
9
10#include "arbdb++.hxx"
11
12#define ad_assert(cond) arb_assert(cond)
13
14// --------------------------------------------------------------------------------
15// class: AD_ALI
16
17AD_ALI::AD_ALI()
18{
19    gb_ali = gb_aligned = gb_name = gb_len = gb_type = 0;
20    ad_main = 0;
21    last = count = 0;
22    ad_name = ad_type = 0;
23    ad_aligned = ad_len = 0;
24}
25
26AD_ALI::~AD_ALI()
27{
28    if (ad_main) new AD_ERR("AD_ALI: no exit !",CORE);
29}
30
31
32
33AD_ERR *AD_ALI::init(AD_MAIN * gbptr)
34{
35    if (!gbptr) {
36        return new AD_ERR("AD_ALI.init(NULL)",CORE);
37    } else {
38        ad_main = gbptr;
39        ddefault();
40        return 0;
41    }
42}
43
44AD_ERR *AD_ALI::exit()
45{
46    if (ad_main) {
47        ad_main = 0;
48        return 0;
49    }
50    return new AD_ERR("AD_ALI: exit() without init()");
51}
52
53AD_ERR *AD_ALI::ddefault()
54{
55    AD_ERR *res;
56    char *def = GBT_get_default_alignment(ad_main->gbd);
57    res =find(def);
58    delete def;
59    return res;
60}
61
62AD_ERR *AD_ALI::initpntr()
63{
64    // initialisiert das objekt
65    // gb_ali sollte veraendert werden, dann aufrufen
66    if (!gb_ali) {
67        last = 1;
68        gb_ali = gb_aligned = gb_name = gb_len = gb_type = 0;
69        return 0;
70    }
71    last = 0;
72
73    gb_name    = GB_entry(gb_ali,"alignment_name");
74    gb_aligned = GB_entry(gb_ali,"aligned");
75    gb_len     = GB_entry(gb_ali,"alignment_len");
76    gb_type    = GB_entry(gb_ali,"alignment_type");
77    ad_name    = GB_read_string(gb_name);
78    ad_type    = GB_read_string(gb_type);
79    ad_len     = GB_read_int(gb_len);
80    ad_aligned = GB_read_int(gb_aligned);
81
82    AD_READWRITE::gbdataptr = gb_ali;
83    return 0;
84}
85
86AD_ERR *AD_ALI::release() {
87    if (ad_name) delete ad_name;
88    if (ad_type) delete ad_type;
89    AD_READWRITE::gbdataptr = 0;
90    ad_name = 0; ad_type = 0;
91    return 0;
92}
93
94
95AD_ERR *AD_ALI::first()
96{
97    // initialisiert das Objekt mit dem ersten gefundenen
98    // Alignment, eof falls keins existiert
99    release();
100    gb_ali = GB_entry(ad_main->gbd,"alignment");
101    initpntr();
102    return 0;
103}
104
105
106AD_ERR *AD_ALI::find(char* ali_name)
107{
108    // sucht nach name, eof wenn nicht gefunden !
109    //
110    release();
111    gb_ali = GBT_get_alignment(ad_main->gbd,  ali_name);
112    initpntr();
113    return 0;
114}
115
116AD_ERR *AD_ALI::next()
117// initialisiert auf das naechste, bzw. erste gefundene Objekt
118// falss kein weiteres liefert es einen Fehler zurueck
119// und setzt last-flag
120{
121    GBDATA *gbptr;
122    if (!gb_ali) {
123        AD_ALI::first();
124        return 0;
125    } else {
126        release();
127        ad_assert(GB_has_key(gb_ali, "alignment"));
128        gbptr = GB_nextEntry(gb_ali);
129        gb_ali = gbptr;
130        initpntr();
131    }
132    return 0;
133}
134
135int AD_ALI::time_stamp(void)
136{
137    if (gb_ali != 0)
138        return GB_read_clock(gb_ali);
139    new AD_ERR("AD_ALI::time_stamp - no alignment selected");
140    return 0;
141}
142
143
144
145int AD_ALI::eof()
146{
147    return last;
148}
149
150int AD_ALI::aligned()
151{
152    return ad_aligned;
153}
154
155int AD_ALI::len()
156{
157    return ad_len;
158}
159
160char *AD_ALI::type()
161{
162    // Achtung: kurzlebiger speicher !! ansonsten read_string !!
163    return ad_type;
164}
165
166char *AD_ALI::name()
167{
168    return ad_name;
169}
170
171
172void AD_ALI::operator=(AD_ALI& ali)
173{
174    ad_main = ali.ad_main;
175    gb_ali = ali.gb_ali;
176    gb_aligned = ali.gb_aligned;
177    gb_name = ali.gb_name;
178    gb_len = ali.gb_len;
179    gb_type = ali.gb_type;
180    count = 0;              // keine contianer haengen am objekt
181    last = ali.last;
182    if (ali.ad_name) ad_name = strdup(ali.ad_name);
183    else    ad_name = 0;
184    if (ali.ad_type) ad_type = strdup(ali.ad_type);
185    else    ad_type = 0;
186}
187
Note: See TracBrowser for help on using the repository browser.