pl_search_cpp 1.4
Loading...
Searching...
No Matches
term.hpp
Go to the documentation of this file.
1/*
2MIT License
3
4Copyright (c) 2025 [Peter Robinson]
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
24
25#ifndef PL_SEARCH_TERM_HPP
26#define PL_SEARCH_TERM_HPP
27
28#include <iostream>
29#include <string>
30
31#include "typedefs.hpp"
32
38namespace pl_search {
39
40class Engine;
41
50class Term : public std::enable_shared_from_this<Term> {
51protected:
57 virtual bool isEqualTo(Term &t) const = 0;
58
65 virtual Term *deref_term() { return this; }
66
67public:
73 virtual TermPtr dereference() { return shared_from_this(); };
74
79 virtual std::string repr() const { return "TERM"; }
80
86 virtual bool isLessThan(Term &t) const = 0;
87
95 virtual bool unifyWith(Engine *engine, TermPtr t) { return false; }
96
101 virtual bool is_var() { return false; }
102
106 Term() {}
107
111 virtual ~Term() {} // Virtual destructor
112
119 friend std::ostream &operator<<(std::ostream &os, const Term &t) {
120 os << t.repr();
121 return os;
122 }
123
140 friend bool operator<(Term &t1, Term &t2);
141
149 friend bool operator<=(Term &t1, Term &t2);
150
158 friend bool operator==(Term &t1, Term &t2);
159};
160
161} // namespace pl_search
162
163#endif // PL_SEARCH_TERM_HPP
The Engine class manages the execution of predicates and backtracking.
Definition engine.hpp:69
Abstract base class for terms that approximate Prolog terms.
Definition term.hpp:50
friend bool operator<=(Term &t1, Term &t2)
<= operator for Term
Definition term.cpp:77
friend bool operator<(Term &t1, Term &t2)
< operator for Terms.
Definition term.cpp:66
virtual Term * deref_term()
Similar to dereference but returning the "raw" pointer.
Definition term.hpp:65
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-d...
Definition term.hpp:95
friend std::ostream & operator<<(std::ostream &os, const Term &t)
Overloaded output stream operator for Term.
Definition term.hpp:119
virtual ~Term()
Virtual destructor for proper cleanup.
Definition term.hpp:111
virtual bool is_var()
Checks if the term is a variable.
Definition term.hpp:101
virtual bool isEqualTo(Term &t) const =0
Checks if the term is equal to another term.
Term()
Default constructor.
Definition term.hpp:106
friend bool operator==(Term &t1, Term &t2)
== operator for Terms
Definition term.cpp:47
virtual TermPtr dereference()
Dereferences the term. The default is to return a shared pointer to term itself.
Definition term.hpp:73
virtual bool isLessThan(Term &t) const =0
Checks if the term is less than another term.
virtual std::string repr() const
Returns a string representation of the term.
Definition term.hpp:79
Definition choice_iterator.hpp:16
std::shared_ptr< Term > TermPtr
Typedefs for shared pointers to Terms and subclasses.
Definition typedefs.hpp:43
Definition of common typedefs used in the pl_search library.