pl_search_cpp 1.8
Loading...
Searching...
No Matches
choice_iterator.hpp
Go to the documentation of this file.
1/*
2MIT License
3
4...license text...
5
6*/
7
8#ifndef PL_SEARCH_CHOICE_ITERATOR_HPP
9#define PL_SEARCH_CHOICE_ITERATOR_HPP
10
11#include "trail.hpp"
12#include "typedefs.hpp"
13
14#include <vector>
15
16namespace pl_search {
17 class Trail;
18 class PVar;
19
24 public:
29 virtual bool has_next() = 0;
30
35 virtual bool make_choice() = 0;
36
42 virtual bool test_choice() { return true; }
43
47 virtual ~ChoiceIterator() = default;
48 };
49
54 public:
61 VarChoiceIterator(Trail* trail, PVarPtr v, std::vector<TermPtr> ch)
62 : trail(trail), var(v), choices(ch), index(0) {
63 }
64
69 bool has_next() override { return index < choices.size(); }
70
76 virtual bool make_choice() override {
77 TermPtr t = choices[index++];
78 return unify(var, t, trail) && test_choice();
79 }
80
81 protected:
83 int index;
85 std::vector<TermPtr> choices;
86 };
87
88} // namespace pl_search
89
90#endif // PL_SEARCH_CHOICE_ITERATOR_HPP
Base class for choice iterators.
Definition choice_iterator.hpp:23
virtual bool test_choice()
Tests a choice which would tyically involve constraint deductions based on the choice.
Definition choice_iterator.hpp:42
virtual bool has_next()=0
Checks if there are more choices available.
virtual ~ChoiceIterator()=default
Virtual destructor for proper cleanup.
virtual bool make_choice()=0
Makes a choice.
Represents a Prolog variable.
Definition pvar.hpp:44
Definition trail.hpp:51
Choice iterator for variables.
Definition choice_iterator.hpp:53
virtual bool make_choice() override
Makes a choice.
Definition choice_iterator.hpp:76
VarChoiceIterator(Trail *trail, PVarPtr v, std::vector< TermPtr > ch)
Constructs a VarChoiceIterator.
Definition choice_iterator.hpp:61
std::vector< TermPtr > choices
Reference to the vector of choices.
Definition choice_iterator.hpp:85
int index
Current index in the choices vector.
Definition choice_iterator.hpp:83
PVarPtr var
Pointer to the variable.
Definition choice_iterator.hpp:84
Trail * trail
Pointer to the Trail.
Definition choice_iterator.hpp:82
bool has_next() override
Checks if there are more choices available.
Definition choice_iterator.hpp:69
Definition choice_iterator.hpp:16
bool unify(TermPtr t1, TermPtr t2, Trail *trail)
Unifies two terms.
Definition term.cpp:165
std::shared_ptr< PVar > PVarPtr
Definition typedefs.hpp:45
std::shared_ptr< Term > TermPtr
Typedefs for shared pointers to Terms and subclasses.
Definition typedefs.hpp:44
Definition of the binding trail.
Definition of common typedefs used in the pl_search library.