Changeset 15630

Show
Ignore:
Timestamp:
22.05.2008 12:58:14 (11 years ago)
Author:
mdewsnip
Message:

(Adding new DB support) Replaced the "getfirstkey()" and "getnextkey()" functions in dbclass with "getkeys()" (which returns them all). These functions were only used in userdb.cpp, and having the one function is simpler without being (much) less efficient. Also, implementing getkeys() for the new sql db classes will be easier than getfirstkey() and getnextkey().

Location:
gsdl/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/lib/dbclass.h

    r15598 r15630  
    6969  virtual bool setinfo(const text_t &key, const infodbclass &info) = 0; 
    7070 
    71   // getfirstkey and getnextkey are used for traversing the database 
    72   // no insertions or deletions should be carried out while traversing 
    73   // the database. when there are no keys left to visit in the database 
    74   // an empty string is returned. 
    75   virtual text_t getfirstkey() = 0; 
    76   virtual text_t getnextkey(const text_t &key) = 0; 
     71  virtual text_tarray getkeys () = 0; 
    7772 
    7873  virtual void deletekey(const text_t &key) = 0; 
  • gsdl/trunk/lib/gdbmclass.cpp

    r15598 r15630  
    239239 
    240240 
     241text_tarray gdbmclass::getkeys () 
     242{ 
     243  text_tarray keys; 
     244 
     245  text_t key = getfirstkey(); 
     246  while (!key.empty()) 
     247  { 
     248    keys.push_back(key); 
     249    key = getnextkey(key); 
     250  } 
     251 
     252  return keys; 
     253} 
     254 
     255 
    241256// getfirstkey and getnextkey are used for traversing the database 
    242257// no insertions or deletions should be carried out while traversing 
  • gsdl/trunk/lib/gdbmclass.h

    r15598 r15630  
    7373  void deletekey (const text_t &key); 
    7474 
    75   // getfirstkey and getnextkey are used for traversing the database 
    76   // no insertions or deletions should be carried out while traversing 
    77   // the database. when there are no keys left to visit in the database 
    78   // an empty string is returned. 
    79   text_t getfirstkey (); 
    80   text_t getnextkey (const text_t &key); 
     75  text_tarray getkeys (); 
    8176 
    8277    // returns true on success 
     
    8782  GDBM_FILE gdbmfile; 
    8883 
     84  // getfirstkey and getnextkey are used for traversing the database 
     85  // no insertions or deletions should be carried out while traversing 
     86  // the database. when there are no keys left to visit in the database 
     87  // an empty string is returned. 
     88  text_t getfirstkey (); 
     89  text_t getnextkey (const text_t &key); 
     90 
    8991  // returns true on success 
    9092  bool getinfoline (text_t::iterator &here, text_t::iterator end,  
  • gsdl/trunk/src/recpt/userdb.cpp

    r15586 r15630  
    332332    { 
    333333      userinfo_array.erase(userinfo_array.begin(), userinfo_array.end()); 
    334       text_t user = userdb->getfirstkey(); 
    335       while (!user.empty()) { 
     334      text_tarray userlist = userdb->getkeys(); 
     335      text_tarray::iterator user_iterator = userlist.begin(); 
     336      while (user_iterator != userlist.end()) 
     337      { 
    336338        userinfo_t one_userinfo; 
    337         int returned = get_user_info(user, one_userinfo); 
     339        int returned = get_user_info(*user_iterator, one_userinfo); 
    338340        if (returned != ERRNO_SUCCEED) return returned; 
    339341        userinfo_array.push_back(one_userinfo); 
    340         user = userdb->getnextkey(user); 
     342    user_iterator++; 
    341343      } 
    342344      return ERRNO_SUCCEED; 
     
    353355    { 
    354356      userlist.erase (userlist.begin(), userlist.end()); 
    355        
    356       text_t user = userdb->getfirstkey (); 
    357       while (!user.empty()) { 
    358         userlist.push_back(user); 
    359         user = userdb->getnextkey (user); 
    360       } 
     357      userlist = userdb->getkeys(); 
    361358      return ERRNO_SUCCEED; 
    362359    } 
     
    490487      // get a list of keys created more than keydecay seconds agon 
    491488      text_tarray oldkeys; 
    492       text_t key = keydb->getfirstkey (); 
    493489      infodbclass info; 
    494490      time_t timenow = text2time(time2text(time(NULL))); 
    495491      time_t keycreation = (time_t)-1; 
    496       while (!key.empty()) { 
    497         if (keydb->getinfo (key, info))  { 
     492 
     493      text_tarray keylist = keydb->getkeys(); 
     494      text_tarray::iterator key_iterator = keylist.begin(); 
     495      while (key_iterator != keylist.end()) 
     496      { 
     497        if (keydb->getinfo (*key_iterator, info))  { 
    498498          keycreation = text2time (info["time"]); 
    499499          if (keycreation != (time_t)-1 && difftime (timenow, keycreation) > keydecay) { 
    500500            // found an old key 
    501             oldkeys.push_back(key); 
     501            oldkeys.push_back(*key_iterator); 
    502502          } 
    503503        } 
    504504         
    505         key = keydb->getnextkey (key); 
     505    key_iterator++; 
    506506      } 
    507507