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

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

  ViewVC Help
Powered by ViewVC 1.1.26