#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
{
= (impl_->settings_.plotFormat() > 0
? static_cast<xvg_format_t>(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<gmx_output_env_t, output_env_done> oenvGuard(oenv);
+ const unique_cptr<gmx_output_env_t, output_env_done> oenvGuard(oenv);
impl_->fp_ = xvgropen(impl_->filename_.c_str(), impl_->title_.c_str(),
impl_->xlabel_.c_str(), impl_->ylabel_.c_str(),
oenv);
#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"
#include <gtest/gtest.h>
#include "gromacs/fileio/warninp.h"
-#include "gromacs/utility/scoped_cptr.h"
#include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/unique_cptr.h"
namespace gmx
{
int numInputs_;
t_inpfile *inputField_;
- gmx::scoped_cptr<t_inpfile> inpGuard_;
+ gmx::unique_cptr<t_inpfile> inpGuard_;
warninp_t wi_;
- gmx::scoped_cptr<struct warninp, free_warning> wiGuard_;
+ gmx::unique_cptr<struct warninp, free_warning> wiGuard_;
};
TEST_F(ReadTest, get_eint_ReadsInteger)
#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;
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<RVec>(x_tmp, x_tmp + top->natoms);
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<RVec>(x_tmp, x_tmp + top->atoms.nr);
#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.
*/
{
// TODO all this file reading stuff should become gmx::BinaryReader
FILE *f = fopen(filename.c_str(), "rb");
- scoped_cptr<FILE, fclose_wrapper> fileGuard(f);
+ const unique_cptr<FILE, fclose_wrapper> fileGuard(f);
if (!f)
{
GMX_THROW(FileIOError("Failed to open binary cache file " + filename));
// TODO more stdio error handling
fseek(f, 0, SEEK_END);
unsigned char *binary;
- scoped_cptr<unsigned char> binaryGuard;
+ unique_cptr<unsigned char> binaryGuard;
size_t fileSize = ftell(f);
snew(binary, fileSize);
binaryGuard.reset(binary);
}
// TODO all this file writing stuff should become gmx::BinaryWriter
- unsigned char *binary;
+ unsigned char *binary;
snew(binary, fileSize);
- scoped_cptr<unsigned char> binaryGuard(binary);
+ const unique_cptr<unsigned char> binaryGuard(binary);
cl_error = clGetProgramInfo(program, CL_PROGRAM_BINARIES, sizeof(binary), &binary, NULL);
if (cl_error != CL_SUCCESS)
}
FILE *f = fopen(filename.c_str(), "wb");
- scoped_cptr<FILE, fclose_wrapper> fileGuard(f);
+ const unique_cptr<FILE, fclose_wrapper> fileGuard(f);
if (!f)
{
GMX_THROW(FileIOError("Failed to open binary cache file " + filename));
#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"
}
char *buildLog = nullptr;
- scoped_cptr<char> buildLogGuard;
+ unique_cptr<char> buildLogGuard;
if (buildLogSize != 0)
{
/* Allocate memory to fit the build log,
#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"
// 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<gmx_mtop_t> mtopGuard(mtop);
+ const unique_cptr<gmx_mtop_t> mtopGuard(mtop);
mtop->mols.nr = 1;
mtop->nmoltype = 1;
snew(mtop->moltype, mtop->nmoltype);
- scoped_cptr<gmx_moltype_t> moltypeGuard(mtop->moltype);
+ const unique_cptr<gmx_moltype_t> moltypeGuard(mtop->moltype);
mtop->nmolblock = 1;
snew(mtop->molblock, mtop->nmolblock);
- scoped_cptr<gmx_molblock_t> molblockGuard(mtop->molblock);
+ const unique_cptr<gmx_molblock_t> molblockGuard(mtop->molblock);
mtop->molblock[0].type = 0;
- std::vector<int> iatoms;
+ std::vector<int> iatoms;
for (int i = 0; i < numSettles; ++i)
{
iatoms.push_back(settleType);
// Set up the SETTLE parameters.
mtop->ffparams.ntypes = 1;
snew(mtop->ffparams.iparams, mtop->ffparams.ntypes);
- scoped_cptr<t_iparams> iparamsGuard(mtop->ffparams.iparams);
- const real dOH = 0.09572;
- const real dHH = 0.15139;
+ const unique_cptr<t_iparams> 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;
#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
{
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)
/*
* 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.
#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"
"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);
/* 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;
#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
#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;
}
#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;
}
#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;
}
#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;
}
#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;
#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;
}
#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;
#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;
#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;
#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;
#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;
#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;
#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;
#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;
#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;
#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;
#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;
}
#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;
}
#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;
| 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
| 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;
}
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;
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;
}
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;
| 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;
| 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;
| 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;
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;
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;
| 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;
| 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;
| 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;
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;
PARAM value_list
{
BEGIN_ACTION;
- scoped_guard_sfree nameGuard($1);
+ const sfree_guard nameGuard($1);
set($$, SelectionParserParameter::create($1, get($2), @$));
END_ACTION;
}
| string %prec PARAM_REDUCT
{
BEGIN_ACTION;
- scoped_guard_sfree stringGuard($1);
+ const sfree_guard stringGuard($1);
set($$, SelectionParserValue::createString($1, @$));
END_ACTION;
}
#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"
}
sfree(area);
}
- scoped_guard_sfree dotsGuard(surfacedots);
+ const sfree_guard dotsGuard(surfacedots);
if (bConnolly)
{
#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
{
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));
+++ /dev/null
-/*
- * 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 <teemu.murtola@gmail.com>
- * \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 <class T>
-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 T, void D(T *) = sfree_wrapper>
-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<void> scoped_guard_sfree;
-
-} // namespace gmx
-
-#endif
--- /dev/null
+/*
+ * 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 <teemu.murtola@gmail.com>
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+#ifndef GMX_UTILITY_UNIQUE_PTR_SFREE_H
+#define GMX_UTILITY_UNIQUE_PTR_SFREE_H
+
+#include <memory>
+
+#include "gromacs/utility/smalloc.h"
+
+namespace gmx
+{
+
+//! sfree wrapper to be used as unique_cptr deleter
+template <class T>
+inline void sfree_wrapper(T *p)
+{
+ sfree(p);
+}
+
+//! \internal \brief wrap function into functor to be used as deleter
+template<class T, void D(T *)>
+struct functor_wrapper {
+ //! call wrapped function
+ void operator()(T* t) { D(t); }
+};
+
+//! unique_ptr which takes function pointer as template argument
+template<typename T, void D(T *) = sfree_wrapper>
+using unique_cptr = std::unique_ptr<T, functor_wrapper<T, D> >;
+
+//! Simple guard which calls sfree. See unique_cptr for details.
+typedef unique_cptr<void> sfree_guard;
+
+} // namespace gmx
+
+#endif
#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"
#include <vector>
#include "gromacs/fileio/enxio.h"
-#include "gromacs/utility/scoped_cptr.h"
+#include "gromacs/utility/unique_cptr.h"
#include "testutils/testasserts.h"
class EnergyFrame;
//! Convenience smart pointer typedef
-typedef scoped_cptr<ener_file, done_ener_file> ener_file_ptr;
+typedef unique_cptr<ener_file, done_ener_file> 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<t_enxframe, done_enxframe> enxframe_ptr;
+typedef unique_cptr<t_enxframe, done_enxframe> enxframe_ptr;
/*! \internal
* \brief Manages returning an EnergyFrame containing required energy
//! Convert energy field name to its index within a t_enxframe from this file.
std::map<std::string, int> 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.
#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"
#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"
class TrajectoryFrame;
//! Convenience smart pointer typedef
-typedef scoped_cptr<gmx_output_env_t, output_env_done> oenv_ptr;
+typedef unique_cptr<gmx_output_env_t, output_env_done> oenv_ptr;
//! Convenience smart pointer typedef
-typedef scoped_cptr<t_trxstatus, close_trx> trxstatus_file_ptr;
+typedef unique_cptr<t_trxstatus, close_trx> trxstatus_file_ptr;
//! Helper function to free all resources
void done_trxframe(t_trxframe *fr);
//! Convenience smart pointer typedef
-typedef scoped_cptr<t_trxframe, done_trxframe> trxframe_ptr;
+typedef unique_cptr<t_trxframe, done_trxframe> trxframe_ptr;
/*! \internal
* \brief Manages returning a t_trxframe whose contents were read from
//! 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).