Clingo
Loading...
Searching...
No Matches
Clingo::Symbol Class Reference

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Symbol() [1/3]

Clingo::Symbol::Symbol ( Symbol const other)
inlinenoexcept

The copy constructor acquires the symbol.

Parameters
otherthe symbol to copy

◆ Symbol() [2/3]

Clingo::Symbol::Symbol ( Symbol &&  other)
inlinenoexcept

The move constructor transfers ownership of the symbol.

Parameters
otherthe symbol to move

◆ Symbol() [3/3]

Clingo::Symbol::Symbol ( clingo_symbol_t  rep,
bool  acquire 
)
inlineexplicit

Construct a symbol from its C API representation.

For internal use.

Parameters
repthe C API representation of the symbol
acquirewhether to acquire the symbol

Member Function Documentation

◆ arguments()

auto Clingo::Symbol::arguments ( ) const -> SymbolSpan
inline

Get the arguments of a function or tuple symbol.

Returns
a span of symbols representing the arguments

◆ hash()

auto Clingo::Symbol::hash ( ) const -> size_t
inlinenoexcept

Compute a hash value for the symbol.

The hash value is entended for usage in hash tables.

Returns
a hash value for the symbol

◆ is_negative()

auto Clingo::Symbol::is_negative ( ) const -> bool
inline

Check whether a function or number symbol is negative.

Returns
whether the symbol is negative

◆ is_positive()

auto Clingo::Symbol::is_positive ( ) const -> bool
inline

Check whether a function or number symbol is positive.

Returns
whether the symbol is positive

◆ match() [1/2]

auto Clingo::Symbol::match ( size_t  arity) const -> bool
inline

Match the symbol against a tuple signature.

Parameters
aritythe number of arguments of the tuple
Returns
whether the symbol matches the tuple signature

◆ match() [2/2]

auto Clingo::Symbol::match ( std::string_view  name,
size_t  arity,
bool  positive = true 
) const -> bool
inline

Match the symbol against a function signature.

Parameters
namethe name of the function
aritythe number of arguments of the function
positivewhether the function is positive
Returns
whether the symbol matches the function signature

◆ name()

auto Clingo::Symbol::name ( ) const -> std::string_view
inline

Get the name of the symbol if it is a function.

Returns
the name of the symbol

◆ number()

auto Clingo::Symbol::number ( ) const -> int
inline

Get the numeric value of the symbol if it is a number.

Returns
the numeric value of the symbol

◆ operator=() [1/2]

auto Clingo::Symbol::operator= ( Symbol &&  other) -> Symbol &
inlinenoexcept

The move assignment transfers ownership and releases the old one.

Parameters
otherthe symbol to move
Returns
a reference to this symbol

◆ operator=() [2/2]

auto Clingo::Symbol::operator= ( Symbol const other) -> Symbol &
inlinenoexcept

The copy assignment acquires the symbol and releases the old one.

Parameters
otherthe symbol to copy
Returns
a reference to this symbol

◆ signature()

auto Clingo::Symbol::signature ( ) const -> std::optional<std::tuple<std::string_view, size_t, bool>>
inline

Get the signature of the symbol if it is a function.

The result is empty if the symbol is not a function.

Returns
an optional name arity positivity tuple

◆ string()

auto Clingo::Symbol::string ( ) const -> std::string_view
inline

Get the string value of the symbol if it is a string.

Returns
the string value of the symbol

◆ to_string()

auto Clingo::Symbol::to_string ( ) const -> std::string
inline

Get a string representation of the symbol.

The string representation adheres to clingo's input language and is parsable by clingo.

Returns
a string representation of the symbol

◆ type()

auto Clingo::Symbol::type ( ) const -> SymbolType
inline

Get the type of the symbol.

Returns
the type of the symbol

Friends And Related Symbol Documentation

◆ c_cast [1/2]

auto c_cast ( Symbol const sym) -> clingo_symbol_t const &
friend

Cast the symbol to its C API representation.

Parameters
symthe symbol to cast
Returns
the C API representation of the symbol

◆ c_cast [2/2]

auto c_cast ( Symbol const sym) -> clingo_symbol_t const *
friend

Cast the symbol to its C API representation.

Parameters
symthe symbol to cast
Returns
the C API representation of the symbol

◆ operator<<

auto operator<< ( std::ostream &  out,
Symbol const sym 
) -> std::ostream &
friend

Output the symbol to a stream.

Parameters
outthe output stream
symthe symbol to output
Returns
the output stream

◆ operator<=>

auto operator<=> ( Symbol const a,
Symbol const b 
) -> std::strong_ordering
friend

Compare two symbols.

Parameters
athe first symbol to compare
bthe second symbol to compare
Returns
the result of the comparison

◆ operator==

auto operator== ( Symbol const a,
Symbol const b 
) -> bool
friend

Compare two symbols for equality.

Parameters
athe first symbol to compare
bthe second symbol to compare
Returns
whether the symbols are equal

The documentation for this class was generated from the following file: