Clingo
Loading...
Searching...
No Matches
literal.hh
1#pragma once
2
3#include <clingo/input/term.hh>
4
5#include <clingo/core/core.hh>
6
7#include <utility>
8
9namespace CppClingo::Input {
10
13
15class Signed {
16 public:
18 explicit Signed(Sign sign) : sign_{sign} {}
20 [[nodiscard]] auto sign() const -> Sign { return sign_; };
21
23 friend auto operator==(Signed const &a, Signed const &b) -> bool = default;
25 friend auto operator<=>(Signed const &a, Signed const &b) -> std::strong_ordering = default;
26
27 private:
28 Sign sign_;
29};
30
32class Unsigned {
34 friend auto operator==(Unsigned const &a, Unsigned const &b) -> bool = default;
36 friend auto operator<=>(Unsigned const &a, Unsigned const &b) -> std::strong_ordering = default;
37};
38
40using Guard = std::pair<Relation, Term>;
43
47class LitBool : public Expression<LitBool> {
48 public:
50 static constexpr auto attributes() {
51 return std::tuple{a_loc = &LitBool::loc_, a_sign = &LitBool::sign_, a_value = &LitBool::value_};
52 }
53
55 explicit LitBool(Location loc, Sign sign, bool value) : loc_{std::move(loc)}, sign_(sign), value_(value) {}
56
58 [[nodiscard]] auto loc() const -> Location const & { return loc_; }
60 [[nodiscard]] auto sign() const -> Sign { return sign_; }
62 [[nodiscard]] auto value() const -> bool { return value_; }
63
64 private:
65 Location loc_;
66 Sign sign_;
67 bool value_;
68};
69
73class LitComparison : public Expression<LitComparison> {
74 public:
76 static constexpr auto attributes() {
77 return std::tuple{a_loc = &LitComparison::loc_, a_sign = &LitComparison::sign_, a_lhs = &LitComparison::lhs_,
78 a_rhs = &LitComparison::rhs_};
79 }
80
83 : loc_{std::move(loc)}, sign_(sign), lhs_(std::move(lhs)), rhs_(std::move(rhs)) {}
84
86 [[nodiscard]] auto loc() const -> Location const & { return loc_; }
88 [[nodiscard]] auto sign() const -> Sign { return sign_; }
90 [[nodiscard]] auto lhs() const -> Term const & { return lhs_; }
92 [[nodiscard]] auto rhs() const -> GuardArray const & { return rhs_; }
93
94 private:
95 Location loc_;
96 Sign sign_;
97 Term lhs_;
98 GuardArray rhs_;
99};
100
104class LitSymbolic : public Expression<LitSymbolic> {
105 public:
107 static constexpr auto attributes() {
108 return std::tuple{a_loc = &LitSymbolic::loc_, a_sign = &LitSymbolic::sign_, a_term = &LitSymbolic::term_};
109 }
110
113 : loc_{std::move(loc)}, sign_(sign), term_(std::move(term)) {}
114
116 [[nodiscard]] auto loc() const -> Location const & { return loc_; }
118 [[nodiscard]] auto sign() const -> Sign { return sign_; }
120 [[nodiscard]] auto term() const -> Term const & { return term_; }
121
122 private:
123 Location loc_;
124 Sign sign_;
125 Term term_;
126};
127
129using Lit = std::variant<LitBool, LitComparison, LitSymbolic>;
130
133
135class CondLit : public Expression<CondLit> {
136 public:
138 static constexpr auto attributes() {
139 return std::tuple{a_loc = &CondLit::loc_, a_lit = &CondLit::lit_, a_cond = &CondLit::cond_};
140 }
141
144 : loc_{std::move(loc)}, lit_{std::move(lit)}, cond_{std::move(cond)} {}
146 [[nodiscard]] auto loc() const -> Location const & { return loc_; }
148 [[nodiscard]] auto lit() const -> Lit const & { return lit_; }
150 [[nodiscard]] auto cond() const -> LitArray const & { return cond_; }
151
152 private:
153 Location loc_;
154 Lit lit_;
155 LitArray cond_;
156};
157
159
160} // namespace CppClingo::Input
A conditional literal.
Definition literal.hh:135
auto cond() const -> LitArray const &
The literals on the right-hand-side.
Definition literal.hh:150
static constexpr auto attributes()
The record attributes.
Definition literal.hh:138
auto lit() const -> Lit const &
The literals on the left-hand-side.
Definition literal.hh:148
CondLit(Location loc, Lit lit, LitArray cond)
Construct a conditional literal.
Definition literal.hh:143
auto loc() const -> Location const &
The location of the literal.
Definition literal.hh:146
A record that friend declares and defines comparison operators.
Definition attributes.hh:60
Literal representing a Boolean constant.
Definition literal.hh:47
auto value() const -> bool
The Boolean value.
Definition literal.hh:62
static constexpr auto attributes()
The record attributes.
Definition literal.hh:50
auto sign() const -> Sign
The sign of the literal.
Definition literal.hh:60
auto loc() const -> Location const &
The location of the literal.
Definition literal.hh:58
LitBool(Location loc, Sign sign, bool value)
Construct a Boolean literal.
Definition literal.hh:55
Literal representing a relation literal.
Definition literal.hh:73
LitComparison(Location loc, Sign sign, Term lhs, GuardArray rhs)
Construct a relation literal.
Definition literal.hh:82
static constexpr auto attributes()
The record attributes.
Definition literal.hh:76
auto loc() const -> Location const &
The location of the literal.
Definition literal.hh:86
auto lhs() const -> Term const &
The term on the left hand side.
Definition literal.hh:90
auto sign() const -> Sign
The sign of the literal.
Definition literal.hh:88
auto rhs() const -> GuardArray const &
The guards on the right hand side.
Definition literal.hh:92
Literal representing a symbolic literal.
Definition literal.hh:104
auto loc() const -> Location const &
The location of the literal.
Definition literal.hh:116
static constexpr auto attributes()
The record attributes.
Definition literal.hh:107
auto term() const -> Term const &
The term representing the atom.
Definition literal.hh:120
LitSymbolic(Location loc, Sign sign, Term term)
Construct a symbolic literal.
Definition literal.hh:112
auto sign() const -> Sign
The sign of the literal.
Definition literal.hh:118
Simple class with a sign.
Definition literal.hh:15
Signed(Sign sign)
Construct with the given sign.
Definition literal.hh:18
friend auto operator==(Signed const &a, Signed const &b) -> bool=default
Compare the signs.
friend auto operator<=>(Signed const &a, Signed const &b) -> std::strong_ordering=default
Compare the signs.
auto sign() const -> Sign
The sign of the class.
Definition literal.hh:20
Simple class without a sign.
Definition literal.hh:32
friend auto operator<=>(Unsigned const &a, Unsigned const &b) -> std::strong_ordering=default
Compare the signs.
friend auto operator==(Unsigned const &a, Unsigned const &b) -> bool=default
Compare the signs.
The Location of an expression in an input source.
Definition location.hh:44
Sign
Enumeration of signs (default negation).
Definition core.hh:16
constexpr auto a_sign
Definition attributes.hh:37
constexpr auto a_cond
Definition attributes.hh:20
constexpr auto a_lhs
Definition attributes.hh:27
constexpr auto a_lit
Definition attributes.hh:28
constexpr auto a_rhs
Definition attributes.hh:36
constexpr auto a_loc
Definition attributes.hh:29
constexpr auto a_term
Definition attributes.hh:41
constexpr auto a_value
Definition attributes.hh:44
std::pair< Relation, Term > Guard
The right-hand-side of a relation atom including the symbol.
Definition literal.hh:40
std::variant< LitBool, LitComparison, LitSymbolic > Lit
Variant holding the different literal types.
Definition literal.hh:129
std::variant< TermVariable, TermSymbol, TermTuple, TermFunction, TermAbs, TermUnary, TermBinary > Term
Variant holding the different term types.
Definition term.hh:45