Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

sum_deltas.h

Go to the documentation of this file.
00001 // Search Graph implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2001-2003 Evgueni Petrov, Hermann Schichl
00004 //
00005 // This file is part of the COCONUT API.  This library
00006 // is free software; you can redistribute it and/or modify it under the
00007 // terms of the Library GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // Library GNU General Public License for more details.
00015 
00016 // As a special exception, you may use this file as part of a free software
00017 // library without restriction.  Specifically, if other files instantiate
00018 // templates or use macros or inline functions from this file, or you compile
00019 // this file and link it with other files to produce an executable, this
00020 // file does not by itself cause the resulting executable to be covered by
00021 // the Library GNU General Public License.  This exception does not however
00022 // invalidate any other reasons why the executable file might be covered by
00023 // the Library GNU General Public License.
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 //  return work_node ( ptr_to_model_from_n_full, n_work_annotation, empty_list_of_delta_id, & ground );
00039 // memory leak !!!
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     // cout << "vinit" << endl;
00060   }
00061 
00062   inline void vcollect(return_value const &)
00063   {
00064     // cout << "vcollect" << endl;
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     // cout << "vvalue" << endl;
00072     return result;
00073   }
00074 
00075   inline bool preorder(search_node* const& r)
00076   {
00077     // cout << "preorder" << endl;
00078     ancestors.clear();
00079     return r->is_delta();
00080   }
00081 
00082   inline void collect(search_node* const&, return_value const &ancestor)
00083   {
00084     // cout << "collect" << endl;
00085     ancestors.push_back(ancestor);
00086   }
00087 
00088   bool postorder(search_node* const &r)
00089   {
00090     // cout << "postorder" << endl;
00091     if(!r->is_delta())
00092     {
00093       full_node *r_as_full_node = (full_node *) r;      //  cast to full_node *
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;     //  cast to delta_node *
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     // cout << "value" << endl;
00119     return result;
00120   }
00121 
00122 };
00123 #endif

Generated on Tue Nov 4 01:57:58 2003 for COCONUT API by doxygen1.2.18