From 3720cc21a629bdc5b3cb16405b75a2ead1090a51 Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Sun, 6 Jul 2014 22:46:13 +0300 Subject: [PATCH] Change some gmx_unique_ptr to shared_ptr in public headers Change "trivial" occurrences of gmx_unique_ptr to boost::shared_ptr in cases where there is a simple factory or a sink function where the ownership of the object passes in or out from the library. The main advantages: - Removes GMX_CXX11 dependencies from installed headers. - Improves memory management, where the memory is deallocated in the same library/executable that allocated it (through the shared_ptr deleter that gets created during construction). The only disadvantage is that this blurs the ownership of the objects slightly. There are only two other instances of gmx_unique_ptr left in installed headers, and those should be relatively easy to remove as well with a bit of refactoring. Related to #1454. Change-Id: I1f694b30e4f8129f5d010115c0968a444e927ca0 --- src/gromacs/analysisdata/modules/histogram.h | 7 ++++--- src/gromacs/commandline/cmdlineprogramcontext.cpp | 4 ++-- src/gromacs/commandline/cmdlineprogramcontext.h | 5 +++-- src/gromacs/commandline/tests/cmdlineprogramcontext.cpp | 6 +++--- src/gromacs/trajectoryanalysis/analysismodule.h | 7 ++++--- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/gromacs/analysisdata/modules/histogram.h b/src/gromacs/analysisdata/modules/histogram.h index 3b626cba25..c577dae07d 100644 --- a/src/gromacs/analysisdata/modules/histogram.h +++ b/src/gromacs/analysisdata/modules/histogram.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by + * Copyright (c) 2010,2011,2012,2013,2014, 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. @@ -43,10 +43,11 @@ #ifndef GMX_ANALYSISDATA_MODULES_HISTOGRAM_H #define GMX_ANALYSISDATA_MODULES_HISTOGRAM_H +#include + #include "../abstractdata.h" #include "../arraydata.h" #include "../datamodule.h" -#include "../../utility/uniqueptr.h" namespace gmx { @@ -246,7 +247,7 @@ class BasicHistogramImpl; class AbstractAverageHistogram; //! Smart pointer to manage an AbstractAverageHistogram object. -typedef gmx_unique_ptr::type +typedef boost::shared_ptr AverageHistogramPointer; /*! \brief diff --git a/src/gromacs/commandline/cmdlineprogramcontext.cpp b/src/gromacs/commandline/cmdlineprogramcontext.cpp index 0f3ce6c383..eefaa2c45d 100644 --- a/src/gromacs/commandline/cmdlineprogramcontext.cpp +++ b/src/gromacs/commandline/cmdlineprogramcontext.cpp @@ -321,7 +321,7 @@ CommandLineProgramContext::Impl::Impl() CommandLineProgramContext::Impl::Impl(int argc, const char *const argv[], ExecutableEnvironmentPointer env) - : executableEnv_(move(env)) + : executableEnv_(env) { invokedName_ = (argc != 0 ? argv[0] : ""); programName_ = Path::getFilename(invokedName_); @@ -370,7 +370,7 @@ CommandLineProgramContext::CommandLineProgramContext( CommandLineProgramContext::CommandLineProgramContext( int argc, const char *const argv[], ExecutableEnvironmentPointer env) - : impl_(new Impl(argc, argv, move(env))) + : impl_(new Impl(argc, argv, env)) { } diff --git a/src/gromacs/commandline/cmdlineprogramcontext.h b/src/gromacs/commandline/cmdlineprogramcontext.h index 09b05bf300..206585669a 100644 --- a/src/gromacs/commandline/cmdlineprogramcontext.h +++ b/src/gromacs/commandline/cmdlineprogramcontext.h @@ -51,9 +51,10 @@ #include #include +#include + #include "../utility/common.h" #include "../utility/programcontext.h" -#include "../utility/uniqueptr.h" namespace gmx { @@ -90,7 +91,7 @@ class ExecutableEnvironmentInterface }; //! Shorthand for a smart pointer to ExecutableEnvironmentInterface. -typedef gmx_unique_ptr::type +typedef boost::shared_ptr ExecutableEnvironmentPointer; /*! \libinternal \brief diff --git a/src/gromacs/commandline/tests/cmdlineprogramcontext.cpp b/src/gromacs/commandline/tests/cmdlineprogramcontext.cpp index 4fb136f52c..df9559608d 100644 --- a/src/gromacs/commandline/tests/cmdlineprogramcontext.cpp +++ b/src/gromacs/commandline/tests/cmdlineprogramcontext.cpp @@ -42,12 +42,12 @@ #include #include +#include #include #include "gromacs/commandline/cmdlineprogramcontext.h" #include "gromacs/utility/common.h" #include "gromacs/utility/path.h" -#include "gromacs/utility/uniqueptr.h" #include "testutils/cmdlinetest.h" @@ -93,7 +93,7 @@ class TestExecutableEnvironment : public gmx::ExecutableEnvironmentInterface }; //! Shorthand for a smart pointer to TestExecutableEnvironment. -typedef gmx::gmx_unique_ptr::type +typedef boost::shared_ptr TestExecutableEnvironmentPointer; class CommandLineProgramContextTest : public ::testing::Test @@ -111,7 +111,7 @@ class CommandLineProgramContextTest : public ::testing::Test void testBinaryPathSearch(const char *argv0) { ASSERT_TRUE(env_.get() != NULL); - gmx::CommandLineProgramContext info(1, &argv0, move(env_)); + gmx::CommandLineProgramContext info(1, &argv0, env_); EXPECT_EQ(expectedExecutable_, info.fullBinaryPath()); } void testBinaryPathSearch(const std::string &argv0) diff --git a/src/gromacs/trajectoryanalysis/analysismodule.h b/src/gromacs/trajectoryanalysis/analysismodule.h index 0a26830726..1bee97d8a9 100644 --- a/src/gromacs/trajectoryanalysis/analysismodule.h +++ b/src/gromacs/trajectoryanalysis/analysismodule.h @@ -47,9 +47,10 @@ #include #include +#include + #include "../selection/selection.h" // For gmx::SelectionList #include "../utility/common.h" -#include "../utility/uniqueptr.h" struct t_pbc; struct t_trxframe; @@ -177,7 +178,7 @@ class TrajectoryAnalysisModuleData }; //! Smart pointer to manage a TrajectoryAnalysisModuleData object. -typedef gmx_unique_ptr::type +typedef boost::shared_ptr TrajectoryAnalysisModuleDataPointer; /*! \brief @@ -496,7 +497,7 @@ class TrajectoryAnalysisModule }; //! Smart pointer to manage a TrajectoryAnalysisModule. -typedef gmx_unique_ptr::type +typedef boost::shared_ptr TrajectoryAnalysisModulePointer; } // namespace gmx -- 2.22.0