pl_search_cpp 1.4
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
pl_search::PVar Class Reference

Represents a Prolog variable. More...

#include <pvar.hpp>

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

Public Member Functions

 PVar ()
 Constructs a PVar.
 
TermPtr dereference () override
 Dereferences the variable to find the actual term it points to.
 
virtual bool bind (const TermPtr &t)
 Binds the variable to a term.
 
void reset (const TermPtr &t)
 Resets the variable to point at the supplied term.
 
bool is_var () override
 Checks if the term is a variable.
 
bool isLessThan (Term &other) const override
 Checks if the variable is less than another term.
 
int getVarId () const
 Returns the variable ID.
 
std::string repr () const override
 Returns a string representation of the term.
 
- Public Member Functions inherited from pl_search::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.
 
 Term ()
 Default constructor.
 
virtual ~Term ()
 Virtual destructor for proper cleanup.
 

Public Attributes

TermPtr value
 The value of the variable.
 

Static Public Attributes

static int id = 0
 Static member to generate unique IDs for variables.
 

Protected Member Functions

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

Protected Attributes

int var_id
 The ID of the variable.
 

Detailed Description

Represents a Prolog variable.

PVar objects approximate Prolog variables. Variables can be bound to other terms. An unbound variable is represented by a PVar object with a null value.

Constructor & Destructor Documentation

◆ PVar()

pl_search::PVar::PVar ( )
inline

Constructs a PVar.

Member Function Documentation

◆ bind()

bool pl_search::PVar::bind ( const TermPtr t)
virtual

Binds the variable to a term.

Parameters
tThe term to bind to.
Returns
True if the binding is successful, false otherwise. Precondition: t has been dereferenced before the call (bind is only called from unify)

◆ deref_term()

Term * pl_search::PVar::deref_term ( )
overrideprotectedvirtual

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 from pl_search::Term.

Reimplemented in pl_search::UpdatablePVar.

◆ dereference()

TermPtr pl_search::PVar::dereference ( )
overridevirtual

Dereferences the variable to find the actual term it points to.

Returns
A pointer to the dereferenced term.

Reimplemented from pl_search::Term.

Reimplemented in pl_search::UpdatablePVar.

◆ getVarId()

int pl_search::PVar::getVarId ( ) const
inline

Returns the variable ID.

Returns
The variable ID.

◆ is_var()

bool pl_search::PVar::is_var ( )
overridevirtual

Checks if the term is a variable.

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

Reimplemented from pl_search::Term.

◆ isEqualTo()

virtual bool pl_search::PVar::isEqualTo ( Term t) const
inlineoverrideprotectedvirtual

Checks if the term is equal to another term.

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

Implements pl_search::Term.

◆ isLessThan()

bool pl_search::PVar::isLessThan ( Term t) const
overridevirtual

Checks if the variable is less than another term.

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

Implements pl_search::Term.

◆ repr()

std::string pl_search::PVar::repr ( ) const
inlineoverridevirtual

Returns a string representation of the term.

Returns
A string representation of the term.

Reimplemented from pl_search::Term.

◆ reset()

void pl_search::PVar::reset ( const TermPtr t)

Resets the variable to point at the supplied term.

Parameters
tThe term to reset to.

Member Data Documentation

◆ id

int pl_search::PVar::id = 0
static

Static member to generate unique IDs for variables.

◆ value

TermPtr pl_search::PVar::value

The value of the variable.

◆ var_id

int pl_search::PVar::var_id
protected

The ID of the variable.


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