42 #ifndef TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H
43 #define TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H
45 #include "Teuchos_ParameterEntryValidator.hpp"
47 #include "Teuchos_ParameterListExceptions.hpp"
50 #include "Teuchos_Assert.hpp"
55 #ifdef HAVE_TEUCHOSCORE_QUADMATH
56 # include <quadmath.h>
57 #endif // HAVE_TEUCHOSCORE_QUADMATH
91 template<
class IntegralType>
115 const std::string& defaultParameterName,
116 const bool caseSensitive =
true);
143 std::string
const& defaultParameterName,
144 const bool caseSensitive =
true);
178 const std::string& defaultParameterName,
179 const bool caseSensitive =
true);
195 const std::string &str,
const std::string ¶mName =
"",
196 const std::string &sublistName =
""
216 const std::string ¶mName =
"",
217 const std::string &sublistName =
"",
218 const bool activeQuery =
true)
const;
237 const std::string ¶mName =
"",
238 const std::string &sublistName =
"",
239 const bool activeQuery =
true)
const;
249 const std::string& paramName,
250 const std::string& defaultValue)
const;
257 const std::string &defaultValue
285 const std::string &str,
const std::string ¶mName =
"",
286 const std::string &sublistName =
""
294 return caseSensitive_;
306 std::string
const& docString,
317 std::string
const& paramName,
318 std::string
const& sublistName
321 #if defined(HAVE_TEUCHOS_MODIFY_DEFAULTS_DURING_VALIDATION)
323 std::string
const& paramName,
324 std::string
const& sublistName,
332 std::string defaultParameterName_;
333 std::string validValues_;
337 typedef std::map<std::string,IntegralType> map_t;
339 typedef std::map<IntegralType,std::string> inv_map_t;
342 const bool caseSensitive_;
367 static std::string upperCase (
const std::string s) {
368 std::string s_upper = s;
369 std::transform (s_upper.begin (), s_upper.end (), s_upper.begin (), ::toupper);
379 template<
class IntegralType>
380 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
381 stringToIntegralParameterEntryValidator(
382 ArrayView<const std::string>
const& strings,
383 std::string
const& defaultParameterName
391 template<
class IntegralType>
392 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
393 stringToIntegralParameterEntryValidator(
394 ArrayView<const std::string>
const& strings,
395 std::string
const& defaultParameterName,
396 const bool caseSensitive
404 template<
class IntegralType>
405 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
406 stringToIntegralParameterEntryValidator(
407 ArrayView<const std::string>
const& strings,
408 ArrayView<const IntegralType>
const& integralValues,
409 std::string
const& defaultParameterName
417 template<
class IntegralType>
418 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
419 stringToIntegralParameterEntryValidator(
420 ArrayView<const std::string>
const& strings,
421 ArrayView<const IntegralType>
const& integralValues,
422 std::string
const& defaultParameterName,
423 const bool caseSensitive
431 template<
class IntegralType>
432 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
433 stringToIntegralParameterEntryValidator(
434 ArrayView<const std::string>
const& strings,
435 ArrayView<const std::string>
const& stringsDocs,
436 ArrayView<const IntegralType>
const& integralValues,
437 std::string
const& defaultParameterName
445 template<
class IntegralType>
446 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
447 stringToIntegralParameterEntryValidator(
448 ArrayView<const std::string>
const& strings,
449 ArrayView<const std::string>
const& stringsDocs,
450 ArrayView<const IntegralType>
const& integralValues,
451 std::string
const& defaultParameterName,
452 const bool caseSensitive
466 template<
class IntegralType>
467 void setStringToIntegralParameter(
468 std::string
const& paramName,
469 std::string
const& defaultValue,
470 std::string
const& docString,
471 ArrayView<const std::string>
const& strings,
472 ParameterList * paramList
487 template<
class IntegralType>
488 void setStringToIntegralParameter(
489 std::string
const& paramName,
490 std::string
const& defaultValue,
491 std::string
const& docString,
492 ArrayView<const std::string>
const& strings,
493 ArrayView<const IntegralType>
const& integralValues,
494 ParameterList * paramList
509 template<
class IntegralType>
510 void setStringToIntegralParameter(
511 std::string
const& paramName,
512 std::string
const& defaultValue,
513 std::string
const& docString,
514 ArrayView<const std::string>
const& strings,
515 ArrayView<const std::string>
const& stringsDocs,
516 ArrayView<const IntegralType>
const& integralValues,
517 ParameterList * paramList
531 template<
class IntegralType>
532 IntegralType getIntegralValue(
533 ParameterList
const& paramList, std::string
const& paramName
548 template<
class IntegralType>
549 std::string getStringValue(
550 ParameterList
const& paramList, std::string
const& paramName
559 template<
class IntegralType>
560 RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
562 ParameterEntry
const& entry, ParameterList
const& paramList,
563 std::string
const& paramName
572 std::string getVerbosityLevelParameterValueName(
581 RCP<StringToIntegralParameterEntryValidator<EVerbosityLevel> >
582 verbosityLevelParameterEntryValidator(std::string
const& defaultParameterName);
589 template<
class IntegralType>
606 template<
class IntegralType>
610 return stringToIntegralParameterEntryValidator<IntegralType>(
611 tuple<std::string>(
""), tuple<std::string>(
""),
612 tuple<IntegralType>((IntegralType)1),
"");
645 const std::string &sublistName =
"",
const bool activeQuery =
true
653 const int defaultValue
662 const std::string getXMLTypeName()
const;
666 std::string
const& docString,
672 validStringValues()
const;
677 std::string
const& paramName,
678 std::string
const& sublistName
682 void validateAndModify(
683 std::string
const& paramName,
684 std::string
const& sublistName,
695 std::string acceptedTypesString_;
700 void finishInitialization();
704 std::string
const& paramName,
705 std::string
const& sublistName
717 boolParameterEntryValidator();
742 enum EPreferredType { PREFER_INT, PREFER_LONG_LONG, PREFER_DOUBLE, PREFER_STRING };
750 :allowInt_(allowAllTypesByDefault)
751 ,allowLongLong_(allowAllTypesByDefault)
752 ,allowDouble_(allowAllTypesByDefault)
753 ,allowString_(allowAllTypesByDefault)
757 { allowInt_ = _allowInt;
return *
this; }
760 { allowLongLong_ = _allowLongLong;
return *
this; }
763 { allowDouble_ = _allowDouble;
return *
this; }
766 { allowString_ = _allowString;
return *
this; }
803 EPreferredType
const preferredType,
804 AcceptedTypes
const& acceptedTypes
819 const std::string &sublistName =
"",
const bool activeQuery =
true
827 long long getLongLong(
829 const std::string &sublistName =
"",
const bool activeQuery =
true
837 const std::string &sublistName =
"",
const bool activeQuery =
true
841 std::string getString(
843 const std::string &sublistName =
"",
const bool activeQuery =
true
851 const int defaultValue
857 long long getLongLong(
859 const long long defaultValue
867 const double defaultValue
873 std::string getString(
875 const std::string &defaultValue
880 bool isIntAllowed()
const;
884 bool isLongLongAllowed()
const;
888 bool isDoubleAllowed()
const;
892 bool isStringAllowed()
const;
896 EPreferredType getPreferredType()
const;
903 return getIntEnumString ();
904 case PREFER_LONG_LONG:
905 return getLongLongEnumString ();
907 return getDoubleEnumString ();
909 return getStringEnumString ();
911 const std::string typeString (toString (enumValue));
912 throw std::runtime_error(
"Cannot convert enumValue: " + typeString +
" to a string");
919 if (enumString == getIntEnumString ()) {
922 else if (enumString == getLongLongEnumString ()) {
923 return PREFER_LONG_LONG;
925 else if (enumString == getDoubleEnumString ()) {
926 return PREFER_DOUBLE;
928 else if (enumString == getStringEnumString ()) {
929 return PREFER_STRING;
932 throw std::runtime_error (
"Cannot convert enumString: " + enumString +
" to an enum");
942 const std::string getXMLTypeName()
const;
946 std::string
const& docString,
952 validStringValues()
const;
957 std::string
const& paramName,
958 std::string
const& sublistName
962 void validateAndModify(
963 std::string
const& paramName,
964 std::string
const& sublistName,
976 EPreferredType preferredType_;
977 std::string acceptedTypesString_;
981 #pragma warning(push)
982 #pragma warning(disable:4251)
984 const AcceptedTypes acceptedTypes_;
993 static const std::string& getIntEnumString(){
995 return intEnumString_;
999 static const std::string& getLongLongEnumString(){
1001 return longLongEnumString_;
1005 static const std::string& getDoubleEnumString(){
1007 return doubleEnumString_;
1011 static const std::string& getStringEnumString(){
1013 return stringEnumString_;
1017 void finishInitialization();
1019 void throwTypeError(
1020 ParameterEntry
const& entry,
1021 std::string
const& paramName,
1022 std::string
const& sublistName
1035 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT RCP<AnyNumberParameterEntryValidator>
1036 anyNumberParameterEntryValidator();
1043 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT RCP<AnyNumberParameterEntryValidator>
1044 anyNumberParameterEntryValidator(
1046 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
1054 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
void setIntParameter(
1055 std::string
const& paramName,
1056 int const value, std::string
const& docString,
1057 ParameterList *paramList,
1058 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
1059 = AnyNumberParameterEntryValidator::AcceptedTypes()
1068 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
void setLongLongParameter(
1069 std::string
const& paramName,
1070 long long const value, std::string
const& docString,
1071 ParameterList *paramList,
1072 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
1073 = AnyNumberParameterEntryValidator::AcceptedTypes()
1081 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
void setDoubleParameter(
1082 std::string
const& paramName,
1083 double const& value, std::string
const& docString,
1084 ParameterList *paramList,
1085 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
1086 = AnyNumberParameterEntryValidator::AcceptedTypes()
1095 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
void setNumericStringParameter(
1096 std::string
const& paramName,
1097 std::string
const& value, std::string
const& docString,
1098 ParameterList *paramList,
1099 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
1100 = AnyNumberParameterEntryValidator::AcceptedTypes()
1118 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
int getIntParameter(
1119 ParameterList
const& paramList, std::string
const& paramName
1137 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
long long getLongLongParameter(
1138 ParameterList
const& paramList, std::string
const& paramName
1155 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
double getDoubleParameter(
1156 ParameterList
const& paramList,
1157 std::string
const& paramName
1176 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT std::string getNumericStringParameter(
1177 ParameterList
const& paramList,
1178 std::string
const& paramName
1212 return T::this_type_is_missing_a_specialization();
1263 class EnhancedNumberTraits<short int>{
1265 static inline short int min() {
return std::numeric_limits<short int>::min(); }
1266 static inline short int max() {
return std::numeric_limits<short int>::max(); }
1267 static inline short int defaultStep() {
return 1; }
1273 class EnhancedNumberTraits<short unsigned int>{
1275 static inline short unsigned int min() {
return std::numeric_limits<short unsigned int>::min(); }
1276 static inline short unsigned int max() {
return std::numeric_limits<short unsigned int>::max(); }
1277 static inline short unsigned int defaultStep() {
return 1; }
1283 class EnhancedNumberTraits<int>{
1285 static inline int min() {
return std::numeric_limits<int>::min(); }
1286 static inline int max() {
return std::numeric_limits<int>::max(); }
1293 class EnhancedNumberTraits<unsigned int>{
1295 static inline unsigned int min() {
return std::numeric_limits<unsigned int>::min(); }
1296 static inline unsigned int max() {
return std::numeric_limits<unsigned int>::max(); }
1297 static inline unsigned int defaultStep() {
return 1; }
1303 class EnhancedNumberTraits<long int>{
1305 static inline long int min() {
return std::numeric_limits<long int>::min(); }
1306 static inline long int max() {
return std::numeric_limits<long int>::max(); }
1307 static inline long int defaultStep() {
return 1; }
1313 class EnhancedNumberTraits<long unsigned int>{
1315 static inline long unsigned int min() {
return std::numeric_limits<long unsigned int>::min(); }
1316 static inline long unsigned int max() {
return std::numeric_limits<long unsigned int>::max(); }
1317 static inline long unsigned int defaultStep() {
return 1; }
1323 class EnhancedNumberTraits<long long int>{
1325 static inline long long int min() {
return std::numeric_limits<long long int>::min(); }
1326 static inline long long int max() {
return std::numeric_limits<long long int>::max(); }
1327 static inline long long int defaultStep() {
return 1; }
1333 class EnhancedNumberTraits<long long unsigned int>{
1335 static inline long long unsigned int min() {
return std::numeric_limits<long long unsigned int>::min(); }
1336 static inline long long unsigned int max() {
return std::numeric_limits<long long unsigned int>::max(); }
1337 static inline long long unsigned int defaultStep() {
return 1; }
1342 #ifdef HAVE_TEUCHOSCORE_QUADMATH
1344 class EnhancedNumberTraits<__float128>{
1346 static inline __float128
min() {
return -std::numeric_limits<__float128>::max(); }
1347 static inline __float128
max() {
return std::numeric_limits<__float128>::max(); }
1348 static inline __float128
defaultStep() {
return 1; }
1351 #endif // HAVE_TEUCHOSCORE_QUADMATH
1354 class EnhancedNumberTraits<double>{
1356 static inline double min() {
return -std::numeric_limits<double>::max(); }
1357 static inline double max() {
return std::numeric_limits<double>::max(); }
1362 #ifdef HAVE_TEUCHOS_LONG_DOUBLE
1364 class EnhancedNumberTraits<long double>{
1366 static inline long double min() {
return -std::numeric_limits<long double>::max(); }
1367 static inline long double max() {
return std::numeric_limits<long double>::max(); }
1368 static inline long double defaultStep() {
return 1; }
1374 class EnhancedNumberTraits<float>{
1376 static inline float min() {
return -std::numeric_limits<float>::max(); }
1377 static inline float max() {
return std::numeric_limits<float>::max(); }
1415 minVal(min), maxVal(max), step_(step), precision_(precision),
1416 containsMin(true), containsMax(true){}
1428 containsMax(false){}
1466 precision_ = precision;
1539 std::string
const &sublistName)
const;
1547 const bool activeQuery)
const;
1555 void printDoc(std::string
const &docString, std::ostream &out)
const{
1557 out <<
"#\tValidator Used: " << std::endl;
1558 out <<
"#\t\tNumber Validator" << std::endl;
1561 out <<
"#\t\tMin (inclusive): " << minVal << std::endl;
1562 out <<
"#\t\tMax (inclusive): " << maxVal << std::endl;
1575 bool useIntConversions()
const;
1597 unsigned short precision_;
1613 std::string
const& paramName,
1614 std::string
const& sublistName,
1622 if( anyValue.
type() ==
typeid(std::string) ) {
1623 anyValue = getNumberFromString(*entry,
false);
1625 any_cast<T>(anyValue),
1632 paramName, sublistName, entry);
1644 if(
typeid(T) ==
typeid(
char))
return true;
1645 if(
typeid(T) ==
typeid(
unsigned char))
return true;
1646 if(
typeid(T) ==
typeid(
int))
return true;
1647 if(
typeid(T) ==
typeid(
unsigned int))
return true;
1648 if(
typeid(T) ==
typeid(
short))
return true;
1649 if(
typeid(T) ==
typeid(
unsigned short))
return true;
1650 if(
typeid(T) ==
typeid(
long))
return true;
1651 if(
typeid(T) ==
typeid(
unsigned long))
return true;
1652 if(
typeid(T) ==
typeid(
long long))
return true;
1653 if(
typeid(T) ==
typeid(
unsigned long long))
return true;
1670 const any &anyValue = entry.
getAny(activeQuery);
1671 if(useIntConversions()) {
1672 return any((T)convertStringToInt(any_cast<std::string>(anyValue)));
1675 return any((T)convertStringToDouble(any_cast<std::string>(anyValue)));
1681 std::string
const &sublistName)
const
1689 if( anyValue.
type() ==
typeid(std::string) ) {
1691 anyValue = getNumberFromString(entry,
false);
1697 "The \"" << paramName <<
"\"" <<
1698 " parameter in the \"" << sublistName <<
1699 "\" sublist is has an error." << std::endl << std::endl <<
1700 "Error: The value that you entered was the wrong type." << std::endl <<
1701 "Parameter: " << paramName << std::endl <<
1702 "Type specified: " << entryName << std::endl <<
1705 bool isValueInRange;
1706 any_cast<T>(anyValue) >= minVal && any_cast<T>(anyValue) <= maxVal
1707 ? isValueInRange =
true : isValueInRange=
false;
1710 "The \"" << paramName <<
"\"" <<
1711 " parameter in the \"" << sublistName <<
1712 "\" sublist is has an error." << std::endl << std::endl <<
1713 "Error: The value that was entered doesn't fall with in " <<
1714 "the range set by the validator" << std::endl <<
1715 "Parameter: " << paramName << std::endl <<
1716 "Min: " << minVal << std::endl <<
1717 "Max: " << maxVal << std::endl <<
1718 "Value entered: " <<
1719 (any_cast<T>(anyValue)) << std::endl << std::endl);
1791 bool fileMustExist()
const;
1806 bool fileEmptyNameOK()
const;
1821 bool setFileMustExist(
bool shouldFileExist);
1831 bool setFileEmptyNameOK(
bool isEmptyNameOK);
1839 ValidStringsList validStringValues()
const;
1844 std::string
const ¶mName,
1845 std::string
const &sublistName)
const;
1848 const std::string getXMLTypeName()
const;
1851 void printDoc(std::string
const &docString, std::ostream &out)
const;
1863 bool mustAlreadyExist_;
1928 ValidStringsList setValidStrings(
1937 ValidStringsList validStringValues()
const;
1940 void validate(
ParameterEntry const &entry, std::string
const ¶mName,
1941 std::string
const &sublistName)
const;
1944 const std::string getXMLTypeName()
const;
1947 void printDoc(std::string
const &docString, std::ostream &out)
const;
1958 ValidStringsList validStrings_;
1990 template<
class Val
idatorType,
class EntryType>
2006 prototypeValidator_(prototypeValidator){}
2015 return prototypeValidator_;
2025 return prototypeValidator_->validStringValues();
2058 template<
class Val
idatorType,
class EntryType>
2080 std::string
const &sublistName)
const;
2084 return "TwoDArrayValidator(" +
2090 virtual void printDoc(std::string
const &docString, std::ostream &out)
const
2093 std::string toPrint;
2094 toPrint +=
"TwoDArrayValidator:\n";
2095 toPrint +=
"Prototype Validator:\n";
2103 template<
class Val
idatorType,
class EntryType>
2105 std::string
const &sublistName)
const
2111 "The \"" << paramName <<
"\"" <<
2112 " parameter in the \"" << sublistName <<
2113 "\" sublist is has an error." << std::endl << std::endl <<
2114 "Error: The value you entered was the wrong type." << std::endl <<
2115 "Parameter: " << paramName << std::endl <<
2116 "Type specified: " << entryName << std::endl <<
2118 std::endl << std::endl);
2121 getValue<Teuchos::TwoDArray<EntryType> >(entry);
2123 for(
int i = 0; i<extracted.getNumRows(); ++i){
2124 for(
int j = 0; j<extracted.getNumCols(); ++j){
2126 dummyParameter.
setValue(extracted(i,j));
2128 prototype->validate(
2129 dummyParameter, paramName, sublistName);
2132 std::stringstream oss;
2133 oss <<
"TwoDArray Validator Exception:" << std::endl <<
2134 "Bad Index: (" << i <<
"," << j <<
")" << std::endl << e.what();
2147 template<
class Val
idatorType,
class EntryType>
2164 template<
class Val
idatorType,
class EntryType>
2243 template<
class Val
idatorType,
class EntryType>
2266 std::string
const &sublistName)
const;
2270 return "ArrayValidator(" +
2276 virtual void printDoc(std::string
const &docString, std::ostream &out)
const
2279 std::string toPrint;
2280 toPrint +=
"ArrayValidator:\n";
2281 toPrint +=
"Prototype Validator:\n";
2289 template<
class Val
idatorType,
class EntryType>
2291 std::string
const &sublistName)
const
2297 "The \"" << paramName <<
"\"" <<
2298 " parameter in the \"" << sublistName <<
2299 "\" sublist is has an error." << std::endl << std::endl <<
2300 "Error: The value you entered was the wrong type." << std::endl <<
2301 "Parameter: " << paramName << std::endl <<
2302 "Type specified: " << entryName << std::endl <<
2304 std::endl << std::endl);
2307 getValue<Teuchos::Array<EntryType> >(entry);
2309 for(
int i = 0; i<extracted.size(); ++i){
2311 dummyParameter.
setValue(extracted[i]);
2313 prototype->validate(
2314 dummyParameter, paramName, sublistName);
2317 std::stringstream oss;
2318 oss <<
"Array Validator Exception:" << std::endl <<
2319 "Bad Index: " << i << std::endl << e.what();
2330 template<
class Val
idatorType,
class EntryType>
2347 template<
class Val
idatorType,
class EntryType>
2441 template<
class IntegralType>
2442 StringToIntegralParameterEntryValidator<IntegralType>::
2444 std::string
const& defaultParameterName,
2445 const bool caseSensitive) :
2447 defaultParameterName_ (defaultParameterName),
2448 caseSensitive_ (caseSensitive)
2450 const int length =
static_cast<int>(strings.
size());
2452 for (
int i = 0; i < length; ++i) integralValues[i] = static_cast<IntegralType>(i);
2453 init(strings, integralValues);
2454 setValidValues (strings);
2458 template<
class IntegralType>
2462 std::string
const& defaultParameterName,
2463 const bool caseSensitive) :
2465 defaultParameterName_ (defaultParameterName),
2466 caseSensitive_ (caseSensitive)
2468 #ifdef TEUCHOS_DEBUG
2471 init(strings, integralValues);
2472 setValidValues (strings);
2475 template<
class IntegralType>
2480 std::string
const& defaultParameterName,
2481 const bool caseSensitive) :
2483 defaultParameterName_ (defaultParameterName),
2484 caseSensitive_ (caseSensitive)
2486 #ifdef TEUCHOS_DEBUG
2491 strings.
size() != stringsDocs.
size(),
2493 "The input arrays strings and stringsDocs must have the same length.");
2495 init(strings, integralValues);
2496 setValidValues(strings,&stringsDocs);
2499 template <
class IntegralType>
2504 #ifdef TEUCHOS_DEBUG
2509 strings.
size() != integralValues.
size(), std::logic_error,
2510 "The input arrays strings and integralValues must have the same length.");
2512 typedef typename map_t::value_type val_t;
2513 typedef typename inv_map_t::value_type inv_val_t;
2514 for (
int i = 0; i < static_cast<int>(strings.
size()); ++i) {
2515 const std::string name =
2516 caseSensitive_ ? strings[i] : upperCase(strings[i]);
2517 const bool unique = map_.insert(val_t(name, integralValues[i])).second;
2519 "For parameter \"" << defaultParameterName_
2522 << i <<
"] = \"" << strings[i]
2523 <<
"\" is a duplicate.");
2524 inv_map_.insert(inv_val_t(integralValues[i], name));
2531 template<
class IntegralType>
2534 const std::string &str,
const std::string ¶mName
2535 ,
const std::string &sublistName
2538 typename map_t::const_iterator itr = map_.find (caseSensitive_ ? str : upperCase (str));
2541 ,
"Error, the value \"" << str <<
"\" is not recognized for the parameter \""
2542 << ( paramName.length() ? paramName : defaultParameterName_ ) <<
"\""
2543 <<
"\nin the sublist \"" << sublistName <<
"\"."
2544 <<
"\n\nValid values include:"
2549 return (*itr).second;
2553 template<
class IntegralType>
2557 ,
const std::string &sublistName,
const bool activeQuery
2560 if (entry.
isType<IntegralType>()){
2561 return any_cast<IntegralType>(entry.
getAny(activeQuery));
2563 const bool validType = ( entry.
getAny(activeQuery).
type() ==
typeid(std::string) );
2566 ,
"Error, the parameter {paramName=\""<<(paramName.length()?paramName:defaultParameterName_)
2568 <<
"\nin the sublist \"" << sublistName <<
"\""
2569 <<
"\nhas the wrong type."
2570 <<
"\n\nThe correct type is \"string\"!"
2573 &strValue = any_cast<std::string>(entry.
getAny(activeQuery));
2574 return getIntegralValue(strValue,paramName,sublistName);
2579 template<
class IntegralType>
2583 ,
const std::string &sublistName,
const bool activeQuery
2586 if (entry.
isType<IntegralType>()){
2587 const IntegralType intVal = any_cast<IntegralType>(entry.
getAny(activeQuery));
2588 typename inv_map_t::const_iterator itr = inv_map_.find(intVal);
2591 return (*itr).second;
2594 this->getIntegralValue(entry,paramName,sublistName,activeQuery);
2596 return any_cast<std::string>(entry.
getAny(activeQuery));
2601 template<
class IntegralType>
2605 ,
const std::string &defaultValue
2608 const std::string& strValue =
2609 paramList.
get (paramName,
2610 caseSensitive_ ? defaultValue : upperCase (defaultValue));
2611 return getIntegralValue (strValue, paramName, paramList.
name ());
2615 template<
class IntegralType>
2619 ,
const std::string &defaultValue
2622 const std::string& strValue =
2623 paramList.
get (paramName,
2624 caseSensitive_ ? defaultValue : upperCase (defaultValue));
2625 getIntegralValue(strValue,paramName,paramList.
name());
2629 template<
class IntegralType>
2633 return validStringValuesDocs_;
2636 template<
class IntegralType>
2640 return defaultParameterName_;
2643 template<
class IntegralType>
2646 const std::string &str,
const std::string ¶mName
2647 ,
const std::string &sublistName
2650 getIntegralValue (caseSensitive_ ? str : upperCase (str),
2659 template<
class IntegralType>
2665 template<
class IntegralType>
2667 std::string
const& docString
2672 out <<
"# Valid std::string values:\n";
2674 if(validStringValuesDocs_.get()) {
2675 for(
int i = 0; i < static_cast<int>(validStringValues_->size()); ++i ) {
2676 out <<
"# \"" << (*validStringValues_)[i] <<
"\"\n";
2689 template<
class IntegralType>
2693 return validStringValues_;
2697 template<
class IntegralType>
2700 ,std::string
const& paramName
2701 ,std::string
const& sublistName
2704 this->getIntegralValue (entry, paramName, sublistName,
false);
2708 #if defined(HAVE_TEUCHOS_MODIFY_DEFAULTS_DURING_VALIDATION)
2709 template<
class IntegralType>
2711 std::string
const& paramName,
2712 std::string
const& sublistName,
2716 entry->
setValue(this->getIntegralValue(*entry, paramName, sublistName,
false));
2723 template<
class IntegralType>
2724 void StringToIntegralParameterEntryValidator<IntegralType>::setValidValues(
2725 ArrayView<const std::string>
const& strings
2726 ,ArrayView<const std::string>
const* stringsDocs
2729 if (caseSensitive_) {
2730 validStringValues_ =
rcp (
new Array<std::string> (strings));
2733 RCP<Array<std::string> > vals (
new Array<std::string> (strings.size ()));
2735 (*vals)[i] = upperCase (strings[i]);
2737 validStringValues_ = rcp_const_cast<
const Array<std::string> > (vals);
2741 validStringValuesDocs_ =
rcp (
new Array<std::string> (*stringsDocs));
2744 std::ostringstream oss;
2745 for (
int i = 0; i < static_cast<int> (strings.size()); ++i) {
2746 oss <<
" \"" << strings[i] <<
"\"\n";
2749 validValues_ = oss.str();
2761 template<
class IntegralType>
2764 Teuchos::stringToIntegralParameterEntryValidator(
2765 ArrayView<const std::string>
const& strings,
2766 std::string
const& defaultParameterName
2770 new StringToIntegralParameterEntryValidator<IntegralType>(
2771 strings, defaultParameterName
2777 template<
class IntegralType>
2780 Teuchos::stringToIntegralParameterEntryValidator(
2781 ArrayView<const std::string>
const& strings,
2782 std::string
const& defaultParameterName,
2783 const bool caseSensitive
2786 typedef StringToIntegralParameterEntryValidator<IntegralType> ret_type;
2787 return rcp (
new ret_type (strings, defaultParameterName, caseSensitive));
2792 template<
class IntegralType>
2795 Teuchos::stringToIntegralParameterEntryValidator(
2796 ArrayView<const std::string>
const& strings,
2797 ArrayView<const IntegralType>
const& integralValues,
2798 std::string
const& defaultParameterName
2802 new StringToIntegralParameterEntryValidator<IntegralType>(
2803 strings, integralValues, defaultParameterName
2809 template<
class IntegralType>
2812 Teuchos::stringToIntegralParameterEntryValidator(
2813 ArrayView<const std::string>
const& strings,
2814 ArrayView<const IntegralType>
const& integralValues,
2815 std::string
const& defaultParameterName,
2816 const bool caseSensitive)
2818 typedef StringToIntegralParameterEntryValidator<IntegralType> ret_type;
2819 return rcp (
new ret_type (strings, integralValues,
2820 defaultParameterName, caseSensitive));
2824 template<
class IntegralType>
2827 Teuchos::stringToIntegralParameterEntryValidator(
2828 ArrayView<const std::string>
const& strings,
2829 ArrayView<const std::string>
const& stringsDocs,
2830 ArrayView<const IntegralType>
const& integralValues,
2831 std::string
const& defaultParameterName
2835 new StringToIntegralParameterEntryValidator<IntegralType>(
2836 strings, stringsDocs, integralValues, defaultParameterName
2842 template<
class IntegralType>
2845 Teuchos::stringToIntegralParameterEntryValidator(
2846 ArrayView<const std::string>
const& strings,
2847 ArrayView<const std::string>
const& stringsDocs,
2848 ArrayView<const IntegralType>
const& integralValues,
2849 std::string
const& defaultParameterName,
2850 const bool caseSensitive)
2852 typedef StringToIntegralParameterEntryValidator<IntegralType> ret_type;
2853 return rcp (
new ret_type (strings, stringsDocs, integralValues,
2854 defaultParameterName, caseSensitive));
2858 template<
class IntegralType>
2859 void Teuchos::setStringToIntegralParameter(
2860 std::string
const& paramName,
2861 std::string
const& defaultValue,
2862 std::string
const& docString,
2863 ArrayView<const std::string>
const& strings,
2864 ParameterList * paramList
2867 typedef ParameterEntryValidator PEV;
2870 paramName, defaultValue, docString,
2871 rcp_implicit_cast<const PEV>(
2872 stringToIntegralParameterEntryValidator<IntegralType>(
2880 template<
class IntegralType>
2881 void Teuchos::setStringToIntegralParameter(
2882 std::string
const& paramName,
2883 std::string
const& defaultValue,
2884 std::string
const& docString,
2885 ArrayView<const std::string>
const& strings,
2886 ArrayView<const IntegralType>
const& integralValues,
2887 ParameterList * paramList
2890 typedef ParameterEntryValidator PEV;
2893 paramName, defaultValue, docString,
2894 rcp_implicit_cast<const PEV>(
2895 stringToIntegralParameterEntryValidator<IntegralType>(
2896 strings, integralValues, paramName
2903 template<
class IntegralType>
2904 void Teuchos::setStringToIntegralParameter(
2905 std::string
const& paramName,
2906 std::string
const& defaultValue,
2907 std::string
const& docString,
2908 ArrayView<const std::string>
const& strings,
2909 ArrayView<const std::string>
const& stringsDocs,
2910 ArrayView<const IntegralType>
const& integralValues,
2911 ParameterList * paramList
2915 typedef ParameterEntryValidator PEV;
2918 paramName, defaultValue, docString,
2919 rcp_implicit_cast<const PEV>(
2920 stringToIntegralParameterEntryValidator<IntegralType>(
2921 strings, stringsDocs, integralValues, paramName
2928 template<
class IntegralType>
2929 IntegralType Teuchos::getIntegralValue(
2930 ParameterList
const& paramList, std::string
const& paramName
2933 const ParameterEntry &entry = paramList.getEntry(paramName);
2934 if (entry.isType<IntegralType>()){
2935 return getValue<IntegralType>(entry);
2937 RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
2938 integralValidator = getStringToIntegralParameterEntryValidator<IntegralType>(
2939 entry, paramList, paramName
2941 return integralValidator->getIntegralValue(
2942 entry, paramName, paramList.name(), true );
2947 template<
class IntegralType>
2948 std::string Teuchos::getStringValue(
2949 ParameterList
const& paramList, std::string
const& paramName
2952 const ParameterEntry &entry = paramList.getEntry(paramName);
2953 RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
2954 integralValidator = getStringToIntegralParameterEntryValidator<IntegralType>(
2955 entry, paramList, paramName
2957 return integralValidator->getStringValue(
2958 entry, paramName, paramList.name(), true
2963 template<
class IntegralType>
2966 ParameterEntry
const& entry, ParameterList
const& paramList,
2967 std::string
const& paramName
2970 const RCP<const ParameterEntryValidator> validator = entry.validator();
2972 is_null(validator), Exceptions::InvalidParameterType,
2973 "Error! The parameter \""<<paramName<<
"\" exists\n"
2974 "in the parameter (sub)list \""<<paramList.name()<<
"\"\n"
2975 "but it does not contain any validator needed to extract\n"
2976 "an integral value of type \""<<TypeNameTraits<IntegralType>::name()<<
"\"!"
2978 const RCP<const StringToIntegralParameterEntryValidator<IntegralType> > integralValidator =
2979 rcp_dynamic_cast<
const StringToIntegralParameterEntryValidator<IntegralType> >(
2983 is_null(integralValidator), Exceptions::InvalidParameterType,
2984 "Error! The parameter \""<<paramName<<
"\" exists\n"
2985 "in the parameter (sub)list \""<<paramList.name()<<
"\"\n"
2986 "but it contains the wrong type of validator. The expected validator type\n"
2987 "is \""<<TypeNameTraits<StringToIntegralParameterEntryValidator<IntegralType> >::name()<<
"\"\n"
2988 "but the contained validator type is \""<<
typeName(*validator)<<
"\"!"
2990 return integralValidator;
2994 #endif // TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H
static bool mustAlreadyExistDefault()
The default value of the mustAlreadyExist parameter in the constructor.
A thin wrapper around the Teuchos Array class that allows for 2 dimensional arrays.
std::string validateString(const std::string &str, const std::string ¶mName="", const std::string &sublistName="") const
Validate the std::string and pass it on.
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...
const std::string & name() const
The name of this ParameterList.
T getMax() const
Gets the maximum acceptable value for the validator.
bool isCaseSensitive() const
Whether this validator is case sensitive.
EnhancedNumberValidator()
Constructs a EnhancedNumberValidator without an explicit minimum or maximum.
Convience class for StringValidators that are to be applied to TwoDArrays.
void printDoc(std::string const &docString, std::ostream &out) const
Print documentation to the given output string.
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
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...
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.
ValidStringsList validStringValues() const
bool allowInt() const
Allow an int value?
Convience class for EnhancedNumberValidators that are to be applied to arrays.
void validateAndModify(std::string const ¶mName, std::string const &sublistName, ParameterEntry *entry) const
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.
virtual void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
bool allowString() const
Allow an std::string value?
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
Default structure used by EnhancedNumberTraits<T> to produce a compile time error when the specializa...
void setMax(T max)
Sets the maximum acceptable value for the validator.
size_type size() const
The total number of items in the managed array.
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.
bool isType() const
Test the type of the data being contained.
bool hasMax() const
Determines whether or not the validator has a maximum value.
T getMin() const
Gets the minimum acceptable value for the validator.
static std::ostream & printLines(std::ostream &os, const std::string &linePrefix, const std::string &lines)
Print lines with prefix first.
EVerbosityLevel
Verbosity level.
Modified boost::any class, which is a container for a templated value.
static EPreferredType getPrefferedTypeStringEnum(const std::string &enumString)
Gets the preferred type enum associated with a give string.
bool is_null(const ArrayRCP< T > &p)
Returns true if p.get()==NULL.
AcceptedTypes & allowInt(bool _allowInt)
Set allow an int value or not.
AbstractArrayValidator(RCP< const ValidatorType > prototypeValidator)
Constructs an AbstractArrayValidator.
Takes a validator, wraps it, and applies it to a TwoDArray.
bool hasMin() const
Determines whether or not the validator has a minimum value.
unsigned short getPrecision() const
Gets the precision specified for the validator.
virtual void validateAndModify(std::string const ¶mName, std::string const &sublistName, ParameterEntry *entry) const
Validate and perhaps modify a parameter entry's value.
A std::string utilities class for Teuchos.
Determines the types that are accepted.
ValidStringsList validStringValues() const
A thin wrapper around the Array class which causes it to be interpreted as a 2D Array.
RCP< const ValidatorType > getPrototype() const
Returns the prototype validator for this Array Validator.
void printDoc(std::string const &docString, std::ostream &out) const
Convience class for StringValidators that are to be applied to arrays.
static T notDefined()
This function should not compile if there is an attempt to instantiate!
ValidStringsList validStringValues() const
Ordinal size_type
The type of Array sizes and capacities.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Templated Parameter List class.
const std::string getXMLTypeName() const
static unsigned short defaultPrecision()
Gets the default precision with which the number type should be displayed.
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
Validate the given ParameterEntry.
const std::string getXMLTypeName() const
Teuchos::any getNumberFromString(const ParameterEntry &entry, const bool activeQuery) const
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.
ArrayStringValidator(RCP< const StringValidator > prototypeValidator)
Convience class for EnhancedNumberValidators that are to be applied to TwoDArray. ...
An abstract base class for all ArrayValidators.
Standard implementation of a BoolParameterEntryValidator that accepts bool values (true/false) or str...
ArrayValidator(RCP< const ValidatorType > prototypeValidator)
Constructs a ArrayValidator.
Convience class for FileNameValidators that are to be applied to TwoDArrays.
Validate a file name entry.
const std::string getXMLTypeName() const
AcceptedTypes(bool allowAllTypesByDefault=true)
Allow all types or not on construction.
void setStep(T step)
Sets the step being used for the validator.
Takes a validator, wraps it, and applies it to an array.
A list of parameters of arbitrary type.
bool allowDouble() const
Allow an double value?
A simple validator that only allows certain string values to be choosen or simply enforces that a par...
static T min()
Gets the minimum possible value the number type can take on.
TwoDArrayValidator(RCP< const ValidatorType > prototypeValidator)
Constructs a ArrayValidator.
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...
void setPrecision(unsigned short precision)
Sets the precision specified for the validator.
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.
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.
virtual void printDoc(std::string const &docString, std::ostream &out) const
RCP< const Array< std::string > > ValidStringsList
Default traits class that just returns typeid(T).name().
Class for retrieving a dummy object of type T.
bool allowLongLong() const
Allow an long long value?
static const std::string & getPrefferedTypeString(EPreferredType enumValue)
Gets the string representation of a given preferred type enum.
ArrayFileNameValidator(RCP< const FileNameValidator > prototypeValidator)
static T defaultStep()
gets default amount a value of the number type should be incremented by when being utilizied in a UI...
static T max()
Gets the maximum possible value the number type can take on.
Class uesd to validate a particular type of number.
Convience class for FileNameValidators that are to be applied to arrays.
Class defining the traits of the number type being used in an EnhancedNumberValidator.
virtual void printDoc(std::string const &docString, std::ostream &out) const
std::string typeName() const
Return the name of the type.
TwoDArrayNumberValidator(RCP< const EnhancedNumberValidator< T > > prototypeValidator)
AcceptedTypes & allowDouble(bool _allowDouble)
Set allow a double value or not.
ValidStringsList getStringDocs() const
Get a pointer to the array containing all the documentation strings.
Smart reference counting pointer class for automatic garbage collection.
TwoDArrayStringValidator(RCP< const StringValidator > prototypeValidator)
const std::type_info & type() const
Return the type of value being stored.
TwoDArrayFileNameValidator(RCP< const FileNameValidator > prototypeValidator)
virtual void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
#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 ...
const std::string & getDefaultParameterName() const
Get the name of the default parameter for the validator.
Standard implementation of a ParameterEntryValidator that accepts numbers from a number of different ...
T getStep() const
Gets the step being used for the validator.
Defines basic traits returning the name of a type in a portable and readable way. ...
AcceptedTypes & allowLongLong(bool _allowLongLong)
Set allow an long long value or not.
#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...
const std::string getXMLTypeName() const
static std::string name()
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
ArrayNumberValidator(RCP< const EnhancedNumberValidator< T > > prototypeValidator)