00001 /************************************************************************* 00002 00003 Copyright Rice University, 2004. 00004 All rights reserved. 00005 00006 Permission is hereby granted, free of charge, to any person obtaining a 00007 copy of this software and associated documentation files (the "Software"), 00008 to deal in the Software without restriction, including without limitation 00009 the rights to use, copy, modify, merge, publish, distribute, and/or sell 00010 copies of the Software, and to permit persons to whom the Software is 00011 furnished to do so, provided that the above copyright notice(s) and this 00012 permission notice appear in all copies of the Software and that both the 00013 above copyright notice(s) and this permission notice appear in supporting 00014 documentation. 00015 00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY 00019 RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS 00020 NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL 00021 DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 00022 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 00023 ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 00024 THIS SOFTWARE. 00025 00026 Except as contained in this notice, the name of a copyright holder shall 00027 not be used in advertising or otherwise to promote the sale, use or other 00028 dealings in this Software without prior written authorization of the 00029 copyright holder. 00030 00031 **************************************************************************/ 00032 00033 #ifndef __RVLALG_BOOL_TERMINATOR 00034 #define __RVLALG_BOOL_TERMINATOR 00035 00036 #include "alg.hh" 00037 00043 namespace RVLAlg { 00044 00046 class BoolTerminator: public Terminator { 00047 private: 00048 bool & ans; 00049 public: 00050 BoolTerminator(bool & _ans): ans(_ans) {} 00051 BoolTerminator(BoolTerminator & bt): ans(bt.ans) {} 00052 ~BoolTerminator() {} 00053 bool query() { return ans; } 00054 }; 00055 00078 class AndTerminator: public Terminator { 00079 public: 00080 00081 AndTerminator( Terminator &a, Terminator &b): first(a), second(b){} 00082 ~AndTerminator() {} 00083 00084 virtual bool query() { 00085 return (first.query() && second.query()); 00086 } 00087 00088 protected: 00089 Terminator & first; 00090 Terminator & second; 00091 00092 }; 00093 00100 class OrTerminator: public Terminator { 00101 public: 00102 00103 OrTerminator( Terminator &a, Terminator &b): first(a), second(b){} 00104 ~OrTerminator() {} 00105 00106 virtual bool query() { 00107 return (first.query() || second.query()); 00108 } 00109 00110 protected: 00111 Terminator & first; 00112 Terminator & second; 00113 }; 00114 00118 class NotTerminator: public Terminator { 00119 public: 00120 00121 NotTerminator( Terminator &a): first(a){} 00122 ~NotTerminator() {} 00123 00124 virtual bool query() { 00125 return (!first.query()); 00126 } 00127 00128 protected: 00129 Terminator & first; 00130 }; 00131 00138 class XorTerminator: public Terminator { 00139 public: 00140 00141 XorTerminator( Terminator &a, Terminator &b): first(a), second(b){} 00142 ~XorTerminator() {} 00143 00144 virtual bool query() { 00145 bool A = first.query(); 00146 bool B = second.query(); 00147 00148 return ((A || B) && (!(A && B))); 00149 } 00150 00151 protected: 00152 Terminator & first; 00153 Terminator & second; 00154 }; 00155 00156 } 00157 00158 #endif