summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGereon Kremer <nafur42@gmail.com>2021-09-13 21:21:50 +0200
committerGitHub <noreply@github.com>2021-09-13 19:21:50 +0000
commit3a67082f2155760917e72efbd08d15af9d06ab13 (patch)
tree863e37f8a5e0a75ba115cde8e96bdebb3822653a
parent4f5b2c6f5e52ce4bf6e0afd317cd7daaa33c1550 (diff)
Add Solver::isOutputOn() (#7187)
This PR adds a new api::Solver::isOutputOn() method, including unit tests for both isOutputOn() and getOutput().
-rw-r--r--src/api/cpp/cvc5.cpp15
-rw-r--r--src/api/cpp/cvc5.h7
-rw-r--r--src/options/outputc.cpp4
-rw-r--r--src/options/outputc.h1
-rw-r--r--test/unit/api/solver_black.cpp12
5 files changed, 39 insertions, 0 deletions
diff --git a/src/api/cpp/cvc5.cpp b/src/api/cpp/cvc5.cpp
index b1fb80336..1aa9a740f 100644
--- a/src/api/cpp/cvc5.cpp
+++ b/src/api/cpp/cvc5.cpp
@@ -7938,6 +7938,21 @@ Statistics Solver::getStatistics() const
return Statistics(d_smtEngine->getStatisticsRegistry());
}
+bool Solver::isOutputOn(const std::string& tag) const
+{
+ // `Output(tag)` may raise an `OptionException`, which we do not want to
+ // forward as such. We thus do not use the standard exception handling macros
+ // here but roll our own.
+ try
+ {
+ return cvc5::OutputChannel.isOn(tag);
+ }
+ catch (const cvc5::Exception& e)
+ {
+ throw CVC5ApiException("Invalid output tag " + tag);
+ }
+}
+
std::ostream& Solver::getOutput(const std::string& tag) const
{
// `Output(tag)` may raise an `OptionException`, which we do not want to
diff --git a/src/api/cpp/cvc5.h b/src/api/cpp/cvc5.h
index e02506d9c..9324e4209 100644
--- a/src/api/cpp/cvc5.h
+++ b/src/api/cpp/cvc5.h
@@ -4353,6 +4353,13 @@ class CVC5_EXPORT Solver
Statistics getStatistics() const;
/**
+ * Whether the output stream for the given tag is enabled. Tags can be enabled
+ * with the `output` option (and `-o <tag>` on the command line). Raises an
+ * exception when an invalid tag is given.
+ */
+ bool isOutputOn(const std::string& tag) const;
+
+ /**
* Returns an output stream for the given tag. Tags can be enabled with the
* `output` option (and `-o <tag>` on the command line). Raises an exception
* when an invalid tag is given.
diff --git a/src/options/outputc.cpp b/src/options/outputc.cpp
index 43c9ced97..d9b7b346b 100644
--- a/src/options/outputc.cpp
+++ b/src/options/outputc.cpp
@@ -27,5 +27,9 @@ bool OutputC::isOn(const options::OutputTag tag) const
{
return options::outputTagHolder()[static_cast<size_t>(tag)];
}
+bool OutputC::isOn(const std::string& tag) const
+{
+ return (*this).isOn(options::stringToOutputTag(tag));
+}
} // namespace cvc5
diff --git a/src/options/outputc.h b/src/options/outputc.h
index d96468e40..7ad7cea76 100644
--- a/src/options/outputc.h
+++ b/src/options/outputc.h
@@ -20,6 +20,7 @@ class OutputC
Cvc5ostream operator()(const std::string& tag) const;
bool isOn(const options::OutputTag tag) const;
+ bool isOn(const std::string& tag) const;
private:
std::ostream* d_os;
diff --git a/test/unit/api/solver_black.cpp b/test/unit/api/solver_black.cpp
index e7d7c0bb4..75cd97060 100644
--- a/test/unit/api/solver_black.cpp
+++ b/test/unit/api/solver_black.cpp
@@ -16,6 +16,7 @@
#include <algorithm>
#include "test_api.h"
+#include "base/output.h"
namespace cvc5 {
@@ -2474,5 +2475,16 @@ TEST_F(TestApiBlackSolver, tupleProject)
projection.toString());
}
+TEST_F(TestApiBlackSolver, Output)
+{
+ ASSERT_THROW(d_solver.isOutputOn("foo-invalid"), CVC5ApiException);
+ ASSERT_THROW(d_solver.getOutput("foo-invalid"), CVC5ApiException);
+ ASSERT_FALSE(d_solver.isOutputOn("inst"));
+ ASSERT_EQ(cvc5::null_os.rdbuf(), d_solver.getOutput("inst").rdbuf());
+ d_solver.setOption("output", "inst");
+ ASSERT_TRUE(d_solver.isOutputOn("inst"));
+ ASSERT_NE(cvc5::null_os.rdbuf(), d_solver.getOutput("inst").rdbuf());
+}
+
} // namespace test
} // namespace cvc5
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback