14 std::string Teuchos::getVerbosityLevelParameterValueName(
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
56 Teuchos::verbosityLevelParameterEntryValidator(
57 std::string
const& defaultParameterName
61 new StringToIntegralParameterEntryValidator<EVerbosityLevel>(
64 getVerbosityLevelParameterValueName(
VERB_NONE),
65 getVerbosityLevelParameterValueName(
VERB_LOW),
67 getVerbosityLevelParameterValueName(
VERB_HIGH),
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>(
114 const std::string &sublistName,
const bool activeQuery
117 const any &anyValue = entry.
getAny(activeQuery);
118 if( anyValue.
type() ==
typeid(bool) )
119 return any_cast<
bool>(anyValue);
120 if( anyValue.
type() ==
typeid(std::string) ) {
121 std::string str = any_cast<std::string>(anyValue);
124 if( str ==
"false" ) {
127 else if( str ==
"true" ) {
138 const int defaultValue
142 if(entry)
return getBool(*entry,paramName,paramList.
name(),
true);
143 return paramList.
get(paramName,defaultValue);
150 return "boolValidator";
154 std::string
const & docString,
172 std::string
const& paramName,
173 std::string
const& sublistName
177 getBool(entry, paramName, sublistName,
false);
182 std::string
const& paramName,
183 std::string
const& sublistName,
197 std::ostringstream oss;
207 std::string
const& paramName,
208 std::string
const& sublistName
214 ,
"Error, the parameter {paramName=\""<<paramName<<
"\""
215 ",type=\""<<entryName<<
"\"}"
216 <<
"\nin the sublist \"" << sublistName <<
"\""
217 <<
"\nhas the wrong type."
231 : preferredType_(PREFER_DOUBLE), acceptedTypes_(
AcceptedTypes())
240 : preferredType_(preferredType), acceptedTypes_(acceptedTypes)
251 const std::string &sublistName,
const bool activeQuery
254 const any &anyValue = entry.
getAny(activeQuery);
256 return any_cast<
int>(anyValue);
258 return as<int>(any_cast<
long long>(anyValue));
260 return as<int>(any_cast<
double>(anyValue));
269 const std::string &sublistName,
const bool activeQuery
272 const any &anyValue = entry.
getAny(activeQuery);
274 return as<long long>(any_cast<
int>(anyValue));
276 return any_cast<
long long>(anyValue);
278 return as<long long>(any_cast<
double>(anyValue));
287 const std::string &sublistName,
const bool activeQuery
290 const any &anyValue = entry.
getAny(activeQuery);
292 return as<double>(any_cast<
int>(anyValue));
294 return as<double>(any_cast<
long long>(anyValue));
296 return any_cast<
double>(anyValue);
306 const std::string &sublistName,
const bool activeQuery
309 const any &anyValue = entry.
getAny(activeQuery);
317 return any_cast<std::string>(anyValue);
325 const int defaultValue
329 if(entry)
return getInt(*entry,paramName,paramList.
name(),
true);
330 return paramList.
get(paramName,defaultValue);
335 const long long defaultValue
340 return paramList.
get(paramName,defaultValue);
345 const double defaultValue
349 if(entry)
return getDouble(*entry,paramName,paramList.
name(),
true);
350 return paramList.
get(paramName,defaultValue);
356 const std::string &defaultValue
360 if(entry)
return getString(*entry,paramName,paramList.
name(),
true);
361 return paramList.
get(paramName,defaultValue);
397 return "anynumberValidator";
402 std::string
const & docString,
420 std::string
const& paramName,
421 std::string
const& sublistName
429 getDouble(entry, paramName, sublistName,
false);
434 std::string
const& paramName,
435 std::string
const& sublistName,
443 getInt(*entry,paramName,sublistName,
false),
455 getDouble(*entry,paramName,sublistName,
false),
461 getString(*entry,paramName,sublistName,
false),
477 std::ostringstream oss;
478 bool addedType =
false;
484 oss <<
"\"long long\"";
488 if(addedType) oss <<
", ";
493 if(addedType) oss <<
", ";
503 std::string
const& paramName,
504 std::string
const& sublistName
510 ,
"Error, the parameter {paramName=\""<<paramName<<
"\""
511 ",type=\""<<entryName<<
"\"}"
512 <<
"\nin the sublist \"" << sublistName <<
"\""
513 <<
"\nhas the wrong type."
522 return anyNumberParameterEntryValidator(
564 std::string
const &sublistName)
const
570 "The \"" << paramName <<
"\"" <<
571 " parameter in the \"" << sublistName <<
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);
579 std::string fileName = getValue<std::string>(entry);
582 "The \"" << paramName <<
"\"" <<
583 " parameter in the \"" << sublistName <<
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;
620 caseSensitive_(caseSensitive)
625 for (
auto it = validStrings.
begin(); it != validStrings.
end(); ++it) {
626 upperCaseValidStrings[k] =
upperCase(*it);
653 std::string
const &sublistName)
const
659 "The \"" << paramName <<
"\"" <<
660 " parameter in the \"" << sublistName <<
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 <<
668 auto value = getValue<std::string>(entry);
676 "The \"" << paramName <<
"\"" <<
677 " parameter in the \"" << sublistName <<
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 <<
683 "Value entered: " << getValue<std::string>(entry) << std::endl <<
691 return "StringValidator";
696 std::ostream &out)
const
699 out <<
"# Validator Used: " << std::endl;
700 out <<
"# String Validator" << std::endl;
702 out <<
"# Acceptable Values: " << *
validStrings_ << std::endl;
718 Teuchos::boolParameterEntryValidator()
720 return rcp(
new BoolParameterEntryValidator());
724 Teuchos::anyNumberParameterEntryValidator()
726 return rcp(
new AnyNumberParameterEntryValidator());
731 Teuchos::anyNumberParameterEntryValidator(
732 AnyNumberParameterEntryValidator::EPreferredType
const preferredType,
733 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
737 new AnyNumberParameterEntryValidator(
738 preferredType, acceptedTypes
743 void 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 =
753 AnyNumberParameterEntryValidator::PREFER_INT, acceptedTypes
755 paramList->set(paramName, value, docString, paramEntryValidator);
759 void 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 =
769 AnyNumberParameterEntryValidator::PREFER_LONG_LONG, acceptedTypes
771 paramList->set(paramName, value, docString, paramEntryValidator);
775 void 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 =
785 AnyNumberParameterEntryValidator::PREFER_DOUBLE, acceptedTypes
787 paramList->set(paramName, value, docString, paramEntryValidator);
791 void 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 =
801 AnyNumberParameterEntryValidator::PREFER_STRING, acceptedTypes
803 paramList->set(paramName, value, docString, paramEntryValidator);
807 int Teuchos::getIntParameter(
808 ParameterList
const& paramList,
809 std::string
const& paramName
812 const ParameterEntry &entry = paramList.getEntry(paramName);
813 RCP<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());
827 long long Teuchos::getLongLongParameter(
828 ParameterList
const& paramList,
829 std::string
const& paramName
832 const ParameterEntry &entry = paramList.getEntry(paramName);
833 RCP<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());
847 double Teuchos::getDoubleParameter(
848 ParameterList
const& paramList,
849 std::string
const& paramName
852 const ParameterEntry &entry = paramList.getEntry(paramName);
853 RCP<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());
867 std::string Teuchos::getNumericStringParameter(
868 ParameterList
const& paramList,
869 std::string
const& paramName
872 const ParameterEntry &entry = paramList.getEntry(paramName);
873 RCP<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());
void throwTypeError(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) 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...
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...
void printDoc(std::string const &docString, std::ostream &out) const
const std::string & name() const
The name of this ParameterList.
ValidStringsList validStringValues() const
ValidStringsList validStringValues() const
EVerbosityLevel
Verbosity level.
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
Generate a high level of output.
int convertStringToInt(std::string str) const
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
bool setFileMustExist(bool shouldFileExist)
Sets whether or not the validator requires the file to already exist.
Generate only a minimal amount of output.
ValidStringsList validStringValues() const
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.
FileNameValidator(bool mustAlreadyExist=mustAlreadyExistDefault())
Constructs a FileNameValidator.
std::string acceptedTypesString_
RCP< T2 > rcp_dynamic_cast(const RCP< T1 > &p1, bool throw_on_fail=false)
Dynamic cast of underlying RCP type from T1* to T2*.
EPreferredType
Determines what type is the preferred type.
T & get(const std::string &name, T def_value)
Return the parameter's value, or the default value if it is not there.
This object is held as the "value" in the Teuchos::ParameterList std::map.
const AcceptedTypes acceptedTypes_
void validateAndModify(std::string const ¶mName, std::string const &sublistName, ParameterEntry *entry) const
void printDoc(std::string const &docString, std::ostream &out) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
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 ...
EPreferredType preferredType_
Standard implementation of a ParameterEntryValidator that maps from a list of strings to an enum or i...
AcceptedTypes & allowString(bool _allowString)
Set allow an std::string value or not.
void finishInitialization()
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.
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.
ValidStringsList validStrings_
An array containing a list of all the valid string values.
Modified boost::any class, which is a container for a templated value.
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
bool is_null(const ArrayRCP< T > &p)
Returns true if p.get()==NULL.
AcceptedTypes & allowInt(bool _allowInt)
Set allow an int value or not.
static std::string toString(const double &x)
Write a double as a std::string.
Generate the most output possible.
ValidStringsList validStringValues() const
ParameterEntry * getEntryPtr(const std::string &name)
Retrieves the pointer for an entry with the name name if it exists.
Determines the types that are accepted.
EPreferredType getPreferredType() const
Lookup the preferred type.
std::string acceptedTypesString_
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
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.
BoolParameterEntryValidator()
double convertStringToDouble(std::string str) const
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
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...
bool setFileEmptyNameOK(bool isEmptyNameOK)
Sets whether or not the validator is OK with empty file name (even if fileMustExist() returns true) ...
Validate a file name entry.
const std::string getXMLTypeName() const
A list of parameters of arbitrary type.
StringValidator()
Constructs a StringValidator.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT RCP< AnyNumberParameterEntryValidator > anyNumberParameterEntryValidator()
Nonmember constructor AnyNumberParameterEntryValidator.
bool mustAlreadyExist_
Whether or not the file specified in the parameter should already exist.
AnyNumberParameterEntryValidator()
Construct with a preferrded type of double and accept all types.
A simple validator that only allows certain string values to be choosen or simply enforces that a par...
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.
Abstract interface for an object that can validate a ParameterEntry's value.
any & getAny(bool activeQry=true)
Direct access to the Teuchos::any data value underlying this object. The bool argument activeQry (def...
int convertStringToLongLong(std::string str) const
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 ...
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
bool isDoubleAllowed() const
Lookup whether or not doubles are allowed.
void printDoc(std::string const &docString, std::ostream &out) const
void throwTypeError(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
void finishInitialization()
static std::string upperCase(const std::string s)
Return an upper-case copy of the string s.
std::string typeName() const
Return the name of the type.
AcceptedTypes & allowDouble(bool _allowDouble)
Set allow a double value or not.
bool isLongLongAllowed() const
Lookup whether or not long longs are allowed.
Smart reference counting pointer class for automatic garbage collection.
bool fileMustExist() const
Gets the variable describing whether or not this validator wants the file that is specified to alread...
const std::type_info & type() const
Return the type of value being stored.
void validateAndModify(std::string const ¶mName, std::string const &sublistName, ParameterEntry *entry) const
bool isStringAllowed() const
Lookup whether or not strings are allowed.
void printDoc(std::string const &docString, std::ostream &out) const
bool isIntAllowed() const
Lookup whether or not ints are allowed.
AcceptedTypes & allowLongLong(bool _allowLongLong)
Set allow an long long value or not.
const std::string getXMLTypeName() const
Definition of Teuchos::as, for conversions between types.
const std::string getXMLTypeName() const
#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...
Generate output as defined by the object.
static std::string name()
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
bool is_null() const
Returns true if the underlying pointer is null.