Skip to content

Commit

Permalink
cleanup pass
Browse files Browse the repository at this point in the history
  • Loading branch information
rkaminsk committed Dec 11, 2024
1 parent eec53c0 commit 7ff4e13
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 4 additions & 2 deletions libclingo/clingo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2838,7 +2838,7 @@ CLINGO_VISIBILITY_DEFAULT bool clingo_control_load(clingo_control_t *control, ch
//! @return whether the call was successful; might set one of the following error codes:
//! - ::clingo_error_bad_alloc
//! - ::clingo_error_runtime if parsing or checking fails
CLINGO_VISIBILITY_DEFAULT bool clingo_control_load_aspif(clingo_control_t *ctl, char const **files, size_t size);
CLINGO_VISIBILITY_DEFAULT bool clingo_control_load_aspif(clingo_control_t *control, char const **files, size_t size);

//! Extend the logic program with the given non-ground logic program in string form.
//!
Expand Down Expand Up @@ -3138,7 +3138,9 @@ CLINGO_VISIBILITY_DEFAULT bool clingo_control_register_observer(clingo_control_t
//! @param[in] type the kind of backend to register
//! @param[in] file the file to write the result to
//! @param[in] replace just pass the grounding to the backend but not the solver
//! @return whether the call was successful
//! @return whether the call was successful; might set one of the following error codes:
//! - ::clingo_error_bad_alloc
//! - ::clingo_error_runtime (for example if the file could not be opened)
CLINGO_VISIBILITY_DEFAULT bool clingo_control_register_backend(clingo_control_t *control, clingo_backend_type_t type, char const *file, bool replace);
//! @}

Expand Down
11 changes: 7 additions & 4 deletions libclingo/src/control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2204,17 +2204,20 @@ extern "C" bool clingo_control_register_observer(clingo_control_t *control, clin
extern "C" bool clingo_control_register_backend(clingo_control_t *control, clingo_backend_type_t type, char const *file, bool replace) {
GRINGO_CLINGO_TRY {
auto out = gringo_make_unique<std::ofstream>(file);
auto backend = UBackend{}; //Output::make_backend(out, OutputFormat::reify, false, false);
if (!out->is_open()) {
throw std::runtime_error("file could not be opened");
}
auto backend = UBackend{};
switch (type & 0xFFFFFFFC) {
case clingo_backend_type_e::clingo_backend_type_reify: {
case clingo_backend_type_reify: {
backend = Output::make_backend(std::move(out), Output::OutputFormat::REIFY, (type & 1) == 1, (type &2) == 2);
break;
}
case clingo_backend_type_e::clingo_backend_type_smodels: {
case clingo_backend_type_smodels: {
backend = Output::make_backend(std::move(out), Output::OutputFormat::SMODELS, false, false);
break;
}
case clingo_backend_type_e::clingo_backend_type_aspif: {
case clingo_backend_type_aspif: {
backend = Output::make_backend(std::move(out), Output::OutputFormat::INTERMEDIATE, false, false);
break;
}
Expand Down
2 changes: 2 additions & 0 deletions libpyclingo/clingo/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ def register_backend(
----------
type
The type of backend to register.
file:
The path of the file to write to.
replace
If set to true, the output is just passed to the backend and no longer to
the underlying solver (or any previously registered backends/observers).
Expand Down

0 comments on commit 7ff4e13

Please sign in to comment.