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

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

  ViewVC Help
Powered by ViewVC 1.1.26