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

Represents the equivalent of Prolog if-then-else i.e. (G1 -> G2; G3) - similar to (G1, !, G2; G3) More...

#include <pred.hpp>

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

Public Member Functions

 IfThenElse (Trail *trail, PredPtr if_pred, PredPtr then_pred, PredPtr else_pred)
 The equlvalent of the Prolog call (If -> Then ; Else)
 
void set_continuation (PredPtr cont) override
 Sets the continuation for the then and else predicates to the given continuation which will be the continuation of the IfThenElse predicate.
 
bool call () override
 
- Public Member Functions inherited from pl_search::Pred
 Pred (Trail *trail)
 Default constructor.
 
PredPtr get_continuation ()
 Gets the continuation of the predicate.
 
PredPtr last_pred ()
 Follows the continuation chain to the last predicate.
 
bool call_continuation ()
 Calls the continuation of the predicate.
 
virtual ~Pred ()=default
 Virtual destructor for proper cleanup.
 
virtual std::string get_name ()
 For debugging.
 

Protected Attributes

PredPtr if_pred
 
PredPtr then_pred
 
PredPtr else_pred
 
- Protected Attributes inherited from pl_search::Pred
PredPtr continuation
 The continuation of the predicate.
 
Trailtrail
 Pointer to the trail for managing variable bindings.
 

Detailed Description

Represents the equivalent of Prolog if-then-else i.e. (G1 -> G2; G3) - similar to (G1, !, G2; G3)

The IfThenElse meta-predicate is used to implement the equivalent of Prolog's if-then-else construct. If the guard predicate G1 succeeds then the then predicate G2 is called and any variable bindings made by G1 are preserved but any choice points made by G1 are removed. If G2 or the continuation fails then the IfThenElse predicate fails and any variable bindings made by G1 and G2 are undone. If G1 fails then the else predicate G3 is called and any variable bindings made by G1 are undone. If G3 or the continuation fails then the IfThenElse predicate fails. Note that G1 is a local call - i.e. its continuation is not related to the continuation of the IfThenElse predicate. Also note that the continuations of G2 and G3 are set to the continuation of the IfThenElse predicate. )

Constructor & Destructor Documentation

◆ IfThenElse()

pl_search::IfThenElse::IfThenElse ( Trail eng,
PredPtr  if_pred,
PredPtr  then_pred,
PredPtr  else_pred 
)

The equlvalent of the Prolog call (If -> Then ; Else)

Parameters
trailPointer to the trail
if_predThe guard predicate
then_predThe then predicate
else_predThe else predicate
engPointer to the trail
if_predThe guard predicate
then_predThe then predicate
else_predThe else predicate

Member Function Documentation

◆ call()

bool pl_search::IfThenElse::call ( )
overridevirtual

Reimplemented from pl_search::Pred.

◆ set_continuation()

void pl_search::IfThenElse::set_continuation ( PredPtr  cont)
overridevirtual

Sets the continuation for the then and else predicates to the given continuation which will be the continuation of the IfThenElse predicate.

Parameters
contA shared pointer to the continuation predicate.

As with DisjPred the continuations of the then and else predicates are set to the continuation of the IfThenElse predicate.

Reimplemented from pl_search::Pred.

Member Data Documentation

◆ else_pred

PredPtr pl_search::IfThenElse::else_pred
protected

◆ if_pred

PredPtr pl_search::IfThenElse::if_pred
protected

◆ then_pred

PredPtr pl_search::IfThenElse::then_pred
protected

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