42#include "Teuchos_StandardParameterEntryValidators.hpp"
47 const EVerbosityLevel verbLevel
65 true, std::invalid_argument,
"Teuchos::getVerbosityLevelParameterValue"
66 "Name(const Teuchos::EVerbosityLevel): Input argument " << verbLevel <<
67 " has an invalid value. Valid values are VERB_DEFAULT=" << VERB_DEFAULT
68 <<
", VERB_NONE=" << VERB_NONE <<
", VERB_LOW=" << VERB_LOW <<
", "
69 "VERB_MEDIUM=" << VERB_MEDIUM <<
", VERB_HIGH=" << VERB_HIGH <<
", AND "
70 "VERB_EXTREME=" << VERB_EXTREME <<
".");
89 std::string
const& defaultParameterName
93 new StringToIntegralParameterEntryValidator<EVerbosityLevel>(
95 getVerbosityLevelParameterValueName(VERB_DEFAULT),
96 getVerbosityLevelParameterValueName(VERB_NONE),
97 getVerbosityLevelParameterValueName(VERB_LOW),
98 getVerbosityLevelParameterValueName(VERB_MEDIUM),
99 getVerbosityLevelParameterValueName(VERB_HIGH),
100 getVerbosityLevelParameterValueName(VERB_EXTREME)
103 "Use level set in code",
105 "Produce minimal output",
106 "Produce a little more output",
107 "Produce a higher level of output",
108 "Produce the highest level of output"
110 tuple<EVerbosityLevel>(
135BoolParameterEntryValidator::BoolParameterEntryValidator()
137 finishInitialization();
150 if(
anyValue.type() ==
typeid(
bool) )
152 if(
anyValue.type() ==
typeid(std::string) ) {
156 if(
str ==
"false" ) {
159 else if(
str ==
"true" ) {
182 return "boolValidator";
186 std::string
const & docString,
191 out <<
"# Accepted types: " << acceptedTypesString_ <<
".\n";
227void BoolParameterEntryValidator::finishInitialization()
229 std::ostringstream
oss;
231 acceptedTypesString_ =
oss.str();
233 acceptedTypesString_ =
oss.str();
237void BoolParameterEntryValidator::throwTypeError(
238 ParameterEntry
const& entry,
239 std::string
const& paramName,
240 std::string
const& sublistName
243 const std::string &entryName = entry.getAny(
false).typeName();
245 true, Exceptions::InvalidParameterType
246 ,
"Error, the parameter {paramName=\""<<paramName<<
"\""
247 ",type=\""<<entryName<<
"\"}"
248 <<
"\nin the sublist \"" << sublistName <<
"\""
249 <<
"\nhas the wrong type."
250 <<
"\n\nThe accepted types are: " << acceptedTypesString_ <<
"!";
263 : preferredType_(PREFER_DOUBLE), acceptedTypes_(
AcceptedTypes())
265 finishInitialization();
274 finishInitialization();
287 if( acceptedTypes_.allowInt() &&
anyValue.type() ==
typeid(
int) )
289 if( acceptedTypes_.allowLongLong() &&
anyValue.type() ==
typeid(
long long) )
291 if( acceptedTypes_.allowDouble() &&
anyValue.type() ==
typeid(
double) )
293 if( acceptedTypes_.allowString() &&
anyValue.type() ==
typeid(std::string) )
305 if( acceptedTypes_.allowInt() &&
anyValue.type() ==
typeid(
int) )
307 if( acceptedTypes_.allowLongLong() &&
anyValue.type() ==
typeid(
long long) )
309 if( acceptedTypes_.allowDouble() &&
anyValue.type() ==
typeid(
double) )
311 if( acceptedTypes_.allowString() &&
anyValue.type() ==
typeid(std::string) )
323 if( acceptedTypes_.allowInt() &&
anyValue.type() ==
typeid(
int) )
325 if( acceptedTypes_.allowLongLong() &&
anyValue.type() ==
typeid(
long long) )
327 if( acceptedTypes_.allowDouble() &&
anyValue.type() ==
typeid(
double) )
329 if( acceptedTypes_.allowString() &&
anyValue.type() ==
typeid(std::string) )
342 if( acceptedTypes_.allowInt() &&
anyValue.type() ==
typeid(
int) )
344 if( acceptedTypes_.allowLongLong() &&
anyValue.type() ==
typeid(
long long) )
346 if( acceptedTypes_.allowDouble() &&
anyValue.type() ==
typeid(
double) )
348 if( acceptedTypes_.allowString() &&
anyValue.type() ==
typeid(std::string) )
398 return acceptedTypes_.allowInt();
403 return acceptedTypes_.allowLongLong();
408 return acceptedTypes_.allowDouble();
413 return acceptedTypes_.allowString();
420 return preferredType_;
429 return "anynumberValidator";
434 std::string
const & docString,
439 out <<
"# Accepted types: " << acceptedTypesString_ <<
".\n";
472 switch(preferredType_) {
479 case PREFER_LONG_LONG:
506void AnyNumberParameterEntryValidator::finishInitialization()
509 std::ostringstream
oss;
511 if(acceptedTypes_.allowInt()) {
515 if(acceptedTypes_.allowLongLong()) {
516 oss <<
"\"long long\"";
519 if(acceptedTypes_.allowDouble()) {
520 if(addedType) oss <<
", ";
524 if(acceptedTypes_.allowString()) {
525 if(addedType) oss <<
", ";
529 acceptedTypesString_ = oss.str();
533void AnyNumberParameterEntryValidator::throwTypeError(
534 ParameterEntry
const& entry,
535 std::string
const& paramName,
536 std::string
const& sublistName
539 const std::string &entryName = entry.getAny(
false).typeName();
541 true, Exceptions::InvalidParameterType
542 ,
"Error, the parameter {paramName=\""<<paramName<<
"\""
543 ",type=\""<<entryName<<
"\"}"
544 <<
"\nin the sublist \"" << sublistName <<
"\""
545 <<
"\nhas the wrong type."
546 <<
"\n\nThe accepted types are: " << acceptedTypesString_ <<
"!";
551RCP<AnyNumberParameterEntryValidator>
554 return anyNumberParameterEntryValidator(
555 AnyNumberParameterEntryValidator::PREFER_INT,
568 return mustAlreadyExist_;
579 return mustAlreadyExist_;
604 "\" sublist is has an error." << std::endl << std::endl <<
605 "Error: The value that you entered was the wrong type." << std::endl <<
606 "Parameter: " <<
paramName << std::endl <<
607 "Type specified: " <<
entryName << std::endl <<
608 "Type accepted: " <<
typeid(std::string).name() <<
609 std::endl << std::endl);
610 if(mustAlreadyExist_ && !EmptyNameOK_){
616 "\" sublist is has an error." << std::endl << std::endl <<
617 "Error: The file must already exists. The value you entered does " <<
618 "not corresspond to an existing file name." << std::endl <<
619 "Parameter: " <<
paramName << std::endl <<
620 "File name specified: " <<
fileName << std::endl << std::endl);
627 return "FilenameValidator";
632 std::string
const &docString, std::ostream &out)
const
635 out <<
"# Validator Used: " << std::endl;
636 out <<
"# FileName Validator" << std::endl;
660 return validStrings_;
667 return validStrings_;
681 "\" sublist is has an error." << std::endl << std::endl <<
682 "Error: The value that you entered was the wrong type." <<
683 "Parameter: " <<
paramName << std::endl <<
684 "Type specified: " <<
entryName << std::endl <<
689 it = std::find(validStrings_->begin(),
695 "\" sublist is has an error." << std::endl << std::endl <<
696 "Error: The value that was entered doesn't fall with in "
697 "the range set by the validator." <<
698 "Parameter: " <<
paramName << std::endl <<
699 "Acceptable Values: " << *validStrings_ << std::endl <<
708 return "StringValidator";
713 std::ostream &out)
const
716 out <<
"# Validator Used: " << std::endl;
717 out <<
"# String Validator" << std::endl;
718 if (validStrings_.
get() && validStrings_->size()){
719 out <<
"# Acceptable Values: " << *validStrings_ << std::endl;
735Teuchos::boolParameterEntryValidator()
737 return rcp(
new BoolParameterEntryValidator());
741Teuchos::anyNumberParameterEntryValidator()
743 return rcp(
new AnyNumberParameterEntryValidator());
748Teuchos::anyNumberParameterEntryValidator(
749 AnyNumberParameterEntryValidator::EPreferredType
const preferredType,
750 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
754 new AnyNumberParameterEntryValidator(
755 preferredType, acceptedTypes
760void Teuchos::setIntParameter(
761 std::string
const& paramName,
762 int const value, std::string
const& docString,
763 ParameterList *paramList,
764 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
768 const RCP<const ParameterEntryValidator> paramEntryValidator =
769 anyNumberParameterEntryValidator(
770 AnyNumberParameterEntryValidator::PREFER_INT, acceptedTypes
772 paramList->set(paramName, value, docString, paramEntryValidator);
776void Teuchos::setDoubleParameter(
777 std::string
const& paramName,
778 double const& value, std::string
const& docString,
779 ParameterList *paramList,
780 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
784 const RCP<const ParameterEntryValidator> paramEntryValidator =
785 anyNumberParameterEntryValidator(
786 AnyNumberParameterEntryValidator::PREFER_DOUBLE, acceptedTypes
788 paramList->set(paramName, value, docString, paramEntryValidator);
792void Teuchos::setNumericStringParameter(
793 std::string
const& paramName,
794 std::string
const& value, std::string
const& docString,
795 ParameterList *paramList,
796 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
800 const RCP<const ParameterEntryValidator> paramEntryValidator =
801 anyNumberParameterEntryValidator(
802 AnyNumberParameterEntryValidator::PREFER_STRING, acceptedTypes
804 paramList->set(paramName, value, docString, paramEntryValidator);
808int Teuchos::getIntParameter(
809 ParameterList
const& paramList,
810 std::string
const& paramName
813 const ParameterEntry &entry = paramList.getEntry(paramName);
814 RCP<const AnyNumberParameterEntryValidator>
815 anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
818 if ( !is_null(anyNumValidator) )
819 return anyNumValidator->getInt(entry,paramName,paramList.name());
820 if (
typeid(
int) == entry.getAny().type() )
821 return any_cast<int>(entry.getAny());
823 const AnyNumberParameterEntryValidator myAnyNumValidator;
824 return myAnyNumValidator.getInt(entry,paramName,paramList.name());
828double Teuchos::getDoubleParameter(
829 ParameterList
const& paramList,
830 std::string
const& paramName
833 const ParameterEntry &entry = paramList.getEntry(paramName);
834 RCP<const AnyNumberParameterEntryValidator>
835 anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
838 if ( !is_null(anyNumValidator) )
839 return anyNumValidator->getDouble(entry,paramName,paramList.name());
840 if (
typeid(
double) == entry.getAny().type() )
841 return any_cast<double>(entry.getAny());
843 const AnyNumberParameterEntryValidator myAnyNumValidator;
844 return myAnyNumValidator.getDouble(entry,paramName,paramList.name());
848std::string Teuchos::getNumericStringParameter(
849 ParameterList
const& paramList,
850 std::string
const& paramName
853 const ParameterEntry &entry = paramList.getEntry(paramName);
854 RCP<const AnyNumberParameterEntryValidator>
855 anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
858 if ( !is_null(anyNumValidator) )
859 return anyNumValidator->getString(entry,paramName,paramList.name());
860 if (
typeid(std::string) == entry.getAny().type() )
861 return any_cast<std::string>(entry.getAny());
863 const AnyNumberParameterEntryValidator myAnyNumValidator;
864 return myAnyNumValidator.getString(entry,paramName,paramList.name());
Definition of Teuchos::as, for conversions between types.
Determines the types that are accepted.
const std::string getXMLTypeName() const
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
void printDoc(std::string const &docString, std::ostream &out) const
double getDouble(const ParameterEntry &entry, const std::string ¶mName="", const std::string &sublistName="", const bool activeQuery=true) const
Get a double value from a parameter entry. will call std::stod.
long long getLongLong(const ParameterEntry &entry, const std::string ¶mName="", const std::string &sublistName="", const bool activeQuery=true) const
Get a long long value from a parameter entry. will call std::stoll Note that std::stoll throws on bad...
std::string getString(const ParameterEntry &entry, const std::string ¶mName="", const std::string &sublistName="", const bool activeQuery=true) const
Get a std::string value from a parameter entry.
AnyNumberParameterEntryValidator()
Construct with a preferrded type of double and accept all types.
int getInt(const ParameterEntry &entry, const std::string ¶mName="", const std::string &sublistName="", const bool activeQuery=true) const
Get an integer value from a parameter entry. will call std::stoi Note that std::stoi throws on badly ...
ValidStringsList validStringValues() const
bool isLongLongAllowed() const
Lookup whether or not long longs are allowed.
void validateAndModify(std::string const ¶mName, std::string const &sublistName, ParameterEntry *entry) const
bool isStringAllowed() const
Lookup whether or not strings are allowed.
bool isDoubleAllowed() const
Lookup whether or not doubles are allowed.
EPreferredType
Determines what type is the preferred type.
EPreferredType getPreferredType() const
Lookup the preferred type.
bool isIntAllowed() const
Lookup whether or not ints are allowed.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
std::vector< T >::const_iterator const_iterator
The type of a const forward iterator.
void validateAndModify(std::string const ¶mName, std::string const &sublistName, ParameterEntry *entry) const
const std::string getXMLTypeName() const
ValidStringsList validStringValues() const
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
bool getBool(const ParameterEntry &entry, const std::string ¶mName="", const std::string &sublistName="", const bool activeQuery=true) const
Get bool value from a parameter entry.
void printDoc(std::string const &docString, std::ostream &out) const
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
Validate a file name entry.
ValidStringsList validStringValues() const
const std::string getXMLTypeName() const
bool fileEmptyNameOK() const
Gets the variable describing whether or not this validator is OK with file name being empty (even if ...
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
bool setFileEmptyNameOK(bool isEmptyNameOK)
Sets whether or not the validator is OK with empty file name (even if fileMustExist() returns true)
bool fileMustExist() const
Gets the variable describing whether or not this validator wants the file that is specified to alread...
FileNameValidator(bool mustAlreadyExist=mustAlreadyExistDefault())
Constructs a FileNameValidator.
bool setFileMustExist(bool shouldFileExist)
Sets whether or not the validator requires the file to already exist.
void printDoc(std::string const &docString, std::ostream &out) const
Abstract interface for an object that can validate a ParameterEntry's value.
This object is held as the "value" in the Teuchos::ParameterList std::map.
any & getAny(bool activeQry=true)
Direct access to the Teuchos::any data value underlying this object. The bool argument activeQry (def...
void setValue(T value, bool isDefault=false, const std::string &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method that uses the input value type to determine the type of parameter.
A list of parameters of arbitrary type.
Smart reference counting pointer class for automatic garbage collection.
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object.
bool is_null() const
Returns true if the underlying pointer is null.
T * get() const
Get the raw C++ pointer to the underlying object.
static std::ostream & printLines(std::ostream &os, const std::string &linePrefix, const std::string &lines)
Print lines with prefix first.
A simple validator that only allows certain string values to be choosen or simply enforces that a par...
const std::string getXMLTypeName() const
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
StringValidator()
Constructs a StringValidator.
void printDoc(std::string const &docString, std::ostream &out) const
ValidStringsList validStringValues() const
ValidStringsList setValidStrings(const Teuchos::Array< std::string > &validStrings)
Sets the Array of valid strings and returns what the current array of valid string now is.
Default traits class that just returns typeid(T).name().
static std::string toString(const double &x)
Write a double as a std::string.
Modified boost::any class, which is a container for a templated value.
std::string typeName() const
Return the name of the type.
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
@ VERB_MEDIUM
Generate more output.
@ VERB_HIGH
Generate a high level of output.
@ VERB_EXTREME
Generate the most output possible.
@ VERB_NONE
Generate no output.
@ VERB_DEFAULT
Generate output as defined by the object.
@ VERB_LOW
Generate only a minimal amount of output.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.