Skip to content

Commit f4ecb3e

Browse files
committed
Use unique_ptr
1 parent 03165c2 commit f4ecb3e

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

src/approxmc.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,16 @@ using namespace ApproxMC;
6161

6262
DLL_PUBLIC AppMC::AppMC(const std::unique_ptr<CMSat::FieldGen>& _fg)
6363
{
64-
data = new AppMCPrivateData(_fg);
65-
data->counter.solver = new SATSolver();
64+
data = std::make_unique<AppMCPrivateData>(_fg);
65+
data->counter.solver = std::make_unique<SATSolver>();
6666
data->counter.solver->set_up_for_scalmc();
6767
data->counter.solver->set_allow_otf_gauss();
6868
}
6969

70-
DLL_PUBLIC AppMC::~AppMC()
71-
{
72-
delete data->counter.solver;
73-
delete data;
74-
}
70+
DLL_PUBLIC AppMC::~AppMC() = default;
7571

7672
// Helper function, used only in this unit
77-
void setup_sampling_vars(AppMCPrivateData* data)
73+
void setup_sampling_vars(unique_ptr<AppMCPrivateData>& data)
7874
{
7975
if (data->conf.verb) {
8076
cout << "c o [appmc] Sampling set size: " << data->conf.sampl_vars.size() << endl;
@@ -279,11 +275,6 @@ DLL_PUBLIC bool AppMC::add_xor_clause(const vector<uint32_t>& vars, bool rhs)
279275
return data->counter.solver_add_xor_clause(vars, rhs);
280276
}
281277

282-
DLL_PUBLIC CMSat::SATSolver* AppMC::get_solver()
283-
{
284-
return data->counter.solver;
285-
}
286-
287278
DLL_PUBLIC const std::vector<uint32_t>& AppMC::get_sampling_set() const
288279
{
289280
return data->conf.sampl_vars;

src/approxmc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <memory>
3434
#include <string>
3535
#include <vector>
36+
#include <memory>
3637
#include <cryptominisat5/cryptominisat.h>
3738
namespace ApproxMC {
3839

@@ -122,7 +123,7 @@ class AppMC
122123
////////////////////////////
123124
// Do not bother with this, it's private
124125
////////////////////////////
125-
AppMCPrivateData* data;
126+
std::unique_ptr<AppMCPrivateData> data;
126127
};
127128

128129
}

src/counter.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ using std::vector;
4141
using std::map;
4242
using std::pair;
4343
using namespace CMSat;
44+
using std::unique_ptr;
4445

4546
namespace AppMCInt {
4647

@@ -93,23 +94,23 @@ struct SparseData {
9394

9495
class Counter {
9596
public:
96-
Counter(Config& _conf, const std::unique_ptr<FieldGen>& _fg) : fg(_fg->dup()), conf(_conf) {}
97+
Counter(Config& _conf, const unique_ptr<FieldGen>& _fg) : fg(_fg->dup()), conf(_conf) {}
9798
ApproxMC::SolCount solve();
9899
string gen_rnd_bits(const uint32_t size,
99100
const uint32_t numhashes, SparseData& sparse_data);
100101
string binary(const uint32_t x, const uint32_t length);
101102
bool find_one_solution();
102103
bool gen_rhs();
103104
uint32_t threshold_appmcgen;
104-
SATSolver* solver = nullptr;
105+
unique_ptr<SATSolver> solver = nullptr;
105106
ApproxMC::SolCount calc_est_count();
106107
const Constants constants;
107108
bool solver_add_clause(const vector<Lit>& cl);
108109
bool solver_add_xor_clause(const vector<uint32_t>& vars, const bool rhs);
109110
bool solver_add_xor_clause(const vector<Lit>& lits, const bool rhs);
110111

111112
private:
112-
std::unique_ptr<FieldGen> fg;
113+
unique_ptr<FieldGen> fg;
113114
Config& conf;
114115
ApproxMC::SolCount count();
115116
void add_appmc_options();

0 commit comments

Comments
 (0)