| 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 | /*********************** |
|---|
| 13 | *************************************************************** |
|---|
| 14 | class AD_SPECIES |
|---|
| 15 | |
|---|
| 16 | ******************************************* |
|---|
| 17 | *******************************************************/ |
|---|
| 18 | |
|---|
| 19 | AD_SPECIES::AD_SPECIES() |
|---|
| 20 | { |
|---|
| 21 | ad_main =0; |
|---|
| 22 | gb_spdata = 0; |
|---|
| 23 | gb_species = 0; |
|---|
| 24 | gb_name = 0; |
|---|
| 25 | last = 0; |
|---|
| 26 | count = 0; |
|---|
| 27 | container = new CONTLIST; |
|---|
| 28 | spname = 0; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | AD_SPECIES::~AD_SPECIES() |
|---|
| 32 | // callbacks nur innerhalb von transaktionen releasen ->exit |
|---|
| 33 | // gibt speicherplatz frei |
|---|
| 34 | { |
|---|
| 35 | if (ad_main) |
|---|
| 36 | new AD_ERR("AD_SPECIES: No exit() !!",CORE); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | AD_ERR * AD_SPECIES::exit() |
|---|
| 40 | { |
|---|
| 41 | if (ad_main) { |
|---|
| 42 | release(); |
|---|
| 43 | delete container; |
|---|
| 44 | } |
|---|
| 45 | ad_main = 0; |
|---|
| 46 | return 0; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | AD_ERR * AD_SPECIES::error() |
|---|
| 50 | // interne funktion, die testet ob ein Fehler in der |
|---|
| 51 | // anwendung aufgetreten ist |
|---|
| 52 | // Funktionen wie next, ... die auf andere spezies initialisieren |
|---|
| 53 | // duerfen nicht veraendert werden,solange container daranhaengen |
|---|
| 54 | // oder aufgerufen wenn schon das letzte erreicht. |
|---|
| 55 | { |
|---|
| 56 | |
|---|
| 57 | if (count > 0) { |
|---|
| 58 | return new AD_ERR("AD_SPECIES: existing Subobjects ! No change of species allowed\n",CORE); |
|---|
| 59 | } |
|---|
| 60 | if (last == 1) |
|---|
| 61 | return new AD_ERR("AD_SPECIES: already at EOF !",CORE); |
|---|
| 62 | return 0; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | AD_ERR * AD_SPECIES::init(AD_MAIN * gb_ptr) |
|---|
| 66 | // stellt verknuepfung mit ubergeordneter Klasse her |
|---|
| 67 | // |
|---|
| 68 | // default einstellung moeglich ni ->initpntr() |
|---|
| 69 | { |
|---|
| 70 | if (ad_main != 0) { |
|---|
| 71 | |
|---|
| 72 | return new AD_ERR("AD_SPECIES: no reinit\n"); |
|---|
| 73 | } |
|---|
| 74 | if (gb_ptr->gbd) { |
|---|
| 75 | ad_main = gb_ptr; |
|---|
| 76 | gb_spdata = gb_ptr->species_data; |
|---|
| 77 | last = count = 0; |
|---|
| 78 | AD_READWRITE::gbdataptr = 0; |
|---|
| 79 | return 0; |
|---|
| 80 | } |
|---|
| 81 | else { |
|---|
| 82 | return new AD_ERR("SPECIES init (NULL)\n"); |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | AD_ERR *AD_SPECIES::first() |
|---|
| 87 | { |
|---|
| 88 | //erstes spezies initialisieren |
|---|
| 89 | |
|---|
| 90 | if (ad_main) { |
|---|
| 91 | gb_species = GB_entry(gb_spdata, "species"); |
|---|
| 92 | //erstes species |
|---|
| 93 | AD_SPECIES::initpntr(); |
|---|
| 94 | return 0; |
|---|
| 95 | } |
|---|
| 96 | return new AD_ERR("AD_species first: NO AD_MAIN\n"); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | void AD_SPECIES::initpntr() |
|---|
| 101 | // gb_spezies muss initialisiert sein |
|---|
| 102 | // je nach AD_fast wird das objekt initialisiert |
|---|
| 103 | { |
|---|
| 104 | long a; |
|---|
| 105 | if (!gb_species) { |
|---|
| 106 | last = 1; |
|---|
| 107 | spname = 0; |
|---|
| 108 | gb_name = 0; |
|---|
| 109 | //kein spezies gefunden |
|---|
| 110 | } else { |
|---|
| 111 | last = 0; |
|---|
| 112 | gb_name = GB_entry(gb_species, "name"); |
|---|
| 113 | //name und flag cachen |
|---|
| 114 | spname = GB_read_string(gb_name); |
|---|
| 115 | if (ad_main->AD_fast == MINCACH) { |
|---|
| 116 | a = GB_read_usr_private(gb_species); |
|---|
| 117 | // Wieviele Variablen existieren |
|---|
| 118 | |
|---|
| 119 | a ++; // auf gb_species |
|---|
| 120 | GB_write_usr_private(gb_species,a); |
|---|
| 121 | } |
|---|
| 122 | AD_READWRITE::gbdataptr = gb_species; |
|---|
| 123 | GB_add_callback(gb_species, GB_CB_DELETE, (GB_CB) AD_SPECIES_destroy, (int *) this); |
|---|
| 124 | GB_add_callback(gb_name, GB_CB_CHANGED, (GB_CB) AD_SPECIES_name_change, (int *) this); |
|---|
| 125 | |
|---|
| 126 | //callback in DB mit routine die beim loeschen der species |
|---|
| 127 | // aufgerufen wird(speicherfreigaben) |
|---|
| 128 | } |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | AD_ERR * AD_SPECIES::find(const char *path) |
|---|
| 132 | // sucht nach species mit namen = path |
|---|
| 133 | { |
|---|
| 134 | error(); |
|---|
| 135 | AD_SPECIES::release(); // speicherplatz freigeben` |
|---|
| 136 | gb_species = GBT_find_species_rel_species_data(ad_main->species_data,path); |
|---|
| 137 | AD_SPECIES::initpntr(); |
|---|
| 138 | return 0; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | void AD_SPECIES::release() |
|---|
| 143 | // gibt den speicherplatz des objektes wieder frei |
|---|
| 144 | // sowie den in der DatenBank belegten speicherplatz |
|---|
| 145 | { |
|---|
| 146 | long a; |
|---|
| 147 | if (count > 0) new AD_ERR("AD_SPECIES: no change of object with subobjects !",CORE); |
|---|
| 148 | if (spname) delete spname; |
|---|
| 149 | if (gb_species) |
|---|
| 150 | { |
|---|
| 151 | GB_remove_callback(gb_species,GB_CB_DELETE,(GB_CB)AD_SPECIES_destroy,(int *)this); |
|---|
| 152 | GB_remove_callback(gb_name,GB_CB_CHANGED,(GB_CB)AD_SPECIES_name_change,(int *)this); |
|---|
| 153 | // altes species wird freigegeben -> callback entfernen |
|---|
| 154 | |
|---|
| 155 | if (ad_main->get_cach_flag() == MINCACH ) { |
|---|
| 156 | // wenn nur ein speichersparendenr Zugriff besteht |
|---|
| 157 | // Speicerplatz freigeben -> Muliteditoraufrufe |
|---|
| 158 | // eines users |
|---|
| 159 | a = GB_read_usr_private(gb_species); |
|---|
| 160 | if (a == 1) { // einziger verweis |
|---|
| 161 | // lokalen cache freigeben |
|---|
| 162 | GB_release(gb_species); |
|---|
| 163 | } |
|---|
| 164 | GB_write_usr_private(gb_species,--a); |
|---|
| 165 | } |
|---|
| 166 | AD_READWRITE::gbdataptr = 0; |
|---|
| 167 | } |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | int AD_SPECIES_destroy(GBDATA *gb_species,AD_SPECIES *ad_species) |
|---|
| 173 | { |
|---|
| 174 | // Diese Funktion wird nach einem commit transaction aufgerufen, wenn |
|---|
| 175 | // das entsprechende species in der DB geloescht wurde |
|---|
| 176 | // |
|---|
| 177 | |
|---|
| 178 | if (ad_species->gb_species != gb_species) { |
|---|
| 179 | // muessen uebereinstimmen |
|---|
| 180 | new AD_ERR(" strange CALLBACK occurred - int AD_SPECIES",CORE); |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | if (ad_species->spname) delete ad_species->spname; |
|---|
| 184 | ad_species->spname = 0; |
|---|
| 185 | |
|---|
| 186 | ad_species->gb_species = 0; |
|---|
| 187 | ad_species->gbdataptr = 0; |
|---|
| 188 | |
|---|
| 189 | // hier stehehn weitere comandos die beim loeschen |
|---|
| 190 | // eines species ausgefuehrt werden sollen |
|---|
| 191 | // (z.B.) untergeordnete Klassen |
|---|
| 192 | |
|---|
| 193 | return 0; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | int AD_SPECIES_name_change(GBDATA *gb_name,AD_SPECIES *ad_species) |
|---|
| 197 | { |
|---|
| 198 | // Diese Funktion wird nach einem commit transaction aufgerufen, wenn |
|---|
| 199 | // das entsprechende species in der DB geloescht wurde |
|---|
| 200 | // |
|---|
| 201 | if (ad_species->spname) delete ad_species->spname; |
|---|
| 202 | ad_species->spname = GB_read_string( gb_name ); // reread name |
|---|
| 203 | return 0; |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | AD_ERR * AD_SPECIES::create(const char *species_name) { |
|---|
| 207 | GBDATA *species; |
|---|
| 208 | if (strlen(species_name) < 2) |
|---|
| 209 | return new AD_ERR("AD_SPECIES::too short name"); |
|---|
| 210 | species = GBT_find_or_create_species_rel_species_data(gb_spdata,species_name); |
|---|
| 211 | gb_species = species; |
|---|
| 212 | initpntr(); |
|---|
| 213 | return 0; |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | const char * AD_SPECIES::name() |
|---|
| 218 | { |
|---|
| 219 | if (AD_SPECIES::gb_species != 0) |
|---|
| 220 | return spname; |
|---|
| 221 | return "deleted"; |
|---|
| 222 | |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | int AD_SPECIES::flag() |
|---|
| 226 | { |
|---|
| 227 | if (gb_species != 0) |
|---|
| 228 | return GB_read_flag(gb_species); |
|---|
| 229 | return 0; |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | const char * AD_SPECIES::fullname() |
|---|
| 233 | { |
|---|
| 234 | GBDATA *gb_ptr; |
|---|
| 235 | gb_ptr = GB_entry(gb_spdata,"full_name"); |
|---|
| 236 | if (gb_ptr) // fullname existiert |
|---|
| 237 | return GB_read_char_pntr(gb_ptr); |
|---|
| 238 | return 0; |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | AD_ERR * AD_SPECIES::next() |
|---|
| 243 | // initialisiert objekt auf naechstes species oder erstes |
|---|
| 244 | { |
|---|
| 245 | error(); |
|---|
| 246 | |
|---|
| 247 | if (!gb_species && last == 0) |
|---|
| 248 | first(); |
|---|
| 249 | AD_SPECIES::release(); // speicherplatz freigeben |
|---|
| 250 | gb_species = GB_nextEntry(gb_species); |
|---|
| 251 | AD_SPECIES::initpntr(); |
|---|
| 252 | return 0; |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | AD_ERR *AD_SPECIES::firstmarked() |
|---|
| 257 | { |
|---|
| 258 | if (ad_main ) |
|---|
| 259 | { |
|---|
| 260 | gb_species = GBT_first_marked_species_rel_species_data(gb_spdata); |
|---|
| 261 | initpntr(); |
|---|
| 262 | return 0; |
|---|
| 263 | } |
|---|
| 264 | return new AD_ERR("AD_SPECIES::firstmarked() but no init()!",CORE); |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | AD_ERR * AD_SPECIES::nextmarked() |
|---|
| 268 | // naechstes markiertes species oder erstes markiertes |
|---|
| 269 | { |
|---|
| 270 | if ((!gb_species && (last ==0))) |
|---|
| 271 | { |
|---|
| 272 | gb_species = GBT_first_marked_species_rel_species_data(gb_spdata); |
|---|
| 273 | initpntr(); |
|---|
| 274 | return 0; |
|---|
| 275 | } |
|---|
| 276 | else { |
|---|
| 277 | release(); |
|---|
| 278 | gb_species = GBT_next_marked_species(gb_species); |
|---|
| 279 | initpntr(); |
|---|
| 280 | return 0; |
|---|
| 281 | } |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | int AD_SPECIES::eof() |
|---|
| 287 | { |
|---|
| 288 | return last; |
|---|
| 289 | } |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | void AD_SPECIES::operator =(const AD_SPECIES& right) |
|---|
| 293 | { |
|---|
| 294 | release(); // free left side |
|---|
| 295 | ad_main = right.ad_main; |
|---|
| 296 | gb_spdata = right.gb_spdata; |
|---|
| 297 | gb_species = right.gb_species; |
|---|
| 298 | this->initpntr(); |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | int AD_SPECIES::time_stamp(void) |
|---|
| 302 | { |
|---|
| 303 | if (gb_species != 0) |
|---|
| 304 | return GB_read_clock(gb_species); |
|---|
| 305 | new AD_ERR("AD_SPECIES::time_stamp - no species selected"); |
|---|
| 306 | return 0; |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | |
|---|