Replace scoped_cptr with unique_cptr
authorRoland Schulz <roland.schulz@intel.com>
Thu, 24 Nov 2016 02:02:45 +0000 (18:02 -0800)
committerRoland Schulz <roland.schulz@intel.com>
Thu, 15 Dec 2016 21:13:18 +0000 (22:13 +0100)
scoped_cptr only exists for historic reasons

Change-Id: Ie77ce22855cbd440bc51d31cf9c1d5d5b30e10eb

19 files changed:
src/gromacs/analysisdata/modules/plot.cpp
src/gromacs/fileio/gmxfio-xdr.cpp
src/gromacs/fileio/tests/readinp.cpp
src/gromacs/gmxpreprocess/read-conformation.cpp
src/gromacs/gpu_utils/ocl_caching.cpp
src/gromacs/gpu_utils/ocl_compiler.cpp
src/gromacs/mdlib/tests/settle.cpp
src/gromacs/mdrunutility/threadaffinity.cpp
src/gromacs/selection/params.cpp
src/gromacs/selection/parser.cpp
src/gromacs/selection/parser.y
src/gromacs/trajectoryanalysis/modules/sasa.cpp
src/gromacs/trajectoryanalysis/modules/select.cpp
src/gromacs/utility/scoped_cptr.h [deleted file]
src/gromacs/utility/unique_cptr.h [new file with mode: 0644]
src/programs/mdrun/tests/energyreader.cpp
src/programs/mdrun/tests/energyreader.h
src/programs/mdrun/tests/trajectoryreader.cpp
src/programs/mdrun/tests/trajectoryreader.h

index 11dfb933a8a29390cb1589eb7119225afa657257..d44a240479fc9ecca5bdace17104d1ad93d86157 100644 (file)
@@ -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<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);
index 99f78af2a09e94146d710a3ca446e57c665fbe38..1da46d4f52d0494bc93ff3793559b21944e4ca69 100644 (file)
@@ -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"
index 506a3dbd1d818ba75681bb271166e6a9f9dffb03..f32c0c0fb1a5fb5752c8bd9abde390e0c527e855 100644 (file)
@@ -45,8 +45,8 @@
 #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
 {
@@ -77,9 +77,9 @@ class ReadTest : public ::testing::Test
 
         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)
index 0d025476b7a70872105d7be4d8ca95054508f716..e391d2141cbae10a24f2966d3510b46a2aa6ae75 100644 (file)
@@ -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<RVec>(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<RVec>(x_tmp, x_tmp + top->atoms.nr);
index d48fdb5de4ba6785f412efe10abd6d7851c922ee..a5046265e88d736bf3c78316026e7ccea2b72d14 100644 (file)
 
 #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<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));
@@ -129,7 +129,7 @@ makeProgramFromCache(const std::string &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);
@@ -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<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)
@@ -187,7 +187,7 @@ writeBinaryToCache(cl_program program, const std::string &filename)
     }
 
     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));
index 3c5e500b42c98de42acc684963ff06e015cf2c2f..1f92b88f5e22fa82ff4d58b53d4693f38087b658 100644 (file)
 #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<char> buildLogGuard;
+    unique_cptr<char> buildLogGuard;
     if (buildLogSize != 0)
     {
         /* Allocate memory to fit the build log,
index 84d54af65615e857c40f6ee558c82fb138e4f5ae..7872839e1571825ab8f48850030695b0ae512f96 100644 (file)
@@ -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<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);
@@ -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<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;
 
index d30e078a74833d64e9e8a0a5b1ace8ab0f8857a1..83bee6730c0ca72d8343c327e23506d13786a685 100644 (file)
@@ -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)
index 1884a63821bb7e5b96091cc23a39946727c787f6..b2a8ff61f2be9b706ab5433ac04a7d842d1ae8f4 100644 (file)
@@ -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);
index 49471388783a6487da6ab8d78850a3567a08bca3..27bb03189a933c86600adecf19c81ed464e36994 100644 (file)
 /* 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;
              }
index c5b989885f0c1b35fa524408deaf600914c65aa0..5f8197db4741d9d3dff591e471f518618331f1b7 100644 (file)
 #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;
              }
index 20cbc4ab4c7d649a54274d8d7a139b36739bf3e7..eaff4344dca92e02044d0f818afe0495189364e4 100644 (file)
@@ -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)
     {
index 4c6ad4dd9587103769005f0f51413fad345174c9..f84fc44e49659c67d8ebeac477173f12379e8a2b 100644 (file)
@@ -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 (file)
index 944d2cc..0000000
+++ /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 <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
diff --git a/src/gromacs/utility/unique_cptr.h b/src/gromacs/utility/unique_cptr.h
new file mode 100644 (file)
index 0000000..41016f7
--- /dev/null
@@ -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 <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
index 47e0414959d67602e129a5d613cb24643a0a4494..e72e0640d7d9259d79b9b08840c50067b6c0b03c 100644 (file)
@@ -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"
index 8ecfae71e4b2a2bfb3b195fb34d068a01182f03b..b33af5466dcbc22b57d938752a2f6088e36fe50b 100644 (file)
@@ -60,7 +60,7 @@
 #include <vector>
 
 #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, 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
@@ -138,9 +138,9 @@ class EnergyFrameReader
         //! 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.
index cda1460c8c83055b13f6f8898e5c55b72b1216dc..35b2a4e10682fe58924085031490a0c9ff43ed4b 100644 (file)
@@ -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"
index a2fe2c68f9565e6d628f2c95ca302000e96f9534..9184cb141bcb25e422635da5ee815b70473858d5 100644 (file)
@@ -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<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
@@ -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).