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