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

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

  ViewVC Help
Powered by ViewVC 1.1.26