This PR adds a new api::Solver::isOutputOn() method, including unit tests for both isOutputOn() and getOutput().
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
*/
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
{
return options::outputTagHolder()[static_cast<size_t>(tag)];
}
+bool OutputC::isOn(const std::string& tag) const
+{
+ return (*this).isOn(options::stringToOutputTag(tag));
+}
} // namespace cvc5
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;
#include <algorithm>
#include "test_api.h"
+#include "base/output.h"
namespace cvc5 {
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