3#include <clingo/symbol.hh>
5#include <clingo/base.h>
31 return Detail::call<clingo_atom_base_literal>(base_, index_);
38 return Symbol{Detail::call<clingo_atom_base_symbol>(base_, index_),
true};
56 return a.index_ ==
b.index_;
66 return a.index_ <=>
b.index_;
90 using pointer = Detail::ArrowProxy<value_type>;
92 using iterator = Detail::RandomAccessIterator<AtomBase>;
111 if (
auto atom =
Atom{base_, index}; index <
size()) {
114 throw std::out_of_range{
"index out of range"};
122 return Detail::call<clingo_atom_base_find>(base_, *c_cast(&
symbol)) <
size();
131 -> std::optional<mapped_type> {
132 auto index = Detail::call<clingo_atom_base_find>(base_, *c_cast(&
symbol));
149static_assert(std::random_access_iterator<AtomBase::iterator>);
164 return Symbol{Detail::call<clingo_term_base_symbol>(base_, index_),
true};
172 size_t const *
sizes =
nullptr;
177 auto res = std::vector<ProgramLiteralVector>{};
179 for (
size_t i = 0;
i < size; ++
i) {
201 return a.index_ ==
b.index_;
211 return a.index_ <=>
b.index_;
235 using pointer = Detail::ArrowProxy<value_type>;
237 using iterator = Detail::RandomAccessIterator<TermBase>;
254 auto term =
Term{*base_, index};
255 return index <
size() ?
value_type{term.symbol(), term} :
throw std::out_of_range{
"index out of range"};
263 return Detail::call<clingo_term_base_find>(base_, *c_cast(&
symbol)) <
size();
272 -> std::optional<mapped_type> {
273 auto index = Detail::call<clingo_term_base_find>(base_, *c_cast(&
symbol));
290static_assert(std::random_access_iterator<TermBase::iterator>);
317 return static_cast<TheoryTermType>(Detail::call<clingo_theory_base_term_type>(base_, index_));
323 [[
nodiscard]]
auto number()
const ->
int {
return Detail::call<clingo_theory_base_term_number>(base_, index_); }
329 auto [
name, size] = Detail::call<clingo_theory_base_term_name>(base_, index_);
340 return Detail::transform(std::span{args, size}, [
this](
clingo_id_t id) {
return TheoryTerm{*base_,
id}; });
349 return std::string{
bld.str()};
367 return a.index_ ==
b.index_;
377 return a.index_ <=>
b.index_;
415 return std::span{cond, size};
425 return Detail::call<clingo_theory_base_element_condition_id>(base_, index_);
434 return std::string{
bld.str()};
452 return a.index_ ==
b.index_;
462 return a.index_ <=>
b.index_;
483 return TheoryTerm{*base_, Detail::call<clingo_theory_base_atom_term>(base_, index_)};
500 return Detail::call<clingo_theory_base_atom_literal>(base_, index_);
507 auto has_guard = Detail::call<clingo_theory_base_atom_has_guard>(base_, index_);
523 return std::string{
bld.str()};
541 return a.index_ ==
b.index_;
551 return a.index_ <=>
b.index_;
571 using pointer = Detail::ArrowProxy<value_type>;
573 using iterator = Detail::RandomAccessIterator<TheoryBase>;
589 return index <
size() ?
TheoryAtom{*base_, index} :
throw std::out_of_range{
"atom index out of range"};
605static_assert(std::random_access_iterator<TheoryBase::iterator>);
611 using key_type = std::tuple<std::string_view, size_t, bool>;
623 using pointer = Detail::ArrowProxy<value_type>;
625 using iterator = Detail::RandomAccessIterator<Base>;
637 return Detail::call<clingo_base_is_external>(base_, lit);
645 return Detail::call<clingo_base_is_fact>(base_, lit);
653 return Detail::call<clingo_base_is_shown>(base_, lit);
661 return Detail::call<clingo_base_is_fact>(base_, lit);
669 return Detail::call<clingo_base_is_current>(base_, lit);
682 if (index <
size()) {
686 return std::pair{std::tuple{sig.name, sig.arity, sig.is_positive},
AtomBase{
atoms}};
688 throw std::out_of_range{
"index out of range"};
698 return Detail::call<clingo_base_atoms_find>(base_, &
csig,
nullptr);
709 return contains({std::get<0>(sig), std::get<1>(sig),
true});
717 if (
auto sig = sym.signature(); sig) {
718 if (
auto base =
get(*sig)) {
719 return base->contains(sym);
731 -> std::optional<mapped_type> {
746 std::optional<mapped_type>
def = std::nullopt)
const -> std::optional<mapped_type> {
747 return get({std::get<0>(sig), std::get<1>(sig),
true},
def);
756 if (
auto sig = sym.signature(); sig) {
757 if (
auto base =
get(*sig)) {
758 return base->get(sym,
def);
787static_assert(std::random_access_iterator<Base::iterator>);
795template <>
struct hash<Clingo::Atom> {
796 auto operator()(
Clingo::Atom const &x)
const noexcept ->
size_t {
return x.hash(); }
799template <>
struct hash<Clingo::
Term> {
800 auto operator()(
Clingo::Term const &x)
const noexcept ->
size_t {
return x.hash(); }
804 auto operator()(
Clingo::TheoryTerm const &x)
const noexcept ->
size_t {
return x.hash(); }
807template <>
struct hash<Clingo::TheoryElement> {
811template <>
struct hash<Clingo::TheoryAtom> {
812 auto operator()(
Clingo::TheoryAtom const &x)
const noexcept ->
size_t {
return x.hash(); }
An atom base that maps symbols to atoms.
Definition base.hh:75
Detail::ArrowProxy< value_type > pointer
The pointer type.
Definition base.hh:90
std::size_t size_type
The size type.
Definition base.hh:84
auto size() const -> size_type
The size of the atom base.
Definition base.hh:104
value_type reference
The reference type.
Definition base.hh:88
AtomBase(clingo_atom_base_t const *base)
Construct an atom base from its C representation.
Definition base.hh:99
auto at(size_t index) const -> value_type
Get the symbol atom pair at the given index.
Definition base.hh:110
std::pair< key_type, mapped_type > value_type
The value type.
Definition base.hh:82
auto get(key_type const &symbol, std::optional< mapped_type > def=std::nullopt) const -> std::optional< mapped_type >
Get the atom for the given symbol.
Definition base.hh:130
auto contains(key_type const &symbol) const -> bool
Whether the atom base contains the given symbol.
Definition base.hh:121
auto end() const -> iterator
Get an iterator pointing to the end of the atom base.
Definition base.hh:144
std::ptrdiff_t difference_type
The difference type.
Definition base.hh:86
auto begin() const -> iterator
Get an iterator pointing to the first element of the atom base.
Definition base.hh:139
Detail::RandomAccessIterator< AtomBase > iterator
The iterator type.
Definition base.hh:92
Class to provide access to symbolic atoms.
Definition base.hh:17
friend auto operator==(Atom const &a, Atom const &b) noexcept -> bool
Compare two atoms for equality.
Definition base.hh:54
auto hash() const noexcept -> size_t
Get the header of the atom.
Definition base.hh:47
auto symbol() const -> Symbol
Get the atom's symbol.
Definition base.hh:37
auto literal() const -> ProgramLiteral
Get the program literal of the atom.
Definition base.hh:30
Atom(clingo_atom_base_t const *base, size_t index)
Construct an atom from its C representation.
Definition base.hh:25
friend auto operator<=>(Atom const &a, Atom const &b) noexcept -> std::strong_ordering
Compare two atoms.
Definition base.hh:64
A base that maps signatures to atom bases, and captures term and theory bases.
Definition base.hh:608
auto at(size_t index) const -> value_type
Get the signature atom base pair at the given index.
Definition base.hh:681
auto is_fact(ProgramLiteral lit) const -> bool
Check whether the given program literal is a fact.
Definition base.hh:644
auto size() const -> size_type
Get the number of atom bases in the base.
Definition base.hh:675
auto terms() const -> TermBase
Get the term base of the program.
Definition base.hh:767
std::tuple< std::string_view, size_t, bool > key_type
The key type.
Definition base.hh:611
Detail::ArrowProxy< value_type > pointer
The pointer type.
Definition base.hh:623
auto is_external(ProgramLiteral lit) const -> bool
Check whether the given program literal is external.
Definition base.hh:636
std::pair< key_type, mapped_type > value_type
The value type.
Definition base.hh:615
value_type reference
The reference type.
Definition base.hh:621
auto theory() const -> TheoryBase
Get the theory base of the program.
Definition base.hh:772
std::size_t size_type
The size type.
Definition base.hh:617
auto contains(Symbol const &sym) const -> bool
Check whether the base contains the given symbol.
Definition base.hh:716
auto is_projected(ProgramLiteral lit) const -> bool
Check whether the (atom of the) given program literal is projected.
Definition base.hh:660
Base(clingo_base_t const *base)
Construct a base from its C representation.
Definition base.hh:630
auto get(Symbol const &sym, std::optional< Atom > def=std::nullopt) const -> std::optional< Atom >
Get the atom base for the given symbol.
Definition base.hh:755
auto is_current(ProgramLiteral lit) const -> bool
Check whether the program literals belongs to the current solving step.
Definition base.hh:668
auto is_shown(ProgramLiteral lit) const -> bool
Check whether the given program literal is shown.
Definition base.hh:652
std::ptrdiff_t difference_type
The difference type.
Definition base.hh:619
auto end() const -> iterator
Get an iterator pointing to the end of the base.
Definition base.hh:782
Detail::RandomAccessIterator< Base > iterator
The iterator type.
Definition base.hh:625
auto begin() const -> iterator
Get an iterator pointing to the first element of the base.
Definition base.hh:777
auto contains(key_type const &sig) const -> bool
Check whether the base contains the given signature.
Definition base.hh:695
auto get(key_type const &sig, std::optional< mapped_type > def=std::nullopt) const -> std::optional< mapped_type >
Get the atom base for the given signature.
Definition base.hh:730
auto contains(std::pair< std::string_view, size_t > const &sig) const -> bool
Check whether the base contains the given short signature.
Definition base.hh:708
auto get(std::pair< std::string_view, size_t > const &sig, std::optional< mapped_type > def=std::nullopt) const -> std::optional< mapped_type >
Get the atom base for the given short signature.
Definition base.hh:745
A string builder for constructing strings.
Definition core.hh:524
Class modeling a symbol in Clingo.
Definition symbol.hh:68
A term base that maps symbols to terms.
Definition base.hh:220
auto size() const -> size_type
The size of the term base.
Definition base.hh:247
auto begin() const -> iterator
Get an iterator pointing to the first element of the term base.
Definition base.hh:280
auto at(size_t index) const -> value_type
Get the symbol term pair at the given index.
Definition base.hh:253
auto end() const -> iterator
Get an iterator pointing to the end of the term base.
Definition base.hh:285
Detail::ArrowProxy< value_type > pointer
The pointer type.
Definition base.hh:235
std::ptrdiff_t difference_type
The difference type.
Definition base.hh:231
auto contains(key_type const &symbol) const -> bool
Whether the term base contains the given symbol.
Definition base.hh:262
std::pair< key_type, mapped_type > value_type
The value type.
Definition base.hh:227
Detail::RandomAccessIterator< TermBase > iterator
The iterator type.
Definition base.hh:237
auto get(key_type const &symbol, std::optional< mapped_type > def=std::nullopt) const -> std::optional< mapped_type >
Get the term for the given symbol.
Definition base.hh:271
value_type reference
The reference type.
Definition base.hh:233
TermBase(clingo_term_base_t const &base)
Construct a term base from its C representation.
Definition base.hh:242
std::size_t size_type
The size type.
Definition base.hh:229
Class to provide access to terms in a program.
Definition base.hh:152
friend auto operator==(Term const &a, Term const &b) noexcept -> bool
Compare two terms for equality.
Definition base.hh:199
auto condition() const -> std::vector< ProgramLiteralVector >
Get the condition of the term.
Definition base.hh:170
friend auto operator<=>(Term const &a, Term const &b) noexcept -> std::strong_ordering
Compare two terms.
Definition base.hh:209
Term(clingo_term_base_t const &base, size_t index)
Construct a term from its C representation.
Definition base.hh:158
auto symbol() const -> Symbol
Get the symbol of the term.
Definition base.hh:163
auto hash() const noexcept -> size_t
Get the hash of the term.
Definition base.hh:192
Class to provide access to theory atoms.
Definition base.hh:471
friend auto operator<=>(TheoryAtom const &a, TheoryAtom const &b) noexcept -> std::strong_ordering
Compare two theory atoms.
Definition base.hh:549
TheoryAtom(clingo_theory_base_t const &base, size_t index)
Constructor from C representation.
Definition base.hh:477
auto hash() const noexcept -> size_t
Get the hash of the theory atom.
Definition base.hh:532
auto to_string() const -> std::string
Convert the theory atom to a string representation.
Definition base.hh:520
auto guard() const -> std::optional< std::pair< std::string_view, TheoryTerm > >
Get the guard of the theory atom.
Definition base.hh:506
friend auto operator==(TheoryAtom const &a, TheoryAtom const &b) noexcept -> bool
Compare two theory atoms for equality.
Definition base.hh:539
auto literal() const -> ProgramLiteral
Get the literal of the theory atom.
Definition base.hh:499
auto elements() const -> TheoryElementVector
Get the elements of the theory atom.
Definition base.hh:489
auto name() const -> TheoryTerm
Get the name of the theory atom.
Definition base.hh:482
A theory base that maps theory atoms.
Definition base.hh:560
std::size_t size_type
The size type.
Definition base.hh:565
auto begin() const -> iterator
Get an iterator pointing to the first element of the theory base.
Definition base.hh:595
TheoryAtom value_type
The value type.
Definition base.hh:563
TheoryBase(clingo_theory_base_t const &base)
Construct a theory base from its C representation.
Definition base.hh:578
auto at(size_t index) const -> value_type
Get the theory atom at the given index.
Definition base.hh:588
std::ptrdiff_t difference_type
The difference type.
Definition base.hh:567
Detail::RandomAccessIterator< TheoryBase > iterator
The iterator type.
Definition base.hh:573
auto size() const -> size_type
Get the size of the theory base.
Definition base.hh:583
Detail::ArrowProxy< value_type > pointer
The pointer type.
Definition base.hh:571
auto end() const -> iterator
Get an iterator pointing to the end of the theory base.
Definition base.hh:600
Class to provide access to theory elements.
Definition base.hh:390
auto tuple() const -> TheoryTermVector
Get the tuple of the theory element.
Definition base.hh:401
auto to_string() const -> std::string
Convert the theory element to a string representation.
Definition base.hh:431
auto hash() const noexcept -> size_t
Get the hash of the theory element.
Definition base.hh:443
friend auto operator<=>(TheoryElement const &a, TheoryElement const &b) noexcept -> std::strong_ordering
Compare two theory elements.
Definition base.hh:460
auto condition() const -> ProgramLiteralSpan
Get the condition of the theory element.
Definition base.hh:411
TheoryElement(clingo_theory_base_t const &base, size_t index)
Constructor from C representation.
Definition base.hh:396
auto condition_id() const -> ProgramLiteral
Get the condition id of the theory element.
Definition base.hh:424
friend auto operator==(TheoryElement const &a, TheoryElement const &b) noexcept -> bool
Compare two theory elements for equality.
Definition base.hh:450
Class to provide access to theory terms.
Definition base.hh:307
auto number() const -> int
Get the numeric value of the term if it is a number term.
Definition base.hh:323
auto arguments() const -> std::vector< TheoryTerm >
Get the arguments of the term if it is a function term.
Definition base.hh:336
friend auto operator<=>(TheoryTerm const &a, TheoryTerm const &b) noexcept -> std::strong_ordering
Compare two theory terms.
Definition base.hh:375
auto name() const -> std::string_view
Get the name of the term if it is a constant or function term.
Definition base.hh:328
auto hash() const noexcept -> size_t
Get the hash of the term.
Definition base.hh:358
auto type() const -> TheoryTermType
Get the type of the theory term.
Definition base.hh:316
TheoryTerm(clingo_theory_base_t const &base, size_t index)
Construct a theory term from its C representation.
Definition base.hh:313
friend auto operator==(TheoryTerm const &a, TheoryTerm const &b) noexcept -> bool
Compare two theory terms for equality.
Definition base.hh:365
auto to_string() const -> std::string
Convert the term to a string representation.
Definition base.hh:346
CLINGO_VISIBILITY_DEFAULT bool clingo_theory_base_element_to_string(clingo_theory_base_t const *theory, clingo_id_t element, clingo_string_builder_t *builder)
Get the string representation of the given theory element.
CLINGO_VISIBILITY_DEFAULT bool clingo_theory_base_atom_elements(clingo_theory_base_t const *theory, clingo_id_t atom, clingo_id_t const **elements, size_t *size)
Get the theory elements associated with the theory atom.
struct clingo_theory_base clingo_theory_base_t
Object to inspect theory atoms.
Definition base.h:93
struct clingo_atom_base clingo_atom_base_t
Object to inspect the symbolic atoms in a program.
Definition base.h:75
CLINGO_VISIBILITY_DEFAULT bool clingo_theory_base_atom_to_string(clingo_theory_base_t const *theory, clingo_id_t atom, clingo_string_builder_t *builder)
Get the string representation of the given theory atom.
CLINGO_VISIBILITY_DEFAULT bool clingo_theory_base_atom_guard(clingo_theory_base_t const *theory, clingo_id_t atom, clingo_string_t *connective, clingo_id_t *term)
Get the guard consisting of a theory operator and a theory term of the given theory atom.
CLINGO_VISIBILITY_DEFAULT bool clingo_base_atoms_find(clingo_base_t const *base, clingo_signature_t const *signature, clingo_atom_base_t const **atoms, bool *found)
Find the atom base wit the given signature.
CLINGO_VISIBILITY_DEFAULT bool clingo_theory_base_term_arguments(clingo_theory_base_t const *theory, clingo_id_t term, clingo_id_t const **arguments, size_t *size)
Get the arguments of the given function theory term.
CLINGO_VISIBILITY_DEFAULT bool clingo_theory_base_term_to_string(clingo_theory_base_t const *theory, clingo_id_t term, clingo_string_builder_t *builder)
Get the string representation of the given theory term.
struct clingo_term_base clingo_term_base_t
Object to inspect the shown terms in a program.
Definition base.h:78
CLINGO_VISIBILITY_DEFAULT bool clingo_base_atoms_at(clingo_base_t const *base, size_t index, clingo_signature_t *signature, clingo_atom_base_t const **atoms)
Get the signature and atom base at the given index.
CLINGO_VISIBILITY_DEFAULT bool clingo_theory_base_element_tuple(clingo_theory_base_t const *theory, clingo_id_t element, clingo_id_t const **tuple, size_t *size)
Get the tuple (array of theory terms) of the given theory element.
struct clingo_base clingo_base_t
Object to inspect symbolic atoms in a program—the relevant Herbrand base gringo uses to instantiate p...
Definition base.h:70
CLINGO_VISIBILITY_DEFAULT bool clingo_term_base_condition(clingo_term_base_t const *terms, size_t index, size_t const **sizes, clingo_literal_t const *const **literals, size_t *size)
Get the conditions of a show directive.
CLINGO_VISIBILITY_DEFAULT bool clingo_theory_base_element_condition(clingo_theory_base_t const *theory, clingo_id_t element, clingo_literal_t const **condition, size_t *size)
Get the condition (array of aspif literals) of the given theory element.
@ clingo_theory_term_type_symbol
a symbol term, e.g., c
Definition base.h:87
@ clingo_theory_term_type_set
a set term, e.g., {1,2,3}
Definition base.h:84
@ clingo_theory_term_type_list
a list term, e.g., [1,2,3]
Definition base.h:83
@ clingo_theory_term_type_number
a number term, e.g., 42
Definition base.h:86
@ clingo_theory_term_type_function
a function term, e.g., f(1,2,3)
Definition base.h:85
@ clingo_theory_term_type_tuple
a tuple term, e.g., (1,2,3)
Definition base.h:82
int32_t clingo_literal_t
Signed integer type used for aspif and solver literals.
Definition core.h:78
uint32_t clingo_id_t
Unsigned integer type used in various places.
Definition core.h:82
@ tuple
Theory tuples "(t1,...,tn)".
@ list
Theory lists "[t1,...,tn]".
@ set
Theory sets "{t1,...,tn}".
std::vector< TheoryTerm > TheoryTermVector
A vector of theory terms.
Definition base.hh:304
std::vector< TheoryElement > TheoryElementVector
A vector of theory elements.
Definition base.hh:387
TheoryTermType
Enumeration of theory term types.
Definition base.hh:293
@ symbol
a symbol term, e.g., c
@ number
a number term, e.g., 42
@ function
a function term, e.g., f(1,2,3)
std::vector< ProgramLiteral > ProgramLiteralVector
A vector of program literals.
Definition core.hh:396
clingo_literal_t ProgramLiteral
A program literal.
Definition core.hh:392
std::span< ProgramLiteral const > ProgramLiteralSpan
A span of program literals.
Definition core.hh:394
Represents a predicate signature.
Definition base.h:58
size_t size
the size of the name
Definition base.h:60
Struct to capture strings that are not null-terminated.
Definition core.h:91
size_t size
the length of the string
Definition core.h:93
char const * data
pointer to the beginning of the string
Definition core.h:92