The example shows how to create and inspect symbols.
The example shows how to create and inspect symbols.
#define STDC_FORMAT_MACROS
#include <clingo/symbol.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
enum constants {
message_limit = 25,
example_number = 42,
};
printf(
"%.*s\n", (
int)str.
size, str.
data);
return false;
}
return true;
}
return ret;
}
return ret;
}
printf(
"%.*s", (
int)str.
size, str.
data);
}
int main(
int argc,
char *argv[]) {
(void)argc;
(void)argv;
int ret = 0;
size_t size = 0;
handle_result(res);
goto out;
}
handle_result(res);
goto out;
}
if (!handle_result(res)) {
goto out;
}
if (!handle_result(res)) {
goto out;
}
for (
size_t i = 0; i <
sizeof(
symbols) /
sizeof(*symbols); ++i) {
printf("the hash of ");
res = print_symbol(symbols[i], builder);
if (!handle_result(res)) {
goto out;
}
}
if (!handle_result(res)) {
goto out;
}
assert(size == 2);
for (size_t i = 0; i < size; ++i) {
res = print_symbol(symbols[0], builder);
if (!handle_result(res)) {
goto out;
}
res = print_symbol(args[i], builder);
if (!handle_result(res)) {
goto out;
}
printf("\n");
}
res = print_symbol(symbols[0], builder);
if (!handle_result(res)) {
goto out;
}
res = print_symbol(symbols[1], builder);
if (!handle_result(res)) {
goto out;
}
printf("\n");
out:
return ret;
}
CLINGO_VISIBILITY_DEFAULT void clingo_lib_release(clingo_lib_t *lib)
Release a library object created with clingo_lib_new().
CLINGO_VISIBILITY_DEFAULT void clingo_string_builder_free(clingo_string_builder_t const *bld)
Free the string builder.
CLINGO_VISIBILITY_DEFAULT void clingo_string_builder_clear(clingo_string_builder_t *bld)
Clear the string in the builder.
CLINGO_VISIBILITY_DEFAULT bool clingo_lib_new(clingo_lib_flags_t flags, clingo_log_level_t level, clingo_logger_t const *logger, void *data, size_t limit, clingo_lib_t **lib)
Create a library object.
struct clingo_lib clingo_lib_t
A library object storing global information.
Definition core.h:176
struct clingo_string_builder clingo_string_builder_t
A builder for strings.
Definition core.h:257
CLINGO_VISIBILITY_DEFAULT bool clingo_string_builder_string(clingo_string_builder_t const *bld, clingo_string_t *value)
Get the (zero-terminated) string in the builder.
CLINGO_VISIBILITY_DEFAULT void clingo_result_string(clingo_result_t code, clingo_string_t *value)
Convert the given result code into a string.
int clingo_result_t
Corresponding type to clingo_result_e.
Definition core.h:111
CLINGO_VISIBILITY_DEFAULT bool clingo_string_builder_new(clingo_string_builder_t **bld)
Create a new string builder.
@ clingo_log_level_info
the info level
Definition core.h:149
@ clingo_result_success
successful API calls
Definition core.h:103
CLINGO_VISIBILITY_DEFAULT int clingo_symbol_compare(clingo_symbol_t a, clingo_symbol_t b)
Check if a symbol is less than another symbol.
CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_to_string(clingo_symbol_t symbol, clingo_string_builder_t *builder)
Get the string representation of a symbol.
CLINGO_VISIBILITY_DEFAULT size_t clingo_symbol_hash(clingo_symbol_t symbol)
Calculate a hash code of a symbol.
CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_create_id(clingo_lib_t *lib, char const *name, size_t size, bool is_positive, clingo_symbol_t *symbol)
Construct a symbol representing an id.
uint64_t clingo_symbol_t
Type to represent a symbol.
Definition symbol.h:51
CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_create_function(clingo_lib_t *lib, char const *name, size_t name_size, clingo_symbol_t const *arguments, size_t arguments_size, bool is_positive, clingo_symbol_t *symbol)
Construct a symbol representing a function.
CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_arguments(clingo_symbol_t symbol, clingo_symbol_t const **arguments, size_t *arguments_size)
Get the arguments of a symbol.
CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_equal(clingo_symbol_t a, clingo_symbol_t b)
Check if two symbols are equal.
CLINGO_VISIBILITY_DEFAULT clingo_symbol_t clingo_symbol_create_number(int32_t number)
Construct a symbol representing a number.
auto main(Library &lib, std::span< std::string_view const > arguments={}, App *app=nullptr, bool raise_errors=false) -> int
Run a clingo based application with the given arguments.
Definition app.hh:219
@ symbols
Whether to write symbols in a structured format.
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