10#include "Teuchos_StandardParameterEntryValidators.hpp"
15 const EVerbosityLevel verbLevel
33 true, std::invalid_argument,
"Teuchos::getVerbosityLevelParameterValue"
34 "Name(const Teuchos::EVerbosityLevel): Input argument " << verbLevel <<
35 " has an invalid value. Valid values are VERB_DEFAULT=" << VERB_DEFAULT
36 <<
", VERB_NONE=" << VERB_NONE <<
", VERB_LOW=" << VERB_LOW <<
", "
37 "VERB_MEDIUM=" << VERB_MEDIUM <<
", VERB_HIGH=" << VERB_HIGH <<
", AND "
38 "VERB_EXTREME=" << VERB_EXTREME <<
".");
57 std::string
const& defaultParameterName
61 new StringToIntegralParameterEntryValidator<EVerbosityLevel>(
63 getVerbosityLevelParameterValueName(VERB_DEFAULT),
64 getVerbosityLevelParameterValueName(VERB_NONE),
65 getVerbosityLevelParameterValueName(VERB_LOW),
66 getVerbosityLevelParameterValueName(VERB_MEDIUM),
67 getVerbosityLevelParameterValueName(VERB_HIGH),
68 getVerbosityLevelParameterValueName(VERB_EXTREME)
71 "Use level set in code",
73 "Produce minimal output",
74 "Produce a little more output",
75 "Produce a higher level of output",
76 "Produce the highest level of output"
78 tuple<EVerbosityLevel>(
103BoolParameterEntryValidator::BoolParameterEntryValidator()
105 finishInitialization();
118 if(
anyValue.type() ==
typeid(
bool) )
120 if(
anyValue.type() ==
typeid(std::string) ) {
124 if(
str ==
"false" ) {
127 else if(
str ==
"true" ) {
150 return "boolValidator";
154 std::string
const & docString,
159 out <<
"# Accepted types: " << acceptedTypesString_ <<
".\n";
195void BoolParameterEntryValidator::finishInitialization()
197 std::ostringstream
oss;
199 acceptedTypesString_ =
oss.str();
201 acceptedTypesString_ =
oss.str();
205void BoolParameterEntryValidator::throwTypeError(
206 ParameterEntry
const& entry,
207 std::string
const& paramName,
208 std::string
const& sublistName
211 const std::string &entryName = entry.getAny(
false).typeName();
213 true, Exceptions::InvalidParameterType
214 ,
"Error, the parameter {paramName=\""<<paramName<<
"\""
215 ",type=\""<<entryName<<
"\"}"
216 <<
"\nin the sublist \"" << sublistName <<
"\""
217 <<
"\nhas the wrong type."
218 <<
"\n\nThe accepted types are: " << acceptedTypesString_ <<
"!";
231 : preferredType_(PREFER_DOUBLE), acceptedTypes_(
AcceptedTypes())
233 finishInitialization();
242 finishInitialization();
255 if( acceptedTypes_.allowInt() &&
anyValue.type() ==
typeid(
int) )
257 if( acceptedTypes_.allowLongLong() &&
anyValue.type() ==
typeid(
long long) )
259 if( acceptedTypes_.allowDouble() &&
anyValue.type() ==
typeid(
double) )
261 if( acceptedTypes_.allowString() &&
anyValue.type() ==
typeid(std::string) )
273 if( acceptedTypes_.allowInt() &&
anyValue.type() ==
typeid(
int) )
275 if( acceptedTypes_.allowLongLong() &&
anyValue.type() ==
typeid(
long long) )
277 if( acceptedTypes_.allowDouble() &&
anyValue.type() ==
typeid(
double) )
279 if( acceptedTypes_.allowString() &&
anyValue.type() ==
typeid(std::string) )
291 if( acceptedTypes_.allowInt() &&
anyValue.type() ==
typeid(
int) )
293 if( acceptedTypes_.allowLongLong() &&
anyValue.type() ==
typeid(
long long) )
295 if( acceptedTypes_.allowDouble() &&
anyValue.type() ==
typeid(
double) )
297 if( acceptedTypes_.allowString() &&
anyValue.type() ==
typeid(std::string) )
310 if( acceptedTypes_.allowInt() &&
anyValue.type() ==
typeid(
int) )
312 if( acceptedTypes_.allowLongLong() &&
anyValue.type() ==
typeid(
long long) )
314 if( acceptedTypes_.allowDouble() &&
anyValue.type() ==
typeid(
double) )
316 if( acceptedTypes_.allowString() &&
anyValue.type() ==
typeid(std::string) )
366 return acceptedTypes_.allowInt();
371 return acceptedTypes_.allowLongLong();
376 return acceptedTypes_.allowDouble();
381 return acceptedTypes_.allowString();
388 return preferredType_;
397 return "anynumberValidator";
402 std::string
const & docString,
407 out <<
"# Accepted types: " << acceptedTypesString_ <<
".\n";
440 switch(preferredType_) {
447 case PREFER_LONG_LONG:
474void AnyNumberParameterEntryValidator::finishInitialization()
477 std::ostringstream
oss;
479 if(acceptedTypes_.allowInt()) {
483 if(acceptedTypes_.allowLongLong()) {
484 oss <<
"\"long long\"";
487 if(acceptedTypes_.allowDouble()) {
488 if(addedType) oss <<
", ";
492 if(acceptedTypes_.allowString()) {
493 if(addedType) oss <<
", ";
497 acceptedTypesString_ = oss.str();
501void AnyNumberParameterEntryValidator::throwTypeError(
502 ParameterEntry
const& entry,
503 std::string
const& paramName,
504 std::string
const& sublistName
507 const std::string &entryName = entry.getAny(
false).typeName();
509 true, Exceptions::InvalidParameterType
510 ,
"Error, the parameter {paramName=\""<<paramName<<
"\""
511 ",type=\""<<entryName<<
"\"}"
512 <<
"\nin the sublist \"" << sublistName <<
"\""
513 <<
"\nhas the wrong type."
514 <<
"\n\nThe accepted types are: " << acceptedTypesString_ <<
"!";
519RCP<AnyNumberParameterEntryValidator>
522 return anyNumberParameterEntryValidator(
523 AnyNumberParameterEntryValidator::PREFER_INT,
536 return mustAlreadyExist_;
547 return mustAlreadyExist_;
572 "\" sublist is has an error." << std::endl << std::endl <<
573 "Error: The value that you entered was the wrong type." << std::endl <<
574 "Parameter: " <<
paramName << std::endl <<
575 "Type specified: " <<
entryName << std::endl <<
576 "Type accepted: " <<
typeid(std::string).name() <<
577 std::endl << std::endl);
578 if(mustAlreadyExist_ && !EmptyNameOK_){
584 "\" sublist is has an error." << std::endl << std::endl <<
585 "Error: The file must already exists. The value you entered does " <<
586 "not corresspond to an existing file name." << std::endl <<
587 "Parameter: " <<
paramName << std::endl <<
588 "File name specified: " <<
fileName << std::endl << std::endl);
595 return "FilenameValidator";
600 std::string
const &docString, std::ostream &out)
const
603 out <<
"# Validator Used: " << std::endl;
604 out <<
"# FileName Validator" << std::endl;
622 if (!caseSensitive_) {
640 return validStrings_;
647 return validStrings_;
661 "\" sublist is has an error." << std::endl << std::endl <<
662 "Error: The value that you entered was the wrong type." <<
663 "Parameter: " <<
paramName << std::endl <<
664 "Type specified: " <<
entryName << std::endl <<
670 value = upperCase(value);
672 it = std::find(validStrings_->begin(),
673 validStrings_->end(), value);
678 "\" sublist is has an error." << std::endl << std::endl <<
679 "Error: The value that was entered doesn't fall with in "
680 "the range set by the validator." <<
681 "Parameter: " <<
paramName << std::endl <<
682 "Acceptable Values: " << *validStrings_ << std::endl <<
691 return "StringValidator";
696 std::ostream &out)
const
699 out <<
"# Validator Used: " << std::endl;
700 out <<
"# String Validator" << std::endl;
701 if (validStrings_.
get() && validStrings_->size()){
702 out <<
"# Acceptable Values: " << *validStrings_ << std::endl;
718Teuchos::boolParameterEntryValidator()
720 return rcp(
new BoolParameterEntryValidator());
724Teuchos::anyNumberParameterEntryValidator()
726 return rcp(
new AnyNumberParameterEntryValidator());
731Teuchos::anyNumberParameterEntryValidator(
732 AnyNumberParameterEntryValidator::EPreferredType
const preferredType,
733 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
737 new AnyNumberParameterEntryValidator(
738 preferredType, acceptedTypes
743void Teuchos::setIntParameter(
744 std::string
const& paramName,
745 int const value, std::string
const& docString,
746 ParameterList *paramList,
747 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
751 const RCP<const ParameterEntryValidator> paramEntryValidator =
752 anyNumberParameterEntryValidator(
753 AnyNumberParameterEntryValidator::PREFER_INT, acceptedTypes
755 paramList->set(paramName, value, docString, paramEntryValidator);
759void Teuchos::setLongLongParameter(
760 std::string
const& paramName,
761 long long const value, std::string
const& docString,
762 ParameterList *paramList,
763 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
767 const RCP<const ParameterEntryValidator> paramEntryValidator =
768 anyNumberParameterEntryValidator(
769 AnyNumberParameterEntryValidator::PREFER_LONG_LONG, acceptedTypes
771 paramList->set(paramName, value, docString, paramEntryValidator);
775void Teuchos::setDoubleParameter(
776 std::string
const& paramName,
777 double const& value, std::string
const& docString,
778 ParameterList *paramList,
779 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
783 const RCP<const ParameterEntryValidator> paramEntryValidator =
784 anyNumberParameterEntryValidator(
785 AnyNumberParameterEntryValidator::PREFER_DOUBLE, acceptedTypes
787 paramList->set(paramName, value, docString, paramEntryValidator);
791void Teuchos::setNumericStringParameter(
792 std::string
const& paramName,
793 std::string
const& value, std::string
const& docString,
794 ParameterList *paramList,
795 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
799 const RCP<const ParameterEntryValidator> paramEntryValidator =
800 anyNumberParameterEntryValidator(
801 AnyNumberParameterEntryValidator::PREFER_STRING, acceptedTypes
803 paramList->set(paramName, value, docString, paramEntryValidator);
807int Teuchos::getIntParameter(
808 ParameterList
const& paramList,
809 std::string
const& paramName
812 const ParameterEntry &entry = paramList.getEntry(paramName);
813 RCP<const AnyNumberParameterEntryValidator>
814 anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
817 if ( !is_null(anyNumValidator) )
818 return anyNumValidator->getInt(entry,paramName,paramList.name());
819 if (
typeid(
int) == entry.getAny().type() )
820 return any_cast<int>(entry.getAny());
822 const AnyNumberParameterEntryValidator myAnyNumValidator;
823 return myAnyNumValidator.getInt(entry,paramName,paramList.name());
827long long Teuchos::getLongLongParameter(
828 ParameterList
const& paramList,
829 std::string
const& paramName
832 const ParameterEntry &entry = paramList.getEntry(paramName);
833 RCP<const AnyNumberParameterEntryValidator>
834 anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
837 if ( !is_null(anyNumValidator) )
838 return anyNumValidator->getLongLong(entry,paramName,paramList.name());
839 if (
typeid(
long long) == entry.getAny().type() )
840 return any_cast<long long>(entry.getAny());
842 const AnyNumberParameterEntryValidator myAnyNumValidator;
843 return myAnyNumValidator.getLongLong(entry,paramName,paramList.name());
847double Teuchos::getDoubleParameter(
848 ParameterList
const& paramList,
849 std::string
const& paramName
852 const ParameterEntry &entry = paramList.getEntry(paramName);
853 RCP<const AnyNumberParameterEntryValidator>
854 anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
857 if ( !is_null(anyNumValidator) )
858 return anyNumValidator->getDouble(entry,paramName,paramList.name());
859 if (
typeid(
double) == entry.getAny().type() )
860 return any_cast<double>(entry.getAny());
862 const AnyNumberParameterEntryValidator myAnyNumValidator;
863 return myAnyNumValidator.getDouble(entry,paramName,paramList.name());
867std::string Teuchos::getNumericStringParameter(
868 ParameterList
const& paramList,
869 std::string
const& paramName
872 const ParameterEntry &entry = paramList.getEntry(paramName);
873 RCP<const AnyNumberParameterEntryValidator>
874 anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
877 if ( !is_null(anyNumValidator) )
878 return anyNumValidator->getString(entry,paramName,paramList.name());
879 if (
typeid(std::string) == entry.getAny().type() )
880 return any_cast<std::string>(entry.getAny());
882 const AnyNumberParameterEntryValidator myAnyNumValidator;
883 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.
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.