45 #include "Teuchos_StrUtils.hpp" 51 const std::string & delim,
52 std::vector<std::string> & output)
75 validate(
const Teuchos::ParameterEntry & entry,
76 const std::string & paramName,
77 const std::string & sublistName)
const 79 const std::string &entryName = entry.getAny(
false).typeName();
80 Teuchos::any anyValue = entry.getAny(
true);
83 TEUCHOS_TEST_FOR_EXCEPTION(!(anyValue.type() ==
typeid(std::string) ),
84 Teuchos::Exceptions::InvalidParameterType,
85 "Sorry but it looks like the \"" << paramName <<
"\"" <<
86 " parameter in the \"" << sublistName <<
87 "\" sublist does not exist." << std::endl << std::endl <<
88 "Error: The value that you entered was the wrong type." << std::endl <<
89 "Parameter: " << paramName << std::endl <<
90 "Type specified: " << entryName << std::endl <<
91 "Type accepted: " <<
typeid(std::string).name() <<
92 std::endl << std::endl);
94 const std::string & value = Teuchos::any_cast<std::string>(anyValue);
96 std::vector<std::string> tokens;
97 split(value,
",",tokens);
100 const std::string errorStr =
"The value for \"string-list\" type parameter in sublist \""+sublistName+
"\" named \""+paramName+
"\" " 101 "is incorrectly formatted. The expected format is\n" 102 " \"<string>[, <string>]*\" " 103 "your value is \""+value+
"\"";
106 TEUCHOS_TEST_FOR_EXCEPTION(tokens.size()==0,
107 Teuchos::Exceptions::InvalidParameterValue,errorStr);
113 std::string
const &docString, std::ostream &out)
const 115 Teuchos::StrUtils::printLines(out,
"# ",docString);
116 out <<
"# Validator Used: " << std::endl;
117 out <<
"# CommaSeparatedEntry Validator" << std::endl;
void validate(const Teuchos::ParameterEntry &entry, const std::string ¶mName, const std::string &sublistName) const
void printDoc(const std::string &docString, std::ostream &out) const
void StringTokenizer(std::vector< std::string > &tokens, const std::string &str, const std::string delimiters, bool trim)
Tokenize a string, put tokens in a vector.
static void split(const std::string &str, const std::string &delim, std::vector< std::string > &tokens)
Utility function for tokenizing.