Skip to content

Commit

Permalink
Merge pull request #8406 from tautschnig/dimacs_cnft-no-dynamic_cast
Browse files Browse the repository at this point in the history
Remove dynamic_cast from bv_dimacst
  • Loading branch information
kroening authored Aug 7, 2024
2 parents 5ef19c8 + 30ff419 commit f244575
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
13 changes: 12 additions & 1 deletion src/solvers/flattening/bv_dimacs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ Author: Daniel Kroening, [email protected]
#include <fstream> // IWYU pragma: keep
#include <iostream>

bv_dimacst::bv_dimacst(
const namespacet &_ns,
dimacs_cnft &_prop,
message_handlert &message_handler,
const std::string &_filename)
: bv_pointerst(_ns, _prop, message_handler),
filename(_filename),
dimacs_cnf_prop(_prop)
{
}

bool bv_dimacst::write_dimacs()
{
if(filename.empty() || filename == "-")
Expand All @@ -34,7 +45,7 @@ bool bv_dimacst::write_dimacs()

bool bv_dimacst::write_dimacs(std::ostream &out)
{
dynamic_cast<dimacs_cnft &>(prop).write_dimacs_cnf(out);
dimacs_cnf_prop.write_dimacs_cnf(out);

// we dump the mapping variable<->literals
for(const auto &s : get_symbols())
Expand Down
11 changes: 6 additions & 5 deletions src/solvers/flattening/bv_dimacs.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ Author: Daniel Kroening, [email protected]

#include "bv_pointers.h"

class dimacs_cnft;

class bv_dimacst : public bv_pointerst
{
public:
bv_dimacst(
const namespacet &_ns,
propt &_prop,
dimacs_cnft &_prop,
message_handlert &message_handler,
const std::string &_filename)
: bv_pointerst(_ns, _prop, message_handler), filename(_filename)
{
}
const std::string &_filename);

virtual ~bv_dimacst()
{
Expand All @@ -33,6 +32,8 @@ class bv_dimacst : public bv_pointerst

protected:
const std::string filename;
const dimacs_cnft &dimacs_cnf_prop;

bool write_dimacs();
bool write_dimacs(std::ostream &);
};
Expand Down
6 changes: 3 additions & 3 deletions src/solvers/sat/dimacs_cnf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ dimacs_cnf_dumpt::dimacs_cnf_dumpt(
{
}

void dimacs_cnft::write_dimacs_cnf(std::ostream &out)
void dimacs_cnft::write_dimacs_cnf(std::ostream &out) const
{
write_problem_line(out);
write_clauses(out);
}

void dimacs_cnft::write_problem_line(std::ostream &out)
void dimacs_cnft::write_problem_line(std::ostream &out) const
{
// We start counting at 1, thus there is one variable fewer.
out << "p cnf " << (no_variables()-1) << " "
Expand Down Expand Up @@ -76,7 +76,7 @@ void dimacs_cnft::write_dimacs_clause(
out << "0" << "\n";
}

void dimacs_cnft::write_clauses(std::ostream &out)
void dimacs_cnft::write_clauses(std::ostream &out) const
{
std::size_t count = 0;
std::stringstream output_block;
Expand Down
6 changes: 3 additions & 3 deletions src/solvers/sat/dimacs_cnf.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class dimacs_cnft:public cnf_clause_listt
explicit dimacs_cnft(message_handlert &);
virtual ~dimacs_cnft() { }

virtual void write_dimacs_cnf(std::ostream &out);
virtual void write_dimacs_cnf(std::ostream &out) const;

// dummy functions

Expand All @@ -36,8 +36,8 @@ class dimacs_cnft:public cnf_clause_listt
write_dimacs_clause(const bvt &, std::ostream &, bool break_lines);

protected:
void write_problem_line(std::ostream &out);
void write_clauses(std::ostream &out);
void write_problem_line(std::ostream &out) const;
void write_clauses(std::ostream &out) const;

bool break_lines;
};
Expand Down

0 comments on commit f244575

Please sign in to comment.