Changeset 204

Show
Ignore:
Timestamp:
10/29/06 20:39:56 (2 years ago)
Author:
ug
Message:

Implemented libkombiloAPI#Playerlist.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/libkombilo/search.cc

    r203 r204  
    34893489  if (rc) throw DBError(); 
    34903490 
    3491   string sql = "select "; // those two we need in any case 
     3491  string sql = "select "; 
    34923492  sql += format1; 
    34933493  sql += " from games order by "; 
     
    35023502  // SQLITE_ERROR may occur since table might not yet exist 
    35033503   
     3504  readPlayersList(); 
     3505 
    35043506  if (rc == SQLITE_OK && !readDBs) { 
    35053507    for(unsigned int a=0; a < 20*boardsizes.size(); a++) { 
     
    39263928  pl.continuations = new Continuation[pattern.sizeX*pattern.sizeY]; 
    39273929  delete searchOptions; 
     3930} 
     3931 
     3932 
     3933int GameList::plSize() { 
     3934  return pl.size(); 
     3935} 
     3936 
     3937string GameList::plEntry(int i) { 
     3938  if (i < 0 || i >= pl.size()) return ""; 
     3939  else return pl[i]; 
     3940} 
     3941 
     3942int rpl_callback(void *pl, int argc, char **argv, char **azColName) { 
     3943  if (!argc) return 1; 
     3944  ((vector<string>*)pl)->push_back(string(argv[0])); 
     3945  return 0; 
     3946} 
     3947 
     3948void GameList::readPlayersList() throw(DBError) { 
     3949  if (pl.size()) pl = vector<string>(); 
     3950  int rc = sqlite3_exec(db, "select p from (select pw p from games union select pb p from games) order by lower(p)", rpl_callback, &pl, 0); 
     3951  if (rc != SQLITE_OK) throw DBError(); 
    39283952} 
    39293953 
  • 06/libkombilo/search.h

    r203 r204  
    584584    Continuation* continuations; 
    585585 
     586    // ---------------------------------------------------------------------------- 
    586587    // the following methods provide the user interface 
    587588 
     589    // ------- constructor -------------------------------------------------------- 
    588590    // p_options will be copied by GameList, so the caller has to free the pointer 
    589591    GameList(char* DBNAME, std::string ORDERBY="", std::string FORMAT="", ProcessOptions* p_options=0) throw(DBError); 
    590592 
     593    // ------- processing SGF games (to populate the db) -------------------------- 
    591594    void start_processing(int PROCESSVARIATIONS=-1) throw(DBError); 
    592595    int process(const char* sgf, const char* path, const char* fn, const char* DBTREE = 0) throw(SGFError,DBError); 
    593596    void finalize_processing() throw(DBError); 
    594597     
     598    // ------- pattern search ----------------------------------------------------- 
    595599    // options is copied in the search method (if != 0), so the caller has to free the pointer 
    596600    void search(Pattern& pattern, SearchOptions* options = 0) throw(DBError); 
     
    598602    Continuation lookupContinuation(char x, char y); 
    599603 
     604    // ------- game info search --------------------------------------------------- 
    600605    void gisearch(char* sql, int complete=0) throw(DBError); 
    601606 
     607    // ------- tagging ------------------------------------------------------------ 
    602608    void tagsearch(int tag) throw(DBError); 
    603609    void setTag(int tag, int start=0, int end=0) throw(DBError); 
     
    605611    std::vector<int> getTags(int i, int tag=0) throw(DBError); // note the order of arguments! 
    606612 
     613    // ------- misc --------------------------------------------------------------- 
    607614    void reset(); // reset currentList to all 
    608615    void resetFormat(std::string ORDERBY="", std::string FORMAT=""); 
     
    615622    std::string getCurrentProperty(int i, std::string tag) throw (DBError); 
    616623 
     624    // ------- list of all players ------------------------------------------------- 
     625    int plSize(); 
     626    std::string plEntry(int i); 
     627 
     628    // ----------------------------------------------------------------------------- 
    617629    // internal methods (called from the algorithm classes) 
    618630    ~GameList(); 
     
    642654    std::vector<std::string>* SGFtags; 
    643655    std::string sql_ins_rnp; // sql string to insert root node properties 
     656    std::vector<std::string> pl; // list of all players 
     657    void readPlayersList() throw(DBError); 
    644658}; 
    645659 
  • 06/libkombilo/testsearch.py

    r201 r204  
    5353print gl.currentEntryAsString(gl.size()-1) 
    5454print gl.getCurrentProperty(gl.size()-1, 'PW'),  gl.getSGF(gl.size()-1) 
     55 
    5556gl.reset() 
     57gl.tagsearch(HANDI_TAG) 
     58print gl.size(), 'handicap games' 
    5659 
     60print gl.plSize(), 'players in the whole database.' 
     61for i in range(100,110): 
     62    print 'Player %d: %s' % (i, gl.plEntry(i)) 
     63