00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00028 #ifndef _SEARCH_GRAPH_HPP
00029 #define _SEARCH_GRAPH_HPP
00030
00031 #include <sgraphctx.h>
00032
00033 namespace coco {
00034
00035 inline search_graph::search_graph(model& root_model, gptr<vdbl::database>& _db)
00036 : _Base(), ptr_ground(NULL), ptr_root_model(NULL),
00037 __dbase(&_db), __dbuser(0),
00038 sgc(new search_graph_context(*this)),
00039 __vdbf(*this->__dbase->get_local_copy(), this->__dbuser, *sgc,
00040 vdbl::V_window),
00041 __maxid(0), __id_ref()
00042 {
00043 ptr_root_model = root_model;
00044 *ground() = new search_node(get_node_id(), __dbuser, *__dbase, snr_virtual);
00045 search_nodes_to_deallocate.push_front(*ground());
00046 ptr_ground = **ground();
00047 root = new full_node(get_node_id(), __dbuser, ptr_root_model, ptr_ground,
00048 *__dbase, snr_root);
00049 search_nodes_to_deallocate.push_front(root);
00050 inspector_for_root = insert(ground(), *root);
00051 __id_ref[root->get_id()] = inspector_for_root;
00052 }
00053
00054 inline search_graph::search_graph(model & root_model, gptr<vdbl::database>& _db,
00055 const std::vector<annotation>& _a)
00056 : _Base(), ptr_ground(NULL), ptr_root_model(NULL),
00057 __dbase(&_db), __dbuser(0),
00058 sgc(new search_graph_context(*this)),
00059 __vdbf(*this->__dbase->get_local_copy(), this->__dbuser, *sgc,
00060 vdbl::V_window),
00061 __maxid(0)
00062 {
00063 ptr_root_model = root_model;
00064 *ground() = new search_node(get_node_id(), __dbuser, *__dbase, snr_virtual);
00065 search_nodes_to_deallocate.push_front(*ground());
00066 ptr_ground = **ground();
00067 root = new full_node(get_node_id(), __dbuser, ptr_root_model, ptr_ground,
00068 *__dbase, _a, snr_root);
00069 search_nodes_to_deallocate.push_front(root);
00070 inspector_for_root = insert(ground(), *root);
00071 __id_ref[root->get_id()] = inspector_for_root;
00072 }
00073
00074 inline search_graph::~search_graph()
00075 {
00076 for(std::list<search_node*>::iterator i = search_nodes_to_deallocate.begin();
00077 i != search_nodes_to_deallocate.end(); ++i)
00078 delete *i;
00079
00080 vdbl::standard_table* dtable = (vdbl::standard_table *)
00081 (*__dbase)->get_table("deltas", __dbuser);
00082 if(dtable == NULL)
00083 throw api_exception(apiee_internal,
00084 "Database inconsistency: Programming Error!");
00085 for(std::list<delta_id>::iterator i = db_deltas_to_remove.begin();
00086 i != db_deltas_to_remove.end(); ++i)
00087 dtable->remove(*i);
00088 vdbl::standard_table* stable = (vdbl::standard_table *)
00089 (*__dbase)->get_table("search info", __dbuser);
00090 for(std::list<work_node_comp_hook*>::iterator __b = wn_hooks.begin();
00091 __b != wn_hooks.end(); ++__b)
00092 {
00093 if(stable)
00094 (*__b)->drop_columns(*stable);
00095 delete *__b;
00096 }
00097 wn_hooks.erase(wn_hooks.begin(), wn_hooks.end());
00098 (*__dbase)->drop_table("search info", __dbuser);
00099 delete sgc;
00100 }
00101
00102 inline search_graph::search_inspector search_graph::child(search_inspector& n,
00103 unsigned int i)
00104 {
00105 if(n.n_children() < i || i < 0)
00106 throw api_exception(apiee_search_graph,
00107 "in search_graph :: child (...) : the index of child is out of range");
00108 return new_inspector(n >> (n.child_begin() + i));
00109 }
00110
00111 inline search_graph::search_inspector search_graph::parent(search_inspector& n,
00112 unsigned int i)
00113 {
00114 if(n.n_parents() < i || i < 0)
00115 throw api_exception(apiee_search_graph,
00116 "in search_graph :: parent (...) : the index of parent is out of range");
00117 return new_inspector(n >> (n.parent_begin() + i));
00118 }
00119
00120 inline search_graph::search_inspector search_graph::get(search_node_id id) const
00121 {
00122 std::map<search_node_id,search_inspector>::const_iterator
00123 i(__id_ref.find(id));
00124 if(i == __id_ref.end())
00125 return ground();
00126 else
00127 return (*i).second;
00128 }
00129
00130 }
00131
00132 #endif // _SEARCH_GRAPH_HPP