Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_CommaSeparatedEntryValidator.cpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Panzer: A partial differential equation assembly
4// engine for strongly coupled complex multiphysics systems
5//
6// Copyright 2011 NTESS and the Panzer contributors.
7// SPDX-License-Identifier: BSD-3-Clause
8// *****************************************************************************
9// @HEADER
10
13#include "Teuchos_StrUtils.hpp"
14
15namespace panzer {
16
18split(const std::string & str,
19 const std::string & delim,
20 std::vector<std::string> & output)
21{
22 output.clear();
23
24 // typedef boost::tokenizer<boost::char_separator<char> >
25 // tokenizer;
26
27 // boost::char_separator<char> sep(delim.c_str());
28 // tokenizer tokens(str, sep);
29 // for(tokenizer::iterator tok_iter = tokens.begin();
30 // tok_iter != tokens.end(); ++tok_iter) {
31 // // extract token, remove spaces
32 // std::string s = *tok_iter;
33 // boost::trim(s);
34 // if(s.length()!=0)
35 // output.push_back(s);
36 // }
37
38 panzer::StringTokenizer(output, str, delim, true);
39}
40
41void
43validate(const Teuchos::ParameterEntry & entry,
44 const std::string & paramName,
45 const std::string & sublistName) const
46{
47 const std::string &entryName = entry.getAny(false).typeName();
48 Teuchos::any anyValue = entry.getAny(true);
49
50 // type passed, validate value
51 TEUCHOS_TEST_FOR_EXCEPTION(!(anyValue.type() == typeid(std::string) ),
52 Teuchos::Exceptions::InvalidParameterType,
53 "Sorry but it looks like the \"" << paramName << "\"" <<
54 " parameter in the \"" << sublistName <<
55 "\" sublist does not exist." << std::endl << std::endl <<
56 "Error: The value that you entered was the wrong type." << std::endl <<
57 "Parameter: " << paramName << std::endl <<
58 "Type specified: " << entryName << std::endl <<
59 "Type accepted: " << typeid(std::string).name() <<
60 std::endl << std::endl);
61
62 const std::string & value = Teuchos::any_cast<std::string>(anyValue);
63
64 std::vector<std::string> tokens;
65 split(value,",",tokens);
66
67 if(!allowEmpty_) {
68 const std::string errorStr = "The value for \"string-list\" type parameter in sublist \""+sublistName+"\" named \""+paramName+"\" "
69 "is incorrectly formatted. The expected format is\n"
70 " \"<string>[, <string>]*\" "
71 "your value is \""+value+"\"";
72
73 // verify that their is a response type and an evaluation type
74 TEUCHOS_TEST_FOR_EXCEPTION(tokens.size()==0,
75 Teuchos::Exceptions::InvalidParameterValue,errorStr);
76 }
77}
78
79
81 std::string const &docString, std::ostream &out) const
82{
83 Teuchos::StrUtils::printLines(out,"# ",docString);
84 out << "# Validator Used: " << std::endl;
85 out << "# CommaSeparatedEntry Validator" << std::endl;
86}
87
88}
static void split(const std::string &str, const std::string &delim, std::vector< std::string > &tokens)
Utility function for tokenizing.
void validate(const Teuchos::ParameterEntry &entry, const std::string &paramName, 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.