Merge branch release-2020 into master
[alexxy/gromacs.git] / src / gromacs / modularsimulator / modularsimulator.h
index 5c51e1cc60448f162978fa354f1c93f485cb6eea..114c4a21aab71bae1edb3ef659ce52a5d00be386 100644 (file)
@@ -219,6 +219,9 @@ private:
     //! \cond
     //! Helper function to add elements or signallers to the call list via raw pointer
     template<typename T, typename U>
+    static void addToCallList(U* element, std::vector<compat::not_null<T*>>& callList);
+    //! Helper function to add elements or signallers to the call list via non-null raw pointer
+    template<typename T, typename U>
     static void addToCallList(compat::not_null<U*> element, std::vector<compat::not_null<T*>>& callList);
     //! Helper function to add elements or signallers to the call list via smart pointer
     template<typename T, typename U>
@@ -295,6 +298,15 @@ ModularSimulator::ModularSimulator(Args&&... args) : ISimulator(std::forward<Arg
 }
 
 //! \cond
+template<typename T, typename U>
+void ModularSimulator::addToCallList(U* element, std::vector<compat::not_null<T*>>& callList)
+{
+    if (element)
+    {
+        callList.emplace_back(element);
+    }
+}
+
 template<typename T, typename U>
 void ModularSimulator::addToCallList(gmx::compat::not_null<U*>          element,
                                      std::vector<compat::not_null<T*>>& callList)
@@ -305,7 +317,10 @@ void ModularSimulator::addToCallList(gmx::compat::not_null<U*>          element,
 template<typename T, typename U>
 void ModularSimulator::addToCallList(std::unique_ptr<U>& element, std::vector<compat::not_null<T*>>& callList)
 {
-    callList.emplace_back(compat::make_not_null(element.get()));
+    if (element)
+    {
+        callList.emplace_back(compat::make_not_null(element.get()));
+    }
 }
 
 template<typename T, typename U>
@@ -313,8 +328,11 @@ void ModularSimulator::addToCallListAndMove(std::unique_ptr<U>                 e
                                             std::vector<compat::not_null<T*>>& callList,
                                             std::vector<std::unique_ptr<T>>&   elementList)
 {
-    callList.emplace_back(compat::make_not_null(element.get()));
-    elementList.emplace_back(std::move(element));
+    if (element)
+    {
+        callList.emplace_back(compat::make_not_null(element.get()));
+        elementList.emplace_back(std::move(element));
+    }
 }
 //! \endcond