dlvhex  2.5.0
vs10/term.h
Go to the documentation of this file.
00001 // Copyright (c) 2009, Roland Kaminski <kaminski@cs.uni-potsdam.de>
00002 //
00003 // This file is part of gringo.
00004 //
00005 // gringo is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // gringo is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with gringo.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 #pragma once
00019 
00020 #include <gringo/gringo.h>
00021 #include <gringo/locateable.h>
00022 
00023 class Term : public Locateable
00024 {
00025 public:
00026     typedef std::pair<Term*, TermPtrVec*> Split;
00027     class Ref
00028     {
00029     public:
00030         virtual void reset(Term *a) const = 0;
00031         virtual void replace(Term *a) const = 0;
00032         virtual ~Ref() { }
00033     };
00034     class VecRef : public Ref
00035     {
00036     public:
00037         VecRef(TermPtrVec &vec, TermPtrVec::iterator pos) : vec_(vec), pos_(pos) { }
00038         void reset(Term *a) const { vec_.replace(pos_, a); }
00039         void replace(Term *a) const { vec_.replace(pos_, a).release(); }
00040     private:
00041         TermPtrVec          &vec_;
00042         TermPtrVec::iterator pos_;
00043     };
00044     class PtrRef : public Ref
00045     {
00046     public:
00047         PtrRef(clone_ptr<Term> &ptr) : ptr_(ptr) { }
00048         void reset(Term *a) const { ptr_.reset(a); }
00049         void replace(Term *a) const { ptr_.release(); ptr_.reset(a); }
00050     private:
00051         clone_ptr<Term> &ptr_;
00052     };
00053 public:
00054     Term(const Loc &loc) : Locateable(loc) { }
00055     virtual Val val(Grounder *grounder) const = 0;
00056     virtual Split split() { return Split( (Term*)0, (TermPtrVec*)0); }
00057     virtual void normalize(Lit *parent, const Ref &ref, Grounder *g, Expander *expander, bool unify) = 0;
00058     virtual bool unify(Grounder *grounder, const Val &v, int binder) const = 0;
00059     virtual void vars(VarSet &v) const = 0;
00060     virtual void visit(PrgVisitor *visitor, bool bind) = 0;
00061     virtual bool constant() const = 0;
00062     virtual void print(Storage *sto, std::ostream &out) const = 0;
00063     virtual Term *clone() const = 0;
00064     virtual ~Term() { }
00065 };
00066 
00067 namespace boost
00068 {
00069     template <>
00070     inline Term* new_clone(const Term& a)
00071     {
00072         return a.clone();
00073     }
00074 }