46 std::string Teuchos::getVerbosityLevelParameterValueName(
73 Teuchos::verbosityLevelParameterEntryValidator(
74 std::string
const& defaultParameterName
78 new StringToIntegralParameterEntryValidator<EVerbosityLevel>(
81 getVerbosityLevelParameterValueName(
VERB_NONE),
82 getVerbosityLevelParameterValueName(
VERB_LOW),
84 getVerbosityLevelParameterValueName(
VERB_HIGH),
88 "Use level set in code",
90 "Produce minimal output",
91 "Produce a little more output",
92 "Produce a higher level of output",
93 "Produce the highest level of output"
95 tuple<EVerbosityLevel>(
121 : preferredType_(PREFER_DOUBLE), acceptedTypes_(
AcceptedTypes())
130 : preferredType_(preferredType), acceptedTypes_(acceptedTypes)
141 const std::string &sublistName,
const bool activeQuery
144 const any &anyValue = entry.
getAny(activeQuery);
146 return any_cast<
int>(anyValue);
148 return as<int>(any_cast<
double>(anyValue));
150 return std::atoi(any_cast<std::string>(anyValue).c_str());
158 const std::string &sublistName,
const bool activeQuery
161 const any &anyValue = entry.
getAny(activeQuery);
163 return as<double>(any_cast<
int>(anyValue));
165 return any_cast<
double>(anyValue);
167 return std::atof(any_cast<std::string>(anyValue).c_str());
175 const std::string &sublistName,
const bool activeQuery
178 const any &anyValue = entry.
getAny(activeQuery);
184 return any_cast<std::string>(anyValue);
192 const int defaultValue
196 if(entry)
return getInt(*entry,paramName,paramList.
name(),
true);
197 return paramList.
get(paramName,defaultValue);
203 const double defaultValue
207 if(entry)
return getDouble(*entry,paramName,paramList.
name(),
true);
208 return paramList.
get(paramName,defaultValue);
214 const std::string &defaultValue
218 if(entry)
return getString(*entry,paramName,paramList.
name(),
true);
219 return paramList.
get(paramName,defaultValue);
253 return "anynumberValidator";
258 std::string
const & docString,
276 std::string
const& paramName,
277 std::string
const& sublistName
285 getDouble(entry, paramName, sublistName,
false);
290 std::string
const& paramName,
291 std::string
const& sublistName,
299 getInt(*entry,paramName,sublistName,
false),
305 getDouble(*entry,paramName,sublistName,
false),
311 getString(*entry,paramName,sublistName,
false),
327 std::ostringstream oss;
328 bool addedType =
false;
334 if(addedType) oss <<
", ";
339 if(addedType) oss <<
", ";
349 std::string
const& paramName,
350 std::string
const& sublistName
356 ,
"Error, the parameter {paramName=\""<<paramName<<
"\""
357 ",type=\""<<entryName<<
"\"}"
358 <<
"\nin the sublist \"" << sublistName <<
"\""
359 <<
"\nhas the wrong type."
368 return anyNumberParameterEntryValidator(
400 std::string
const &sublistName)
const
406 "The \"" << paramName <<
"\"" <<
407 " parameter in the \"" << sublistName <<
408 "\" sublist is has an error." << std::endl << std::endl <<
409 "Error: The value that you entered was the wrong type." << std::endl <<
410 "Parameter: " << paramName << std::endl <<
411 "Type specified: " << entryName << std::endl <<
412 "Type accepted: " <<
typeid(std::string).name() <<
413 std::endl << std::endl);
415 std::string fileName = getValue<std::string>(entry);
418 "The \"" << paramName <<
"\"" <<
419 " parameter in the \"" << sublistName <<
420 "\" sublist is has an error." << std::endl << std::endl <<
421 "Error: The file must already exists. The value you entered does " <<
422 "not corresspond to an existing file name." << std::endl <<
423 "Parameter: " << paramName << std::endl <<
424 "File name specified: " << fileName << std::endl << std::endl);
431 return "FilenameValidator";
436 std::string
const &docString, std::ostream &out)
const
439 out <<
"# Validator Used: " << std::endl;
440 out <<
"# FileName Validator" << std::endl;
456 validStrings_(
rcp(new
Array<std::string>(validStrings)))
477 std::string
const &sublistName)
const
483 "The \"" << paramName <<
"\"" <<
484 " parameter in the \"" << sublistName <<
485 "\" sublist is has an error." << std::endl << std::endl <<
486 "Error: The value that you entered was the wrong type." <<
487 "Parameter: " << paramName << std::endl <<
488 "Type specified: " << entryName << std::endl <<
497 "The \"" << paramName <<
"\"" <<
498 " parameter in the \"" << sublistName <<
499 "\" sublist is has an error." << std::endl << std::endl <<
500 "Error: The value that was entered doesn't fall with in "
501 "the range set by the validator." <<
502 "Parameter: " << paramName << std::endl <<
504 "Value entered: " << getValue<std::string>(entry) << std::endl <<
512 return "StringValidator";
517 std::ostream &out)
const
520 out <<
"# Validator Used: " << std::endl;
521 out <<
"# String Validator" << std::endl;
523 out <<
"# Acceptable Values: " << *
validStrings_ << std::endl;
540 Teuchos::anyNumberParameterEntryValidator()
542 return rcp(
new AnyNumberParameterEntryValidator());
547 Teuchos::anyNumberParameterEntryValidator(
548 AnyNumberParameterEntryValidator::EPreferredType
const preferredType,
549 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
553 new AnyNumberParameterEntryValidator(
554 preferredType, acceptedTypes
559 void Teuchos::setIntParameter(
560 std::string
const& paramName,
561 int const value, std::string
const& docString,
562 ParameterList *paramList,
563 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
567 const RCP<const ParameterEntryValidator> paramEntryValidator =
569 AnyNumberParameterEntryValidator::PREFER_INT, acceptedTypes
571 paramList->set(paramName, value, docString, paramEntryValidator);
575 void Teuchos::setDoubleParameter(
576 std::string
const& paramName,
577 double const& value, std::string
const& docString,
578 ParameterList *paramList,
579 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
583 const RCP<const ParameterEntryValidator> paramEntryValidator =
585 AnyNumberParameterEntryValidator::PREFER_DOUBLE, acceptedTypes
587 paramList->set(paramName, value, docString, paramEntryValidator);
591 void Teuchos::setNumericStringParameter(
592 std::string
const& paramName,
593 std::string
const& value, std::string
const& docString,
594 ParameterList *paramList,
595 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
599 const RCP<const ParameterEntryValidator> paramEntryValidator =
601 AnyNumberParameterEntryValidator::PREFER_STRING, acceptedTypes
603 paramList->set(paramName, value, docString, paramEntryValidator);
607 int Teuchos::getIntParameter(
608 ParameterList
const& paramList,
609 std::string
const& paramName
612 const ParameterEntry &entry = paramList.getEntry(paramName);
613 RCP<const AnyNumberParameterEntryValidator>
617 if ( !
is_null(anyNumValidator) )
618 return anyNumValidator->getInt(entry,paramName,paramList.name());
619 if (
typeid(
int) == entry.getAny().type() )
620 return any_cast<int>(entry.getAny());
622 const AnyNumberParameterEntryValidator myAnyNumValidator;
623 return myAnyNumValidator.getInt(entry,paramName,paramList.name());
627 double Teuchos::getDoubleParameter(
628 ParameterList
const& paramList,
629 std::string
const& paramName
632 const ParameterEntry &entry = paramList.getEntry(paramName);
633 RCP<const AnyNumberParameterEntryValidator>
637 if ( !
is_null(anyNumValidator) )
638 return anyNumValidator->getDouble(entry,paramName,paramList.name());
639 if (
typeid(
double) == entry.getAny().type() )
640 return any_cast<double>(entry.getAny());
642 const AnyNumberParameterEntryValidator myAnyNumValidator;
643 return myAnyNumValidator.getDouble(entry,paramName,paramList.name());
647 std::string Teuchos::getNumericStringParameter(
648 ParameterList
const& paramList,
649 std::string
const& paramName
652 const ParameterEntry &entry = paramList.getEntry(paramName);
653 RCP<const AnyNumberParameterEntryValidator>
657 if ( !
is_null(anyNumValidator) )
658 return anyNumValidator->getString(entry,paramName,paramList.name());
659 if (
typeid(std::string) == entry.getAny().type() )
660 return any_cast<std::string>(entry.getAny());
662 const AnyNumberParameterEntryValidator myAnyNumValidator;
663 return myAnyNumValidator.getString(entry,paramName,paramList.name());
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
EVerbosityLevel
Verbosity level.
Generate a high level of output.
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_
#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
EPreferredType preferredType_
Standard implementation of a ParameterEntryValidator that maps from a list of strings to some integra...
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.
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.
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
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...
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 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.
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
std::string typeName() const
Return the name of the type.
AcceptedTypes & allowDouble(bool _allowDouble)
Set allow a double value or not.
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.
const std::string getXMLTypeName() const
Definition of Teuchos::as, for conversions between types.
#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.