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

split_delta.h

Go to the documentation of this file.
00001 // Split Delta implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2001-2003 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 _SPLIT_DELTA_H_
00028 #define _SPLIT_DELTA_H_
00029 
00030 #include <api_delta.h>
00031 #include <bound_delta.h>
00032 
00033 class split_undelta : public undelta_base
00034 {
00035 private:
00036   work_node::transaction_number se;
00037 
00038 public:
00039   split_undelta(const work_node::transaction_number& _se) : se(_se) {}
00040 
00041   split_undelta(const split_undelta& _su) : se(_su.se)
00042       {
00043 #if DEBUG_DELTA
00044         std::cerr << "Called split_undelta copy constructor" << std::endl;
00045 #endif
00046       }
00047 
00048   virtual ~split_undelta() {}
00049 
00050   split_undelta* new_copy() const { return new split_undelta(*this); }
00051   void destroy_copy(split_undelta* __d) { delete __d; }
00052 
00053   bool unapply(work_node& x) const
00054   {
00055     std::map<work_node::transaction_number,std::list<std::vector<delta> > >::iterator _f;
00056     _f = x.proposed_splits.find(se);
00057     if(_f != x.proposed_splits.end())
00058     {
00059       x.proposed_splits.erase(_f);
00060       return true;
00061     }
00062     else
00063       return false;
00064   }
00065 };
00066 
00067 class split_delta : public delta_base
00068 {
00069 public:
00070   std::list<std::vector<delta> > splits;// we could also use dag<delta*>
00071                                         // splits or std::list<delta*> splits
00072                                         // if trees are not necessary.  
00073   // splits represents a list of newly created submodels. Each of these
00074   // submodels is generated from the work node by a number of deltas stored
00075   // in the inner vector.
00076 
00077   split_delta() : delta_base("split"), splits() {}
00078                                 // we do not need to keep data for unapply,
00079                                 // because unapplying a split effectively
00080                                 // means to remove the information from the
00081                                 // list of suggested splits
00082 
00083   split_delta(unsigned int _node_num, const interval& _l, const interval& _u)
00084                                         : delta_base("split"), splits()
00085       {
00086         splits.push_back(std::vector<delta>(1,
00087                                 delta(bound_delta(_node_num, _l))));
00088         splits.push_back(std::vector<delta>(1,
00089                                 delta(bound_delta(_node_num, _u))));
00090       }
00091 
00092   split_delta(unsigned int _node_num, const std::vector<interval>& _m)
00093                         : delta_base("split"), splits()
00094       {
00095         for(std::vector<interval>::const_iterator __l = _m.begin();
00096             __l != _m.end(); ++__l)
00097         {
00098           splits.push_back(std::vector<delta>(1,
00099                                 delta(bound_delta(_node_num, *__l))));
00100         }
00101       }
00102 
00103   split_delta(const std::vector<unsigned int>& _i,
00104               const std::vector<interval>& _l, const std::vector<interval>& _u)
00105                         : delta_base("split"), splits()
00106       {
00107         splits.push_back(std::vector<delta>(1,delta(bound_delta(_i, _l))));
00108         splits.push_back(std::vector<delta>(1,delta(bound_delta(_i, _u))));
00109       }
00110 
00111   split_delta(const std::list<std::vector<delta> >& __dl)
00112                         : delta_base("split"), splits(__dl)
00113       {}
00114 
00115   ~split_delta() {}
00116 
00117   split_delta(const split_delta& __s) : delta_base(__s), splits(__s.splits) {}
00118 
00119   split_delta* new_copy() const { return new split_delta(*this); }
00120   void destroy_copy(split_delta* __d) { delete __d; }
00121 
00122   void add_delta(const delta& __d)
00123   {
00124     splits.push_back(std::vector<delta>(1,__d));
00125   }
00126 
00127   void add_deltas(const std::vector<delta>& __d)
00128   {
00129     splits.push_back(__d);
00130   }
00131 
00132   void add_split(unsigned int _nnum, interval _l, interval _u)
00133   {
00134     splits.push_back(std::vector<delta>(1,delta(bound_delta(_nnum, _l))));
00135     splits.push_back(std::vector<delta>(1,delta(bound_delta(_nnum, _u))));
00136   }
00137 
00138   void add_split(const std::vector<unsigned int>& _i,
00139                  const std::vector<interval>& _l,
00140                  const std::vector<interval>& _u)
00141   {
00142     splits.push_back(std::vector<delta>(1,delta(bound_delta(_i, _l))));
00143     splits.push_back(std::vector<delta>(1,delta(bound_delta(_i, _u))));
00144   }
00145 
00146   bool apply(work_node& x, undelta_base*& _u) const
00147   {
00148     work_node::transaction_number se(x.get_transaction_number());
00149     x.proposed_splits.insert(std::make_pair(se,splits));
00150     _u = (undelta_base*) new split_undelta(se);
00151     return true;
00152   }
00153 };
00154 
00155 #endif /* _SPLIT_DELTA_H_ */

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