From 02d6d5a8bc4bdcbb77b14c153c0095c8aae2b67b Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Tue, 11 Dec 2018 14:42:46 +0100
Subject: [PATCH] Fix #421

Notice that I had to change to interface of a couple of functions
ActionSet:getLabelList() and getLabelVector()
adding a template parameter.
Should be harmless since these functions were used in a few places only.
---
 src/core/ActionSet.cpp           | 19 -------------------
 src/core/ActionSet.h             | 25 +++++++++++++++++++++++++
 src/core/ActionWithArguments.cpp | 12 ++++++------
 3 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/src/core/ActionSet.cpp b/src/core/ActionSet.cpp
index da711c95d..f7f29806c 100644
--- a/src/core/ActionSet.cpp
+++ b/src/core/ActionSet.cpp
@@ -40,23 +40,4 @@ void ActionSet::clearDelete() {
 }
 
 
-std::string ActionSet::getLabelList() const {
-  std::string outlist;
-  for(const auto & p : (*this)) {
-    outlist+=dynamic_cast<Action*>(p)->getLabel()+" ";
-  };
-  return  outlist;
-}
-
-std::vector<std::string> ActionSet::getLabelVector() const {
-  std::vector<std::string> outlist;
-  for(const auto & p : (*this)) {
-    outlist.push_back(dynamic_cast<Action*>(p)->getLabel());
-  };
-  return  outlist;
-}
-
-
-
-
 }
diff --git a/src/core/ActionSet.h b/src/core/ActionSet.h
index 3d5ea6fc7..63136f002 100644
--- a/src/core/ActionSet.h
+++ b/src/core/ActionSet.h
@@ -61,8 +61,12 @@ public:
   template <class T>
   T selectWithLabel(const std::string&s)const;
 /// get the labels in the list of actions in form of a string (useful to debug)
+/// Only classes that can be dynamic casted to T are reported
+  template <class T>
   std::string getLabelList() const;
 /// get the labels in the form of a vector of strings
+/// Only classes that can be dynamic casted to T are reported
+  template <class T>
   std::vector<std::string> getLabelVector() const;
 };
 
@@ -98,6 +102,27 @@ std::vector<Action*> ActionSet::selectNot()const {
   return ret;
 }
 
+template <class T>
+std::string ActionSet::getLabelList() const {
+  std::string outlist;
+  for(const auto & p : (*this)) {
+    if(dynamic_cast<T>(p)) outlist+=p->getLabel()+" ";
+  };
+  return  outlist;
+}
+
+
+template <class T>
+std::vector<std::string> ActionSet::getLabelVector() const {
+  std::vector<std::string> outlist;
+  for(const auto & p : (*this)) {
+    if(dynamic_cast<T>(p)) outlist.push_back(p->getLabel());
+  };
+  return  outlist;
+}
+
+
+
 }
 
 #endif
diff --git a/src/core/ActionWithArguments.cpp b/src/core/ActionWithArguments.cpp
index 5865375d8..3a211f6d6 100644
--- a/src/core/ActionWithArguments.cpp
+++ b/src/core/ActionWithArguments.cpp
@@ -148,8 +148,8 @@ void ActionWithArguments::interpretArgumentList(const std::vector<std::string>&
           // Take all the values from an action with a specific name
           ActionWithValue* action=plumed.getActionSet().selectWithLabel<ActionWithValue*>(a);
           if(!action) {
-            std::string str=" (hint! the actions in this ActionSet are: ";
-            str+=plumed.getActionSet().getLabelList()+")";
+            std::string str=" (hint! the actions with value in this ActionSet are: ";
+            str+=plumed.getActionSet().getLabelList<ActionWithValue*>()+")";
             error("cannot find action named " + a + str);
           }
           if( action->getNumberOfComponents()==0 ) error("found " + a +".* indicating use all components calculated by action with label " + a + " but this action has no components");
@@ -168,8 +168,8 @@ void ActionWithArguments::interpretArgumentList(const std::vector<std::string>&
           // Take values with a specific name
           ActionWithValue* action=plumed.getActionSet().selectWithLabel<ActionWithValue*>(a);
           if(!action) {
-            std::string str=" (hint! the actions in this ActionSet are: ";
-            str+=plumed.getActionSet().getLabelList()+")";
+            std::string str=" (hint! the actions with value in this ActionSet are: ";
+            str+=plumed.getActionSet().getLabelList<ActionWithValue*>()+")";
             error("cannot find action named " + a +str);
           }
           if( !(action->exists(c[i])) ) {
@@ -190,8 +190,8 @@ void ActionWithArguments::interpretArgumentList(const std::vector<std::string>&
         } else {
           ActionWithValue* action=plumed.getActionSet().selectWithLabel<ActionWithValue*>(c[i]);
           if(!action) {
-            std::string str=" (hint! the actions in this ActionSet are: ";
-            str+=plumed.getActionSet().getLabelList()+")";
+            std::string str=" (hint! the actions with value in this ActionSet are: ";
+            str+=plumed.getActionSet().getLabelList<ActionWithValue*>()+")";
             error("cannot find action named " + c[i] + str );
           }
           if( !(action->exists(c[i])) ) {
-- 
GitLab