Change some gmx_unique_ptr to shared_ptr in public headers
authorTeemu Murtola <teemu.murtola@gmail.com>
Sun, 6 Jul 2014 19:46:13 +0000 (22:46 +0300)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 8 Jul 2014 13:05:18 +0000 (15:05 +0200)
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
src/gromacs/commandline/cmdlineprogramcontext.cpp
src/gromacs/commandline/cmdlineprogramcontext.h
src/gromacs/commandline/tests/cmdlineprogramcontext.cpp
src/gromacs/trajectoryanalysis/analysismodule.h

index 3b626cba259f45b6560dc66d6a91a55aa99ebf58..c577dae07d12d132ef0071a5f85cbb35d4102ca2 100644 (file)
@@ -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.
 #ifndef GMX_ANALYSISDATA_MODULES_HISTOGRAM_H
 #define GMX_ANALYSISDATA_MODULES_HISTOGRAM_H
 
+#include <boost/shared_ptr.hpp>
+
 #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<AbstractAverageHistogram>::type
+typedef boost::shared_ptr<AbstractAverageHistogram>
     AverageHistogramPointer;
 
 /*! \brief
index 0f3ce6c383458e8a9e3913a98a500e45f1c80be5..eefaa2c45d7b403aad6c1ccb96d95f7a056b6197 100644 (file)
@@ -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))
 {
 }
 
index 09b05bf300242a2c658f167d409c4c27b2bcc318..206585669aebbcd832e78f2021d317858fc19670 100644 (file)
 #include <string>
 #include <vector>
 
+#include <boost/shared_ptr.hpp>
+
 #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<ExecutableEnvironmentInterface>::type
+typedef boost::shared_ptr<ExecutableEnvironmentInterface>
     ExecutableEnvironmentPointer;
 
 /*! \libinternal \brief
index 4fb136f52c2624f62cfc127c6648f3682a2ae793..df9559608d10327219522e7c413d768a47595e22 100644 (file)
 #include <string>
 #include <vector>
 
+#include <boost/shared_ptr.hpp>
 #include <gtest/gtest.h>
 
 #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<TestExecutableEnvironment>::type
+typedef boost::shared_ptr<TestExecutableEnvironment>
     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)
index 0a26830726614c5640c7a714be197f3a4a34a4ba..1bee97d8a95a32ede03a24ebf49066245a93ab84 100644 (file)
 #include <string>
 #include <vector>
 
+#include <boost/shared_ptr.hpp>
+
 #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<TrajectoryAnalysisModuleData>::type
+typedef boost::shared_ptr<TrajectoryAnalysisModuleData>
     TrajectoryAnalysisModuleDataPointer;
 
 /*! \brief
@@ -496,7 +497,7 @@ class TrajectoryAnalysisModule
 };
 
 //! Smart pointer to manage a TrajectoryAnalysisModule.
-typedef gmx_unique_ptr<TrajectoryAnalysisModule>::type
+typedef boost::shared_ptr<TrajectoryAnalysisModule>
     TrajectoryAnalysisModulePointer;
 
 } // namespace gmx