00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00027 #ifndef SUM_DELTAS
00028 #define SUM_DELTAS
00029 #include <vector>
00030 #include "delta.h"
00031 using namespace std;
00032
00033 inline work_node full_node_to_work_node(full_node& n_full,
00034 gptr<search_node> &ground)
00035 {
00036 ptr<model> ptr_to_model_from_n_full(*n_full.get_model_ptr());
00037 ptr<vdbl::database> ptr_to_dbase_from_n_full(*n_full.get_database_ptr());
00038
00039
00040 list<delta_id> empty_list_of_delta_id;
00041 return work_node(n_full.get_id(), n_full.get_dbuserid(),
00042 *new ptr<model>(ptr_to_model_from_n_full),
00043 *new ptr<vdbl::database>(ptr_to_dbase_from_n_full),
00044 n_full.get_annotations(), empty_list_of_delta_id, &ground);
00045 }
00046
00047 class sum_deltas:public prepost_visitor<search_node*, work_node*>
00048 {
00049 public:
00050 vector<return_value> ancestors;
00051 return_value result;
00052 gptr<search_node> &ground;
00053
00054 sum_deltas(gptr<search_node>& search_graph_ground) : result(NULL),
00055 ground(search_graph_ground) {}
00056
00057 inline void vinit()
00058 {
00059
00060 }
00061
00062 inline void vcollect(return_value const &)
00063 {
00064
00065 throw search_graph_exception
00066 ("in sum_deltas :: vcollect (...) : do not know how to handle virtual nodes");
00067 }
00068
00069 inline return_value vvalue()
00070 {
00071
00072 return result;
00073 }
00074
00075 inline bool preorder(search_node* const& r)
00076 {
00077
00078 ancestors.clear();
00079 return r->is_delta();
00080 }
00081
00082 inline void collect(search_node* const&, return_value const &ancestor)
00083 {
00084
00085 ancestors.push_back(ancestor);
00086 }
00087
00088 bool postorder(search_node* const &r)
00089 {
00090
00091 if(!r->is_delta())
00092 {
00093 full_node *r_as_full_node = (full_node *) r;
00094
00095 if(result != NULL)
00096 delete result;
00097
00098 result = new work_node(full_node_to_work_node(*r_as_full_node, ground));
00099 return false;
00100 }
00101 if(ancestors.size() >= 2)
00102 throw search_graph_exception
00103 ("in sum_deltas :: postorder (...) : search_node has several ancestors");
00104 delta_node *r_as_delta_node = (delta_node *) r;
00105 work_node ancestor_plus_r_as_delta_node(*ancestors[0]);
00106
00107 for(unsigned int i = 0; i < r_as_delta_node->n_deltas(); ++i)
00108 ancestor_plus_r_as_delta_node += r_as_delta_node->get_delta_id(i);
00109 if(result != NULL)
00110 delete result;
00111
00112 result = new work_node(ancestor_plus_r_as_delta_node);
00113 return false;
00114 }
00115
00116 inline return_value value()
00117 {
00118
00119 return result;
00120 }
00121
00122 };
00123 #endif