#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Logic/Base/And.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_AND_HEADER #define RAVLLOGIC_AND_HEADER 1 /////////////////////////////////////////////////////////////// //! rcsid="$Id: And.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/And.hh" #include "Ravl/Logic/Condition.hh" namespace RavlLogicN { //! userlevel=Develop //: And a set of conditions. class AndBodyC : public ConditionBodyC { public: AndBodyC(); //: Default constructor. AndBodyC(UIntT arity); //: Create an and term with 'arity' elements. AndBodyC(const SArray1dC &set,bool useArrayDirectly = false); //: Constructor. // If useArrayDirectly is true then use the array directly, the first // element must be literalAnd. 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; } //: Get the number of terms to be anded together. virtual LiteralIterC Solutions(const StateC &state,BindSetC &binds) const; //: Return iterator through possibile matches to this literal in 'state', if any. 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. void AndAdd(const LiteralC &lit); //: Add literal. void AndAdd(const SArray1dC &lits); //: Add literals. }; //! userlevel=Normal //: And a set of conditions. class AndC : public ConditionC { public: AndC() {} //: Default constructor. // creates an invalid handle. AndC(const SArray1dC &set,bool useArrayDirectly = false) : ConditionC(*new AndBodyC(set,useArrayDirectly)) {} //: Constructor from a single term. // If useArrayDirectly is true then use the array directly, the first // element must be literalAnd. AndC(bool) : ConditionC(*new AndBodyC()) {} //: Constructor. protected: AndC(AndBodyC &bod) : ConditionC(bod) {} //: Body constructor. AndBodyC &Body() { return static_cast(LiteralC::Body()); } //: Access body. const AndBodyC &Body() const { return static_cast(LiteralC::Body()); } //: Access body. public: AndC(const LiteralC &term) : ConditionC(term) { if(!IsValid()) return ; if(dynamic_cast(&LiteralC::Body()) == 0) Invalidate(); } //: Construct from base class. 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(); } //: Get the number of terms to be anded together. void AndAdd(const LiteralC &lit) { Body().AndAdd(lit); } //: Add literal. void AndAdd(const SArray1dC &lits) { Body().AndAdd(lits); } //: Add literals. const AndC &operator*=(const LiteralC &lit) { AndAdd(lit); return *this; } //: Add some terms. const AndC &operator*=(const SArray1dC &lits) { AndAdd(lits); return *this; } //: Add some terms. friend class AndBodyC; }; TupleC operator*(const LiteralC &l1,const LiteralC &l2); //: And operator. extern LiteralC literalAnd; } #endif