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
24 # include <quadmath.h>
25 #endif // HAVE_TEUCHOSCORE_QUADMATH
59 template<
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);
347 template<
class IntegralType>
348 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
349 stringToIntegralParameterEntryValidator(
350 ArrayView<const std::string>
const& strings,
351 std::string
const& defaultParameterName
359 template<
class IntegralType>
360 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
361 stringToIntegralParameterEntryValidator(
362 ArrayView<const std::string>
const& strings,
363 std::string
const& defaultParameterName,
364 const bool caseSensitive
372 template<
class IntegralType>
373 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
374 stringToIntegralParameterEntryValidator(
375 ArrayView<const std::string>
const& strings,
376 ArrayView<const IntegralType>
const& integralValues,
377 std::string
const& defaultParameterName
385 template<
class IntegralType>
386 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
387 stringToIntegralParameterEntryValidator(
388 ArrayView<const std::string>
const& strings,
389 ArrayView<const IntegralType>
const& integralValues,
390 std::string
const& defaultParameterName,
391 const bool caseSensitive
399 template<
class IntegralType>
400 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
401 stringToIntegralParameterEntryValidator(
402 ArrayView<const std::string>
const& strings,
403 ArrayView<const std::string>
const& stringsDocs,
404 ArrayView<const IntegralType>
const& integralValues,
405 std::string
const& defaultParameterName
413 template<
class IntegralType>
414 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
415 stringToIntegralParameterEntryValidator(
416 ArrayView<const std::string>
const& strings,
417 ArrayView<const std::string>
const& stringsDocs,
418 ArrayView<const IntegralType>
const& integralValues,
419 std::string
const& defaultParameterName,
420 const bool caseSensitive
434 template<
class IntegralType>
435 void setStringToIntegralParameter(
436 std::string
const& paramName,
437 std::string
const& defaultValue,
438 std::string
const& docString,
439 ArrayView<const std::string>
const& strings,
440 ParameterList * paramList
455 template<
class IntegralType>
456 void setStringToIntegralParameter(
457 std::string
const& paramName,
458 std::string
const& defaultValue,
459 std::string
const& docString,
460 ArrayView<const std::string>
const& strings,
461 ArrayView<const IntegralType>
const& integralValues,
462 ParameterList * paramList
477 template<
class IntegralType>
478 void setStringToIntegralParameter(
479 std::string
const& paramName,
480 std::string
const& defaultValue,
481 std::string
const& docString,
482 ArrayView<const std::string>
const& strings,
483 ArrayView<const std::string>
const& stringsDocs,
484 ArrayView<const IntegralType>
const& integralValues,
485 ParameterList * paramList
499 template<
class IntegralType>
500 IntegralType getIntegralValue(
501 ParameterList
const& paramList, std::string
const& paramName
516 template<
class IntegralType>
517 std::string getStringValue(
518 ParameterList
const& paramList, std::string
const& paramName
527 template<
class IntegralType>
528 RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
530 ParameterEntry
const& entry, ParameterList
const& paramList,
531 std::string
const& paramName
540 std::string getVerbosityLevelParameterValueName(
549 RCP<StringToIntegralParameterEntryValidator<EVerbosityLevel> >
550 verbosityLevelParameterEntryValidator(std::string
const& defaultParameterName);
557 template<
class IntegralType>
574 template<
class IntegralType>
578 return stringToIntegralParameterEntryValidator<IntegralType>(
579 tuple<std::string>(
""), tuple<std::string>(
""),
580 tuple<IntegralType>((IntegralType)1),
"");
613 const std::string &sublistName =
"",
const bool activeQuery =
true
621 const int defaultValue
630 const std::string getXMLTypeName()
const;
634 std::string
const& docString,
640 validStringValues()
const;
645 std::string
const& paramName,
646 std::string
const& sublistName
650 void validateAndModify(
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
685 boolParameterEntryValidator();
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_;
949 #pragma warning(push)
950 #pragma warning(disable:4251)
952 const AcceptedTypes acceptedTypes_;
961 static const std::string& getIntEnumString(){
963 return intEnumString_;
967 static const std::string& getLongLongEnumString(){
969 return longLongEnumString_;
973 static const std::string& getDoubleEnumString(){
975 return doubleEnumString_;
979 static const std::string& getStringEnumString(){
981 return stringEnumString_;
985 void finishInitialization();
988 ParameterEntry
const& entry,
989 std::string
const& paramName,
990 std::string
const& sublistName
1003 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT RCP<AnyNumberParameterEntryValidator>
1004 anyNumberParameterEntryValidator();
1011 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT RCP<AnyNumberParameterEntryValidator>
1012 anyNumberParameterEntryValidator(
1014 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
1022 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
void setIntParameter(
1023 std::string
const& paramName,
1024 int const value, std::string
const& docString,
1025 ParameterList *paramList,
1026 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
1027 = AnyNumberParameterEntryValidator::AcceptedTypes()
1036 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
void setLongLongParameter(
1037 std::string
const& paramName,
1038 long long const value, std::string
const& docString,
1039 ParameterList *paramList,
1040 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
1041 = AnyNumberParameterEntryValidator::AcceptedTypes()
1049 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
void setDoubleParameter(
1050 std::string
const& paramName,
1051 double const& value, std::string
const& docString,
1052 ParameterList *paramList,
1053 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
1054 = AnyNumberParameterEntryValidator::AcceptedTypes()
1063 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
void setNumericStringParameter(
1064 std::string
const& paramName,
1065 std::string
const& value, std::string
const& docString,
1066 ParameterList *paramList,
1067 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
1068 = AnyNumberParameterEntryValidator::AcceptedTypes()
1086 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
int getIntParameter(
1087 ParameterList
const& paramList, std::string
const& paramName
1105 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
long long getLongLongParameter(
1106 ParameterList
const& paramList, std::string
const& paramName
1123 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
double getDoubleParameter(
1124 ParameterList
const& paramList,
1125 std::string
const& paramName
1144 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT std::string getNumericStringParameter(
1145 ParameterList
const& paramList,
1146 std::string
const& paramName
1180 return T::this_type_is_missing_a_specialization();
1231 class 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; }
1241 class EnhancedNumberTraits<short unsigned int>{
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; }
1251 class EnhancedNumberTraits<int>{
1253 static inline int min() {
return std::numeric_limits<int>::min(); }
1254 static inline int max() {
return std::numeric_limits<int>::max(); }
1261 class EnhancedNumberTraits<unsigned int>{
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; }
1271 class EnhancedNumberTraits<long int>{
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; }
1281 class EnhancedNumberTraits<long unsigned int>{
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; }
1291 class EnhancedNumberTraits<long long int>{
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; }
1301 class EnhancedNumberTraits<long long unsigned int>{
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
1312 class EnhancedNumberTraits<__float128>{
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; }
1319 #endif // HAVE_TEUCHOSCORE_QUADMATH
1322 class EnhancedNumberTraits<double>{
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
1332 class EnhancedNumberTraits<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; }
1342 class EnhancedNumberTraits<float>{
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) ) {
1591 anyValue = getNumberFromString(*entry,
false);
1593 any_cast<T>(anyValue),
1600 paramName, sublistName, entry);
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()) {
1640 return any((T)convertStringToInt(any_cast<std::string>(anyValue)));
1643 return any((T)convertStringToDouble(any_cast<std::string>(anyValue)));
1649 std::string
const &sublistName)
const
1657 if( anyValue.
type() ==
typeid(std::string) ) {
1659 anyValue = getNumberFromString(entry,
false);
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;
1674 any_cast<T>(anyValue) >= minVal && any_cast<T>(anyValue) <= maxVal
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_;
1896 ValidStringsList setValidStrings(
1904 return caseSensitive_;
1913 ValidStringsList validStringValues()
const;
1916 void validate(
ParameterEntry const &entry, std::string
const ¶mName,
1917 std::string
const &sublistName)
const;
1920 const std::string getXMLTypeName()
const;
1923 void printDoc(std::string
const &docString, std::ostream &out)
const;
1934 ValidStringsList validStrings_;
1936 bool caseSensitive_;
1939 static std::string upperCase (
const std::string s) {
1940 std::string s_upper = s;
1941 std::transform (s_upper.begin (), s_upper.end (), s_upper.begin (), ::toupper);
1975 template<
class Val
idatorType,
class EntryType>
1991 prototypeValidator_(prototypeValidator){}
2000 return prototypeValidator_;
2010 return prototypeValidator_->validStringValues();
2043 template<
class Val
idatorType,
class EntryType>
2065 std::string
const &sublistName)
const;
2069 return "TwoDArrayValidator(" +
2075 virtual void printDoc(std::string
const &docString, std::ostream &out)
const
2078 std::string toPrint;
2079 toPrint +=
"TwoDArrayValidator:\n";
2080 toPrint +=
"Prototype Validator:\n";
2088 template<
class Val
idatorType,
class EntryType>
2090 std::string
const &sublistName)
const
2096 "The \"" << paramName <<
"\"" <<
2097 " parameter in the \"" << sublistName <<
2098 "\" sublist is has an error." << std::endl << std::endl <<
2099 "Error: The value you entered was the wrong type." << std::endl <<
2100 "Parameter: " << paramName << std::endl <<
2101 "Type specified: " << entryName << std::endl <<
2103 std::endl << std::endl);
2106 getValue<Teuchos::TwoDArray<EntryType> >(entry);
2108 for(
int i = 0; i<extracted.getNumRows(); ++i){
2109 for(
int j = 0; j<extracted.getNumCols(); ++j){
2111 dummyParameter.
setValue(extracted(i,j));
2113 prototype->validate(
2114 dummyParameter, paramName, sublistName);
2117 std::stringstream oss;
2118 oss <<
"TwoDArray Validator Exception:" << std::endl <<
2119 "Bad Index: (" << i <<
"," << j <<
")" << std::endl << e.what();
2132 template<
class Val
idatorType,
class EntryType>
2149 template<
class Val
idatorType,
class EntryType>
2228 template<
class Val
idatorType,
class EntryType>
2251 std::string
const &sublistName)
const;
2255 return "ArrayValidator(" +
2261 virtual void printDoc(std::string
const &docString, std::ostream &out)
const
2264 std::string toPrint;
2265 toPrint +=
"ArrayValidator:\n";
2266 toPrint +=
"Prototype Validator:\n";
2274 template<
class Val
idatorType,
class EntryType>
2276 std::string
const &sublistName)
const
2282 "The \"" << paramName <<
"\"" <<
2283 " parameter in the \"" << sublistName <<
2284 "\" sublist is has an error." << std::endl << std::endl <<
2285 "Error: The value you entered was the wrong type." << std::endl <<
2286 "Parameter: " << paramName << std::endl <<
2287 "Type specified: " << entryName << std::endl <<
2289 std::endl << std::endl);
2292 getValue<Teuchos::Array<EntryType> >(entry);
2294 for(
int i = 0; i<extracted.size(); ++i){
2296 dummyParameter.
setValue(extracted[i]);
2298 prototype->validate(
2299 dummyParameter, paramName, sublistName);
2302 std::stringstream oss;
2303 oss <<
"Array Validator Exception:" << std::endl <<
2304 "Bad Index: " << i << std::endl << e.what();
2315 template<
class Val
idatorType,
class EntryType>
2332 template<
class Val
idatorType,
class EntryType>
2426 template<
class IntegralType>
2427 StringToIntegralParameterEntryValidator<IntegralType>::
2429 std::string
const& defaultParameterName,
2430 const bool caseSensitive) :
2432 defaultParameterName_ (defaultParameterName),
2433 caseSensitive_ (caseSensitive)
2435 const int length =
static_cast<int>(strings.
size());
2437 for (
int i = 0; i < length; ++i) integralValues[i] = static_cast<IntegralType>(i);
2438 init(strings, integralValues);
2439 setValidValues (strings);
2443 template<
class IntegralType>
2447 std::string
const& defaultParameterName,
2448 const bool caseSensitive) :
2450 defaultParameterName_ (defaultParameterName),
2451 caseSensitive_ (caseSensitive)
2453 #ifdef TEUCHOS_DEBUG
2456 init(strings, integralValues);
2457 setValidValues (strings);
2460 template<
class IntegralType>
2465 std::string
const& defaultParameterName,
2466 const bool caseSensitive) :
2468 defaultParameterName_ (defaultParameterName),
2469 caseSensitive_ (caseSensitive)
2471 #ifdef TEUCHOS_DEBUG
2476 strings.
size() != stringsDocs.
size(),
2478 "The input arrays strings and stringsDocs must have the same length.");
2480 init(strings, integralValues);
2481 setValidValues(strings,&stringsDocs);
2484 template <
class IntegralType>
2489 #ifdef TEUCHOS_DEBUG
2494 strings.
size() != integralValues.
size(), std::logic_error,
2495 "The input arrays strings and integralValues must have the same length.");
2497 typedef typename map_t::value_type val_t;
2498 typedef typename inv_map_t::value_type inv_val_t;
2499 for (
int i = 0; i < static_cast<int>(strings.
size()); ++i) {
2500 const std::string name =
2501 caseSensitive_ ? strings[i] : upperCase(strings[i]);
2502 const bool unique = map_.insert(val_t(name, integralValues[i])).second;
2504 "For parameter \"" << defaultParameterName_
2507 << i <<
"] = \"" << strings[i]
2508 <<
"\" is a duplicate.");
2509 inv_map_.insert(inv_val_t(integralValues[i], name));
2516 template<
class IntegralType>
2519 const std::string &str,
const std::string ¶mName
2520 ,
const std::string &sublistName
2523 typename map_t::const_iterator itr = map_.find (caseSensitive_ ? str : upperCase (str));
2526 ,
"Error, the value \"" << str <<
"\" is not recognized for the parameter \""
2527 << ( paramName.length() ? paramName : defaultParameterName_ ) <<
"\""
2528 <<
"\nin the sublist \"" << sublistName <<
"\"."
2529 <<
"\n\nValid values include:"
2534 return (*itr).second;
2538 template<
class IntegralType>
2542 ,
const std::string &sublistName,
const bool activeQuery
2545 if (entry.
isType<IntegralType>()){
2546 return any_cast<IntegralType>(entry.
getAny(activeQuery));
2548 const bool validType = ( entry.
getAny(activeQuery).
type() ==
typeid(std::string) );
2551 ,
"Error, the parameter {paramName=\""<<(paramName.length()?paramName:defaultParameterName_)
2553 <<
"\nin the sublist \"" << sublistName <<
"\""
2554 <<
"\nhas the wrong type."
2555 <<
"\n\nThe correct type is \"string\"!"
2558 &strValue = any_cast<std::string>(entry.
getAny(activeQuery));
2559 return getIntegralValue(strValue,paramName,sublistName);
2564 template<
class IntegralType>
2568 ,
const std::string &sublistName,
const bool activeQuery
2571 if (entry.
isType<IntegralType>()){
2572 const IntegralType intVal = any_cast<IntegralType>(entry.
getAny(activeQuery));
2573 typename inv_map_t::const_iterator itr = inv_map_.find(intVal);
2576 return (*itr).second;
2579 this->getIntegralValue(entry,paramName,sublistName,activeQuery);
2581 return any_cast<std::string>(entry.
getAny(activeQuery));
2586 template<
class IntegralType>
2590 ,
const std::string &defaultValue
2593 const std::string& strValue =
2594 paramList.
get (paramName,
2595 caseSensitive_ ? defaultValue : upperCase (defaultValue));
2596 return getIntegralValue (strValue, paramName, paramList.
name ());
2600 template<
class IntegralType>
2604 ,
const std::string &defaultValue
2607 const std::string& strValue =
2608 paramList.
get (paramName,
2609 caseSensitive_ ? defaultValue : upperCase (defaultValue));
2610 getIntegralValue(strValue,paramName,paramList.
name());
2614 template<
class IntegralType>
2618 return validStringValuesDocs_;
2621 template<
class IntegralType>
2625 return defaultParameterName_;
2628 template<
class IntegralType>
2631 const std::string &str,
const std::string ¶mName
2632 ,
const std::string &sublistName
2635 getIntegralValue (caseSensitive_ ? str : upperCase (str),
2644 template<
class IntegralType>
2650 template<
class IntegralType>
2652 std::string
const& docString
2657 out <<
"# Valid std::string values:\n";
2659 if(validStringValuesDocs_.get()) {
2660 for(
int i = 0; i < static_cast<int>(validStringValues_->size()); ++i ) {
2661 out <<
"# \"" << (*validStringValues_)[i] <<
"\"\n";
2674 template<
class IntegralType>
2678 return validStringValues_;
2682 template<
class IntegralType>
2685 ,std::string
const& paramName
2686 ,std::string
const& sublistName
2689 this->getIntegralValue (entry, paramName, sublistName,
false);
2693 #if defined(HAVE_TEUCHOS_MODIFY_DEFAULTS_DURING_VALIDATION)
2694 template<
class IntegralType>
2696 std::string
const& paramName,
2697 std::string
const& sublistName,
2701 entry->
setValue(this->getIntegralValue(*entry, paramName, sublistName,
false));
2708 template<
class IntegralType>
2709 void StringToIntegralParameterEntryValidator<IntegralType>::setValidValues(
2710 ArrayView<const std::string>
const& strings
2711 ,ArrayView<const std::string>
const* stringsDocs
2714 if (caseSensitive_) {
2715 validStringValues_ =
rcp (
new Array<std::string> (strings));
2718 RCP<Array<std::string> > vals (
new Array<std::string> (strings.size ()));
2720 (*vals)[i] = upperCase (strings[i]);
2722 validStringValues_ = rcp_const_cast<
const Array<std::string> > (vals);
2726 validStringValuesDocs_ =
rcp (
new Array<std::string> (*stringsDocs));
2729 std::ostringstream oss;
2730 for (
int i = 0; i < static_cast<int> (strings.size()); ++i) {
2731 oss <<
" \"" << strings[i] <<
"\"\n";
2734 validValues_ = oss.str();
2746 template<
class IntegralType>
2749 Teuchos::stringToIntegralParameterEntryValidator(
2750 ArrayView<const std::string>
const& strings,
2751 std::string
const& defaultParameterName
2755 new StringToIntegralParameterEntryValidator<IntegralType>(
2756 strings, defaultParameterName
2762 template<
class IntegralType>
2765 Teuchos::stringToIntegralParameterEntryValidator(
2766 ArrayView<const std::string>
const& strings,
2767 std::string
const& defaultParameterName,
2768 const bool caseSensitive
2771 typedef StringToIntegralParameterEntryValidator<IntegralType> ret_type;
2772 return rcp (
new ret_type (strings, defaultParameterName, caseSensitive));
2777 template<
class IntegralType>
2780 Teuchos::stringToIntegralParameterEntryValidator(
2781 ArrayView<const std::string>
const& strings,
2782 ArrayView<const IntegralType>
const& integralValues,
2783 std::string
const& defaultParameterName
2787 new StringToIntegralParameterEntryValidator<IntegralType>(
2788 strings, integralValues, defaultParameterName
2794 template<
class IntegralType>
2797 Teuchos::stringToIntegralParameterEntryValidator(
2798 ArrayView<const std::string>
const& strings,
2799 ArrayView<const IntegralType>
const& integralValues,
2800 std::string
const& defaultParameterName,
2801 const bool caseSensitive)
2803 typedef StringToIntegralParameterEntryValidator<IntegralType> ret_type;
2804 return rcp (
new ret_type (strings, integralValues,
2805 defaultParameterName, caseSensitive));
2809 template<
class IntegralType>
2812 Teuchos::stringToIntegralParameterEntryValidator(
2813 ArrayView<const std::string>
const& strings,
2814 ArrayView<const std::string>
const& stringsDocs,
2815 ArrayView<const IntegralType>
const& integralValues,
2816 std::string
const& defaultParameterName
2820 new StringToIntegralParameterEntryValidator<IntegralType>(
2821 strings, stringsDocs, integralValues, defaultParameterName
2827 template<
class IntegralType>
2830 Teuchos::stringToIntegralParameterEntryValidator(
2831 ArrayView<const std::string>
const& strings,
2832 ArrayView<const std::string>
const& stringsDocs,
2833 ArrayView<const IntegralType>
const& integralValues,
2834 std::string
const& defaultParameterName,
2835 const bool caseSensitive)
2837 typedef StringToIntegralParameterEntryValidator<IntegralType> ret_type;
2838 return rcp (
new ret_type (strings, stringsDocs, integralValues,
2839 defaultParameterName, caseSensitive));
2843 template<
class IntegralType>
2844 void Teuchos::setStringToIntegralParameter(
2845 std::string
const& paramName,
2846 std::string
const& defaultValue,
2847 std::string
const& docString,
2848 ArrayView<const std::string>
const& strings,
2849 ParameterList * paramList
2852 typedef ParameterEntryValidator PEV;
2855 paramName, defaultValue, docString,
2856 rcp_implicit_cast<const PEV>(
2857 stringToIntegralParameterEntryValidator<IntegralType>(
2865 template<
class IntegralType>
2866 void Teuchos::setStringToIntegralParameter(
2867 std::string
const& paramName,
2868 std::string
const& defaultValue,
2869 std::string
const& docString,
2870 ArrayView<const std::string>
const& strings,
2871 ArrayView<const IntegralType>
const& integralValues,
2872 ParameterList * paramList
2875 typedef ParameterEntryValidator PEV;
2878 paramName, defaultValue, docString,
2879 rcp_implicit_cast<const PEV>(
2880 stringToIntegralParameterEntryValidator<IntegralType>(
2881 strings, integralValues, paramName
2888 template<
class IntegralType>
2889 void Teuchos::setStringToIntegralParameter(
2890 std::string
const& paramName,
2891 std::string
const& defaultValue,
2892 std::string
const& docString,
2893 ArrayView<const std::string>
const& strings,
2894 ArrayView<const std::string>
const& stringsDocs,
2895 ArrayView<const IntegralType>
const& integralValues,
2896 ParameterList * paramList
2900 typedef ParameterEntryValidator PEV;
2903 paramName, defaultValue, docString,
2904 rcp_implicit_cast<const PEV>(
2905 stringToIntegralParameterEntryValidator<IntegralType>(
2906 strings, stringsDocs, integralValues, paramName
2913 template<
class IntegralType>
2914 IntegralType Teuchos::getIntegralValue(
2915 ParameterList
const& paramList, std::string
const& paramName
2918 const ParameterEntry &entry = paramList.getEntry(paramName);
2919 if (entry.isType<IntegralType>()){
2920 return getValue<IntegralType>(entry);
2922 RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
2923 integralValidator = getStringToIntegralParameterEntryValidator<IntegralType>(
2924 entry, paramList, paramName
2926 return integralValidator->getIntegralValue(
2927 entry, paramName, paramList.name(), true );
2932 template<
class IntegralType>
2933 std::string Teuchos::getStringValue(
2934 ParameterList
const& paramList, std::string
const& paramName
2937 const ParameterEntry &entry = paramList.getEntry(paramName);
2938 RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
2939 integralValidator = getStringToIntegralParameterEntryValidator<IntegralType>(
2940 entry, paramList, paramName
2942 return integralValidator->getStringValue(
2943 entry, paramName, paramList.name(), true
2948 template<
class IntegralType>
2951 ParameterEntry
const& entry, ParameterList
const& paramList,
2952 std::string
const& paramName
2955 const RCP<const ParameterEntryValidator> validator = entry.validator();
2957 is_null(validator), Exceptions::InvalidParameterType,
2958 "Error! The parameter \""<<paramName<<
"\" exists\n"
2959 "in the parameter (sub)list \""<<paramList.name()<<
"\"\n"
2960 "but it does not contain any validator needed to extract\n"
2961 "an integral value of type \""<<TypeNameTraits<IntegralType>::name()<<
"\"!"
2963 const RCP<const StringToIntegralParameterEntryValidator<IntegralType> > integralValidator =
2964 rcp_dynamic_cast<
const StringToIntegralParameterEntryValidator<IntegralType> >(
2968 is_null(integralValidator), Exceptions::InvalidParameterType,
2969 "Error! The parameter \""<<paramName<<
"\" exists\n"
2970 "in the parameter (sub)list \""<<paramList.name()<<
"\"\n"
2971 "but it contains the wrong type of validator. The expected validator type\n"
2972 "is \""<<TypeNameTraits<StringToIntegralParameterEntryValidator<IntegralType> >::name()<<
"\"\n"
2973 "but the contained validator type is \""<<
typeName(*validator)<<
"\"!"
2975 return integralValidator;
2979 #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.
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)