pl_search_cpp 1.4
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Friends | List of all members
pl_search::Term Class Referenceabstract

Abstract base class for terms that approximate Prolog terms. More...

#include <term.hpp>

Inheritance diagram for pl_search::Term:
Inheritance graph
[legend]
Collaboration diagram for pl_search::Term:
Collaboration graph
[legend]

Public Member Functions

virtual TermPtr dereference ()
 Dereferences the term. The default is to return a shared pointer to term itself.
 
virtual std::string repr () const
 Returns a string representation of the term.
 
virtual bool isLessThan (Term &t) const =0
 Checks if the term is less than another term.
 
virtual bool unifyWith (Engine *engine, TermPtr t)
 A hook for unification of user-defined classes. Only override this method if you want to unify user-defined classes.
 
virtual bool is_var ()
 Checks if the term is a variable.
 
 Term ()
 Default constructor.
 
virtual ~Term ()
 Virtual destructor for proper cleanup.
 

Protected Member Functions

virtual bool isEqualTo (Term &t) const =0
 Checks if the term is equal to another term.
 
virtual Termderef_term ()
 Similar to dereference but returning the "raw" pointer.
 

Friends

std::ostream & operator<< (std::ostream &os, const Term &t)
 Overloaded output stream operator for Term.
 
bool operator< (Term &t1, Term &t2)
 < operator for Terms.
 
bool operator<= (Term &t1, Term &t2)
 <= operator for Term
 
bool operator== (Term &t1, Term &t2)
 == operator for Terms
 

Detailed Description

Abstract base class for terms that approximate Prolog terms.

The Term class provides an interface for Prolog-like terms. It includes methods for dereferencing, binding, resetting, and representing terms as strings. It also includes methods for comparing terms and unifying user-defined classes.

Constructor & Destructor Documentation

◆ Term()

pl_search::Term::Term ( )
inline

Default constructor.

◆ ~Term()

virtual pl_search::Term::~Term ( )
inlinevirtual

Virtual destructor for proper cleanup.

Member Function Documentation

◆ deref_term()

virtual Term * pl_search::Term::deref_term ( )
inlineprotectedvirtual

Similar to dereference but returning the "raw" pointer.

Returns
A pointer to the dereferenced term. WARNING: This should only be used for testing as it returns the raw pointer of a shared_ptr.

Reimplemented in pl_search::PVar, and pl_search::UpdatablePVar.

◆ dereference()

virtual TermPtr pl_search::Term::dereference ( )
inlinevirtual

Dereferences the term. The default is to return a shared pointer to term itself.

Returns
A shared pointer to the dereferenced term.

Reimplemented in pl_search::PVar, and pl_search::UpdatablePVar.

◆ is_var()

virtual bool pl_search::Term::is_var ( )
inlinevirtual

Checks if the term is a variable.

Returns
True if the term is a variable, false otherwise.

Reimplemented in pl_search::PVar.

◆ isEqualTo()

virtual bool pl_search::Term::isEqualTo ( Term t) const
protectedpure virtual

Checks if the term is equal to another term.

Parameters
tThe term to compare to.
Returns
True if the terms are equal, false otherwise.

Implemented in pl_search::CList, pl_search::PVar, pl_search::PAtom, pl_search::PFloat, and pl_search::PInt.

◆ isLessThan()

virtual bool pl_search::Term::isLessThan ( Term t) const
pure virtual

Checks if the term is less than another term.

Parameters
tThe term to compare to.
Returns
True if the term is less than the other term, false otherwise.

Implemented in pl_search::CList, pl_search::PVar, pl_search::PAtom, pl_search::PFloat, and pl_search::PInt.

◆ repr()

virtual std::string pl_search::Term::repr ( ) const
inlinevirtual

Returns a string representation of the term.

Returns
A string representation of the term.

Reimplemented in pl_search::CList, pl_search::PAtom, pl_search::PFloat, pl_search::PInt, and pl_search::PVar.

◆ unifyWith()

virtual bool pl_search::Term::unifyWith ( Engine engine,
TermPtr  t 
)
inlinevirtual

A hook for unification of user-defined classes. Only override this method if you want to unify user-defined classes.

Parameters
enginePointer to the Engine.
tThe term to unify with.
Returns
True if the unification is successful, false otherwise.

Friends And Related Symbol Documentation

◆ operator<

bool operator< ( Term t1,
Term t2 
)
friend

< operator for Terms.

Approximates the @< operator in Prolog. The ordering is as follows:

  • pvar < pint, pfloat < patom < clist < user-defined classes;
  • "older" vars are less than "newer" vars;
  • patoms are ordered by name;
  • pints and pfloats are ordered by value;
  • clists are ordered by the first element, then the second, etc.
Parameters
t1The first term.
t2The second term.
Returns
True if the first term is less than the second term, false otherwise.
Parameters
t1The first term.
t2The second term.
Returns
True if the first term is less than the second term, false otherwise.

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Term t 
)
friend

Overloaded output stream operator for Term.

Parameters
osThe output stream.
tThe term to output.
Returns
The output stream.

◆ operator<=

bool operator<= ( Term t1,
Term t2 
)
friend

<= operator for Term

Parameters
t1The first term.
t2The second term.
Returns
True if the first term is less than or equal to the second term, false otherwise.

◆ operator==

bool operator== ( Term t1,
Term t2 
)
friend

== operator for Terms

Parameters
t1The first term.
t2The second term.
Returns
True if the terms are equal using the appropriate isEqualTo method, false otherwise.
Parameters
t1The first term.
t2The second term.
Returns
True if the terms are equal using the isEqualTo method, false otherwise.

The documentation for this class was generated from the following file: