Changeset 7434
- Timestamp:
- 2004-05-26T14:19:28+12:00 (20 years ago)
- Location:
- trunk/gsdl/src/recpt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/infodbclass.cpp
r2400 r7434 63 63 } 64 64 65 text_t *infodbclass::getinfo (const text_t &key, const text_t& slang) { 66 text_tarray *t = getmultinfo(key, slang); 67 if (t == NULL || t->empty()) return NULL; 68 return &((*t)[0]); 69 } 70 65 71 int infodbclass::getintinfo (const text_t &key) { 66 72 text_t *t = getinfo (key); 67 73 if (t == NULL) return 0; 68 74 return t->getint(); 75 } 76 77 int infodbclass::getintinfo (const text_t &key, const text_t& slang) { 78 text_tarray *t = getmultinfo(key, slang); 79 if (t == NULL || t->empty()) return 0; 80 return (*t)[0].getint(); 69 81 } 70 82 … … 96 108 text_tarray *infodbclass::getmultinfo (const text_t &key) { 97 109 iterator here = info.find (key); 110 if (here == info.end()) return NULL; 111 112 return &((*here).second); 113 } 114 115 text_tarray *infodbclass::getmultinfo (const text_t &key, const text_t& slang) { 116 iterator here = info.end(); 117 if (slang.empty()) { 118 here = info.find (key); 119 } 120 else { 121 here = info.find (key+":"+slang); 122 if (here == info.end()) { 123 here = info.find (key); 124 } 125 } 98 126 if (here == info.end()) return NULL; 99 127 … … 134 162 } while (num_retrys>0 && gdbmfile==NULL && 135 163 (gdbm_errno==GDBM_CANT_BE_READER || gdbm_errno==GDBM_CANT_BE_WRITER)); 136 delete namebuffer;164 delete []namebuffer; 137 165 138 166 if (gdbmfile == NULL && logout != NULL) { … … 181 209 subkey.push_back (*subkey_here); 182 210 } 183 subkey_here++;211 ++subkey_here; 184 212 } 185 213 subkey.push_back('>'); … … 206 234 } 207 235 208 thissubvalue_here++;236 ++thissubvalue_here; 209 237 } 210 238 211 239 data.push_back('\n'); 212 subvalue_here++;213 } 214 215 info_here++;240 ++subvalue_here; 241 } 242 243 ++info_here; 216 244 } 217 245 … … 231 259 if (data_data.dptr == NULL) { 232 260 if (logout != NULL) (*logout) << "gdbmclass: out of memory\n"; 233 delete key_data.dptr; 261 delete []key_data.dptr; 262 return false; 234 263 } 235 264 data_data.dsize = strlen (data_data.dptr); 236 265 237 266 int ret = gdbm_store (gdbmfile, key_data, data_data, GDBM_REPLACE); 238 delete key_data.dptr;239 delete data_data.dptr;267 delete []key_data.dptr; 268 delete []data_data.dptr; 240 269 241 270 return (ret == 0); … … 262 291 if (data_data.dptr == NULL) { 263 292 if (logout != NULL) (*logout) << "gdbmclass: out of memory\n"; 264 delete key_data.dptr; 293 delete []key_data.dptr; 294 return false; 265 295 } 266 296 data_data.dsize = strlen (data_data.dptr); 267 297 268 298 int ret = gdbm_store (gdbmfile, key_data, data_data, GDBM_REPLACE); 269 delete key_data.dptr;270 delete data_data.dptr;299 delete []key_data.dptr; 300 delete []data_data.dptr; 271 301 272 302 return (ret == 0); … … 288 318 289 319 // free up the key memory 290 delete key_data.dptr;320 delete []key_data.dptr; 291 321 } 292 322 … … 297 327 // an empty string is returned. 298 328 text_t gdbmclass::getfirstkey () { 299 if (gdbmfile == NULL) return "";329 if (gdbmfile == NULL) return g_EmptyText; 300 330 301 331 // get the first key 302 332 datum firstkey_data = gdbm_firstkey (gdbmfile); 303 if (firstkey_data.dptr == NULL) return "";333 if (firstkey_data.dptr == NULL) return g_EmptyText; 304 334 305 335 // convert it to text_t … … 311 341 312 342 text_t gdbmclass::getnextkey (const text_t &key) { 313 if (gdbmfile == NULL || key.empty()) return "";343 if (gdbmfile == NULL || key.empty()) return g_EmptyText; 314 344 315 345 // get a utf-8 encoded c string of the unicode key 316 346 datum key_data; 317 347 key_data.dptr = (to_utf8(key)).getcstr(); 318 if (key_data.dptr == NULL) return "";348 if (key_data.dptr == NULL) return g_EmptyText; 319 349 key_data.dsize = strlen (key_data.dptr); 320 350 … … 322 352 datum nextkey_data = gdbm_nextkey (gdbmfile, key_data); 323 353 if (nextkey_data.dptr == NULL) { 324 delete key_data.dptr;325 return "";354 delete []key_data.dptr; 355 return g_EmptyText; 326 356 } 327 357 … … 330 360 nextkey.setcarr (nextkey_data.dptr, nextkey_data.dsize); 331 361 free (nextkey_data.dptr); 332 delete key_data.dptr;362 delete []key_data.dptr; 333 363 return to_uni(nextkey); // convert to unicode 334 364 } … … 371 401 get_previous_sibling (OID, info); 372 402 373 here --;403 --here; 374 404 } 375 405 return OID; … … 424 454 break; 425 455 } 426 here ++;456 ++here; 427 457 } 428 458 } … … 449 479 break; 450 480 } 451 here ++;481 ++here; 452 482 } 453 483 } … … 456 486 457 487 // returns true on success 458 bool gdbmclass::getinfo ( text_tkey, infodbclass &info) {488 bool gdbmclass::getinfo (const text_t& key, infodbclass &info) { 459 489 text_t data; 460 490 … … 474 504 475 505 // returns true if exists 476 bool gdbmclass::exists ( text_tkey) {506 bool gdbmclass::exists (const text_t& key) { 477 507 text_t data; 478 508 return getkeydata (key, data); … … 480 510 481 511 // returns true on success 482 bool gdbmclass::getkeydata ( text_tkey, text_t &data) {512 bool gdbmclass::getkeydata (const text_t& key, text_t &data) { 483 513 datum key_data; 484 514 datum return_data; … … 496 526 // fetch the result 497 527 return_data = gdbm_fetch (gdbmfile, key_data); 498 delete key_data.dptr;528 delete []key_data.dptr; 499 529 500 530 if (return_data.dptr == NULL) return false; … … 514 544 515 545 // ignore white space 516 while (here != end && is_unicode_space (*here)) here++;546 while (here != end && is_unicode_space (*here)) ++here; 517 547 518 548 // get the '<' 519 549 if (here == end || *here != '<') return false; 520 here++;550 ++here; 521 551 522 552 // get the key 523 553 while (here != end && *here != '>') { 524 554 key.push_back(*here); 525 here++;555 ++here; 526 556 } 527 557 528 558 // get the '>' 529 559 if (here == end || *here != '>') return false; 530 here++;560 ++here; 531 561 532 562 // get the value … … 534 564 if (*here == '\\') { 535 565 // found escape character 536 here++;566 ++here; 537 567 if (here != end) { 538 568 if (*here == 'n') value.push_back ('\n'); … … 546 576 } 547 577 548 here++;578 ++here; 549 579 } 550 580 -
trunk/gsdl/src/recpt/infodbclass.h
r1459 r7434 46 46 47 47 #ifdef __cplusplus 48 extern "C" {48 extern "C" { 49 49 #endif 50 50 #include "autoconf.h" … … 53 53 #include "gdbm.h" 54 54 #ifdef __cplusplus 55 }55 } 56 56 #endif 57 57 … … 68 68 protected: 69 69 text_tarraymap info; 70 text_t lang; 70 71 71 72 public: … … 100 101 void clear () {info.erase(info.begin(),info.end());} 101 102 103 // set default language 104 void set_language(const text_t& str_lang) { lang = str_lang; } 105 const text_t &get_language() const { return lang; } 106 102 107 // the following functions deal with keys that can only 103 108 // have one value for compatibility … … 111 116 void setcinfo (const text_t &key, unsigned short c); 112 117 text_t *getinfo (const text_t &key); 118 // get info overriding language set on this object 119 text_t *getinfo (const text_t &key, const text_t& lang); 113 120 int getintinfo (const text_t &key); 121 // get info overriding language set on this object 122 int getintinfo (const text_t &key, const text_t& lang); 114 123 text_t &operator[] (const text_t &key); 115 124 … … 124 133 void addcinfo (const text_t &key, unsigned short c); 125 134 text_tarray *getmultinfo (const text_t &key); 135 // get info overriding language set on this object 136 text_tarray *getmultinfo (const text_t &key, const text_t& lang); 126 137 }; 127 138 … … 143 154 144 155 // returns true on success 145 bool getinfo ( text_tkey, infodbclass &info);156 bool getinfo (const text_t& key, infodbclass &info); 146 157 void setlogout (ostream *thelogout) {logout = thelogout;} 147 158 148 159 // returns true if exists 149 bool exists ( text_tkey);160 bool exists (const text_t& key); 150 161 151 162 // returns true on success … … 164 175 165 176 // returns true on success 166 bool getkeydata ( text_tkey, text_t &data);177 bool getkeydata (const text_t& key, text_t &data); 167 178 168 179 protected:
Note:
See TracChangeset
for help on using the changeset viewer.