diff --git a/src/tools/PlumedHandle.cpp b/src/tools/PlumedHandle.cpp index e1d0a3efe3..952e07540c 100644 --- a/src/tools/PlumedHandle.cpp +++ b/src/tools/PlumedHandle.cpp @@ -86,4 +86,21 @@ void PlumedHandle::cmd(const std::string & key,const TypesafePtr & ptr) { } else plumed_error() << "should never arrive here (either one or the other should work)"; } +PlumedHandle::PlumedHandle(PlumedHandle && other) noexcept: + local(std::move(other.local)), + loaded(other.loaded) +{ + other.loaded=nullptr; +} + +PlumedHandle & PlumedHandle::operator=(PlumedHandle && other) noexcept { + if(this!=&other) { + if(loaded) plumed_finalize(plumed_v2c(loaded)); + local=std::move(other.local); + loaded=other.loaded; + other.loaded=nullptr; + } + return *this; +} + } diff --git a/src/tools/PlumedHandle.h b/src/tools/PlumedHandle.h index c0ea543249..d3e1d5d77c 100644 --- a/src/tools/PlumedHandle.h +++ b/src/tools/PlumedHandle.h @@ -77,7 +77,7 @@ class PlumedHandle : /// Used when using the current kernel in order to avoid unneeded indirections. std::unique_ptr local; /// Pointer to loaded Plumed object; - void* const loaded=nullptr; + void* loaded=nullptr; /// Constructor using the path to a kernel. /// I keep it private to avoid confusion wrt the /// similar constructor of PLMD::Plumed that accepts a string (conversion from FORTRAN). @@ -94,7 +94,9 @@ class PlumedHandle : /// I make it virtual for future extensibility, though this is not necessary now. virtual ~PlumedHandle(); /// Move constructor. - PlumedHandle(PlumedHandle &&) = default; + PlumedHandle(PlumedHandle && other) noexcept; +/// Move assignment. + PlumedHandle & operator=(PlumedHandle && other) noexcept; /// Execute cmd. void cmd(const std::string & key,const TypesafePtr & ptr=nullptr); /// Bring in the possibility to pass shape/nelem