Skip to content

Commit

Permalink
replace boost::scoped_ptr and auto_ptr with std::unique_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
wojdyr committed Aug 7, 2022
1 parent e262bcc commit 2b8174e
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 27 deletions.
3 changes: 0 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ AC_CHECK_HEADER([boost/math/special_functions/gamma.hpp], [], [AC_MSG_ERROR(
AC_CHECK_HEADER([boost/array.hpp], [], [AC_MSG_ERROR(
[Boost::Array headers not found. Make sure you have Boost installed.])])

AC_CHECK_HEADER([boost/scoped_ptr.hpp], [], [AC_MSG_ERROR(
[Boost Smart Pointers not found. Make sure you have Boost installed.])])

AC_LANG_POP([C++])

AC_CHECK_HEADER([zlib.h], [], [AC_MSG_ERROR(
Expand Down
5 changes: 3 additions & 2 deletions fityk/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <memory> // for unique_ptr

#include "common.h"
#include "data.h"
Expand Down Expand Up @@ -221,7 +222,7 @@ void DataKeeper::do_import_dataset(bool new_dataset, int slot,
BasicContext* ctx, ModelManager &mgr)
{
Data *d;
auto_ptr<Data> auto_d;
unique_ptr<Data> auto_d;
if (!new_dataset)
d = data(slot);
else if (count() == 1 && data(0)->completely_empty()) // reusable slot 0
Expand All @@ -231,7 +232,7 @@ void DataKeeper::do_import_dataset(bool new_dataset, int slot,
d = auto_d.get();
}
d->load_file(spec);
if (auto_d.get())
if (auto_d)
append(auto_d.release());
}

Expand Down
2 changes: 1 addition & 1 deletion fityk/mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void ModelManager::remove_unreferred()
/// puts Variable into `variables_' vector, checking dependencies
int ModelManager::add_variable(Variable* new_var, bool old_domain)
{
auto_ptr<Variable> var(new_var);
unique_ptr<Variable> var(new_var);
var->set_var_idx(variables_);
int pos = find_variable_nr(var->name);
if (pos == -1) {
Expand Down
6 changes: 3 additions & 3 deletions fityk/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define BUILDING_LIBFITYK
#include "runner.h"

#include <boost/scoped_ptr.hpp>
#include <memory> // for unique_ptr

#include "cparser.h"
#include "eparser.h"
Expand Down Expand Up @@ -310,7 +310,7 @@ void Runner::command_dataset_tr(const vector<Token>& args)
ExpressionParser::kDatasetTrMode);

if (n == Lexer::kNew) {
auto_ptr<Data> data_out(new Data(F_, F_->mgr.create_model()));
unique_ptr<Data> data_out(new Data(F_, F_->mgr.create_model()));
run_data_transform(F_->dk, ep_.vm(), data_out.get());
F_->dk.append(data_out.release());
} else
Expand Down Expand Up @@ -851,7 +851,7 @@ void Runner::recalculate_command(Command& c, int ds, Statement& st)
// Throws ExecuteError, ExitRequestedException.
void Runner::execute_statement(Statement& st)
{
boost::scoped_ptr<Settings> s_orig;
unique_ptr<Settings> s_orig;
vdlist_ = &st.vdlist;
try {
if (!st.with_args.empty()) {
Expand Down
4 changes: 2 additions & 2 deletions fityk/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory> // for unique_ptr
#include <zlib.h>
#include <boost/scoped_ptr.hpp>
#ifdef _WIN32
# include <windows.h>
#else
Expand Down Expand Up @@ -255,7 +255,7 @@ void UserInterface::exec_fityk_script(const string& filename)
{
user_interrupt = 0;

boost::scoped_ptr<FileOpener> opener;
unique_ptr<FileOpener> opener;
if (endswith(filename, ".gz"))
opener.reset(new GzipFileOpener);
else
Expand Down
8 changes: 4 additions & 4 deletions tests/gradient.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#include <stdio.h>
#include <boost/scoped_ptr.hpp>
#include <memory> // for unique_ptr
#include "fityk/logic.h"
#include "fityk/data.h"
#include "fityk/fit.h"
Expand Down Expand Up @@ -41,7 +41,7 @@ static double boxbetts_f(const double *a, double *grad)

static double boxbetts_in_fityk(const double *a, double *grad)
{
boost::scoped_ptr<Fityk> ftk(new Fityk);
unique_ptr<Fityk> ftk(new Fityk);
Full* priv = ftk->priv();
ftk->set_option_as_number("verbosity", -1);
for (int i = 1; i <= 10; ++i)
Expand Down Expand Up @@ -87,7 +87,7 @@ TEST_CASE("gradient", "test Fit::compute_wssr_gradient()") {
//----------- + some unrelated random tests

TEST_CASE("set-throws", "test Fityk::set_throws()") {
boost::scoped_ptr<Fityk> fik(new Fityk);
unique_ptr<Fityk> fik(new Fityk);
REQUIRE(fik->get_throws() == true);
REQUIRE_THROWS_AS(fik->execute("hi"), SyntaxError);
REQUIRE_THROWS_AS(fik->execute("fit"), ExecuteError);
Expand All @@ -102,7 +102,7 @@ TEST_CASE("set-throws", "test Fityk::set_throws()") {


TEST_CASE("set-get-option", "test Fityk::[gs]et_option_as_*()") {
boost::scoped_ptr<Fityk> fik(new Fityk);
unique_ptr<Fityk> fik(new Fityk);

REQUIRE(fik->get_option_as_string("numeric_format") == "%g"); // string
REQUIRE(fik->get_option_as_string("on_error") == "stop"); // enum
Expand Down
4 changes: 2 additions & 2 deletions tests/guess.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#include <stdio.h>
#include <boost/scoped_ptr.hpp>
#include <memory> // for unique_ptr
#include "fityk/logic.h"
#include "fityk/guess.h"
#include "fityk/data.h"
Expand Down Expand Up @@ -66,7 +66,7 @@ bool is_vector_sorted(const vector<T>& v)
}

TEST_CASE("linear-guess", "test Guess::estimate_linear_parameters()") {
boost::scoped_ptr<Full> ftk(new Full);
unique_ptr<Full> ftk(new Full);
Data *data = ftk->dk.data(0);
//ftk->settings_mgr()->set_as_number("verbosity", -1);
int n = sizeof(norris::yx) / sizeof(norris::yx[0]);
Expand Down
4 changes: 2 additions & 2 deletions tests/lua.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

#include <boost/scoped_ptr.hpp>
#include <memory> // for unique_ptr
#include <string>
#include "fityk/fityk.h"
#include "fityk/logic.h"
#include "fityk/luabridge.h"
#include "catch.hpp"

TEST_CASE("formatted F:execute", "") {
boost::scoped_ptr<fityk::Fityk> fik(new fityk::Fityk);
std::unique_ptr<fityk::Fityk> fik(new fityk::Fityk);
fityk::Full* priv = fik->priv();
std::string str = "a=123.456; F:execute('$v = %g' % a)";
priv->lua_bridge()->exec_lua_string(str);
Expand Down
1 change: 0 additions & 1 deletion tests/num.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

#include <boost/scoped_ptr.hpp>
#include "fityk/numfuncs.h"
#include "catch.hpp"

Expand Down
6 changes: 3 additions & 3 deletions tests/psvoigt.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#include <stdio.h>
#include <boost/scoped_ptr.hpp>
#include <memory> // for unique_ptr
#include "fityk/fityk.h"
// derivatives need private API
#include "fityk/logic.h"
Expand All @@ -23,7 +23,7 @@ static const char* PV4 = "define PV4(height, center, hwhm, shape) = "
"SplitPseudoVoigt(height, center, hwhm, hwhm, shape, shape)";

TEST_CASE("pseudo-voigt", "") {
boost::scoped_ptr<fityk::Fityk> fik(new fityk::Fityk);
unique_ptr<fityk::Fityk> fik(new fityk::Fityk);
fik->set_option_as_number("verbosity", -1);
fik->execute(PV2);
fik->execute(PV3);
Expand Down Expand Up @@ -74,7 +74,7 @@ TEST_CASE("pseudo-voigt", "") {
// test Function::get_nonzero_range() implementations

static double nonzero_left(double level, const string& func) {
boost::scoped_ptr<fityk::Fityk> fik(new fityk::Fityk);
unique_ptr<fityk::Fityk> fik(new fityk::Fityk);
fik->set_option_as_number("verbosity", -1);
fik->execute("%f = " + func);
const fityk::Func *f = fik->get_function("f");
Expand Down
4 changes: 2 additions & 2 deletions wxgui/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <stdlib.h>
#include <vector>
#include <string>
#include <boost/scoped_ptr.hpp>
#include <memory> // for unique_ptr

#ifndef _WIN32
# include <signal.h>
Expand Down Expand Up @@ -254,7 +254,7 @@ bool FApp::OnInit(void)
if (!wxDirExists(config_dir)) {
wxMkdir(config_dir);
// create white-background config
boost::scoped_ptr<wxFileConfig> w(new wxFileConfig("", "",
unique_ptr<wxFileConfig> w(new wxFileConfig("", "",
config_dir+"white"));
write_white_config(w.get());
}
Expand Down
4 changes: 2 additions & 2 deletions wxgui/mplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <wx/fontpicker.h>
#include <wx/dcgraph.h>
#include <algorithm>
#include <boost/scoped_ptr.hpp>
#include <memory> // for unique_ptr

#include "mplot.h"
#include "plotpane.h"
Expand Down Expand Up @@ -1427,7 +1427,7 @@ void calculate_values(const vector<realt>& xx, vector<realt>& yy,
vector<string> varnames(len);
for (int i = 0; i != len; ++i)
varnames[i] = "v" + S(i);
boost::scoped_ptr<Function> f(
unique_ptr<Function> f(
(*tp->create)(ftk->get_settings(), "tmp", tp, varnames));
f->init();

Expand Down

0 comments on commit 2b8174e

Please sign in to comment.