Skip to content

Commit

Permalink
Fix #421
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
GiovanniBussi committed Dec 11, 2018
1 parent 1d010c7 commit 02d6d5a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
19 changes: 0 additions & 19 deletions src/core/ActionSet.cpp
Expand Up @@ -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;
}




}
25 changes: 25 additions & 0 deletions src/core/ActionSet.h
Expand Up @@ -61,8 +61,12 @@ class ActionSet:
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;
};

Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/core/ActionWithArguments.cpp
Expand Up @@ -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");
Expand All @@ -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])) ) {
Expand All @@ -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])) ) {
Expand Down

0 comments on commit 02d6d5a

Please sign in to comment.