/[hyperestraier_wrappers]/trunk/perl/HyperEstraierWrapper.cpp
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/perl/HyperEstraierWrapper.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6 by dpavlin, Sat Sep 3 20:00:11 2005 UTC revision 32 by dpavlin, Tue Oct 11 14:04:20 2005 UTC
# Line 10  Line 10 
10  #include <map>  #include <map>
11  #include <cassert>  #include <cassert>
12  #include <stdexcept>  #include <stdexcept>
13    #include <estnode.h>
14    
15  /* backward compatibility for 0.5.4 */  /* backward compatibility for 0.5.4 */
16    /*
17  #ifndef ESTCONDAGITO  #ifndef ESTCONDAGITO
18  #define ESTCONDAGITO ESTCONDAGIT  #define ESTCONDAGITO ESTCONDAGIT
19  #endif  #endif
20    */
21    
22  namespace estraier {  namespace estraier {
23    
# Line 414  namespace estraier { Line 417  namespace estraier {
417                          if (!db) throw IOError("closed database");                          if (!db) throw IOError("closed database");
418                          return est_mtdb_size(db);                          return est_mtdb_size(db);
419                  }                  }
420                  void set_cache_size(size_t size, int anum, int tnum) {                  void set_cache_size(size_t size, int anum, int tnum, int rnum) {
421                          /**                          /**
422                           * set the maximum size of the cache memory of a database                           * set the maximum size of the cache memory of a database
423                           */                           */
424                          if (!db) throw IOError("closed database");                          if (!db) throw IOError("closed database");
425                          est_mtdb_set_cache_size(db, size, anum, tnum);                          est_mtdb_set_cache_size(db, size, anum, tnum, rnum);
426                  }                  }
427                  void set_special_cache(const char *name, int num) {                  void set_special_cache(const char *name, int num) {
428                          /**                          /**
# Line 454  namespace estraier { Line 457  namespace estraier {
457                  return vs;                  return vs;
458          }          }
459    
460            class ResultDocument {
461            public:
462                    ESTRESDOC *rdoc;
463                    ResultDocument(ESTRESDOC *_rdoc) {
464                            rdoc = _rdoc;
465                    }
466                    const char *uri(void) {
467                            return est_resdoc_uri(rdoc);
468                    }
469                    std::vector<std::string> * attr_names() {
470                            std::vector<std::string> * vs = new std::vector<std::string>;
471                            CBLIST * attr_names = est_resdoc_attr_names(rdoc);
472                            for (int i=0; i < cblistnum(attr_names); i++) {
473                                    vs->push_back(cblistval(attr_names, i, NULL));
474                            }
475                            cblistclose(attr_names);
476                            return vs;
477                    }
478                    const char *attr(const char *name) {
479                            return est_resdoc_attr(rdoc, name);
480                    }
481                    const char *snippet(void) {
482                            return est_resdoc_snippet(rdoc);
483                    }
484            };
485    
486            class NodeRes {
487            private:
488                    ESTNODERES *nres;
489            public:
490                    NodeRes(ESTNODE *node, Condition *cond, int depth) {
491                            nres = est_node_search(node, cond->cond, depth);
492                    }
493                    ~NodeRes() {
494                            est_noderes_delete(nres);
495                    }
496                    std::map<std::string, std::string> * hints(void) {
497                            std::map<std::string, std::string> * hints = new std::map<std::string, std::string>;
498                            CBMAP * keys = est_noderes_hints(nres);
499                            cbmapiterinit(keys);
500                            int ksiz;
501                            while (const char *key = cbmapiternext(keys, &ksiz)) {
502                                    hints->insert(std::make_pair(key, cbmapget(keys, key, ksiz, NULL)));
503                            }
504                            return hints;
505                    }
506                    int doc_num(void) {
507                            return est_noderes_doc_num(nres);
508                    }
509                    ResultDocument * get_doc(int index) {
510                            ESTRESDOC *rdoc = est_noderes_get_doc(nres, index);
511                            if (rdoc) {
512                                    return new ResultDocument(rdoc);
513                            } else {
514                                    return NULL;
515                            }
516                    }
517            };
518    
519            class Node {
520            private:
521                    ESTNODE *node;
522                    int netenv_ok;
523            public:
524                    Node(const char *url) {
525                            netenv_ok = est_init_net_env();
526                            if (! netenv_ok) throw IOError("can't init net env");
527                            node = est_node_new(url);
528                            if (! node) throw IOError("can't create node");
529                    }
530                    ~Node() {
531                            est_node_delete(node);
532                            est_free_net_env();
533                    }
534                    void set_proxy(const char *host, int port) {
535                            est_node_set_proxy(node, host, port);
536                    }
537                    void set_timeout(int sec) {
538                            est_node_set_timeout(node, sec);
539                    }
540                    void set_auth(const char *name, const char *passwd) {
541                            est_node_set_auth(node, name, passwd);
542                    }
543                    int status(void) {
544                            return est_node_status(node);
545                    }
546                    bool put_doc(Document *doc) {
547                            return est_node_put_doc(node, doc->doc);
548                    }
549                    bool out_doc(int id) {
550                            return est_node_out_doc(node, id);
551                    }
552                    bool out_doc_by_uri(const char *uri) {
553                            return est_node_out_doc_by_uri(node, uri);
554                    }
555    #ifdef est_node_edit_doc
556                    bool edit_doc(Document *doc) {
557                            return est_node_edit_doc(node, doc->doc);
558                    }
559    #endif
560                    Document * get_doc(int id) {
561                            ESTDOC *doc = est_node_get_doc(node, id);
562                            if (!doc) {
563                                    return NULL;
564                            } else {
565                                    return new Document(doc);
566                            }
567                    }
568                    Document * get_doc_by_uri(const char *uri) {
569                            ESTDOC *doc = est_node_get_doc_by_uri(node, uri);
570                            if (!doc) {
571                                    return NULL;
572                            } else {
573                                    return new Document(doc);
574                            }
575                    }
576                    char * get_doc_attr(int id, const char *name) {
577                            /* is this leeking memory? shouldn't I create
578                             * object and free memory region returned?
579                             */
580                            return est_node_get_doc_attr(node, id, name);
581                    }
582                    char * get_doc_attr_by_uri(const char *uri, const char *name) {
583                            return est_node_get_doc_attr_by_uri(node, uri, name);
584                    }
585                    int uri_to_id(const char *uri) {
586                            return est_node_uri_to_id(node, uri);
587                    }
588                    const char * name(void) {
589                            return est_node_name(node);
590                    }
591                    const char * label(void) {
592                            return est_node_label(node);
593                    }
594                    int doc_num(void) {
595                            return est_node_doc_num(node);
596                    }
597                    int word_num(void) {
598                            return est_node_word_num(node);
599                    }
600                    double size(void) {
601                            return est_node_size(node);
602                    }
603                    NodeRes * search(Condition *cond, int depth) {
604                            return new NodeRes(node, cond, depth);
605                    }
606                    int set_user(const char *name, int mode) {
607                            return est_node_set_user(node, name, mode);
608                    }
609                    int set_link(const char *url, const char *label, int credit) {
610                            return est_node_set_link(node, url, label, credit);
611                    }
612            };
613    
614  };  };

Legend:
Removed from v.6  
changed lines
  Added in v.32

  ViewVC Help
Powered by ViewVC 1.1.26