#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Logic/Base/Or.hh" // This file is part of RAVL, Recognition And Vision Library // Copyright (C) 2001, University of Surrey // This code may be redistributed under the terms of the GNU Lesser // General Public License (LGPL). See the lgpl.licence file for details or // see http://www.gnu.org/copyleft/lesser.html // file-header-ends-here #ifndef RAVLLOGIC_OR_HEADER #define RAVLLOGIC_OR_HEADER 1 /////////////////////////////////////////////////////////////// //! rcsid="$Id: Or.hh,v 1.12 2002/05/25 19:27:16 craftit Exp $" //! docentry="Ravl.Logic.Condition" //! author="Charles Galambos" //! lib=RavlLogic //! file="Ravl/Logic/Base/Or.hh" #include "Ravl/Logic/Condition.hh" #include "Ravl/HSet.hh" namespace RavlLogicN { //! userlevel=Develop //: Coniditional Or. class OrBodyC : public ConditionBodyC { public: OrBodyC(); //: Default constructor. OrBodyC(const SArray1dC &nterms,bool useArrayDirectly = false); //: Constructor. // If useArrayDirectly is true then use the array directly, the first // element must be literalOr. OrBodyC(const LiteralC &term); //: Constructor. SArray1dC &Terms() { return args; } //: Access set of terms. const SArray1dC &Terms() const { return args; } //: Access set of terms. virtual bool Unify(const LiteralC &oth,BindSetC &bs) const; //: Unify with another variable. SizeT Size() const { return args.Size()-1; } //: Numnber of terms in or. virtual LiteralIterC Solutions(const StateC &state,BindSetC &binds) const; //: Return iterator through possibile matches to this literal in 'state', if any. void OrAdd(const LiteralC &lit); //: Add literal. void OrAdd(const SArray1dC &lits); //: Add literals. virtual bool Substitute(const BindSetC &binds,LiteralC &result) const; //: Substitute variables in 'binds' for their bound values. // This builds a new literal with the substute values (if there // are any). The new value is assigned to 'result'

// Returns true if at least one substitution has been made, // false if none. }; //! userlevel=Normal //: Or a set of conditions. class OrC : public ConditionC { public: OrC() {} //: Default constructor. // creates an invalid handle. OrC(bool) : ConditionC(*new OrBodyC()) {} //: Constructor from a single term. OrC(const SArray1dC &nterms,bool useArrayDirectly = false) : ConditionC(*new OrBodyC(nterms,useArrayDirectly)) {} //: Construct from an array of Literals. // If useArrayDirectly is true then use the array directly, the first // element must be literalOr. protected: OrC(OrBodyC &bod) : ConditionC(bod) {} //: Body constructor. OrBodyC &Body() { return static_cast(LiteralC::Body()); } //: Access body. const OrBodyC &Body() const { return static_cast(LiteralC::Body()); } //: Access body. public: OrC(const LiteralC &term) : ConditionC(term) { if(!IsValid()) return ; if(dynamic_cast(&LiteralC::Body()) == 0) Invalidate(); } //: Construct from base class. OrC(bool add,const LiteralC &term) : ConditionC(*new OrBodyC(term)) {} //: Construct from term. SArray1dC &Terms() { return Body().Terms(); } //: Access set of terms. const SArray1dC &Terms() const { return Body().Terms(); } //: Access set of terms. SizeT Size() const { return Body().Size(); } //: Numnber of terms in or. void OrAdd(const LiteralC &lit) { Body().OrAdd(lit); } //: Add literal. void OrAdd(const SArray1dC &lits) { Body().OrAdd(lits); } //: Add literals. const OrC &operator+=(const LiteralC &lit) { OrAdd(lit); return *this; } //: Add literal. friend class OrBodyC; }; TupleC operator+(const LiteralC &l1,const LiteralC &l2); //: Or two literals. extern LiteralC literalOr; } #endif