10#ifndef TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H
11#define TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H
13#include "Teuchos_ParameterEntryValidator.hpp"
15#include "Teuchos_ParameterListExceptions.hpp"
18#include "Teuchos_Assert.hpp"
23#ifdef HAVE_TEUCHOSCORE_QUADMATH
59template<
class IntegralType>
83 const std::string& defaultParameterName,
84 const bool caseSensitive =
true);
111 std::string
const& defaultParameterName,
112 const bool caseSensitive =
true);
146 const std::string& defaultParameterName,
147 const bool caseSensitive =
true);
163 const std::string &str,
const std::string ¶mName =
"",
164 const std::string &sublistName =
""
184 const std::string ¶mName =
"",
185 const std::string &sublistName =
"",
186 const bool activeQuery =
true)
const;
205 const std::string ¶mName =
"",
206 const std::string &sublistName =
"",
207 const bool activeQuery =
true)
const;
217 const std::string& paramName,
218 const std::string& defaultValue)
const;
225 const std::string &defaultValue
253 const std::string &str,
const std::string ¶mName =
"",
254 const std::string &sublistName =
""
262 return caseSensitive_;
274 std::string
const& docString,
285 std::string
const& paramName,
286 std::string
const& sublistName
289#if defined(HAVE_TEUCHOS_MODIFY_DEFAULTS_DURING_VALIDATION)
291 std::string
const& paramName,
292 std::string
const& sublistName,
300 std::string defaultParameterName_;
301 std::string validValues_;
305 typedef std::map<std::string,IntegralType> map_t;
307 typedef std::map<IntegralType,std::string> inv_map_t;
310 const bool caseSensitive_;
335 static std::string upperCase (
const std::string s) {
336 std::string s_upper = s;
337 std::transform (s_upper.begin (), s_upper.end (), s_upper.begin (), ::toupper);
347template<
class IntegralType>
348RCP<StringToIntegralParameterEntryValidator<IntegralType> >
351 std::string
const& defaultParameterName
359template<
class IntegralType>
363 std::string
const& defaultParameterName,
364 const bool caseSensitive
372template<
class IntegralType>
377 std::string
const& defaultParameterName
385template<
class IntegralType>
390 std::string
const& defaultParameterName,
391 const bool caseSensitive
399template<
class IntegralType>
405 std::string
const& defaultParameterName
413template<
class IntegralType>
419 std::string
const& defaultParameterName,
420 const bool caseSensitive
434template<
class IntegralType>
436 std::string
const& paramName,
437 std::string
const& defaultValue,
438 std::string
const& docString,
455template<
class IntegralType>
457 std::string
const& paramName,
458 std::string
const& defaultValue,
459 std::string
const& docString,
477template<
class IntegralType>
479 std::string
const& paramName,
480 std::string
const& defaultValue,
481 std::string
const& docString,
499template<
class IntegralType>
516template<
class IntegralType>
527template<
class IntegralType>
531 std::string
const& paramName
540std::string getVerbosityLevelParameterValueName(
550verbosityLevelParameterEntryValidator(std::string
const& defaultParameterName);
557template<
class IntegralType>
574template<
class IntegralType>
595class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT BoolParameterEntryValidator
603 BoolParameterEntryValidator();
613 const std::string &sublistName =
"",
const bool activeQuery =
true
621 const int defaultValue
634 std::string
const& docString,
645 std::string
const& paramName,
646 std::string
const& sublistName
651 std::string
const& paramName,
652 std::string
const& sublistName,
663 std::string acceptedTypesString_;
668 void finishInitialization();
672 std::string
const& paramName,
673 std::string
const& sublistName
710 enum EPreferredType { PREFER_INT, PREFER_LONG_LONG, PREFER_DOUBLE, PREFER_STRING };
718 :allowInt_(allowAllTypesByDefault)
719 ,allowLongLong_(allowAllTypesByDefault)
720 ,allowDouble_(allowAllTypesByDefault)
721 ,allowString_(allowAllTypesByDefault)
725 { allowInt_ = _allowInt;
return *
this; }
728 { allowLongLong_ = _allowLongLong;
return *
this; }
731 { allowDouble_ = _allowDouble;
return *
this; }
734 { allowString_ = _allowString;
return *
this; }
771 EPreferredType
const preferredType,
772 AcceptedTypes
const& acceptedTypes
787 const std::string &sublistName =
"",
const bool activeQuery =
true
795 long long getLongLong(
797 const std::string &sublistName =
"",
const bool activeQuery =
true
805 const std::string &sublistName =
"",
const bool activeQuery =
true
809 std::string getString(
811 const std::string &sublistName =
"",
const bool activeQuery =
true
819 const int defaultValue
825 long long getLongLong(
827 const long long defaultValue
835 const double defaultValue
841 std::string getString(
843 const std::string &defaultValue
848 bool isIntAllowed()
const;
852 bool isLongLongAllowed()
const;
856 bool isDoubleAllowed()
const;
860 bool isStringAllowed()
const;
864 EPreferredType getPreferredType()
const;
871 return getIntEnumString ();
872 case PREFER_LONG_LONG:
873 return getLongLongEnumString ();
875 return getDoubleEnumString ();
877 return getStringEnumString ();
879 const std::string typeString (toString (enumValue));
880 throw std::runtime_error(
"Cannot convert enumValue: " + typeString +
" to a string");
887 if (enumString == getIntEnumString ()) {
890 else if (enumString == getLongLongEnumString ()) {
891 return PREFER_LONG_LONG;
893 else if (enumString == getDoubleEnumString ()) {
894 return PREFER_DOUBLE;
896 else if (enumString == getStringEnumString ()) {
897 return PREFER_STRING;
900 throw std::runtime_error (
"Cannot convert enumString: " + enumString +
" to an enum");
910 const std::string getXMLTypeName()
const;
914 std::string
const& docString,
920 validStringValues()
const;
925 std::string
const& paramName,
926 std::string
const& sublistName
930 void validateAndModify(
931 std::string
const& paramName,
932 std::string
const& sublistName,
944 EPreferredType preferredType_;
945 std::string acceptedTypesString_;
950#pragma warning(disable:4251)
952 const AcceptedTypes acceptedTypes_;
961 static const std::string& getIntEnumString(){
963 return intEnumString_;
967 static const std::string& getLongLongEnumString(){
968 static const std::string longLongEnumString_ = TypeNameTraits<long long>::name();
969 return longLongEnumString_;
973 static const std::string& getDoubleEnumString(){
974 static const std::string doubleEnumString_ = TypeNameTraits<double>::name();
975 return doubleEnumString_;
979 static const std::string& getStringEnumString(){
980 static const std::string stringEnumString_ = TypeNameTraits<std::string>::name();
981 return stringEnumString_;
985 void finishInitialization();
988 ParameterEntry
const& entry,
989 std::string
const& paramName,
990 std::string
const& sublistName
1023 std::string
const& paramName,
1024 int const value, std::string
const& docString,
1037 std::string
const& paramName,
1038 long long const value, std::string
const& docString,
1050 std::string
const& paramName,
1051 double const& value, std::string
const& docString,
1064 std::string
const& paramName,
1065 std::string
const& value, std::string
const& docString,
1087 ParameterList const& paramList, std::string
const& paramName
1106 ParameterList const& paramList, std::string
const& paramName
1125 std::string
const& paramName
1146 std::string
const& paramName
1180 return T::this_type_is_missing_a_specialization();
1231class EnhancedNumberTraits<short int>{
1233 static inline short int min() {
return std::numeric_limits<short int>::min(); }
1234 static inline short int max() {
return std::numeric_limits<short int>::max(); }
1235 static inline short int defaultStep() {
return 1; }
1243 static inline short unsigned int min() {
return std::numeric_limits<short unsigned int>::min(); }
1244 static inline short unsigned int max() {
return std::numeric_limits<short unsigned int>::max(); }
1245 static inline short unsigned int defaultStep() {
return 1; }
1253 static inline int min() {
return std::numeric_limits<int>::min(); }
1254 static inline int max() {
return std::numeric_limits<int>::max(); }
1263 static inline unsigned int min() {
return std::numeric_limits<unsigned int>::min(); }
1264 static inline unsigned int max() {
return std::numeric_limits<unsigned int>::max(); }
1265 static inline unsigned int defaultStep() {
return 1; }
1273 static inline long int min() {
return std::numeric_limits<long int>::min(); }
1274 static inline long int max() {
return std::numeric_limits<long int>::max(); }
1275 static inline long int defaultStep() {
return 1; }
1283 static inline long unsigned int min() {
return std::numeric_limits<long unsigned int>::min(); }
1284 static inline long unsigned int max() {
return std::numeric_limits<long unsigned int>::max(); }
1285 static inline long unsigned int defaultStep() {
return 1; }
1293 static inline long long int min() {
return std::numeric_limits<long long int>::min(); }
1294 static inline long long int max() {
return std::numeric_limits<long long int>::max(); }
1295 static inline long long int defaultStep() {
return 1; }
1303 static inline long long unsigned int min() {
return std::numeric_limits<long long unsigned int>::min(); }
1304 static inline long long unsigned int max() {
return std::numeric_limits<long long unsigned int>::max(); }
1305 static inline long long unsigned int defaultStep() {
return 1; }
1310#ifdef HAVE_TEUCHOSCORE_QUADMATH
1314 static inline __float128
min() {
return -std::numeric_limits<__float128>::max(); }
1315 static inline __float128
max() {
return std::numeric_limits<__float128>::max(); }
1316 static inline __float128
defaultStep() {
return 1; }
1324 static inline double min() {
return -std::numeric_limits<double>::max(); }
1325 static inline double max() {
return std::numeric_limits<double>::max(); }
1330#ifdef HAVE_TEUCHOS_LONG_DOUBLE
1334 static inline long double min() {
return -std::numeric_limits<long double>::max(); }
1335 static inline long double max() {
return std::numeric_limits<long double>::max(); }
1336 static inline long double defaultStep() {
return 1; }
1344 static inline float min() {
return -std::numeric_limits<float>::max(); }
1345 static inline float max() {
return std::numeric_limits<float>::max(); }
1383 minVal(min), maxVal(max), step_(step), precision_(precision),
1384 containsMin(true), containsMax(true){}
1396 containsMax(false){}
1434 precision_ = precision;
1507 std::string
const &sublistName)
const;
1515 const bool activeQuery)
const;
1523 void printDoc(std::string
const &docString, std::ostream &out)
const{
1525 out <<
"#\tValidator Used: " << std::endl;
1526 out <<
"#\t\tNumber Validator" << std::endl;
1529 out <<
"#\t\tMin (inclusive): " << minVal << std::endl;
1530 out <<
"#\t\tMax (inclusive): " << maxVal << std::endl;
1543 bool useIntConversions()
const;
1565 unsigned short precision_;
1581 std::string
const& paramName,
1582 std::string
const& sublistName,
1590 if( anyValue.
type() ==
typeid(std::string) ) {
1600 paramName, sublistName, entry);
1605bool EnhancedNumberValidator<T>::useIntConversions()
const
1612 if(
typeid(T) ==
typeid(
char))
return true;
1613 if(
typeid(T) ==
typeid(
unsigned char))
return true;
1614 if(
typeid(T) ==
typeid(
int))
return true;
1615 if(
typeid(T) ==
typeid(
unsigned int))
return true;
1616 if(
typeid(T) ==
typeid(
short))
return true;
1617 if(
typeid(T) ==
typeid(
unsigned short))
return true;
1618 if(
typeid(T) ==
typeid(
long))
return true;
1619 if(
typeid(T) ==
typeid(
unsigned long))
return true;
1620 if(
typeid(T) ==
typeid(
long long))
return true;
1621 if(
typeid(T) ==
typeid(
unsigned long long))
return true;
1638 const any &anyValue = entry.
getAny(activeQuery);
1639 if(useIntConversions()) {
1649 std::string
const &sublistName)
const
1657 if( anyValue.
type() ==
typeid(std::string) ) {
1665 "The \"" << paramName <<
"\"" <<
1666 " parameter in the \"" << sublistName <<
1667 "\" sublist is has an error." << std::endl << std::endl <<
1668 "Error: The value that you entered was the wrong type." << std::endl <<
1669 "Parameter: " << paramName << std::endl <<
1670 "Type specified: " << entryName << std::endl <<
1673 bool isValueInRange;
1675 ? isValueInRange = true : isValueInRange=
false;
1678 "The \"" << paramName <<
"\"" <<
1679 " parameter in the \"" << sublistName <<
1680 "\" sublist is has an error." << std::endl << std::endl <<
1681 "Error: The value that was entered doesn't fall with in " <<
1682 "the range set by the validator" << std::endl <<
1683 "Parameter: " << paramName << std::endl <<
1684 "Min: " << minVal << std::endl <<
1685 "Max: " << maxVal << std::endl <<
1686 "Value entered: " <<
1687 (
any_cast<T>(anyValue)) << std::endl << std::endl);
1759 bool fileMustExist()
const;
1774 bool fileEmptyNameOK()
const;
1789 bool setFileMustExist(
bool shouldFileExist);
1799 bool setFileEmptyNameOK(
bool isEmptyNameOK);
1807 ValidStringsList validStringValues()
const;
1812 std::string
const ¶mName,
1813 std::string
const &sublistName)
const;
1816 const std::string getXMLTypeName()
const;
1819 void printDoc(std::string
const &docString, std::ostream &out)
const;
1831 bool mustAlreadyExist_;
1909 std::string
const &sublistName)
const;
1915 void printDoc(std::string
const &docString, std::ostream &out)
const;
1958template<
class Val
idatorType,
class EntryType>
1974 prototypeValidator_(prototypeValidator){}
1983 return prototypeValidator_;
1993 return prototypeValidator_->validStringValues();
2026template<
class Val
idatorType,
class EntryType>
2048 std::string
const &sublistName)
const;
2052 return "TwoDArrayValidator(" +
2058 virtual void printDoc(std::string
const &docString, std::ostream &out)
const
2061 std::string toPrint;
2062 toPrint +=
"TwoDArrayValidator:\n";
2063 toPrint +=
"Prototype Validator:\n";
2071template<
class Val
idatorType,
class EntryType>
2073 std::string
const &sublistName)
const
2079 "The \"" << paramName <<
"\"" <<
2080 " parameter in the \"" << sublistName <<
2081 "\" sublist is has an error." << std::endl << std::endl <<
2082 "Error: The value you entered was the wrong type." << std::endl <<
2083 "Parameter: " << paramName << std::endl <<
2084 "Type specified: " << entryName << std::endl <<
2086 std::endl << std::endl);
2091 for(
int i = 0; i<extracted.
getNumRows(); ++i){
2092 for(
int j = 0; j<extracted.
getNumCols(); ++j){
2094 dummyParameter.
setValue(extracted(i,j));
2096 prototype->validate(
2097 dummyParameter, paramName, sublistName);
2100 std::stringstream oss;
2101 oss <<
"TwoDArray Validator Exception:" << std::endl <<
2102 "Bad Index: (" << i <<
"," << j <<
")" << std::endl << e.what();
2115template<
class Val
idatorType,
class EntryType>
2132template<
class Val
idatorType,
class EntryType>
2211template<
class Val
idatorType,
class EntryType>
2234 std::string
const &sublistName)
const;
2238 return "ArrayValidator(" +
2244 virtual void printDoc(std::string
const &docString, std::ostream &out)
const
2247 std::string toPrint;
2248 toPrint +=
"ArrayValidator:\n";
2249 toPrint +=
"Prototype Validator:\n";
2257template<
class Val
idatorType,
class EntryType>
2259 std::string
const &sublistName)
const
2265 "The \"" << paramName <<
"\"" <<
2266 " parameter in the \"" << sublistName <<
2267 "\" sublist is has an error." << std::endl << std::endl <<
2268 "Error: The value you entered was the wrong type." << std::endl <<
2269 "Parameter: " << paramName << std::endl <<
2270 "Type specified: " << entryName << std::endl <<
2272 std::endl << std::endl);
2277 for(
int i = 0; i<extracted.
size(); ++i){
2279 dummyParameter.
setValue(extracted[i]);
2281 prototype->validate(
2282 dummyParameter, paramName, sublistName);
2285 std::stringstream oss;
2286 oss <<
"Array Validator Exception:" << std::endl <<
2287 "Bad Index: " << i << std::endl << e.what();
2298template<
class Val
idatorType,
class EntryType>
2315template<
class Val
idatorType,
class EntryType>
2409template<
class IntegralType>
2412 std::string
const& defaultParameterName,
2413 const bool caseSensitive) :
2415 defaultParameterName_ (defaultParameterName),
2416 caseSensitive_ (caseSensitive)
2418 const int length =
static_cast<int>(strings.
size());
2420 for (
int i = 0; i < length; ++i) integralValues[i] = static_cast<IntegralType>(i);
2421 init(strings, integralValues);
2422 setValidValues (strings);
2426template<
class IntegralType>
2430 std::string
const& defaultParameterName,
2431 const bool caseSensitive) :
2433 defaultParameterName_ (defaultParameterName),
2434 caseSensitive_ (caseSensitive)
2439 init(strings, integralValues);
2440 setValidValues (strings);
2443template<
class IntegralType>
2448 std::string
const& defaultParameterName,
2449 const bool caseSensitive) :
2451 defaultParameterName_ (defaultParameterName),
2452 caseSensitive_ (caseSensitive)
2459 strings.
size() != stringsDocs.
size(),
2461 "The input arrays strings and stringsDocs must have the same length.");
2463 init(strings, integralValues);
2464 setValidValues(strings,&stringsDocs);
2467template <
class IntegralType>
2468void StringToIntegralParameterEntryValidator<IntegralType>::init(
2477 strings.
size() != integralValues.
size(), std::logic_error,
2478 "The input arrays strings and integralValues must have the same length.");
2480 typedef typename map_t::value_type val_t;
2481 typedef typename inv_map_t::value_type inv_val_t;
2482 for (
int i = 0; i < static_cast<int>(strings.
size()); ++i) {
2483 const std::string name =
2484 caseSensitive_ ? strings[i] : upperCase(strings[i]);
2485 const bool unique = map_.insert(val_t(name, integralValues[i])).second;
2487 "For parameter \"" << defaultParameterName_
2490 << i <<
"] = \"" << strings[i]
2491 <<
"\" is a duplicate.");
2492 inv_map_.insert(inv_val_t(integralValues[i], name));
2499template<
class IntegralType>
2502 const std::string &str,
const std::string ¶mName
2503 ,
const std::string &sublistName
2506 typename map_t::const_iterator itr = map_.find (caseSensitive_ ? str : upperCase (str));
2509 ,
"Error, the value \"" << str <<
"\" is not recognized for the parameter \""
2510 << ( paramName.length() ? paramName : defaultParameterName_ ) <<
"\""
2511 <<
"\nin the sublist \"" << sublistName <<
"\"."
2512 <<
"\n\nValid values include:"
2517 return (*itr).second;
2521template<
class IntegralType>
2525 ,
const std::string &sublistName,
const bool activeQuery
2528 if (entry.
isType<IntegralType>()){
2531 const bool validType = ( entry.
getAny(activeQuery).type() ==
typeid(std::string) );
2534 ,
"Error, the parameter {paramName=\""<<(paramName.length()?paramName:defaultParameterName_)
2536 <<
"\nin the sublist \"" << sublistName <<
"\""
2537 <<
"\nhas the wrong type."
2538 <<
"\n\nThe correct type is \"string\"!"
2547template<
class IntegralType>
2551 ,
const std::string &sublistName,
const bool activeQuery
2554 if (entry.
isType<IntegralType>()){
2556 typename inv_map_t::const_iterator itr = inv_map_.find(intVal);
2559 return (*itr).second;
2569template<
class IntegralType>
2573 ,
const std::string &defaultValue
2576 const std::string& strValue =
2577 paramList.
get (paramName,
2578 caseSensitive_ ? defaultValue : upperCase (defaultValue));
2583template<
class IntegralType>
2587 ,
const std::string &defaultValue
2590 const std::string& strValue =
2591 paramList.
get (paramName,
2592 caseSensitive_ ? defaultValue : upperCase (defaultValue));
2597template<
class IntegralType>
2601 return validStringValuesDocs_;
2604template<
class IntegralType>
2608 return defaultParameterName_;
2611template<
class IntegralType>
2614 const std::string &str,
const std::string ¶mName
2615 ,
const std::string &sublistName
2627template<
class IntegralType>
2633template<
class IntegralType>
2635 std::string
const& docString
2640 out <<
"# Valid std::string values:\n";
2642 if(validStringValuesDocs_.get()) {
2643 for(
int i = 0; i < static_cast<int>(validStringValues_->size()); ++i ) {
2644 out <<
"# \"" << (*validStringValues_)[i] <<
"\"\n";
2657template<
class IntegralType>
2661 return validStringValues_;
2665template<
class IntegralType>
2668 ,std::string
const& paramName
2669 ,std::string
const& sublistName
2676#if defined(HAVE_TEUCHOS_MODIFY_DEFAULTS_DURING_VALIDATION)
2677template<
class IntegralType>
2679 std::string
const& paramName,
2680 std::string
const& sublistName,
2691template<
class IntegralType>
2692void StringToIntegralParameterEntryValidator<IntegralType>::setValidValues(
2693 ArrayView<const std::string>
const& strings
2694 ,ArrayView<const std::string>
const* stringsDocs
2697 if (caseSensitive_) {
2698 validStringValues_ =
rcp (
new Array<std::string> (strings));
2703 (*vals)[i] = upperCase (strings[i]);
2712 std::ostringstream oss;
2713 for (
int i = 0; i < static_cast<int> (strings.size()); ++i) {
2714 oss <<
" \"" << strings[i] <<
"\"\n";
2717 validValues_ = oss.str();
2729template<
class IntegralType>
2733 ArrayView<const std::string>
const& strings,
2734 std::string
const& defaultParameterName
2738 new StringToIntegralParameterEntryValidator<IntegralType>(
2739 strings, defaultParameterName
2745template<
class IntegralType>
2749 ArrayView<const std::string>
const& strings,
2750 std::string
const& defaultParameterName,
2751 const bool caseSensitive
2754 typedef StringToIntegralParameterEntryValidator<IntegralType> ret_type;
2755 return rcp (
new ret_type (strings, defaultParameterName, caseSensitive));
2760template<
class IntegralType>
2764 ArrayView<const std::string>
const& strings,
2765 ArrayView<const IntegralType>
const& integralValues,
2766 std::string
const& defaultParameterName
2770 new StringToIntegralParameterEntryValidator<IntegralType>(
2771 strings, integralValues, defaultParameterName
2777template<
class IntegralType>
2781 ArrayView<const std::string>
const& strings,
2782 ArrayView<const IntegralType>
const& integralValues,
2783 std::string
const& defaultParameterName,
2784 const bool caseSensitive)
2786 typedef StringToIntegralParameterEntryValidator<IntegralType> ret_type;
2787 return rcp (
new ret_type (strings, integralValues,
2788 defaultParameterName, caseSensitive));
2792template<
class IntegralType>
2796 ArrayView<const std::string>
const& strings,
2797 ArrayView<const std::string>
const& stringsDocs,
2798 ArrayView<const IntegralType>
const& integralValues,
2799 std::string
const& defaultParameterName
2803 new StringToIntegralParameterEntryValidator<IntegralType>(
2804 strings, stringsDocs, integralValues, defaultParameterName
2810template<
class IntegralType>
2814 ArrayView<const std::string>
const& strings,
2815 ArrayView<const std::string>
const& stringsDocs,
2816 ArrayView<const IntegralType>
const& integralValues,
2817 std::string
const& defaultParameterName,
2818 const bool caseSensitive)
2820 typedef StringToIntegralParameterEntryValidator<IntegralType> ret_type;
2821 return rcp (
new ret_type (strings, stringsDocs, integralValues,
2822 defaultParameterName, caseSensitive));
2826template<
class IntegralType>
2828 std::string
const& paramName,
2829 std::string
const& defaultValue,
2830 std::string
const& docString,
2838 paramName, defaultValue, docString,
2848template<
class IntegralType>
2850 std::string
const& paramName,
2851 std::string
const& defaultValue,
2852 std::string
const& docString,
2861 paramName, defaultValue, docString,
2864 strings, integralValues, paramName
2871template<
class IntegralType>
2873 std::string
const& paramName,
2874 std::string
const& defaultValue,
2875 std::string
const& docString,
2886 paramName, defaultValue, docString,
2889 strings, stringsDocs, integralValues, paramName
2896template<
class IntegralType>
2898 ParameterList const& paramList, std::string
const& paramName
2902 if (
entry.isType<IntegralType>()){
2907 entry, paramList, paramName
2909 return integralValidator->getIntegralValue(
2910 entry, paramName, paramList.
name(),
true );
2915template<
class IntegralType>
2917 ParameterList const& paramList, std::string
const& paramName
2923 entry, paramList, paramName
2925 return integralValidator->getStringValue(
2926 entry, paramName, paramList.
name(),
true
2931template<
class IntegralType>
2935 std::string
const& paramName
2941 "Error! The parameter \""<<paramName<<
"\" exists\n"
2942 "in the parameter (sub)list \""<<paramList.
name()<<
"\"\n"
2943 "but it does not contain any validator needed to extract\n"
2952 "Error! The parameter \""<<paramName<<
"\" exists\n"
2953 "in the parameter (sub)list \""<<paramList.
name()<<
"\"\n"
2954 "but it contains the wrong type of validator. The expected validator type\n"
2956 "but the contained validator type is \""<<
typeName(*validator)<<
"\"!"
2958 return integralValidator;
Templated Parameter List class.
A std::string utilities class for Teuchos.
A thin wrapper around the Teuchos Array class that allows for 2 dimensional arrays.
Defines basic traits returning the name of a type in a portable and readable way.
RCP< const ValidatorType > getPrototype() const
Returns the prototype validator for this Array Validator.
AbstractArrayValidator(RCP< const ValidatorType > prototypeValidator)
Constructs an AbstractArrayValidator.
ValidStringsList validStringValues() const
Determines the types that are accepted.
AcceptedTypes & allowInt(bool _allowInt)
Set allow an int value or not.
bool allowString() const
Allow an std::string value?
bool allowInt() const
Allow an int value?
AcceptedTypes & allowDouble(bool _allowDouble)
Set allow a double value or not.
AcceptedTypes & allowLongLong(bool _allowLongLong)
Set allow an long long value or not.
bool allowDouble() const
Allow an double value?
bool allowLongLong() const
Allow an long long value?
AcceptedTypes & allowString(bool _allowString)
Set allow an std::string value or not.
AcceptedTypes(bool allowAllTypesByDefault=true)
Allow all types or not on construction.
Standard implementation of a ParameterEntryValidator that accepts numbers from a number of different ...
static EPreferredType getPrefferedTypeStringEnum(const std::string &enumString)
Gets the preferred type enum associated with a give string.
static const std::string & getPrefferedTypeString(EPreferredType enumValue)
Gets the string representation of a given preferred type enum.
AnyNumberParameterEntryValidator()
Construct with a preferrded type of double and accept all types.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT RCP< AnyNumberParameterEntryValidator > anyNumberParameterEntryValidator()
Nonmember constructor AnyNumberParameterEntryValidator.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT RCP< AnyNumberParameterEntryValidator > anyNumberParameterEntryValidator(AnyNumberParameterEntryValidator::EPreferredType const preferredType, AnyNumberParameterEntryValidator::AcceptedTypes const &acceptedTypes)
Nonmember constructor AnyNumberParameterEntryValidator.
EPreferredType
Determines what type is the preferred type.
ArrayFileNameValidator(RCP< const FileNameValidator > prototypeValidator)
ArrayNumberValidator(RCP< const EnhancedNumberValidator< T > > prototypeValidator)
ArrayStringValidator(RCP< const StringValidator > prototypeValidator)
Takes a validator, wraps it, and applies it to an array.
ArrayValidator(RCP< const ValidatorType > prototypeValidator)
Constructs a ArrayValidator.
const std::string getXMLTypeName() const
virtual void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
virtual void printDoc(std::string const &docString, std::ostream &out) const
size_type size() const
The total number of items in the managed array.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
Ordinal size_type
The type of Array sizes and capacities.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT RCP< BoolParameterEntryValidator > boolParameterEntryValidator()
Nonmember constructor BoolParameterEntryValidator.
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< AnyNumberParameterEntryValidator > getDummyObject()
Retrieves a dummy object of type AnyNumberParameterEntryValidator.
static RCP< ArrayValidator< ValidatorType, EntryType > > getDummyObject()
Retrieves a dummy object of type ArrayValidator<ValidatorType, EntryType>.
static RCP< EnhancedNumberValidator< T > > getDummyObject()
Retrieves a dummy object of type EnhancedNumberValidator<T>.
static RCP< FileNameValidator > getDummyObject()
Retrieves a dummy object of type FileNameValidator.
static RCP< StringToIntegralParameterEntryValidator< IntegralType > > getDummyObject()
Retrieves a dummy object of type StringToIntegralParameterEntryValidator<IntegralType>.
static RCP< StringValidator > getDummyObject()
Retrieves a dummy object of type StringValidator.
static RCP< TwoDArrayValidator< ValidatorType, EntryType > > getDummyObject()
Retrieves a dummy object of type TwoDArrayValidator<ValidatorType, EntryType>.
Class for retrieving a dummy object of type T.
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
Class defining the traits of the number type being used in an EnhancedNumberValidator.
static T max()
Gets the maximum possible value the number type can take on.
static unsigned short defaultPrecision()
Gets the default precision with which the number type should be displayed.
static T defaultStep()
gets default amount a value of the number type should be incremented by when being utilizied in a UI.
static T min()
Gets the minimum possible value the number type can take on.
Class uesd to validate a particular type of number.
T getMax() const
Gets the maximum acceptable value for the validator.
Teuchos::any getNumberFromString(const ParameterEntry &entry, const bool activeQuery) const
void setMin(T min)
Sets the minimum acceptable value for the validator.
EnhancedNumberValidator(T min, T max, T step=EnhancedNumberTraits< T >::defaultStep(), unsigned short precision=EnhancedNumberTraits< T >::defaultPrecision())
Constructs a EnhancedNumberValidator.
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
void setMax(T max)
Sets the maximum acceptable value for the validator.
void validateAndModify(std::string const ¶mName, std::string const &sublistName, ParameterEntry *entry) const
T getStep() const
Gets the step being used for the validator.
unsigned short getPrecision() const
Gets the precision specified for the validator.
ValidStringsList validStringValues() const
void setStep(T step)
Sets the step being used for the validator.
bool hasMax() const
Determines whether or not the validator has a maximum value.
T getMin() const
Gets the minimum acceptable value for the validator.
void setPrecision(unsigned short precision)
Sets the precision specified for the validator.
const std::string getXMLTypeName() const
void printDoc(std::string const &docString, std::ostream &out) const
EnhancedNumberValidator()
Constructs a EnhancedNumberValidator without an explicit minimum or maximum.
bool hasMin() const
Determines whether or not the validator has a minimum value.
Validate a file name entry.
static bool mustAlreadyExistDefault()
The default value of the mustAlreadyExist parameter in the constructor.
FileNameValidator(bool mustAlreadyExist=mustAlreadyExistDefault())
Constructs a FileNameValidator.
Abstract interface for an object that can validate a ParameterEntry's value.
virtual void validateAndModify(std::string const ¶mName, std::string const &sublistName, ParameterEntry *entry) const
Validate and perhaps modify a parameter entry's value.
RCP< const Array< std::string > > ValidStringsList
ParameterEntryValidator()
Default Constructor.
This object is held as the "value" in the Teuchos::ParameterList std::map.
bool isType() const
Test the type of the data being contained.
any & getAny(bool activeQry=true)
Direct access to the Teuchos::any data value underlying this object. The bool argument activeQry (def...
RCP< const ParameterEntryValidator > validator() const
Return the (optional) validator object.
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.
T & getValue(const ParameterEntry &entry)
A templated helper function for returning the value of type T held in the ParameterEntry object,...
A list of parameters of arbitrary type.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT std::string getNumericStringParameter(ParameterList const ¶mList, std::string const ¶mName)
Get std::string numeric parameter.
std::string getStringValue(ParameterList const ¶mList, std::string const ¶mName)
Get a std::string value for a parameter that is assumed to already be set.
const ParameterEntry & entry(ConstIterator i) const
Access to ParameterEntry (i.e., returns i->second).
IntegralType getIntegralValue(ParameterList const ¶mList, std::string const ¶mName)
Get an integral value for a parameter that is assumed to already be set.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void setDoubleParameter(std::string const ¶mName, double const &value, std::string const &docString, ParameterList *paramList, AnyNumberParameterEntryValidator::AcceptedTypes const &acceptedTypes=AnyNumberParameterEntryValidator::AcceptedTypes())
Set an double parameter that allows for (nearly) any input parameter type that is convertible to a do...
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void setLongLongParameter(std::string const ¶mName, long long const value, std::string const &docString, ParameterList *paramList, AnyNumberParameterEntryValidator::AcceptedTypes const &acceptedTypes=AnyNumberParameterEntryValidator::AcceptedTypes())
Set an integer parameter that allows for (nearly) any input parameter type that is convertible to an ...
const std::string & name() const
The name of this ParameterList.
ParameterList()=default
Constructor.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method.
ParameterEntry & getEntry(const std::string &name)
Retrieves an entry with the name name.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT double getDoubleParameter(ParameterList const ¶mList, std::string const ¶mName)
Get double integer parameter.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void setIntParameter(std::string const ¶mName, int const value, std::string const &docString, ParameterList *paramList, AnyNumberParameterEntryValidator::AcceptedTypes const &acceptedTypes=AnyNumberParameterEntryValidator::AcceptedTypes())
Set an integer parameter that allows for (nearly) any input parameter type that is convertible to an ...
T & get(const std::string &name, T def_value)
Return the parameter's value, or the default value if it is not there.
void setStringToIntegralParameter(std::string const ¶mName, std::string const &defaultValue, std::string const &docString, ArrayView< const std::string > const &strings, ParameterList *paramList)
Set up a std::string parameter that will use an embedded validator to allow the extraction of an inte...
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void setNumericStringParameter(std::string const ¶mName, std::string const &value, std::string const &docString, ParameterList *paramList, AnyNumberParameterEntryValidator::AcceptedTypes const &acceptedTypes=AnyNumberParameterEntryValidator::AcceptedTypes())
Set an numeric parameter preferred as a std::string that allows for (nearly) any input parameter type...
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT long long getLongLongParameter(ParameterList const ¶mList, std::string const ¶mName)
Get a long long parameter.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT int getIntParameter(ParameterList const ¶mList, std::string const ¶mName)
Get an integer parameter.
Smart reference counting pointer class for automatic garbage collection.
RCP< T2 > rcp_dynamic_cast(const RCP< T1 > &p1, bool throw_on_fail=false)
Dynamic cast of underlying RCP type from T1* to T2*.
RCP< T2 > rcp_implicit_cast(const RCP< T1 > &p1)
Implicit cast of underlying RCP type from T1* to T2*.
RCP< T2 > rcp_const_cast(const RCP< T1 > &p1)
Constant cast of underlying RCP type from T1* to T2*.
static std::ostream & printLines(std::ostream &os, const std::string &linePrefix, const std::string &lines)
Print lines with prefix first.
Standard implementation of a ParameterEntryValidator that maps from a list of strings to an enum or i...
StringToIntegralParameterEntryValidator(const ArrayView< const std::string > &strings, const std::string &defaultParameterName, const bool caseSensitive=true)
Construct with a mapping from strings to the enum or integer values .
IntegralType getIntegralValue(const std::string &str, const std::string ¶mName="", const std::string &sublistName="") const
For a string value, find its corresponding enum or integer value.
ValidStringsList getStringDocs() const
Get a pointer to the array containing all the documentation strings.
RCP< StringToIntegralParameterEntryValidator< IntegralType > > stringToIntegralParameterEntryValidator(ArrayView< const std::string > const &strings, std::string const &defaultParameterName, const bool caseSensitive)
Nonmember constructor (see implementation).
std::string validateString(const std::string &str, const std::string ¶mName="", const std::string &sublistName="") const
Validate the std::string and pass it on.
std::string getStringValue(const ParameterEntry &entry, const std::string ¶mName="", const std::string &sublistName="", const bool activeQuery=true) const
Find the string value for the given ParameterEntry.
RCP< StringToIntegralParameterEntryValidator< IntegralType > > stringToIntegralParameterEntryValidator(ArrayView< const std::string > const &strings, std::string const &defaultParameterName)
Nonmember constructor (see implementation).
bool isCaseSensitive() const
Whether this validator is case sensitive.
void printDoc(std::string const &docString, std::ostream &out) const
Print documentation to the given output string.
RCP< StringToIntegralParameterEntryValidator< IntegralType > > stringToIntegralParameterEntryValidator(ArrayView< const std::string > const &strings, ArrayView< const IntegralType > const &integralValues, std::string const &defaultParameterName)
Nonmember constructor (see implementation).
RCP< StringToIntegralParameterEntryValidator< IntegralType > > stringToIntegralParameterEntryValidator(ArrayView< const std::string > const &strings, ArrayView< const std::string > const &stringsDocs, ArrayView< const IntegralType > const &integralValues, std::string const &defaultParameterName, const bool caseSensitive)
Nonmember constructor (see implementation).
RCP< StringToIntegralParameterEntryValidator< IntegralType > > stringToIntegralParameterEntryValidator(ArrayView< const std::string > const &strings, ArrayView< const std::string > const &stringsDocs, ArrayView< const IntegralType > const &integralValues, std::string const &defaultParameterName)
Nonmember constructor (see implementation).
RCP< StringToIntegralParameterEntryValidator< IntegralType > > stringToIntegralParameterEntryValidator(ArrayView< const std::string > const &strings, ArrayView< const IntegralType > const &integralValues, std::string const &defaultParameterName, const bool caseSensitive)
Nonmember constructor (see implementation).
ValidStringsList validStringValues() const
const std::string & getDefaultParameterName() const
Get the name of the default parameter for the validator.
const std::string getXMLTypeName() const
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
Validate the given ParameterEntry.
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.
Tuple< T, 1 > tuple(const T &a)
Create a Tuple<T,1>.
TwoDArrayFileNameValidator(RCP< const FileNameValidator > prototypeValidator)
TwoDArrayNumberValidator(RCP< const EnhancedNumberValidator< T > > prototypeValidator)
TwoDArrayStringValidator(RCP< const StringValidator > prototypeValidator)
Takes a validator, wraps it, and applies it to a TwoDArray.
virtual void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
const std::string getXMLTypeName() const
TwoDArrayValidator(RCP< const ValidatorType > prototypeValidator)
Constructs a ArrayValidator.
virtual void printDoc(std::string const &docString, std::ostream &out) const
A thin wrapper around the Array class which causes it to be interpreted as a 2D Array.
size_type getNumCols() const
returns the number of columns in the TwoDArray.
size_type getNumRows() const
returns the number of rows in the TwoDArray.
Default traits class that just returns typeid(T).name().
static std::string name()
Modified boost::any class, which is a container for a templated value.
ValueType & any_cast(any &operand)
Used to extract the templated value held in Teuchos::any to a given value type.
std::string typeName() const
Return the name of the type.
const std::type_info & type() const
Return the type of value being stored.
#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.
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
This macro is checks that to numbers are equal and if not then throws an exception with a good error ...
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
EVerbosityLevel
Verbosity level.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
RCP< const StringToIntegralParameterEntryValidator< IntegralType > > getStringToIntegralParameterEntryValidator(ParameterEntry const &entry, ParameterList const ¶mList, std::string const ¶mName)
Get a StringToIntegralParameterEntryValidator<IntegralType> object out of a ParameterEntry object.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Default structure used by EnhancedNumberTraits<T> to produce a compile time error when the specializa...
static T notDefined()
This function should not compile if there is an attempt to instantiate!