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_H
00029 #define _SEARCH_GRAPH_H
00030
00031 #include <iostream>
00032 #include <algorithm>
00033 #include <dag.h>
00034 #include <coconut_config.h>
00035 #include <search_node.h>
00036 #include <comp_hook.h>
00037 #include <api_exception.h>
00038
00039 using namespace vgtl;
00040
00041 namespace coco {
00042
00043 class search_graph_context;
00044
00046
00053 class search_graph : public dag<search_node*>
00054 {
00055 private:
00057 typedef dag<search_node*> _Base;
00058 typedef search_graph _Self;
00060 typedef search_graph::const_walker search_inspector;
00062 typedef search_graph::walker search_focus;
00063
00064
00065 public:
00067 std::list<walker> focus;
00069 std::list<const_walker> inspector;
00070
00072 search_node *root;
00074 search_inspector inspector_for_root;
00076 ptr<search_node> ptr_ground;
00079 ptr<model> ptr_root_model;
00082 std::list<search_node*> search_nodes_to_deallocate;
00085 std::list<delta_id> db_deltas_to_remove;
00088 gptr<vdbl::database> *__dbase;
00091 vdbl::userid __dbuser;
00092
00094 search_graph_context* sgc;
00097 vdbl::viewdbase __vdbf;
00098
00099
00100 private:
00102 search_node_id __maxid;
00105 std::map<search_node_id,search_inspector> __id_ref;
00106
00108 void _internal_remove(search_focus& _sf);
00109
00112 void _extract(work_node& wnode, const search_inspector& where) const;
00113
00116 void _extract_indirect(work_node& wnode, const search_inspector & from,
00117 const search_inspector & to) const;
00118
00121 void _extract_full(work_node& wnode, const search_inspector & where,
00122 std::list<delta_id>& dels, std::set<search_node_id>& nds,
00123 full_node* fn) const;
00124
00125 private:
00130 std::list<work_node_comp_hook*> wn_hooks;
00131
00132 public:
00136 search_graph(model& root_model, gptr<vdbl::database>& _db);
00137
00142 search_graph(model & root_model, gptr<vdbl::database>& _db,
00143 const std::vector<annotation>& _a);
00144
00146 ~search_graph();
00147
00149 search_node_id get_node_id() { return ++__maxid; }
00150
00152 search_graph_context* get_search_graph_context() { return sgc; }
00153
00155 const search_graph_context* get_search_graph_context() const { return sgc; }
00156
00158 vdbl::viewdbase& get_viewdbase() { return __vdbf; }
00159
00161 const vdbl::viewdbase& get_viewdbase() const { return __vdbf; }
00162
00169 bool possible_focus(const search_inspector& _si,
00170 const search_focus& not_this) const;
00173 bool possible_focus(const search_inspector& _si,
00174 const std::list<search_focus>::const_iterator* not_this = NULL) const;
00177 search_focus& new_focus(const search_inspector& _si);
00181 const search_focus& get_focus(const search_inspector& _si, bool& isNew);
00183 void destroy_focus(const search_focus& _sf);
00186 search_focus& set_focus(search_focus& _fc, const search_inspector& _si);
00187
00190 search_inspector& new_inspector(const search_inspector& inspector_to_add);
00191
00194 search_inspector& new_inspector()
00195 { return new_inspector(ground()); }
00196
00199 void destroy_inspector(const search_inspector& inspector_to_destroy);
00200
00203 search_inspector child(search_inspector& n, unsigned int i);
00204
00207 search_inspector parent(search_inspector& n, unsigned int i);
00208
00211 search_inspector get(search_node_id id) const;
00213
00220 work_node extract(const search_inspector& where) const;
00223 work_node extract(const search_focus& where) const;
00226 void extract(work_node& wnode, const search_inspector& where) const;
00229 void extract(work_node& wnode, const search_focus& where) const;
00232 search_focus& update(work_node& wnode, search_focus& foc,
00233 const search_inspector& where);
00241 search_focus& update_and_delete(work_node& wnode, search_focus& foc,
00242 const search_inspector& where, bool just_this,
00243 bool relaxation_kills);
00246 search_inspector& insert(const search_focus& where, const search_node& what);
00249 search_inspector& replace(search_focus& where, const search_node& what);
00254 bool add_deltas(const search_focus& where,
00255 const std::vector<delta_id>& del_vec);
00258 void remove(search_focus& _sf);
00264 void remove_upwards(search_focus& _sf, bool relaxation_kills);
00268 search_focus& promote(search_focus& _sf);
00270
00272 bool register_hook(const work_node_comp_hook& wnch);
00274 bool unregister_hook(const std::string& name);
00279 void apply_hooks(const work_node& w, const search_node_id& id,
00280 vdbl::rowid& rid, std::list<delta>& add_ds,
00281 std::list<certificate>& add_cs);
00282 };
00283
00284 }
00285
00286 #include <search_graph.hpp>
00287
00288 #if DEBUG_SEARCH_NODES
00289 #include <g_algotest.h>
00290 namespace coco {
00291
00293
00297 class __test_sn_help
00298 {
00299 public:
00300 search_node_id operator()(const search_node* __sn) const
00301 {
00302 return __sn->test();
00303 }
00304 };
00305
00307
00311 inline void consistency_test(const search_graph& __s)
00312 {
00313 recursive_consistency_test(__s.ground(), __test_sn_help());
00314 }
00315
00316 }
00317 #endif
00318
00319 namespace coco {
00320
00322
00326 typedef search_graph::const_walker search_inspector;
00328
00333 typedef search_graph::walker search_focus;
00334
00335 }
00336
00337 #endif // _SEARCH_GRAPH_H