--- trunk/perl/HyperEstraierWrapper.cpp 2005/09/03 20:00:11 6 +++ trunk/perl/HyperEstraierWrapper.cpp 2005/09/08 16:42:55 9 @@ -10,6 +10,7 @@ #include #include #include +#include /* backward compatibility for 0.5.4 */ #ifndef ESTCONDAGITO @@ -454,4 +455,163 @@ return vs; } + class NetEnv { + private: + int ok; + public: + NetEnv() { + ok = est_init_net_env(); + if (! ok) throw IOError("can't init net env"); + } + ~NetEnv() { + est_free_net_env(); + } + }; + + class NodeDocument { + private: + ESTRESDOC *rdoc; + public: + NodeDocument(ESTNODERES *nres, int index) { + rdoc = est_noderes_get_doc(nres, index); + } + const char *uri(void) { + return est_resdoc_uri(rdoc); + } + std::vector * attr_names() { + std::vector * vs = new std::vector; + CBLIST * attr_names = est_resdoc_attr_names(rdoc); + for (int i=0; i < cblistnum(attr_names); i++) { + vs->push_back(cblistval(attr_names, i, NULL)); + } + cblistclose(attr_names); + return vs; + } + const char *attr(const char *name) { + return est_resdoc_attr(rdoc, name); + } + const char *snippet(void) { + return est_resdoc_snippet(rdoc); + } + }; + + class NodeRes { + private: + ESTNODERES *nres; + public: + NodeRes(ESTNODE *node, ESTCOND *cond, int depth) { + nres = est_node_search(node, cond, depth); + } + ~NodeRes() { + est_noderes_delete(nres); + } + std::map * hints(void) { + std::map * hints = new std::map; + CBMAP * keys = est_noderes_hints(nres); + cbmapiterinit(keys); + int ksiz; + while (const char *key = cbmapiternext(keys, &ksiz)) { + hints->insert(std::make_pair(key, cbmapget(keys, key, ksiz, NULL))); + } + return hints; + } + int doc_num(void) { + return est_noderes_doc_num(nres); + } + NodeDocument * get_doc(int index) { + return new NodeDocument(nres, index); + } + }; + + class Node { + private: + ESTNODE *node; + public: + Node(const char *url) { + node = est_node_new(url); + if (! node) throw IOError("can't create node"); + } + ~Node() { + est_node_delete(node); + } + void set_proxy(const char *host, int port) { + est_node_set_proxy(node, host, port); + } + void set_timeout(int sec) { + est_node_set_timeout(node, sec); + } + void set_auth(const char *name, const char *passwd) { + est_node_set_auth(node, name, passwd); + } + int status(void) { + return est_node_status(node); + } + bool put_doc(Document *doc) { + return est_node_put_doc(node, doc->doc); + } + bool out_doc(int id) { + return est_node_out_doc(node, id); + } + bool out_doc_by_uri(const char *uri) { + return est_node_out_doc_by_uri(node, uri); + } +#ifdef est_node_edit_doc + bool edit_doc(Document *doc) { + return est_node_edit_doc(node, doc->doc); + } +#endif + Document * get_doc(int id) { + ESTDOC *doc = est_node_get_doc(node, id); + if (!doc) { + return NULL; + } else { + return new Document(doc); + } + } + Document * get_doc_by_uri(const char *uri) { + ESTDOC *doc = est_node_get_doc_by_uri(node, uri); + if (!doc) { + return NULL; + } else { + return new Document(doc); + } + } + char * get_doc_attr(int id, const char *name) { + /* is this leeking memory? shouldn't I create + * object and free memory region returned? + */ + return est_node_get_doc_attr(node, id, name); + } + char * get_doc_attr_by_uri(const char *uri, const char *name) { + return est_node_get_doc_attr_by_uri(node, uri, name); + } + int uri_to_id(const char *uri) { + return est_node_uri_to_id(node, uri); + } + const char * name(void) { + return est_node_name(node); + } + const char * label(void) { + return est_node_label(node); + } + int doc_num(void) { + return est_node_doc_num(node); + } + int word_num(void) { + return est_node_word_num(node); + } + double size(void) { + return est_node_size(node); + } + NodeRes * search(ESTCOND *cond, int depth) { + return new NodeRes(node, cond, depth); + } + int set_user(const char *name, int mode) { + return est_node_set_user(node, name, mode); + } + int set_link(const char *url, const char *label, int credit) { + return est_node_set_link(node, url, label, credit); + } + }; + };