pl_search_cpp 1.4
Loading...
Searching...
No Matches
pint.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_PINT_HPP
26#define PL_SEARCH_PINT_HPP
27
28#include "term.hpp"
29#include "typedefs.hpp"
30
31#include <string>
32#include <typeinfo>
33
39namespace pl_search {
40
47class PInt : public Term {
48public:
53 PInt(int value) : value(value) {}
54
59 std::string repr() const override { return std::to_string(value); }
60
66 bool isEqualTo(Term &t) const override {
67 PInt *i = dynamic_cast<PInt *>(&t);
68 if (i == nullptr)
69 return false;
70 return value == i->value;
71 }
72
78 bool isLessThan(Term &t) const override;
79
84 int getValue() const { return value; }
85
86protected:
87 int value;
88};
89
90} // namespace pl_search
91
92#endif // PL_SEARCH_PINT_HPP
Represents a Prolog integer.
Definition pint.hpp:47
bool isLessThan(Term &t) const override
< operator for a PInt and a Term
Definition term.cpp:88
int value
The value of the integer.
Definition pint.hpp:87
int getValue() const
Get the value of the integer.
Definition pint.hpp:84
bool isEqualTo(Term &t) const override
Checks if the term is equal to another term.
Definition pint.hpp:66
PInt(int value)
Constructs a PInt with the given value.
Definition pint.hpp:53
std::string repr() const override
Returns a string representation of the integer.
Definition pint.hpp:59
Abstract base class for terms that approximate Prolog terms.
Definition term.hpp:50
Definition choice_iterator.hpp:16
Definition of the Term class.
Definition of common typedefs used in the pl_search library.