46 std::string Teuchos::getVerbosityLevelParameterValueName(
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
88 Teuchos::verbosityLevelParameterEntryValidator(
89 std::string
const& defaultParameterName
93 new StringToIntegralParameterEntryValidator<EVerbosityLevel>(
96 getVerbosityLevelParameterValueName(
VERB_NONE),
97 getVerbosityLevelParameterValueName(
VERB_LOW),
99 getVerbosityLevelParameterValueName(
VERB_HIGH),
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>(
146 const std::string &sublistName,
const bool activeQuery
149 const any &anyValue = entry.
getAny(activeQuery);
150 if( anyValue.
type() ==
typeid(bool) )
151 return any_cast<
bool>(anyValue);
152 if( anyValue.
type() ==
typeid(std::string) ) {
153 std::string str = any_cast<std::string>(anyValue);
156 if( str ==
"false" ) {
159 else if( str ==
"true" ) {
170 const int defaultValue
174 if(entry)
return getBool(*entry,paramName,paramList.
name(),
true);
175 return paramList.
get(paramName,defaultValue);
182 return "boolValidator";
186 std::string
const & docString,
204 std::string
const& paramName,
205 std::string
const& sublistName
209 getBool(entry, paramName, sublistName,
false);
214 std::string
const& paramName,
215 std::string
const& sublistName,
229 std::ostringstream oss;
239 std::string
const& paramName,
240 std::string
const& sublistName
246 ,
"Error, the parameter {paramName=\""<<paramName<<
"\""
247 ",type=\""<<entryName<<
"\"}"
248 <<
"\nin the sublist \"" << sublistName <<
"\""
249 <<
"\nhas the wrong type."
263 : preferredType_(PREFER_DOUBLE), acceptedTypes_(
AcceptedTypes())
272 : preferredType_(preferredType), acceptedTypes_(acceptedTypes)
283 const std::string &sublistName,
const bool activeQuery
286 const any &anyValue = entry.
getAny(activeQuery);
288 return any_cast<
int>(anyValue);
290 return as<int>(any_cast<
long long>(anyValue));
292 return as<int>(any_cast<
double>(anyValue));
301 const std::string &sublistName,
const bool activeQuery
304 const any &anyValue = entry.
getAny(activeQuery);
306 return as<long long>(any_cast<
int>(anyValue));
308 return any_cast<
long long>(anyValue);
310 return as<int>(any_cast<
double>(anyValue));
319 const std::string &sublistName,
const bool activeQuery
322 const any &anyValue = entry.
getAny(activeQuery);
324 return as<double>(any_cast<
int>(anyValue));
326 return as<double>(any_cast<
long long>(anyValue));
328 return any_cast<
double>(anyValue);
338 const std::string &sublistName,
const bool activeQuery
341 const any &anyValue = entry.
getAny(activeQuery);
349 return any_cast<std::string>(anyValue);
357 const int defaultValue
361 if(entry)
return getInt(*entry,paramName,paramList.
name(),
true);
362 return paramList.
get(paramName,defaultValue);
367 const long long defaultValue
372 return paramList.
get(paramName,defaultValue);
377 const double defaultValue
381 if(entry)
return getDouble(*entry,paramName,paramList.
name(),
true);
382 return paramList.
get(paramName,defaultValue);
388 const std::string &defaultValue
392 if(entry)
return getString(*entry,paramName,paramList.
name(),
true);
393 return paramList.
get(paramName,defaultValue);
429 return "anynumberValidator";
434 std::string
const & docString,
452 std::string
const& paramName,
453 std::string
const& sublistName
461 getDouble(entry, paramName, sublistName,
false);
466 std::string
const& paramName,
467 std::string
const& sublistName,
475 getInt(*entry,paramName,sublistName,
false),
487 getDouble(*entry,paramName,sublistName,
false),
493 getString(*entry,paramName,sublistName,
false),
509 std::ostringstream oss;
510 bool addedType =
false;
516 oss <<
"\"long long\"";
520 if(addedType) oss <<
", ";
525 if(addedType) oss <<
", ";
535 std::string
const& paramName,
536 std::string
const& sublistName
542 ,
"Error, the parameter {paramName=\""<<paramName<<
"\""
543 ",type=\""<<entryName<<
"\"}"
544 <<
"\nin the sublist \"" << sublistName <<
"\""
545 <<
"\nhas the wrong type."
554 return anyNumberParameterEntryValidator(
596 std::string
const &sublistName)
const
602 "The \"" << paramName <<
"\"" <<
603 " parameter in the \"" << sublistName <<
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);
611 std::string fileName = getValue<std::string>(entry);
614 "The \"" << paramName <<
"\"" <<
615 " parameter in the \"" << sublistName <<
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;
652 validStrings_(
rcp(new
Array<std::string>(validStrings)))
673 std::string
const &sublistName)
const
679 "The \"" << paramName <<
"\"" <<
680 " parameter in the \"" << sublistName <<
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 <<
693 "The \"" << paramName <<
"\"" <<
694 " parameter in the \"" << sublistName <<
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 <<
700 "Value entered: " << getValue<std::string>(entry) << std::endl <<
708 return "StringValidator";
713 std::ostream &out)
const
716 out <<
"# Validator Used: " << std::endl;
717 out <<
"# String Validator" << std::endl;
719 out <<
"# Acceptable Values: " << *
validStrings_ << std::endl;
735 Teuchos::boolParameterEntryValidator()
737 return rcp(
new BoolParameterEntryValidator());
741 Teuchos::anyNumberParameterEntryValidator()
743 return rcp(
new AnyNumberParameterEntryValidator());
748 Teuchos::anyNumberParameterEntryValidator(
749 AnyNumberParameterEntryValidator::EPreferredType
const preferredType,
750 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
754 new AnyNumberParameterEntryValidator(
755 preferredType, acceptedTypes
760 void 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 =
770 AnyNumberParameterEntryValidator::PREFER_INT, acceptedTypes
772 paramList->set(paramName, value, docString, paramEntryValidator);
776 void 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 =
786 AnyNumberParameterEntryValidator::PREFER_DOUBLE, acceptedTypes
788 paramList->set(paramName, value, docString, paramEntryValidator);
792 void 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 =
802 AnyNumberParameterEntryValidator::PREFER_STRING, acceptedTypes
804 paramList->set(paramName, value, docString, paramEntryValidator);
808 int Teuchos::getIntParameter(
809 ParameterList
const& paramList,
810 std::string
const& paramName
813 const ParameterEntry &entry = paramList.getEntry(paramName);
814 RCP<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());
828 double Teuchos::getDoubleParameter(
829 ParameterList
const& paramList,
830 std::string
const& paramName
833 const ParameterEntry &entry = paramList.getEntry(paramName);
834 RCP<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());
848 std::string Teuchos::getNumericStringParameter(
849 ParameterList
const& paramList,
850 std::string
const& paramName
853 const ParameterEntry &entry = paramList.getEntry(paramName);
854 RCP<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());
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()
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.