|
dlvhex
2.1.0
|
00001 /* dlvhex -- Answer-Set Programming with external interfaces. 00002 * Copyright (C) 2005, 2006, 2007 Roman Schindlauer 00003 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Thomas Krennwallner 00004 * Copyright (C) 2009, 2010 Peter Schüller 00005 * 00006 * This file is part of dlvhex. 00007 * 00008 * dlvhex is free software; you can redistribute it and/or modify it 00009 * under the terms of the GNU Lesser General Public License as 00010 * published by the Free Software Foundation; either version 2.1 of 00011 * the License, or (at your option) any later version. 00012 * 00013 * dlvhex is distributed in the hope that it will be useful, but 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with dlvhex; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00021 * 02110-1301 USA. 00022 */ 00023 00024 00035 #ifdef HAVE_CONFIG_H 00036 #include "config.h" 00037 #endif // HAVE_CONFIG_H 00038 00039 #include "dlvhex2/Literal.h" 00040 #include "dlvhex2/BaseVisitor.h" 00041 #include "dlvhex2/PrintVisitor.h" 00042 00043 DLVHEX_NAMESPACE_BEGIN 00044 00045 Literal::Literal() 00046 { } 00047 00048 00049 Literal::~Literal() 00050 { 00051 } 00052 00053 00054 Literal& 00055 Literal::operator=(const Literal& lit2) 00056 { 00057 this->isWeaklyNegated = lit2.isWeaklyNegated; 00058 00059 const_cast<AtomPtr&>(this->atom) = lit2.atom; 00060 00061 return *this; 00062 } 00063 00064 Literal::Literal(const AtomPtr at, bool naf) 00065 : atom(at), 00066 isWeaklyNegated(naf) 00067 { 00068 } 00069 00070 00071 const AtomPtr 00072 Literal::getAtom() const 00073 { 00074 return atom; 00075 } 00076 00077 00078 bool 00079 Literal::isNAF() const 00080 { 00081 return isWeaklyNegated; 00082 } 00083 00084 bool 00085 Literal::isHigherOrder() const 00086 { 00087 return atom->isHigherOrder(); 00088 } 00089 00090 00091 bool 00092 Literal::operator== (const Literal& lit2) const 00093 { 00094 if (!(*atom == *(lit2.getAtom()))) 00095 return 0; 00096 00097 if (isWeaklyNegated != lit2.isNAF()) 00098 return 0; 00099 00100 return 1; 00101 } 00102 00103 00104 bool 00105 Literal::operator!= (const Literal& lit2) const 00106 { 00107 return !(*this == lit2); 00108 } 00109 00110 00111 bool 00112 Literal::operator< (const Literal& lit2) const 00113 { 00114 if (!this->isNAF() && lit2.isNAF()) 00115 return 1; 00116 if (this->isNAF() && !lit2.isNAF()) 00117 return 0; 00118 00119 return (this->getAtom() < lit2.getAtom()); 00120 } 00121 00122 00123 void 00124 Literal::accept(BaseVisitor& v) const 00125 { 00126 v.visit(this); 00127 } 00128 00129 00130 std::ostream& 00131 operator<<(std::ostream& o, const Literal& l) 00132 { 00133 RawPrintVisitor rpv(o); 00134 const_cast<Literal*>(&l)->accept(rpv); 00135 return o; 00136 } 00137 00138 00139 bool 00140 operator< (const RuleBody_t& body1, const RuleBody_t& body2) 00141 { 00142 return std::lexicographical_compare(body1.begin(), body1.end(), 00143 body2.begin(), body2.end()); 00144 } 00145 00146 DLVHEX_NAMESPACE_END 00147 00148 // Local Variables: 00149 // mode: C++ 00150 // End: