From 237345ec17c12fe42dd68fe730c2edb3f0797e50 Mon Sep 17 00:00:00 2001 From: Roland Schulz Date: Wed, 23 Nov 2016 18:02:45 -0800 Subject: [PATCH] Replace scoped_cptr with unique_cptr scoped_cptr only exists for historic reasons Change-Id: Ie77ce22855cbd440bc51d31cf9c1d5d5b30e10eb --- src/gromacs/analysisdata/modules/plot.cpp | 6 +- src/gromacs/fileio/gmxfio-xdr.cpp | 1 - src/gromacs/fileio/tests/readinp.cpp | 6 +- .../gmxpreprocess/read-conformation.cpp | 10 +- src/gromacs/gpu_utils/ocl_caching.cpp | 16 +-- src/gromacs/gpu_utils/ocl_compiler.cpp | 4 +- src/gromacs/mdlib/tests/settle.cpp | 18 +-- src/gromacs/mdrunutility/threadaffinity.cpp | 4 +- src/gromacs/selection/params.cpp | 6 +- src/gromacs/selection/parser.cpp | 42 +++---- src/gromacs/selection/parser.y | 42 +++---- .../trajectoryanalysis/modules/sasa.cpp | 4 +- .../trajectoryanalysis/modules/select.cpp | 4 +- src/gromacs/utility/scoped_cptr.h | 107 ------------------ src/gromacs/utility/unique_cptr.h | 76 +++++++++++++ src/programs/mdrun/tests/energyreader.cpp | 1 - src/programs/mdrun/tests/energyreader.h | 10 +- src/programs/mdrun/tests/trajectoryreader.cpp | 1 - src/programs/mdrun/tests/trajectoryreader.h | 10 +- 19 files changed, 167 insertions(+), 201 deletions(-) delete mode 100644 src/gromacs/utility/scoped_cptr.h create mode 100644 src/gromacs/utility/unique_cptr.h diff --git a/src/gromacs/analysisdata/modules/plot.cpp b/src/gromacs/analysisdata/modules/plot.cpp index 11dfb933a8..d44a240479 100644 --- a/src/gromacs/analysisdata/modules/plot.cpp +++ b/src/gromacs/analysisdata/modules/plot.cpp @@ -61,8 +61,8 @@ #include "gromacs/utility/exceptions.h" #include "gromacs/utility/gmxassert.h" #include "gromacs/utility/programcontext.h" -#include "gromacs/utility/scoped_cptr.h" #include "gromacs/utility/stringutil.h" +#include "gromacs/utility/unique_cptr.h" namespace { @@ -342,9 +342,9 @@ AbstractPlotModule::dataStarted(AbstractAnalysisData * /* data */) = (impl_->settings_.plotFormat() > 0 ? static_cast(impl_->settings_.plotFormat()) : exvgNONE); - gmx_output_env_t *oenv; + gmx_output_env_t *oenv; output_env_init(&oenv, getProgramContext(), time_unit, FALSE, xvg_format, 0); - scoped_cptr oenvGuard(oenv); + const unique_cptr oenvGuard(oenv); impl_->fp_ = xvgropen(impl_->filename_.c_str(), impl_->title_.c_str(), impl_->xlabel_.c_str(), impl_->ylabel_.c_str(), oenv); diff --git a/src/gromacs/fileio/gmxfio-xdr.cpp b/src/gromacs/fileio/gmxfio-xdr.cpp index 99f78af2a0..1da46d4f52 100644 --- a/src/gromacs/fileio/gmxfio-xdr.cpp +++ b/src/gromacs/fileio/gmxfio-xdr.cpp @@ -45,7 +45,6 @@ #include "gromacs/fileio/xdrf.h" #include "gromacs/utility/fatalerror.h" #include "gromacs/utility/gmxassert.h" -#include "gromacs/utility/scoped_cptr.h" #include "gromacs/utility/smalloc.h" #include "gmxfio-impl.h" diff --git a/src/gromacs/fileio/tests/readinp.cpp b/src/gromacs/fileio/tests/readinp.cpp index 506a3dbd1d..f32c0c0fb1 100644 --- a/src/gromacs/fileio/tests/readinp.cpp +++ b/src/gromacs/fileio/tests/readinp.cpp @@ -45,8 +45,8 @@ #include #include "gromacs/fileio/warninp.h" -#include "gromacs/utility/scoped_cptr.h" #include "gromacs/utility/smalloc.h" +#include "gromacs/utility/unique_cptr.h" namespace gmx { @@ -77,9 +77,9 @@ class ReadTest : public ::testing::Test int numInputs_; t_inpfile *inputField_; - gmx::scoped_cptr inpGuard_; + gmx::unique_cptr inpGuard_; warninp_t wi_; - gmx::scoped_cptr wiGuard_; + gmx::unique_cptr wiGuard_; }; TEST_F(ReadTest, get_eint_ReadsInteger) diff --git a/src/gromacs/gmxpreprocess/read-conformation.cpp b/src/gromacs/gmxpreprocess/read-conformation.cpp index 0d025476b7..e391d2141c 100644 --- a/src/gromacs/gmxpreprocess/read-conformation.cpp +++ b/src/gromacs/gmxpreprocess/read-conformation.cpp @@ -44,8 +44,8 @@ #include "gromacs/topology/mtop_util.h" #include "gromacs/topology/topology.h" #include "gromacs/utility/cstringutil.h" -#include "gromacs/utility/scoped_cptr.h" #include "gromacs/utility/smalloc.h" +#include "gromacs/utility/unique_cptr.h" using gmx::RVec; @@ -83,8 +83,8 @@ void readConformation(const char *confin, gmx_mtop_t *top, rvec *x_tmp = NULL, *v_tmp = NULL; bool dummy; readConfAndTopology(confin, &dummy, top, ePBC, x ? &x_tmp : NULL, v ? &v_tmp : NULL, box); - gmx::scoped_guard_sfree xguard(x_tmp); - gmx::scoped_guard_sfree vguard(v_tmp); + const gmx::sfree_guard xguard(x_tmp); + const gmx::sfree_guard vguard(v_tmp); if (x && x_tmp) { *x = std::vector(x_tmp, x_tmp + top->natoms); @@ -105,8 +105,8 @@ void readConformation(const char *confin, t_topology *top, v ? " and velocities" : ""); rvec *x_tmp = NULL, *v_tmp = NULL; read_tps_conf(confin, top, ePBC, x ? &x_tmp : NULL, v ? &v_tmp : NULL, box, FALSE); - gmx::scoped_guard_sfree xguard(x_tmp); - gmx::scoped_guard_sfree vguard(v_tmp); + const gmx::sfree_guard xguard(x_tmp); + const gmx::sfree_guard vguard(v_tmp); if (x && x_tmp) { *x = std::vector(x_tmp, x_tmp + top->atoms.nr); diff --git a/src/gromacs/gpu_utils/ocl_caching.cpp b/src/gromacs/gpu_utils/ocl_caching.cpp index d48fdb5de4..a5046265e8 100644 --- a/src/gromacs/gpu_utils/ocl_caching.cpp +++ b/src/gromacs/gpu_utils/ocl_caching.cpp @@ -58,22 +58,22 @@ #include "gromacs/utility/exceptions.h" #include "gromacs/utility/programcontext.h" -#include "gromacs/utility/scoped_cptr.h" #include "gromacs/utility/smalloc.h" #include "gromacs/utility/stringutil.h" #include "gromacs/utility/textreader.h" +#include "gromacs/utility/unique_cptr.h" namespace gmx { namespace ocl { -/*! \brief RAII helper to use with scoped_cptr +/*! \brief RAII helper to use with unique_cptr * * Can't use fclose because the template requires a function that * returns void. * - * \todo Either generalise scoped_cptr somehow, or (better) make + * \todo Either generalise unique_cptr somehow, or (better) make * general infrastructure for reading and writing binary lumps. * Neither of these is a priority while JIT caching is inactive. */ @@ -120,7 +120,7 @@ makeProgramFromCache(const std::string &filename, { // TODO all this file reading stuff should become gmx::BinaryReader FILE *f = fopen(filename.c_str(), "rb"); - scoped_cptr fileGuard(f); + const unique_cptr fileGuard(f); if (!f) { GMX_THROW(FileIOError("Failed to open binary cache file " + filename)); @@ -129,7 +129,7 @@ makeProgramFromCache(const std::string &filename, // TODO more stdio error handling fseek(f, 0, SEEK_END); unsigned char *binary; - scoped_cptr binaryGuard; + unique_cptr binaryGuard; size_t fileSize = ftell(f); snew(binary, fileSize); binaryGuard.reset(binary); @@ -176,9 +176,9 @@ writeBinaryToCache(cl_program program, const std::string &filename) } // TODO all this file writing stuff should become gmx::BinaryWriter - unsigned char *binary; + unsigned char *binary; snew(binary, fileSize); - scoped_cptr binaryGuard(binary); + const unique_cptr binaryGuard(binary); cl_error = clGetProgramInfo(program, CL_PROGRAM_BINARIES, sizeof(binary), &binary, NULL); if (cl_error != CL_SUCCESS) @@ -187,7 +187,7 @@ writeBinaryToCache(cl_program program, const std::string &filename) } FILE *f = fopen(filename.c_str(), "wb"); - scoped_cptr fileGuard(f); + const unique_cptr fileGuard(f); if (!f) { GMX_THROW(FileIOError("Failed to open binary cache file " + filename)); diff --git a/src/gromacs/gpu_utils/ocl_compiler.cpp b/src/gromacs/gpu_utils/ocl_compiler.cpp index 3c5e500b42..1f92b88f5e 100644 --- a/src/gromacs/gpu_utils/ocl_compiler.cpp +++ b/src/gromacs/gpu_utils/ocl_compiler.cpp @@ -58,10 +58,10 @@ #include "gromacs/utility/gmxassert.h" #include "gromacs/utility/path.h" #include "gromacs/utility/programcontext.h" -#include "gromacs/utility/scoped_cptr.h" #include "gromacs/utility/smalloc.h" #include "gromacs/utility/stringutil.h" #include "gromacs/utility/textreader.h" +#include "gromacs/utility/unique_cptr.h" #include "ocl_caching.h" @@ -120,7 +120,7 @@ writeOclBuildLog(FILE *fplog, } char *buildLog = nullptr; - scoped_cptr buildLogGuard; + unique_cptr buildLogGuard; if (buildLogSize != 0) { /* Allocate memory to fit the build log, diff --git a/src/gromacs/mdlib/tests/settle.cpp b/src/gromacs/mdlib/tests/settle.cpp index 84d54af656..7872839e15 100644 --- a/src/gromacs/mdlib/tests/settle.cpp +++ b/src/gromacs/mdlib/tests/settle.cpp @@ -46,9 +46,9 @@ #include "gromacs/pbcutil/pbc.h" #include "gromacs/topology/idef.h" #include "gromacs/topology/topology.h" -#include "gromacs/utility/scoped_cptr.h" #include "gromacs/utility/smalloc.h" #include "gromacs/utility/stringutil.h" +#include "gromacs/utility/unique_cptr.h" #include "testutils/testasserts.h" @@ -196,18 +196,18 @@ TEST_P(SettleTest, SatisfiesConstraints) // Set up the topology. We still have to make some raw pointers, // but they are put into scope guards for automatic cleanup. - gmx_mtop_t *mtop; + gmx_mtop_t *mtop; snew(mtop, 1); - scoped_cptr mtopGuard(mtop); + const unique_cptr mtopGuard(mtop); mtop->mols.nr = 1; mtop->nmoltype = 1; snew(mtop->moltype, mtop->nmoltype); - scoped_cptr moltypeGuard(mtop->moltype); + const unique_cptr moltypeGuard(mtop->moltype); mtop->nmolblock = 1; snew(mtop->molblock, mtop->nmolblock); - scoped_cptr molblockGuard(mtop->molblock); + const unique_cptr molblockGuard(mtop->molblock); mtop->molblock[0].type = 0; - std::vector iatoms; + std::vector iatoms; for (int i = 0; i < numSettles; ++i) { iatoms.push_back(settleType); @@ -221,9 +221,9 @@ TEST_P(SettleTest, SatisfiesConstraints) // Set up the SETTLE parameters. mtop->ffparams.ntypes = 1; snew(mtop->ffparams.iparams, mtop->ffparams.ntypes); - scoped_cptr iparamsGuard(mtop->ffparams.iparams); - const real dOH = 0.09572; - const real dHH = 0.15139; + const unique_cptr iparamsGuard(mtop->ffparams.iparams); + const real dOH = 0.09572; + const real dHH = 0.15139; mtop->ffparams.iparams[settleType].settle.doh = dOH; mtop->ffparams.iparams[settleType].settle.dhh = dHH; diff --git a/src/gromacs/mdrunutility/threadaffinity.cpp b/src/gromacs/mdrunutility/threadaffinity.cpp index d30e078a74..83bee6730c 100644 --- a/src/gromacs/mdrunutility/threadaffinity.cpp +++ b/src/gromacs/mdrunutility/threadaffinity.cpp @@ -60,8 +60,8 @@ #include "gromacs/utility/gmxomp.h" #include "gromacs/utility/logger.h" #include "gromacs/utility/programcontext.h" -#include "gromacs/utility/scoped_cptr.h" #include "gromacs/utility/smalloc.h" +#include "gromacs/utility/unique_cptr.h" namespace { @@ -425,7 +425,7 @@ gmx_set_thread_affinity(FILE *fplog, bool validLayout = get_thread_affinity_layout(fplog, mdlog, cr, hwTop, nthread_node, automatic, offset, &core_pinning_stride, &localityOrder); - gmx::scoped_guard_sfree localityOrderGuard(localityOrder); + const gmx::sfree_guard localityOrderGuard(localityOrder); bool allAffinitiesSet; if (validLayout) diff --git a/src/gromacs/selection/params.cpp b/src/gromacs/selection/params.cpp index 1884a63821..b2a8ff61f2 100644 --- a/src/gromacs/selection/params.cpp +++ b/src/gromacs/selection/params.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by + * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -50,9 +50,9 @@ #include "gromacs/utility/cstringutil.h" #include "gromacs/utility/exceptions.h" #include "gromacs/utility/gmxassert.h" -#include "gromacs/utility/scoped_cptr.h" #include "gromacs/utility/smalloc.h" #include "gromacs/utility/stringutil.h" +#include "gromacs/utility/unique_cptr.h" #include "parsetree.h" #include "scanner.h" @@ -311,7 +311,7 @@ parse_values_range(const SelectionParserValueList &values, "Invalid range parameter type"); int *idata = NULL; real *rdata = NULL; - scoped_guard_sfree dataGuard; + sfree_guard dataGuard; if (param->val.type == INT_VALUE) { snew(idata, values.size()*2); diff --git a/src/gromacs/selection/parser.cpp b/src/gromacs/selection/parser.cpp index 4947138878..27bb03189a 100644 --- a/src/gromacs/selection/parser.cpp +++ b/src/gromacs/selection/parser.cpp @@ -89,11 +89,11 @@ /* Copy the first part of user declarations. */ #line 56 "parser.y" /* yacc.c:339 */ -#include "gromacs/utility/scoped_cptr.h" +#include "gromacs/utility/unique_cptr.h" #include "parser_internal.h" -using gmx::scoped_guard_sfree; +using gmx::sfree_guard; using gmx::SelectionParserValue; using gmx::SelectionParserValueList; using gmx::SelectionParserValueListPointer; @@ -1886,7 +1886,7 @@ yyreduce: #line 255 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree nameGuard((yyvsp[0].str)); + const sfree_guard nameGuard((yyvsp[0].str)); SelectionTreeElementPointer s = _gmx_sel_init_group_by_name((yyvsp[0].str), scanner); SelectionTreeElementPointer p @@ -1912,7 +1912,7 @@ yyreduce: #line 273 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree nameGuard((yyvsp[-1].str)); + const sfree_guard nameGuard((yyvsp[-1].str)); set((yyval.sel), _gmx_sel_init_selection((yyvsp[-1].str), get((yyvsp[0].sel)), scanner)); END_ACTION; } @@ -1923,7 +1923,7 @@ yyreduce: #line 280 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree nameGuard((yyvsp[-2].str)); + const sfree_guard nameGuard((yyvsp[-2].str)); set((yyval.sel), _gmx_sel_assign_variable((yyvsp[-2].str), get((yyvsp[0].sel)), scanner)); END_ACTION; } @@ -1934,7 +1934,7 @@ yyreduce: #line 287 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree nameGuard((yyvsp[-2].str)); + const sfree_guard nameGuard((yyvsp[-2].str)); set((yyval.sel), _gmx_sel_assign_variable((yyvsp[-2].str), get((yyvsp[0].sel)), scanner)); END_ACTION; } @@ -1945,7 +1945,7 @@ yyreduce: #line 294 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree nameGuard((yyvsp[-2].str)); + const sfree_guard nameGuard((yyvsp[-2].str)); set((yyval.sel), _gmx_sel_assign_variable((yyvsp[-2].str), get((yyvsp[0].sel)), scanner)); END_ACTION; } @@ -2089,7 +2089,7 @@ yyreduce: #line 386 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree opGuard((yyvsp[-1].str)); + const sfree_guard opGuard((yyvsp[-1].str)); set((yyval.sel), _gmx_sel_init_comparison(get((yyvsp[-2].sel)), get((yyvsp[0].sel)), (yyvsp[-1].str), scanner)); CHECK_SEL((yyval.sel)); END_ACTION; @@ -2101,7 +2101,7 @@ yyreduce: #line 397 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree nameGuard((yyvsp[0].str)); + const sfree_guard nameGuard((yyvsp[0].str)); set((yyval.sel), _gmx_sel_init_group_by_name((yyvsp[0].str), scanner)); END_ACTION; } @@ -2152,7 +2152,7 @@ yyreduce: #line 425 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree posmodGuard((yyvsp[-1].str)); + const sfree_guard posmodGuard((yyvsp[-1].str)); set((yyval.sel), _gmx_sel_init_keyword((yyvsp[0].meth), SelectionParserValueListPointer(), (yyvsp[-1].str), scanner)); CHECK_SEL((yyval.sel)); END_ACTION; @@ -2164,7 +2164,7 @@ yyreduce: #line 433 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree posmodGuard((yyvsp[-2].str)); + const sfree_guard posmodGuard((yyvsp[-2].str)); set((yyval.sel), _gmx_sel_init_keyword_strmatch((yyvsp[-1].meth), gmx::eStringMatchType_Auto, get((yyvsp[0].vlist)), (yyvsp[-2].str), scanner)); CHECK_SEL((yyval.sel)); END_ACTION; @@ -2176,7 +2176,7 @@ yyreduce: #line 441 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree posmodGuard((yyvsp[-3].str)); + const sfree_guard posmodGuard((yyvsp[-3].str)); set((yyval.sel), _gmx_sel_init_keyword_strmatch((yyvsp[-2].meth), (yyvsp[-1].smt), get((yyvsp[0].vlist)), (yyvsp[-3].str), scanner)); CHECK_SEL((yyval.sel)); END_ACTION; @@ -2188,7 +2188,7 @@ yyreduce: #line 449 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree posmodGuard((yyvsp[-2].str)); + const sfree_guard posmodGuard((yyvsp[-2].str)); set((yyval.sel), _gmx_sel_init_keyword((yyvsp[-1].meth), get((yyvsp[0].vlist)), (yyvsp[-2].str), scanner)); CHECK_SEL((yyval.sel)); END_ACTION; @@ -2200,7 +2200,7 @@ yyreduce: #line 460 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree posmodGuard((yyvsp[-2].str)); + const sfree_guard posmodGuard((yyvsp[-2].str)); set((yyval.sel), _gmx_sel_init_method((yyvsp[-1].meth), get((yyvsp[0].plist)), (yyvsp[-2].str), scanner)); CHECK_SEL((yyval.sel)); END_ACTION; @@ -2242,7 +2242,7 @@ yyreduce: #line 500 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree posmodGuard((yyvsp[-1].str)); + const sfree_guard posmodGuard((yyvsp[-1].str)); set((yyval.sel), _gmx_sel_init_keyword((yyvsp[0].meth), SelectionParserValueListPointer(), (yyvsp[-1].str), scanner)); CHECK_SEL((yyval.sel)); END_ACTION; @@ -2254,7 +2254,7 @@ yyreduce: #line 508 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree posmodGuard((yyvsp[-3].str)); + const sfree_guard posmodGuard((yyvsp[-3].str)); set((yyval.sel), _gmx_sel_init_keyword_of((yyvsp[-2].meth), get((yyvsp[0].sel)), (yyvsp[-3].str), scanner)); CHECK_SEL((yyval.sel)); END_ACTION; @@ -2266,7 +2266,7 @@ yyreduce: #line 516 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree posmodGuard((yyvsp[-2].str)); + const sfree_guard posmodGuard((yyvsp[-2].str)); set((yyval.sel), _gmx_sel_init_method((yyvsp[-1].meth), get((yyvsp[0].plist)), (yyvsp[-2].str), scanner)); CHECK_SEL((yyval.sel)); END_ACTION; @@ -2359,7 +2359,7 @@ yyreduce: #line 581 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree posmodGuard((yyvsp[-1].str)); + const sfree_guard posmodGuard((yyvsp[-1].str)); set((yyval.sel), _gmx_sel_init_keyword((yyvsp[0].meth), SelectionParserValueListPointer(), (yyvsp[-1].str), scanner)); CHECK_SEL((yyval.sel)); END_ACTION; @@ -2398,7 +2398,7 @@ yyreduce: #line 619 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree keywordGuard((yyvsp[-2].str)); + const sfree_guard keywordGuard((yyvsp[-2].str)); set((yyval.sel), _gmx_sel_init_position(get((yyvsp[0].sel)), (yyvsp[-2].str), scanner)); CHECK_SEL((yyval.sel)); END_ACTION; @@ -2474,7 +2474,7 @@ yyreduce: #line 686 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree nameGuard((yyvsp[-1].str)); + const sfree_guard nameGuard((yyvsp[-1].str)); set((yyval.param), SelectionParserParameter::create((yyvsp[-1].str), get((yyvsp[0].vlist)), (yyloc))); END_ACTION; } @@ -2643,7 +2643,7 @@ yyreduce: #line 794 "parser.y" /* yacc.c:1646 */ { BEGIN_ACTION; - scoped_guard_sfree stringGuard((yyvsp[0].str)); + const sfree_guard stringGuard((yyvsp[0].str)); set((yyval.val), SelectionParserValue::createString((yyvsp[0].str), (yyloc))); END_ACTION; } diff --git a/src/gromacs/selection/parser.y b/src/gromacs/selection/parser.y index c5b989885f..5f8197db47 100644 --- a/src/gromacs/selection/parser.y +++ b/src/gromacs/selection/parser.y @@ -54,11 +54,11 @@ #include "gmxpre.h" } %{ -#include "gromacs/utility/scoped_cptr.h" +#include "gromacs/utility/unique_cptr.h" #include "parser_internal.h" -using gmx::scoped_guard_sfree; +using gmx::sfree_guard; using gmx::SelectionParserValue; using gmx::SelectionParserValueList; using gmx::SelectionParserValueListPointer; @@ -254,7 +254,7 @@ cmd_plain: /* empty */ | string { BEGIN_ACTION; - scoped_guard_sfree nameGuard($1); + const sfree_guard nameGuard($1); SelectionTreeElementPointer s = _gmx_sel_init_group_by_name($1, scanner); SelectionTreeElementPointer p @@ -272,28 +272,28 @@ cmd_plain: /* empty */ | STR selection { BEGIN_ACTION; - scoped_guard_sfree nameGuard($1); + const sfree_guard nameGuard($1); set($$, _gmx_sel_init_selection($1, get($2), scanner)); END_ACTION; } | IDENTIFIER '=' sel_expr { BEGIN_ACTION; - scoped_guard_sfree nameGuard($1); + const sfree_guard nameGuard($1); set($$, _gmx_sel_assign_variable($1, get($3), scanner)); END_ACTION; } | IDENTIFIER '=' num_expr { BEGIN_ACTION; - scoped_guard_sfree nameGuard($1); + const sfree_guard nameGuard($1); set($$, _gmx_sel_assign_variable($1, get($3), scanner)); END_ACTION; } | IDENTIFIER '=' pos_expr { BEGIN_ACTION; - scoped_guard_sfree nameGuard($1); + const sfree_guard nameGuard($1); set($$, _gmx_sel_assign_variable($1, get($3), scanner)); END_ACTION; } @@ -385,7 +385,7 @@ sel_expr: NOT sel_expr sel_expr: num_expr CMP_OP num_expr { BEGIN_ACTION; - scoped_guard_sfree opGuard($2); + const sfree_guard opGuard($2); set($$, _gmx_sel_init_comparison(get($1), get($3), $2, scanner)); CHECK_SEL($$); END_ACTION; @@ -396,7 +396,7 @@ sel_expr: num_expr CMP_OP num_expr sel_expr: GROUP string { BEGIN_ACTION; - scoped_guard_sfree nameGuard($2); + const sfree_guard nameGuard($2); set($$, _gmx_sel_init_group_by_name($2, scanner)); END_ACTION; } @@ -424,7 +424,7 @@ str_match_type: sel_expr: pos_mod KEYWORD_GROUP { BEGIN_ACTION; - scoped_guard_sfree posmodGuard($1); + const sfree_guard posmodGuard($1); set($$, _gmx_sel_init_keyword($2, SelectionParserValueListPointer(), $1, scanner)); CHECK_SEL($$); END_ACTION; @@ -432,7 +432,7 @@ sel_expr: pos_mod KEYWORD_GROUP | pos_mod KEYWORD_STR basic_value_list { BEGIN_ACTION; - scoped_guard_sfree posmodGuard($1); + const sfree_guard posmodGuard($1); set($$, _gmx_sel_init_keyword_strmatch($2, gmx::eStringMatchType_Auto, get($3), $1, scanner)); CHECK_SEL($$); END_ACTION; @@ -440,7 +440,7 @@ sel_expr: pos_mod KEYWORD_GROUP | pos_mod KEYWORD_STR str_match_type basic_value_list { BEGIN_ACTION; - scoped_guard_sfree posmodGuard($1); + const sfree_guard posmodGuard($1); set($$, _gmx_sel_init_keyword_strmatch($2, $3, get($4), $1, scanner)); CHECK_SEL($$); END_ACTION; @@ -448,7 +448,7 @@ sel_expr: pos_mod KEYWORD_GROUP | pos_mod KEYWORD_NUMERIC basic_value_list { BEGIN_ACTION; - scoped_guard_sfree posmodGuard($1); + const sfree_guard posmodGuard($1); set($$, _gmx_sel_init_keyword($2, get($3), $1, scanner)); CHECK_SEL($$); END_ACTION; @@ -459,7 +459,7 @@ sel_expr: pos_mod KEYWORD_GROUP sel_expr: pos_mod METHOD_GROUP method_params { BEGIN_ACTION; - scoped_guard_sfree posmodGuard($1); + const sfree_guard posmodGuard($1); set($$, _gmx_sel_init_method($2, get($3), $1, scanner)); CHECK_SEL($$); END_ACTION; @@ -499,7 +499,7 @@ num_expr: TOK_INT num_expr: pos_mod KEYWORD_NUMERIC %prec NUM_REDUCT { BEGIN_ACTION; - scoped_guard_sfree posmodGuard($1); + const sfree_guard posmodGuard($1); set($$, _gmx_sel_init_keyword($2, SelectionParserValueListPointer(), $1, scanner)); CHECK_SEL($$); END_ACTION; @@ -507,7 +507,7 @@ num_expr: pos_mod KEYWORD_NUMERIC %prec NUM_REDUCT | pos_mod KEYWORD_NUMERIC OF pos_expr { BEGIN_ACTION; - scoped_guard_sfree posmodGuard($1); + const sfree_guard posmodGuard($1); set($$, _gmx_sel_init_keyword_of($2, get($4), $1, scanner)); CHECK_SEL($$); END_ACTION; @@ -515,7 +515,7 @@ num_expr: pos_mod KEYWORD_NUMERIC %prec NUM_REDUCT | pos_mod METHOD_NUMERIC method_params { BEGIN_ACTION; - scoped_guard_sfree posmodGuard($1); + const sfree_guard posmodGuard($1); set($$, _gmx_sel_init_method($2, get($3), $1, scanner)); CHECK_SEL($$); END_ACTION; @@ -580,7 +580,7 @@ str_expr: string | pos_mod KEYWORD_STR { BEGIN_ACTION; - scoped_guard_sfree posmodGuard($1); + const sfree_guard posmodGuard($1); set($$, _gmx_sel_init_keyword($2, SelectionParserValueListPointer(), $1, scanner)); CHECK_SEL($$); END_ACTION; @@ -618,7 +618,7 @@ pos_expr: METHOD_POS method_params pos_expr: KEYWORD_POS OF sel_expr %prec PARAM_REDUCT { BEGIN_ACTION; - scoped_guard_sfree keywordGuard($1); + const sfree_guard keywordGuard($1); set($$, _gmx_sel_init_position(get($3), $1, scanner)); CHECK_SEL($$); END_ACTION; @@ -685,7 +685,7 @@ method_param: PARAM value_list { BEGIN_ACTION; - scoped_guard_sfree nameGuard($1); + const sfree_guard nameGuard($1); set($$, SelectionParserParameter::create($1, get($2), @$)); END_ACTION; } @@ -793,7 +793,7 @@ basic_value_item: | string %prec PARAM_REDUCT { BEGIN_ACTION; - scoped_guard_sfree stringGuard($1); + const sfree_guard stringGuard($1); set($$, SelectionParserValue::createString($1, @$)); END_ACTION; } diff --git a/src/gromacs/trajectoryanalysis/modules/sasa.cpp b/src/gromacs/trajectoryanalysis/modules/sasa.cpp index 20cbc4ab4c..eaff4344dc 100644 --- a/src/gromacs/trajectoryanalysis/modules/sasa.cpp +++ b/src/gromacs/trajectoryanalysis/modules/sasa.cpp @@ -71,9 +71,9 @@ #include "gromacs/utility/exceptions.h" #include "gromacs/utility/futil.h" #include "gromacs/utility/pleasecite.h" -#include "gromacs/utility/scoped_cptr.h" #include "gromacs/utility/smalloc.h" #include "gromacs/utility/stringutil.h" +#include "gromacs/utility/unique_cptr.h" #include "surfacearea.h" @@ -950,7 +950,7 @@ Sasa::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc, } sfree(area); } - scoped_guard_sfree dotsGuard(surfacedots); + const sfree_guard dotsGuard(surfacedots); if (bConnolly) { diff --git a/src/gromacs/trajectoryanalysis/modules/select.cpp b/src/gromacs/trajectoryanalysis/modules/select.cpp index 4c6ad4dd95..f84fc44e49 100644 --- a/src/gromacs/trajectoryanalysis/modules/select.cpp +++ b/src/gromacs/trajectoryanalysis/modules/select.cpp @@ -70,9 +70,9 @@ #include "gromacs/utility/arrayref.h" #include "gromacs/utility/exceptions.h" #include "gromacs/utility/gmxassert.h" -#include "gromacs/utility/scoped_cptr.h" #include "gromacs/utility/smalloc.h" #include "gromacs/utility/stringutil.h" +#include "gromacs/utility/unique_cptr.h" namespace gmx { @@ -682,7 +682,7 @@ Select::writeOutput() atoms = top_->topology()->atoms; t_pdbinfo *pdbinfo; snew(pdbinfo, atoms.nr); - scoped_guard_sfree pdbinfoGuard(pdbinfo); + const sfree_guard pdbinfoGuard(pdbinfo); if (atoms.havePdbInfo) { std::memcpy(pdbinfo, atoms.pdbinfo, atoms.nr*sizeof(*pdbinfo)); diff --git a/src/gromacs/utility/scoped_cptr.h b/src/gromacs/utility/scoped_cptr.h deleted file mode 100644 index 944d2cc2d3..0000000000 --- a/src/gromacs/utility/scoped_cptr.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * This file is part of the GROMACS molecular simulation package. - * - * Copyright (c) 2012,2014,2015, by the GROMACS development team, led by - * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, - * and including many others, as listed in the AUTHORS file in the - * top-level source directory and at http://www.gromacs.org. - * - * GROMACS is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 - * of the License, or (at your option) any later version. - * - * GROMACS is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with GROMACS; if not, see - * http://www.gnu.org/licenses, or write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * If you want to redistribute modifications to GROMACS, please - * consider that scientific software is very special. Version - * control is crucial - bugs must be traceable. We will be happy to - * consider code for inclusion in the official distribution, but - * derived work must not be called official GROMACS. Details are found - * in the README & COPYING files - if they are missing, get the - * official version at http://www.gromacs.org. - * - * To help us fund GROMACS development, we humbly ask that you cite - * the research papers on the package. Check out http://www.gromacs.org. - */ -/*! \libinternal \file - * \brief - * Declares gmx::scoped_cptr and gmx::scoped_guard_sfree. - * - * \author Teemu Murtola - * \inlibraryapi - * \ingroup module_utility - */ -#ifndef GMX_UTILITY_SCOPED_PTR_SFREE_H -#define GMX_UTILITY_SCOPED_PTR_SFREE_H - -#include "gromacs/utility/classhelpers.h" -#include "gromacs/utility/smalloc.h" - -namespace gmx -{ - -//! sfree wrapper to be used as scoped_cptr deleter -template -inline void sfree_wrapper(T *p) -{ - sfree(p); -} - -/*! \libinternal \brief - * Stripped-down version of scoped_ptr that uses sfree() or custom deleter. - * - * Currently only implements some operations; other operations can be added - * if they become necessary. - * The presence of a release() method is not strictly according to `scoped_ptr` - * design, but makes it easier to make existing C code exception-safe, and does - * not really warrant a separate class for such a purpose. - * - * This class provides a basic guard/smart pointer for C pointers. - * - * Methods in this class do not throw. - * - * \inlibraryapi - * \ingroup module_utility - */ -template -class scoped_cptr -{ - public: - /*! \brief - * Initializes a scoped_cptr that frees \p ptr on scope exit. - * - * \param[in] ptr Pointer to use for initialization. - */ - explicit scoped_cptr(T *ptr = NULL) : ptr_(ptr) {} - //! Frees the pointer passed to the constructor. - ~scoped_cptr() { D(ptr_); } - //! Returns the stored pointer. - T *get() const { return ptr_; } - //! Check for non-null pointer in boolean context. - explicit operator bool () const { return ptr_ != 0; } - //! Sets the pointer and frees previous pointer if necessary. - void reset(T *ptr) { D(ptr_); ptr_ = ptr; } - //! Clears the pointer without freeing the memory, and returns the old value. - T *release() { T *ptr = ptr_; ptr_ = NULL; return ptr; } - - private: - T *ptr_; - - GMX_DISALLOW_COPY_AND_ASSIGN(scoped_cptr); -}; - -//! Simple guard which calls sfree. See scoped_cptr for details. -typedef scoped_cptr scoped_guard_sfree; - -} // namespace gmx - -#endif diff --git a/src/gromacs/utility/unique_cptr.h b/src/gromacs/utility/unique_cptr.h new file mode 100644 index 0000000000..41016f7492 --- /dev/null +++ b/src/gromacs/utility/unique_cptr.h @@ -0,0 +1,76 @@ +/* + * This file is part of the GROMACS molecular simulation package. + * + * Copyright (c) 2012,2014,2015,2016, by the GROMACS development team, led by + * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, + * and including many others, as listed in the AUTHORS file in the + * top-level source directory and at http://www.gromacs.org. + * + * GROMACS is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * GROMACS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with GROMACS; if not, see + * http://www.gnu.org/licenses, or write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * If you want to redistribute modifications to GROMACS, please + * consider that scientific software is very special. Version + * control is crucial - bugs must be traceable. We will be happy to + * consider code for inclusion in the official distribution, but + * derived work must not be called official GROMACS. Details are found + * in the README & COPYING files - if they are missing, get the + * official version at http://www.gromacs.org. + * + * To help us fund GROMACS development, we humbly ask that you cite + * the research papers on the package. Check out http://www.gromacs.org. + */ +/*! \libinternal \file + * \brief + * Declares gmx::unique_cptr and gmx::sfree_guard. + * + * \author Teemu Murtola + * \inlibraryapi + * \ingroup module_utility + */ +#ifndef GMX_UTILITY_UNIQUE_PTR_SFREE_H +#define GMX_UTILITY_UNIQUE_PTR_SFREE_H + +#include + +#include "gromacs/utility/smalloc.h" + +namespace gmx +{ + +//! sfree wrapper to be used as unique_cptr deleter +template +inline void sfree_wrapper(T *p) +{ + sfree(p); +} + +//! \internal \brief wrap function into functor to be used as deleter +template +struct functor_wrapper { + //! call wrapped function + void operator()(T* t) { D(t); } +}; + +//! unique_ptr which takes function pointer as template argument +template +using unique_cptr = std::unique_ptr >; + +//! Simple guard which calls sfree. See unique_cptr for details. +typedef unique_cptr sfree_guard; + +} // namespace gmx + +#endif diff --git a/src/programs/mdrun/tests/energyreader.cpp b/src/programs/mdrun/tests/energyreader.cpp index 47e0414959..e72e0640d7 100644 --- a/src/programs/mdrun/tests/energyreader.cpp +++ b/src/programs/mdrun/tests/energyreader.cpp @@ -52,7 +52,6 @@ #include "gromacs/fileio/enxio.h" #include "gromacs/utility/exceptions.h" -#include "gromacs/utility/scoped_cptr.h" #include "gromacs/utility/stringutil.h" #include "testutils/testasserts.h" diff --git a/src/programs/mdrun/tests/energyreader.h b/src/programs/mdrun/tests/energyreader.h index 8ecfae71e4..b33af5466d 100644 --- a/src/programs/mdrun/tests/energyreader.h +++ b/src/programs/mdrun/tests/energyreader.h @@ -60,7 +60,7 @@ #include #include "gromacs/fileio/enxio.h" -#include "gromacs/utility/scoped_cptr.h" +#include "gromacs/utility/unique_cptr.h" #include "testutils/testasserts.h" @@ -91,11 +91,11 @@ EnergyFrameReaderPtr openEnergyFileToReadFields(const std::string & class EnergyFrame; //! Convenience smart pointer typedef -typedef scoped_cptr ener_file_ptr; +typedef unique_cptr ener_file_ptr; //! Helper function to free resources (NB free_enxframe only frees the contents, not the pointer itself) void done_enxframe(t_enxframe *fr); //! Convenience smart pointer typedef -typedef scoped_cptr enxframe_ptr; +typedef unique_cptr enxframe_ptr; /*! \internal * \brief Manages returning an EnergyFrame containing required energy @@ -138,9 +138,9 @@ class EnergyFrameReader //! Convert energy field name to its index within a t_enxframe from this file. std::map indicesOfEnergyFields_; //! Owning handle of an open energy file ready to read frames. - ener_file_ptr energyFileGuard_; + const ener_file_ptr energyFileGuard_; //! Owning handle of contents of .edr file frame after reading. - enxframe_ptr enxframeGuard_; + const enxframe_ptr enxframeGuard_; //! Whether the API has been used properly (ie. probe before reading). bool haveProbedForNextFrame_; //! Whether there has been a probe that found a next frame. diff --git a/src/programs/mdrun/tests/trajectoryreader.cpp b/src/programs/mdrun/tests/trajectoryreader.cpp index cda1460c8c..35b2a4e106 100644 --- a/src/programs/mdrun/tests/trajectoryreader.cpp +++ b/src/programs/mdrun/tests/trajectoryreader.cpp @@ -51,7 +51,6 @@ #include "gromacs/fileio/trxio.h" #include "gromacs/trajectory/trajectoryframe.h" #include "gromacs/utility/exceptions.h" -#include "gromacs/utility/scoped_cptr.h" #include "gromacs/utility/stringutil.h" #include "testutils/testasserts.h" diff --git a/src/programs/mdrun/tests/trajectoryreader.h b/src/programs/mdrun/tests/trajectoryreader.h index a2fe2c68f9..9184cb141b 100644 --- a/src/programs/mdrun/tests/trajectoryreader.h +++ b/src/programs/mdrun/tests/trajectoryreader.h @@ -54,7 +54,7 @@ #include "gromacs/fileio/oenv.h" #include "gromacs/fileio/trxio.h" #include "gromacs/trajectory/trajectoryframe.h" -#include "gromacs/utility/scoped_cptr.h" +#include "gromacs/utility/unique_cptr.h" #include "testutils/testasserts.h" @@ -70,13 +70,13 @@ namespace test class TrajectoryFrame; //! Convenience smart pointer typedef -typedef scoped_cptr oenv_ptr; +typedef unique_cptr oenv_ptr; //! Convenience smart pointer typedef -typedef scoped_cptr trxstatus_file_ptr; +typedef unique_cptr trxstatus_file_ptr; //! Helper function to free all resources void done_trxframe(t_trxframe *fr); //! Convenience smart pointer typedef -typedef scoped_cptr trxframe_ptr; +typedef unique_cptr trxframe_ptr; /*! \internal * \brief Manages returning a t_trxframe whose contents were read from @@ -125,7 +125,7 @@ class TrajectoryFrameReader //! Owning handle of an open trajectory file ready to read frames. trxstatus_file_ptr trajectoryFileGuard_; //! Owning handle of contents of trajectory file frame after reading. - trxframe_ptr trxframeGuard_; + const trxframe_ptr trxframeGuard_; //! Whether the first frame has been read bool haveReadFirstFrame_; //! Whether the API has been used properly (ie. probe before reading). -- 2.22.0