Clingo
|
Class modeling a symbol in Clingo. More...
#include <symbol.hh>
Public Member Functions | |
Symbol ()=default | |
Default constructor, creates a symbol holding number zero. | |
~Symbol () | |
The destructor releases the symbol. | |
Symbol (Symbol const &other) noexcept | |
The copy constructor acquires the symbol. | |
auto | operator= (Symbol const &other) noexcept -> Symbol & |
The copy assignment acquires the symbol and releases the old one. | |
Symbol (Symbol &&other) noexcept | |
The move constructor transfers ownership of the symbol. | |
auto | operator= (Symbol &&other) noexcept -> Symbol & |
The move assignment transfers ownership and releases the old one. | |
Symbol (clingo_symbol_t rep, bool acquire) | |
Construct a symbol from its C API representation. | |
auto | number () const -> int |
Get the numeric value of the symbol if it is a number. | |
auto | name () const -> std::string_view |
Get the name of the symbol if it is a function. | |
auto | string () const -> std::string_view |
Get the string value of the symbol if it is a string. | |
auto | is_positive () const -> bool |
Check whether a function or number symbol is positive. | |
auto | is_negative () const -> bool |
Check whether a function or number symbol is negative. | |
auto | arguments () const -> SymbolSpan |
Get the arguments of a function or tuple symbol. | |
auto | type () const -> SymbolType |
Get the type of the symbol. | |
auto | to_string () const -> std::string |
Get a string representation of the symbol. | |
auto | signature () const -> std::optional< std::tuple< std::string_view, size_t, bool > > |
Get the signature of the symbol if it is a function. | |
auto | match (std::string_view name, size_t arity, bool positive=true) const -> bool |
Match the symbol against a function signature. | |
auto | match (size_t arity) const -> bool |
Match the symbol against a tuple signature. | |
auto | hash () const noexcept -> size_t |
Compute a hash value for the symbol. | |
Friends | |
auto | c_cast (Symbol const &sym) -> clingo_symbol_t const & |
Cast the symbol to its C API representation. | |
auto | c_cast (Symbol const *sym) -> clingo_symbol_t const * |
Cast the symbol to its C API representation. | |
auto | operator== (Symbol const &a, Symbol const &b) noexcept -> bool |
Compare two symbols for equality. | |
auto | operator<=> (Symbol const &a, Symbol const &b) noexcept -> std::strong_ordering |
Compare two symbols. | |
auto | operator<< (std::ostream &out, Symbol const &sym) -> std::ostream & |
Output the symbol to a stream. | |
Class modeling a symbol in Clingo.
Symbols are immutable and can be created from numbers, strings, functions, tuples, or parsed terms.
They are totally ordered and support hashing also provding a specialization for std::hash
.
Symbols are reference counted modeling value semantics. They are stored in library objects and should all be released before the library is. Failing to do so won't lead to crashed but prevents release of the underlying symbol store.
The copy constructor acquires the symbol.
other | the symbol to copy |
|
inlinenoexcept |
The move constructor transfers ownership of the symbol.
other | the symbol to move |
|
inlineexplicit |
Construct a symbol from its C API representation.
For internal use.
rep | the C API representation of the symbol |
acquire | whether to acquire the symbol |
|
inline |
Get the arguments of a function or tuple symbol.
Compute a hash value for the symbol.
The hash value is entended for usage in hash tables.
Check whether a function or number symbol is negative.
Check whether a function or number symbol is positive.
Match the symbol against a tuple signature.
arity | the number of arguments of the tuple |
|
inline |
Match the symbol against a function signature.
name | the name of the function |
arity | the number of arguments of the function |
positive | whether the function is positive |
|
inline |
Get the name of the symbol if it is a function.
Get the numeric value of the symbol if it is a number.
The move assignment transfers ownership and releases the old one.
other | the symbol to move |
The copy assignment acquires the symbol and releases the old one.
other | the symbol to copy |
|
inline |
Get the signature of the symbol if it is a function.
The result is empty if the symbol is not a function.
|
inline |
Get the string value of the symbol if it is a string.
|
inline |
Get a string representation of the symbol.
The string representation adheres to clingo's input language and is parsable by clingo.
|
inline |
Get the type of the symbol.
|
friend |
Cast the symbol to its C API representation.
sym | the symbol to cast |
|
friend |
Cast the symbol to its C API representation.
sym | the symbol to cast |
Output the symbol to a stream.
out | the output stream |
sym | the symbol to output |
Compare two symbols.
a | the first symbol to compare |
b | the second symbol to compare |
Compare two symbols for equality.
a | the first symbol to compare |
b | the second symbol to compare |