Changeset 375 for trunk/gsdl/src/recpt


Ignore:
Timestamp:
1999-07-14T11:24:06+12:00 (25 years ago)
Author:
rjmcnab
Message:

Added functionality to modify a gdbm database.

Location:
trunk/gsdl/src/recpt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/infodbclass.cpp

    r368 r375  
    1212/*
    1313   $Log$
     14   Revision 1.2  1999/07/13 23:24:05  rjmcnab
     15   Added functionality to modify a gdbm database.
     16
    1417   Revision 1.1  1999/07/11 08:27:52  rjmcnab
    1518   Moved from src/colservr and added capability to write out data.
     
    182185
    183186
     187void gdbmclass::deletekey (const text_t &key) {
     188  if (gdbmfile == NULL) return;
     189
     190  // get a utf-8 encoded c string of the unicode key
     191  datum key_data;
     192  key_data.dptr = (to_utf8(key)).getcstr();
     193  if (key_data.dptr == NULL) return;
     194  key_data.dsize = strlen (key_data.dptr);
     195
     196  // delete the key
     197  gdbm_delete (gdbmfile, key_data);
     198
     199  // free up the key memory
     200  delete key_data.dptr;
     201}
     202
     203
     204// getfirstkey and getnextkey are used for traversing the database
     205// no insertions or deletions should be carried out while traversing
     206// the database. when there are no keys left to visit in the database
     207// an empty string is returned.
     208text_t gdbmclass::getfirstkey () {
     209  if (gdbmfile == NULL) return "";
     210
     211  // get the first key
     212  datum firstkey_data = gdbm_firstkey (gdbmfile);
     213  if (firstkey_data.dptr == NULL) return "";
     214
     215  // convert it to text_t
     216  text_t firstkey;
     217  firstkey.setcarr (firstkey_data.dptr, firstkey_data.dsize);
     218  free (firstkey_data.dptr);
     219  return to_uni(firstkey);  // convert to unicode
     220}
     221
     222text_t gdbmclass::getnextkey (const text_t &key) {
     223  if (gdbmfile == NULL || key.empty()) return "";
     224
     225  // get a utf-8 encoded c string of the unicode key
     226  datum key_data;
     227  key_data.dptr = (to_utf8(key)).getcstr();
     228  if (key_data.dptr == NULL) return "";
     229  key_data.dsize = strlen (key_data.dptr);
     230 
     231  // get the next key
     232  datum nextkey_data = gdbm_nextkey (gdbmfile, key_data);
     233  if (nextkey_data.dptr == NULL) {
     234    delete key_data.dptr;
     235    return "";
     236  }
     237
     238  // convert it to text_t
     239  text_t nextkey;
     240  nextkey.setcarr (nextkey_data.dptr, nextkey_data.dsize);
     241  free (nextkey_data.dptr);
     242  delete key_data.dptr;
     243  return to_uni(nextkey);  // convert to unicode
     244}
     245
    184246
    185247// replaces the .fc, .lc, .pr, .ns and .ps syntax (first child,
  • trunk/gsdl/src/recpt/infodbclass.h

    r368 r375  
    101101  // returns true on success
    102102  bool setinfo (const text_t &key, const infodbclass &info);
     103
     104  void deletekey (const text_t &key);
     105
     106  // getfirstkey and getnextkey are used for traversing the database
     107  // no insertions or deletions should be carried out while traversing
     108  // the database. when there are no keys left to visit in the database
     109  // an empty string is returned.
     110  text_t getfirstkey ();
     111  text_t getnextkey (const text_t &key);
    103112 
    104113protected:
Note: See TracChangeset for help on using the changeset viewer.