00001 // Infeasible Delta implementation -*- C++ -*- 00002 00003 // $Id: infeasible_delta.h 631 2008-05-19 17:38:05Z mihaly $ 00004 // Copyright (C) 2001-2003 Hermann Schichl 00005 // 00006 // This file is part of the COCONUT API. This library 00007 // is free software; you can redistribute it and/or modify it under the 00008 // terms of the Library GNU General Public License as published by the 00009 // Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // Library GNU General Public License for more details. 00016 00017 // As a special exception, you may use this file as part of a free software 00018 // library without restriction. Specifically, if other files instantiate 00019 // templates or use macros or inline functions from this file, or you compile 00020 // this file and link it with other files to produce an executable, this 00021 // file does not by itself cause the resulting executable to be covered by 00022 // the Library GNU General Public License. This exception does not however 00023 // invalidate any other reasons why the executable file might be covered by 00024 // the Library GNU General Public License. 00025 00028 #ifndef _INFEASIBLE_DELTA_H_ 00029 #define _INFEASIBLE_DELTA_H_ 00030 00031 #include <api_delta.h> 00032 00033 namespace coco { 00034 00036 00041 class infeasible_undelta : public undelta_base 00042 { 00043 private: 00046 bool old_infeasible; 00047 00048 public: 00050 infeasible_undelta(bool _oi = false) : undelta_base(), old_infeasible(_oi) {} 00052 infeasible_undelta(const infeasible_undelta& __d) : undelta_base(__d), 00053 old_infeasible(__d.old_infeasible) 00054 { 00055 #if DEBUG_DELTA 00056 std::cerr << "Called infeasible_undelta copy constructor" << std::endl; 00057 #endif 00058 } 00059 00061 ~infeasible_undelta() {} 00062 00064 infeasible_undelta* new_copy() const { return new infeasible_undelta(*this); } 00066 void destroy_copy(undelta_base* __d) const { delete (infeasible_undelta*)__d; } 00067 00069 bool unapply(work_node& _x, const delta_id& _did) const 00070 { 00071 _x.infeasible = old_infeasible; 00072 return true; 00073 } 00074 }; 00075 00077 00081 class infeasible_delta : public delta_base 00082 { 00083 public: 00085 infeasible_delta() : delta_base("infeasible") {} 00087 infeasible_delta(const infeasible_delta& __d) : delta_base(__d) 00088 { 00089 #if DEBUG_DELTA 00090 std::cerr << "Called infeasible_delta copy constructor" << std::endl; 00091 #endif 00092 } 00093 00095 ~infeasible_delta() {} 00096 00098 infeasible_delta* new_copy() const { return new infeasible_delta(*this); } 00100 void destroy_copy(delta_base* __d) const { delete (infeasible_delta*)__d; } 00101 00104 bool apply(work_node& _x, undelta_base*& _u, const delta_id& _did) const 00105 { 00106 _u = (undelta_base *) new infeasible_undelta(_x.infeasible); 00107 _x.infeasible = true; 00108 return true; 00109 } 00110 00112 bool operator==(const delta_base& _c) const 00113 { return _c.get_action() == get_action() && 00114 this->operator==(*(infeasible_delta*)&_c); } 00115 bool operator!=(const delta_base& _c) const 00116 { return _c.get_action() != get_action() || 00117 this->operator!=(*(infeasible_delta*)&_c); } 00118 00120 bool operator==(const infeasible_delta& _c) const { return true; } 00121 bool operator!=(const infeasible_delta& _c) const { return false; } 00122 }; 00123 00124 } // namespace coco 00125 00126 #endif /* _INFEASIBLE_DELTA_H_ */