Changeset 7434


Ignore:
Timestamp:
2004-05-26T14:19:28+12:00 (20 years ago)
Author:
mdewsnip
Message:

(Human Info) Initial support for retrieving language specific information.

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

Legend:

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

    r2400 r7434  
    6363}
    6464
     65text_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
    6571int infodbclass::getintinfo (const text_t &key) {
    6672  text_t *t = getinfo (key);
    6773  if (t == NULL) return 0;
    6874  return t->getint();
     75}
     76
     77int 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();
    6981}
    7082
     
    96108text_tarray *infodbclass::getmultinfo (const text_t &key) {
    97109  iterator here = info.find (key);
     110  if (here == info.end()) return NULL;
     111
     112  return &((*here).second);
     113}
     114
     115text_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  }
    98126  if (here == info.end()) return NULL;
    99127
     
    134162  } while (num_retrys>0 && gdbmfile==NULL &&
    135163       (gdbm_errno==GDBM_CANT_BE_READER || gdbm_errno==GDBM_CANT_BE_WRITER));
    136   delete namebuffer;
     164  delete []namebuffer;
    137165 
    138166  if (gdbmfile == NULL && logout != NULL) {
     
    181209    subkey.push_back (*subkey_here);
    182210      }
    183       subkey_here++;
     211      ++subkey_here;
    184212    }
    185213    subkey.push_back('>');
     
    206234    }
    207235   
    208     thissubvalue_here++;
     236    ++thissubvalue_here;
    209237      }
    210238     
    211239      data.push_back('\n');
    212       subvalue_here++;
    213     }
    214 
    215     info_here++;
     240      ++subvalue_here;
     241    }
     242
     243    ++info_here;
    216244  }
    217245
     
    231259  if (data_data.dptr == NULL) {
    232260    if (logout != NULL) (*logout) << "gdbmclass: out of memory\n";
    233     delete key_data.dptr;
     261    delete []key_data.dptr;
     262    return false;
    234263  }
    235264  data_data.dsize = strlen (data_data.dptr);
    236265
    237266  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;
    240269
    241270  return (ret == 0);
     
    262291  if (data_data.dptr == NULL) {
    263292    if (logout != NULL) (*logout) << "gdbmclass: out of memory\n";
    264     delete key_data.dptr;
     293    delete []key_data.dptr;
     294    return false;
    265295  }
    266296  data_data.dsize = strlen (data_data.dptr);
    267297
    268298  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;
    271301
    272302  return (ret == 0);
     
    288318
    289319  // free up the key memory
    290   delete key_data.dptr;
     320  delete []key_data.dptr;
    291321}
    292322
     
    297327// an empty string is returned.
    298328text_t gdbmclass::getfirstkey () {
    299   if (gdbmfile == NULL) return "";
     329  if (gdbmfile == NULL) return g_EmptyText;
    300330
    301331  // get the first key
    302332  datum firstkey_data = gdbm_firstkey (gdbmfile);
    303   if (firstkey_data.dptr == NULL) return "";
     333  if (firstkey_data.dptr == NULL) return g_EmptyText;
    304334
    305335  // convert it to text_t
     
    311341
    312342text_t gdbmclass::getnextkey (const text_t &key) {
    313   if (gdbmfile == NULL || key.empty()) return "";
     343  if (gdbmfile == NULL || key.empty()) return g_EmptyText;
    314344
    315345  // get a utf-8 encoded c string of the unicode key
    316346  datum key_data;
    317347  key_data.dptr = (to_utf8(key)).getcstr();
    318   if (key_data.dptr == NULL) return "";
     348  if (key_data.dptr == NULL) return g_EmptyText;
    319349  key_data.dsize = strlen (key_data.dptr);
    320350 
     
    322352  datum nextkey_data = gdbm_nextkey (gdbmfile, key_data);
    323353  if (nextkey_data.dptr == NULL) {
    324     delete key_data.dptr;
    325     return "";
     354    delete []key_data.dptr;
     355    return g_EmptyText;
    326356  }
    327357
     
    330360  nextkey.setcarr (nextkey_data.dptr, nextkey_data.dsize);
    331361  free (nextkey_data.dptr);
    332   delete key_data.dptr;
     362  delete []key_data.dptr;
    333363  return to_uni(nextkey);  // convert to unicode
    334364}
     
    371401      get_previous_sibling (OID, info);
    372402   
    373     here --;
     403    --here;
    374404  }
    375405  return OID;
     
    424454      break;
    425455    }
    426     here ++;
     456    ++here;
    427457      }
    428458    }
     
    449479      break;
    450480    }
    451     here ++;
     481    ++here;
    452482      }
    453483    }
     
    456486
    457487// returns true on success
    458 bool gdbmclass::getinfo (text_t key, infodbclass &info) {
     488bool gdbmclass::getinfo (const text_t& key, infodbclass &info) {
    459489  text_t data;
    460490 
     
    474504
    475505// returns true if exists
    476 bool gdbmclass::exists (text_t key) {
     506bool gdbmclass::exists (const text_t& key) {
    477507  text_t data;
    478508  return getkeydata (key, data);
     
    480510
    481511// returns true on success
    482 bool gdbmclass::getkeydata (text_t key, text_t &data) {
     512bool gdbmclass::getkeydata (const text_t& key, text_t &data) {
    483513  datum key_data;
    484514  datum return_data;
     
    496526  // fetch the result
    497527  return_data = gdbm_fetch (gdbmfile, key_data);
    498   delete key_data.dptr;
     528  delete []key_data.dptr;
    499529 
    500530  if (return_data.dptr == NULL) return false;
     
    514544
    515545  // ignore white space
    516   while (here != end && is_unicode_space (*here)) here++;
     546  while (here != end && is_unicode_space (*here)) ++here;
    517547
    518548  // get the '<'
    519549  if (here == end || *here != '<') return false;
    520   here++;
     550  ++here;
    521551 
    522552  // get the key
    523553  while (here != end && *here != '>') {
    524554    key.push_back(*here);
    525     here++;
     555    ++here;
    526556  }
    527557 
    528558  // get the '>'
    529559  if (here == end || *here != '>') return false;
    530   here++;
     560  ++here;
    531561 
    532562  // get the value
     
    534564    if (*here == '\\') {
    535565      // found escape character
    536       here++;
     566      ++here;
    537567      if (here != end) {
    538568    if (*here == 'n') value.push_back ('\n');
     
    546576    }
    547577
    548     here++;
     578    ++here;
    549579  }
    550580
  • trunk/gsdl/src/recpt/infodbclass.h

    r1459 r7434  
    4646
    4747#ifdef __cplusplus
    48 extern "C" {
     48  extern "C" {
    4949#endif
    5050#include "autoconf.h"
     
    5353#include "gdbm.h"
    5454#ifdef __cplusplus
    55 }
     55  }
    5656#endif
    5757
     
    6868protected:
    6969  text_tarraymap info;
     70  text_t lang;
    7071
    7172public:
     
    100101  void clear () {info.erase(info.begin(),info.end());}
    101102
     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
    102107  // the following functions deal with keys that can only
    103108  // have one value for compatibility
     
    111116  void setcinfo (const text_t &key, unsigned short c);
    112117  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);
    113120  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);
    114123  text_t &operator[] (const text_t &key);
    115124
     
    124133  void addcinfo (const text_t &key, unsigned short c);
    125134  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);
    126137};
    127138
     
    143154
    144155  // returns true on success
    145   bool getinfo (text_t key, infodbclass &info);
     156  bool getinfo (const text_t& key, infodbclass &info);
    146157  void setlogout (ostream *thelogout) {logout = thelogout;}
    147158
    148159  // returns true if exists
    149   bool exists (text_t key);
     160  bool exists (const text_t& key);
    150161
    151162  // returns true on success
     
    164175
    165176    // returns true on success
    166   bool getkeydata (text_t key, text_t &data);
     177  bool getkeydata (const text_t& key, text_t &data);
    167178
    168179protected:
Note: See TracChangeset for help on using the changeset viewer.