Skip to content

Commit f244575

Browse files
authored
Merge pull request #8406 from tautschnig/dimacs_cnft-no-dynamic_cast
Remove dynamic_cast from bv_dimacst
2 parents 5ef19c8 + 30ff419 commit f244575

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

src/solvers/flattening/bv_dimacs.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ Author: Daniel Kroening, [email protected]
1616
#include <fstream> // IWYU pragma: keep
1717
#include <iostream>
1818

19+
bv_dimacst::bv_dimacst(
20+
const namespacet &_ns,
21+
dimacs_cnft &_prop,
22+
message_handlert &message_handler,
23+
const std::string &_filename)
24+
: bv_pointerst(_ns, _prop, message_handler),
25+
filename(_filename),
26+
dimacs_cnf_prop(_prop)
27+
{
28+
}
29+
1930
bool bv_dimacst::write_dimacs()
2031
{
2132
if(filename.empty() || filename == "-")
@@ -34,7 +45,7 @@ bool bv_dimacst::write_dimacs()
3445

3546
bool bv_dimacst::write_dimacs(std::ostream &out)
3647
{
37-
dynamic_cast<dimacs_cnft &>(prop).write_dimacs_cnf(out);
48+
dimacs_cnf_prop.write_dimacs_cnf(out);
3849

3950
// we dump the mapping variable<->literals
4051
for(const auto &s : get_symbols())

src/solvers/flattening/bv_dimacs.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include "bv_pointers.h"
1616

17+
class dimacs_cnft;
18+
1719
class bv_dimacst : public bv_pointerst
1820
{
1921
public:
2022
bv_dimacst(
2123
const namespacet &_ns,
22-
propt &_prop,
24+
dimacs_cnft &_prop,
2325
message_handlert &message_handler,
24-
const std::string &_filename)
25-
: bv_pointerst(_ns, _prop, message_handler), filename(_filename)
26-
{
27-
}
26+
const std::string &_filename);
2827

2928
virtual ~bv_dimacst()
3029
{
@@ -33,6 +32,8 @@ class bv_dimacst : public bv_pointerst
3332

3433
protected:
3534
const std::string filename;
35+
const dimacs_cnft &dimacs_cnf_prop;
36+
3637
bool write_dimacs();
3738
bool write_dimacs(std::ostream &);
3839
};

src/solvers/sat/dimacs_cnf.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ dimacs_cnf_dumpt::dimacs_cnf_dumpt(
3737
{
3838
}
3939

40-
void dimacs_cnft::write_dimacs_cnf(std::ostream &out)
40+
void dimacs_cnft::write_dimacs_cnf(std::ostream &out) const
4141
{
4242
write_problem_line(out);
4343
write_clauses(out);
4444
}
4545

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

79-
void dimacs_cnft::write_clauses(std::ostream &out)
79+
void dimacs_cnft::write_clauses(std::ostream &out) const
8080
{
8181
std::size_t count = 0;
8282
std::stringstream output_block;

src/solvers/sat/dimacs_cnf.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class dimacs_cnft:public cnf_clause_listt
2020
explicit dimacs_cnft(message_handlert &);
2121
virtual ~dimacs_cnft() { }
2222

23-
virtual void write_dimacs_cnf(std::ostream &out);
23+
virtual void write_dimacs_cnf(std::ostream &out) const;
2424

2525
// dummy functions
2626

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

3838
protected:
39-
void write_problem_line(std::ostream &out);
40-
void write_clauses(std::ostream &out);
39+
void write_problem_line(std::ostream &out) const;
40+
void write_clauses(std::ostream &out) const;
4141

4242
bool break_lines;
4343
};

0 commit comments

Comments
 (0)