42 #ifndef TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H 43 #define TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H 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 =
"" 306 std::string
const& docString,
317 std::string
const& paramName,
318 std::string
const& sublistName
329 typedef std::map<std::string,IntegralType>
map_t;
344 std::string s_upper = s;
345 std::transform (s_upper.begin (), s_upper.end (), s_upper.begin (), ::toupper);
355 template<
class IntegralType>
356 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
357 stringToIntegralParameterEntryValidator(
358 ArrayView<const std::string>
const& strings,
359 std::string
const& defaultParameterName
367 template<
class IntegralType>
368 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
369 stringToIntegralParameterEntryValidator(
370 ArrayView<const std::string>
const& strings,
371 std::string
const& defaultParameterName,
372 const bool caseSensitive
380 template<
class IntegralType>
381 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
382 stringToIntegralParameterEntryValidator(
383 ArrayView<const std::string>
const& strings,
384 ArrayView<const IntegralType>
const& integralValues,
385 std::string
const& defaultParameterName
393 template<
class IntegralType>
394 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
395 stringToIntegralParameterEntryValidator(
396 ArrayView<const std::string>
const& strings,
397 ArrayView<const IntegralType>
const& integralValues,
398 std::string
const& defaultParameterName,
399 const bool caseSensitive
407 template<
class IntegralType>
408 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
409 stringToIntegralParameterEntryValidator(
410 ArrayView<const std::string>
const& strings,
411 ArrayView<const std::string>
const& stringsDocs,
412 ArrayView<const IntegralType>
const& integralValues,
413 std::string
const& defaultParameterName
421 template<
class IntegralType>
422 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
423 stringToIntegralParameterEntryValidator(
424 ArrayView<const std::string>
const& strings,
425 ArrayView<const std::string>
const& stringsDocs,
426 ArrayView<const IntegralType>
const& integralValues,
427 std::string
const& defaultParameterName,
428 const bool caseSensitive
442 template<
class IntegralType>
443 void setStringToIntegralParameter(
444 std::string
const& paramName,
445 std::string
const& defaultValue,
446 std::string
const& docString,
447 ArrayView<const std::string>
const& strings,
448 ParameterList * paramList
463 template<
class IntegralType>
464 void setStringToIntegralParameter(
465 std::string
const& paramName,
466 std::string
const& defaultValue,
467 std::string
const& docString,
468 ArrayView<const std::string>
const& strings,
469 ArrayView<const IntegralType>
const& integralValues,
470 ParameterList * paramList
485 template<
class IntegralType>
486 void setStringToIntegralParameter(
487 std::string
const& paramName,
488 std::string
const& defaultValue,
489 std::string
const& docString,
490 ArrayView<const std::string>
const& strings,
491 ArrayView<const std::string>
const& stringsDocs,
492 ArrayView<const IntegralType>
const& integralValues,
493 ParameterList * paramList
507 template<
class IntegralType>
508 IntegralType getIntegralValue(
509 ParameterList
const& paramList, std::string
const& paramName
524 template<
class IntegralType>
525 std::string getStringValue(
526 ParameterList
const& paramList, std::string
const& paramName
535 template<
class IntegralType>
536 RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
538 ParameterEntry
const& entry, ParameterList
const& paramList,
539 std::string
const& paramName
548 std::string getVerbosityLevelParameterValueName(
557 RCP<StringToIntegralParameterEntryValidator<EVerbosityLevel> >
558 verbosityLevelParameterEntryValidator(std::string
const& defaultParameterName);
565 template<
class IntegralType>
582 template<
class IntegralType>
586 return stringToIntegralParameterEntryValidator<IntegralType>(
587 tuple<std::string>(
""), tuple<std::string>(
""),
588 tuple<IntegralType>((IntegralType)1),
"");
621 const std::string &sublistName =
"",
const bool activeQuery =
true 629 const int defaultValue
638 const std::string getXMLTypeName()
const;
642 std::string
const& docString,
648 validStringValues()
const;
653 std::string
const& paramName,
654 std::string
const& sublistName
658 void validateAndModify(
659 std::string
const& paramName,
660 std::string
const& sublistName,
676 void finishInitialization();
680 std::string
const& paramName,
681 std::string
const& sublistName
693 boolParameterEntryValidator();
726 :allowInt_(allowAllTypesByDefault),allowDouble_(allowAllTypesByDefault),
727 allowString_(allowAllTypesByDefault)
731 { allowInt_ = _allowInt;
return *
this; }
734 { allowDouble_ = _allowDouble;
return *
this; }
737 { allowString_ = _allowString;
return *
this; }
788 const std::string &sublistName =
"",
const bool activeQuery =
true 798 const std::string &sublistName =
"",
const bool activeQuery =
true 802 std::string getString(
804 const std::string &sublistName =
"",
const bool activeQuery =
true 812 const int defaultValue
820 const double defaultValue
826 std::string getString(
828 const std::string &defaultValue
833 bool isDoubleAllowed()
const;
837 bool isIntAllowed()
const;
841 bool isStringAllowed()
const;
852 return getIntEnumString ();
854 return getDoubleEnumString ();
856 return getStringEnumString ();
858 const std::string typeString (
toString (enumValue));
859 throw std::runtime_error(
"Cannot convert enumValue: " + typeString +
" to a string");
866 if (enumString == getIntEnumString ()) {
869 else if (enumString == getDoubleEnumString ()) {
870 return PREFER_DOUBLE;
872 else if (enumString == getStringEnumString ()) {
873 return PREFER_STRING;
876 throw std::runtime_error (
"Cannot convert enumString: " + enumString +
" to an enum");
886 const std::string getXMLTypeName()
const;
890 std::string
const& docString,
896 validStringValues()
const;
901 std::string
const& paramName,
902 std::string
const& sublistName
906 void validateAndModify(
907 std::string
const& paramName,
908 std::string
const& sublistName,
925 #pragma warning(push) 926 #pragma warning(disable:4251) 939 return intEnumString_;
945 return doubleEnumString_;
951 return stringEnumString_;
955 void finishInitialization();
959 std::string
const& paramName,
960 std::string
const& sublistName
974 anyNumberParameterEntryValidator();
982 anyNumberParameterEntryValidator(
984 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
993 std::string
const& paramName,
994 int const value, std::string
const& docString,
995 ParameterList *paramList,
996 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
997 = AnyNumberParameterEntryValidator::AcceptedTypes()
1007 std::string
const& paramName,
1008 double const& value, std::string
const& docString,
1009 ParameterList *paramList,
1010 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
1011 = AnyNumberParameterEntryValidator::AcceptedTypes()
1021 std::string
const& paramName,
1022 std::string
const& value, std::string
const& docString,
1023 ParameterList *paramList,
1024 AnyNumberParameterEntryValidator::AcceptedTypes
const& acceptedTypes
1025 = AnyNumberParameterEntryValidator::AcceptedTypes()
1044 ParameterList
const& paramList, std::string
const& paramName
1063 ParameterList
const& paramList,
1064 std::string
const& paramName
1084 ParameterList
const& paramList,
1085 std::string
const& paramName
1119 return T::this_type_is_missing_a_specialization();
1172 static inline short int min() {
return std::numeric_limits<short int>::min(); }
1173 static inline short int max() {
return std::numeric_limits<short int>::max(); }
1182 static inline short unsigned int min() {
return std::numeric_limits<short unsigned int>::min(); }
1183 static inline short unsigned int max() {
return std::numeric_limits<short unsigned int>::max(); }
1192 static inline int min() {
return std::numeric_limits<int>::min(); }
1193 static inline int max() {
return std::numeric_limits<int>::max(); }
1202 static inline unsigned int min() {
return std::numeric_limits<unsigned int>::min(); }
1203 static inline unsigned int max() {
return std::numeric_limits<unsigned int>::max(); }
1212 static inline long int min() {
return std::numeric_limits<long int>::min(); }
1213 static inline long int max() {
return std::numeric_limits<long int>::max(); }
1222 static inline long unsigned int min() {
return std::numeric_limits<long unsigned int>::min(); }
1223 static inline long unsigned int max() {
return std::numeric_limits<long unsigned int>::max(); }
1229 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 1233 class EnhancedNumberTraits<long long int>{
1235 static inline long long int min() {
return std::numeric_limits<long long int>::min(); }
1236 static inline long long int max() {
return std::numeric_limits<long long int>::max(); }
1237 static inline long long int defaultStep() {
return 1; }
1243 class EnhancedNumberTraits<long long unsigned int>{
1245 static inline long long unsigned int min() {
return std::numeric_limits<long long unsigned int>::min(); }
1246 static inline long long unsigned int max() {
return std::numeric_limits<long long unsigned int>::max(); }
1247 static inline long long unsigned int defaultStep() {
return 1; }
1252 #endif // HAVE_TEUCHOS_LONG_LONG_INT 1255 #ifdef HAVE_TEUCHOSCORE_QUADMATH 1257 class EnhancedNumberTraits<__float128>{
1259 static inline __float128
min() {
return -std::numeric_limits<__float128>::max(); }
1260 static inline __float128
max() {
return std::numeric_limits<__float128>::max(); }
1261 static inline __float128
defaultStep() {
return 1; }
1264 #endif // HAVE_TEUCHOSCORE_QUADMATH 1269 static inline double min() {
return -std::numeric_limits<double>::max(); }
1270 static inline double max() {
return std::numeric_limits<double>::max(); }
1278 static inline float min() {
return -std::numeric_limits<float>::max(); }
1279 static inline float max() {
return std::numeric_limits<float>::max(); }
1441 std::string
const &sublistName)
const;
1449 const bool activeQuery)
const;
1457 void printDoc(std::string
const &docString, std::ostream &out)
const{
1459 out <<
"#\tValidator Used: " << std::endl;
1460 out <<
"#\t\tNumber Validator" << std::endl;
1463 out <<
"#\t\tMin (inclusive): " <<
minVal << std::endl;
1464 out <<
"#\t\tMax (inclusive): " <<
maxVal << std::endl;
1515 std::string
const& paramName,
1516 std::string
const& sublistName,
1524 if( anyValue.
type() ==
typeid(std::string) ) {
1525 anyValue = getNumberFromString(*entry,
false);
1527 any_cast<T>(anyValue),
1534 paramName, sublistName, entry);
1546 if(
typeid(T) ==
typeid(
char))
return true;
1547 if(
typeid(T) ==
typeid(
unsigned char))
return true;
1548 if(
typeid(T) ==
typeid(
int))
return true;
1549 if(
typeid(T) ==
typeid(
unsigned int))
return true;
1550 if(
typeid(T) ==
typeid(
short))
return true;
1551 if(
typeid(T) ==
typeid(
unsigned short))
return true;
1552 if(
typeid(T) ==
typeid(
long))
return true;
1553 if(
typeid(T) ==
typeid(
unsigned long))
return true;
1554 if(
typeid(T) ==
typeid(
long long))
return true;
1555 if(
typeid(T) ==
typeid(
unsigned long long))
return true;
1572 const any &anyValue = entry.
getAny(activeQuery);
1573 if(useIntConversions()) {
1574 return any((T)convertStringToInt(any_cast<std::string>(anyValue)));
1577 return any((T)convertStringToDouble(any_cast<std::string>(anyValue)));
1583 std::string
const &sublistName)
const 1591 if( anyValue.
type() ==
typeid(std::string) ) {
1593 anyValue = getNumberFromString(entry,
false);
1599 "The \"" << paramName <<
"\"" <<
1600 " parameter in the \"" << sublistName <<
1601 "\" sublist is has an error." << std::endl << std::endl <<
1602 "Error: The value that you entered was the wrong type." << std::endl <<
1603 "Parameter: " << paramName << std::endl <<
1604 "Type specified: " << entryName << std::endl <<
1607 bool isValueInRange;
1608 any_cast<T>(anyValue) >= minVal && any_cast<T>(anyValue) <= maxVal
1609 ? isValueInRange = true : isValueInRange=
false;
1612 "The \"" << paramName <<
"\"" <<
1613 " parameter in the \"" << sublistName <<
1614 "\" sublist is has an error." << std::endl << std::endl <<
1615 "Error: The value that was entered doesn't fall with in " <<
1616 "the range set by the validator" << std::endl <<
1617 "Parameter: " << paramName << std::endl <<
1618 "Min: " << minVal << std::endl <<
1619 "Max: " << maxVal << std::endl <<
1620 "Value entered: " <<
1621 (any_cast<T>(anyValue)) << std::endl << std::endl);
1693 bool fileMustExist()
const;
1708 bool fileEmptyNameOK()
const;
1723 bool setFileMustExist(
bool shouldFileExist);
1733 bool setFileEmptyNameOK(
bool isEmptyNameOK);
1741 ValidStringsList validStringValues()
const;
1746 std::string
const ¶mName,
1747 std::string
const &sublistName)
const;
1750 const std::string getXMLTypeName()
const;
1753 void printDoc(std::string
const &docString, std::ostream &out)
const;
1830 ValidStringsList setValidStrings(
1839 ValidStringsList validStringValues()
const;
1842 void validate(
ParameterEntry const &entry, std::string
const ¶mName,
1843 std::string
const &sublistName)
const;
1846 const std::string getXMLTypeName()
const;
1849 void printDoc(std::string
const &docString, std::ostream &out)
const;
1892 template<
class Val
idatorType,
class EntryType>
1960 template<
class Val
idatorType,
class EntryType>
1982 std::string
const &sublistName)
const;
1986 return "TwoDArrayValidator(" +
1992 virtual void printDoc(std::string
const &docString, std::ostream &out)
const 1995 std::string toPrint;
1996 toPrint +=
"TwoDArrayValidator:\n";
1997 toPrint +=
"Prototype Validator:\n";
2005 template<
class Val
idatorType,
class EntryType>
2007 std::string
const &sublistName)
const 2013 "The \"" << paramName <<
"\"" <<
2014 " parameter in the \"" << sublistName <<
2015 "\" sublist is has an error." << std::endl << std::endl <<
2016 "Error: The value you entered was the wrong type." << std::endl <<
2017 "Parameter: " << paramName << std::endl <<
2018 "Type specified: " << entryName << std::endl <<
2020 std::endl << std::endl);
2023 getValue<Teuchos::TwoDArray<EntryType> >(entry);
2025 for(
int i = 0; i<extracted.getNumRows(); ++i){
2026 for(
int j = 0; j<extracted.getNumCols(); ++j){
2028 dummyParameter.
setValue(extracted(i,j));
2030 prototype->validate(
2031 dummyParameter, paramName, sublistName);
2034 std::stringstream oss;
2035 oss <<
"TwoDArray Validator Exception:" << std::endl <<
2036 "Bad Index: (" << i <<
"," << j <<
")" << std::endl << e.what();
2049 template<
class Val
idatorType,
class EntryType>
2066 template<
class Val
idatorType,
class EntryType>
2145 template<
class Val
idatorType,
class EntryType>
2168 std::string
const &sublistName)
const;
2172 return "ArrayValidator(" +
2178 virtual void printDoc(std::string
const &docString, std::ostream &out)
const 2181 std::string toPrint;
2182 toPrint +=
"ArrayValidator:\n";
2183 toPrint +=
"Prototype Validator:\n";
2191 template<
class Val
idatorType,
class EntryType>
2193 std::string
const &sublistName)
const 2199 "The \"" << paramName <<
"\"" <<
2200 " parameter in the \"" << sublistName <<
2201 "\" sublist is has an error." << std::endl << std::endl <<
2202 "Error: The value you entered was the wrong type." << std::endl <<
2203 "Parameter: " << paramName << std::endl <<
2204 "Type specified: " << entryName << std::endl <<
2206 std::endl << std::endl);
2209 getValue<Teuchos::Array<EntryType> >(entry);
2211 for(
int i = 0; i<extracted.size(); ++i){
2213 dummyParameter.
setValue(extracted[i]);
2215 prototype->validate(
2216 dummyParameter, paramName, sublistName);
2219 std::stringstream oss;
2220 oss <<
"Array Validator Exception:" << std::endl <<
2221 "Bad Index: " << i << std::endl << e.what();
2232 template<
class Val
idatorType,
class EntryType>
2249 template<
class Val
idatorType,
class EntryType>
2343 template<
class IntegralType>
2346 std::string
const& defaultParameterName,
2347 const bool caseSensitive) :
2349 defaultParameterName_ (defaultParameterName),
2350 caseSensitive_ (caseSensitive)
2352 typedef typename map_t::value_type val_t;
2353 for (
int i = 0; i < static_cast<int> (strings.
size ()); ++i) {
2354 const bool unique = caseSensitive_ ?
2355 map_.insert (val_t (strings[i], static_cast<IntegralType> (i))).second :
2356 map_.insert (val_t (upperCase (strings[i]), static_cast<IntegralType> (i))).second;
2358 ! unique, std::logic_error,
2359 "For parameter \"" << defaultParameterName_ <<
"\": " 2360 "strings[" << i <<
"] = \"" << strings[i] <<
"\" is a duplicate.");
2362 setValidValues (strings);
2366 template<
class IntegralType>
2370 std::string
const& defaultParameterName,
2371 const bool caseSensitive) :
2373 defaultParameterName_ (defaultParameterName),
2374 caseSensitive_ (caseSensitive)
2376 #ifdef TEUCHOS_DEBUG 2380 strings.
size() != integralValues.
size(),
2382 "The input arrays strings and integralValues must have the same length.");
2384 typedef typename map_t::value_type val_t;
2385 for (
int i = 0; i < static_cast<int> (strings.
size ()); ++i) {
2386 const bool unique = caseSensitive_ ?
2387 map_.insert (val_t (strings[i], integralValues[i])).second :
2388 map_.insert (val_t (upperCase (strings[i]), integralValues[i])).second;
2391 ! unique, std::logic_error,
2392 "For parameter \"" << defaultParameterName_ <<
"\": " 2393 "strings[" << i <<
"] = \"" << strings[i] <<
"\" is a duplicate.");
2395 setValidValues (strings);
2398 template<
class IntegralType>
2403 std::string
const& defaultParameterName,
2404 const bool caseSensitive) :
2406 defaultParameterName_ (defaultParameterName),
2407 caseSensitive_ (caseSensitive)
2409 #ifdef TEUCHOS_DEBUG 2415 strings.
size() != integralValues.
size(),
2417 "The input arrays strings and integralValues must have the same length.");
2420 strings.
size() != stringsDocs.
size(),
2422 "The input arrays strings and stringsDocs must have the same length.");
2424 typedef typename map_t::value_type val_t;
2425 for (
int i = 0; i < static_cast<int> (strings.
size ()); ++i) {
2426 const bool unique = caseSensitive_ ?
2427 map_.insert (val_t (strings[i], integralValues[i])).second :
2428 map_.insert (val_t (upperCase (strings[i]), integralValues[i])).second;
2430 ! unique, std::logic_error,
2431 "For parameter \"" << defaultParameterName_ <<
"\": " 2432 "strings[" << i <<
"] = \"" << strings[i] <<
"\" is a duplicate.");
2434 setValidValues(strings,&stringsDocs);
2440 template<
class IntegralType>
2443 const std::string &str,
const std::string ¶mName
2444 ,
const std::string &sublistName
2447 typename map_t::const_iterator itr = map_.find (caseSensitive_ ? str : upperCase (str));
2450 ,
"Error, the value \"" << str <<
"\" is not recognized for the parameter \"" 2451 << ( paramName.length() ? paramName : defaultParameterName_ ) <<
"\"" 2452 <<
"\nin the sublist \"" << sublistName <<
"\"." 2453 <<
"\n\nValid values include:" 2458 return (*itr).second;
2462 template<
class IntegralType>
2466 ,
const std::string &sublistName,
const bool activeQuery
2469 const bool validType = ( entry.
getAny(activeQuery).
type() ==
typeid(std::string) );
2472 ,
"Error, the parameter {paramName=\""<<(paramName.length()?paramName:defaultParameterName_)
2474 <<
"\nin the sublist \"" << sublistName <<
"\"" 2475 <<
"\nhas the wrong type." 2476 <<
"\n\nThe correct type is \"string\"!" 2484 template<
class IntegralType>
2488 ,
const std::string &sublistName,
const bool activeQuery
2498 template<
class IntegralType>
2502 ,
const std::string &defaultValue
2505 const std::string& strValue =
2506 paramList.
get (paramName,
2507 caseSensitive_ ? defaultValue : upperCase (defaultValue));
2512 template<
class IntegralType>
2516 ,
const std::string &defaultValue
2519 const std::string& strValue =
2520 paramList.
get (paramName,
2521 caseSensitive_ ? defaultValue : upperCase (defaultValue));
2526 template<
class IntegralType>
2530 return validStringValuesDocs_;
2533 template<
class IntegralType>
2537 return defaultParameterName_;
2540 template<
class IntegralType>
2543 const std::string &str,
const std::string ¶mName
2544 ,
const std::string &sublistName
2556 template<
class IntegralType>
2562 template<
class IntegralType>
2564 std::string
const& docString
2568 StrUtils::printLines(out,
"# ",docString);
2569 out <<
"# Valid std::string values:\n";
2571 if(validStringValuesDocs_.get()) {
2572 for(
int i = 0; i < static_cast<int>(validStringValues_->size()); ++i ) {
2573 out <<
"# \"" << (*validStringValues_)[i] <<
"\"\n";
2574 StrUtils::printLines(out,
"# ",(*validStringValuesDocs_)[i] );
2578 StrUtils::printLines(out,
"# ",validValues_);
2586 template<
class IntegralType>
2590 return validStringValues_;
2594 template<
class IntegralType>
2597 ,std::string
const& paramName
2598 ,std::string
const& sublistName
2607 template<
class IntegralType>
2613 if (caseSensitive_) {
2619 (*vals)[i] = upperCase (strings[i]);
2628 std::ostringstream oss;
2629 for (
int i = 0; i < static_cast<int> (strings.
size()); ++i) {
2630 oss <<
" \"" << strings[i] <<
"\"\n";
2633 validValues_ = oss.str();
2645 template<
class IntegralType>
2648 Teuchos::stringToIntegralParameterEntryValidator(
2649 ArrayView<const std::string>
const& strings,
2650 std::string
const& defaultParameterName
2654 new StringToIntegralParameterEntryValidator<IntegralType>(
2655 strings, defaultParameterName
2661 template<
class IntegralType>
2664 Teuchos::stringToIntegralParameterEntryValidator(
2665 ArrayView<const std::string>
const& strings,
2666 std::string
const& defaultParameterName,
2667 const bool caseSensitive
2670 typedef StringToIntegralParameterEntryValidator<IntegralType> ret_type;
2671 return rcp (
new ret_type (strings, defaultParameterName, caseSensitive));
2676 template<
class IntegralType>
2679 Teuchos::stringToIntegralParameterEntryValidator(
2680 ArrayView<const std::string>
const& strings,
2681 ArrayView<const IntegralType>
const& integralValues,
2682 std::string
const& defaultParameterName
2686 new StringToIntegralParameterEntryValidator<IntegralType>(
2687 strings, integralValues, defaultParameterName
2693 template<
class IntegralType>
2696 Teuchos::stringToIntegralParameterEntryValidator(
2697 ArrayView<const std::string>
const& strings,
2698 ArrayView<const IntegralType>
const& integralValues,
2699 std::string
const& defaultParameterName,
2700 const bool caseSensitive)
2702 typedef StringToIntegralParameterEntryValidator<IntegralType> ret_type;
2703 return rcp (
new ret_type (strings, integralValues,
2704 defaultParameterName, caseSensitive));
2708 template<
class IntegralType>
2711 Teuchos::stringToIntegralParameterEntryValidator(
2712 ArrayView<const std::string>
const& strings,
2713 ArrayView<const std::string>
const& stringsDocs,
2714 ArrayView<const IntegralType>
const& integralValues,
2715 std::string
const& defaultParameterName
2719 new StringToIntegralParameterEntryValidator<IntegralType>(
2720 strings, stringsDocs, integralValues, defaultParameterName
2726 template<
class IntegralType>
2729 Teuchos::stringToIntegralParameterEntryValidator(
2730 ArrayView<const std::string>
const& strings,
2731 ArrayView<const std::string>
const& stringsDocs,
2732 ArrayView<const IntegralType>
const& integralValues,
2733 std::string
const& defaultParameterName,
2734 const bool caseSensitive)
2736 typedef StringToIntegralParameterEntryValidator<IntegralType> ret_type;
2737 return rcp (
new ret_type (strings, stringsDocs, integralValues,
2738 defaultParameterName, caseSensitive));
2742 template<
class IntegralType>
2743 void Teuchos::setStringToIntegralParameter(
2744 std::string
const& paramName,
2745 std::string
const& defaultValue,
2746 std::string
const& docString,
2747 ArrayView<const std::string>
const& strings,
2748 ParameterList * paramList
2751 typedef ParameterEntryValidator PEV;
2754 paramName, defaultValue, docString,
2755 rcp_implicit_cast<const PEV>(
2756 stringToIntegralParameterEntryValidator<IntegralType>(
2764 template<
class IntegralType>
2765 void Teuchos::setStringToIntegralParameter(
2766 std::string
const& paramName,
2767 std::string
const& defaultValue,
2768 std::string
const& docString,
2769 ArrayView<const std::string>
const& strings,
2770 ArrayView<const IntegralType>
const& integralValues,
2771 ParameterList * paramList
2774 typedef ParameterEntryValidator PEV;
2777 paramName, defaultValue, docString,
2778 rcp_implicit_cast<const PEV>(
2779 stringToIntegralParameterEntryValidator<IntegralType>(
2780 strings, integralValues, paramName
2787 template<
class IntegralType>
2788 void Teuchos::setStringToIntegralParameter(
2789 std::string
const& paramName,
2790 std::string
const& defaultValue,
2791 std::string
const& docString,
2792 ArrayView<const std::string>
const& strings,
2793 ArrayView<const std::string>
const& stringsDocs,
2794 ArrayView<const IntegralType>
const& integralValues,
2795 ParameterList * paramList
2799 typedef ParameterEntryValidator PEV;
2802 paramName, defaultValue, docString,
2803 rcp_implicit_cast<const PEV>(
2804 stringToIntegralParameterEntryValidator<IntegralType>(
2805 strings, stringsDocs, integralValues, paramName
2812 template<
class IntegralType>
2813 IntegralType Teuchos::getIntegralValue(
2814 ParameterList
const& paramList, std::string
const& paramName
2817 const ParameterEntry &entry = paramList.getEntry(paramName);
2818 RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
2819 integralValidator = getStringToIntegralParameterEntryValidator<IntegralType>(
2820 entry, paramList, paramName
2822 return integralValidator->getIntegralValue(
2823 entry, paramName, paramList.name(), true );
2827 template<
class IntegralType>
2828 std::string Teuchos::getStringValue(
2829 ParameterList
const& paramList, std::string
const& paramName
2832 const ParameterEntry &entry = paramList.getEntry(paramName);
2833 RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
2834 integralValidator = getStringToIntegralParameterEntryValidator<IntegralType>(
2835 entry, paramList, paramName
2837 return integralValidator->getStringValue(
2838 entry, paramName, paramList.name(), true
2843 template<
class IntegralType>
2846 ParameterEntry
const& entry, ParameterList
const& paramList,
2847 std::string
const& paramName
2850 const RCP<const ParameterEntryValidator> validator = entry.validator();
2852 is_null(validator), Exceptions::InvalidParameterType,
2853 "Error! The parameter \""<<paramName<<
"\" exists\n" 2854 "in the parameter (sub)list \""<<paramList.name()<<
"\"\n" 2855 "but it does not contain any validator needed to extract\n" 2856 "an integral value of type \""<<TypeNameTraits<IntegralType>::name()<<
"\"!" 2858 const RCP<const StringToIntegralParameterEntryValidator<IntegralType> > integralValidator =
2859 rcp_dynamic_cast<
const StringToIntegralParameterEntryValidator<IntegralType> >(
2863 is_null(integralValidator), Exceptions::InvalidParameterType,
2864 "Error! The parameter \""<<paramName<<
"\" exists\n" 2865 "in the parameter (sub)list \""<<paramList.name()<<
"\"\n" 2866 "but it contains the wrong type of validator. The expected validator type\n" 2867 "is \""<<TypeNameTraits<StringToIntegralParameterEntryValidator<IntegralType> >::name()<<
"\"\n" 2868 "but the contained validator type is \""<<
typeName(*validator)<<
"\"!" 2870 return integralValidator;
2874 #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.
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...
static const std::string & getStringEnumString()
static short int defaultStep()
const std::string getXMLTypeName() const
EVerbosityLevel
Verbosity level.
EnhancedNumberValidator()
Constructs a EnhancedNumberValidator without an explicit minimum or maximum.
void printDoc(std::string const &docString, std::ostream &out) const
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
Convience class for StringValidators that are to be applied to TwoDArrays.
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...
bool isCaseSensitive() const
Whether this validator is case sensitive.
const bool caseSensitive_
static float defaultStep()
bool useIntConversions() const
void setValue(T value, bool isDefault=false, const std::string &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method that uses the input value type to determine the type of parameter.
std::string acceptedTypesString_
Convience class for EnhancedNumberValidators that are to be applied to arrays.
RCP< T2 > rcp_dynamic_cast(const RCP< T1 > &p1, bool throw_on_fail=false)
Dynamic cast of underlying RCP type from T1* to T2*.
bool allowString() const
Allow an std::string value?
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
const AcceptedTypes acceptedTypes_
T minVal
The minimum value accepted by the validator.
bool hasMax() const
Determines whether or not the validator has a maximum value.
ValueType & any_cast(any &operand)
Used to extract the templated value held in Teuchos::any to a given value type.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
static unsigned short defaultPrecision()
static long unsigned int defaultStep()
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.
const std::string getXMLTypeName() const
EPreferredType preferredType_
Standard implementation of a ParameterEntryValidator that maps from a list of strings to an enum or i...
AcceptedTypes & allowString(bool _allowString)
Set allow an std::string value or not.
static long int defaultStep()
size_type size() const
The total number of items in the managed array.
static double defaultStep()
static std::ostream & printLines(std::ostream &os, const std::string &linePrefix, const std::string &lines)
Print lines with prefix first.
ValidStringsList validStrings_
An array containing a list of all the valid string values.
static const std::string & getDoubleEnumString()
unsigned short getPrecision() const
Gets the precision specified for the validator.
static unsigned short defaultPrecision()
ValidStringsList getStringDocs() const
Get a pointer to the array containing all the documentation strings.
static unsigned short defaultPrecision()
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.
ValidStringsList validStringValuesDocs_
virtual void printDoc(std::string const &docString, std::ostream &out) const
static unsigned short defaultPrecision()
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.
IntegralType getIntegralValue(ParameterList const ¶mList, std::string const ¶mName)
Get an integral value for a parameter that is assumed to already be set.
const std::string getXMLTypeName() const
A std::string utilities class for Teuchos.
Determines the types that are accepted.
std::string validateString(const std::string &str, const std::string ¶mName="", const std::string &sublistName="") const
Validate the std::string and pass it on.
ValidStringsList validStringValues() const
StringToIntegralParameterEntryValidator()
A thin wrapper around the Array class which causes it to be interpurted as a 2D Array.
std::string acceptedTypesString_
static const std::string & getIntEnumString()
Convience class for StringValidators that are to be applied to arrays.
static unsigned short defaultPrecision()
static T notDefined()
This function should not compile if there is an attempt to instantiate!
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Templated Parameter List class.
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
Validate the given ParameterEntry.
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.
static unsigned short defaultPrecision()
Gets the default precision with which the number type should be displayed.
bool containsMax
Whetehr or not a maximum value has been specified for this validator.
const std::string getXMLTypeName() const
static unsigned short defaultPrecision()
virtual void validateAndModify(std::string const ¶mName, std::string const &sublistName, ParameterEntry *entry) const
Validate and perhaps modify a parameter entry's value.
ValidStringsList validStringValues() const
std::string toString(const HashSet< Key > &h)
T getMax() const
Gets the maximum acceptable value for the validator.
virtual void printDoc(std::string const &docString, std::ostream &out) const
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.
static short unsigned int defaultStep()
Validate a file name entry.
std::map< std::string, IntegralType > map_t
AcceptedTypes(bool allowAllTypesByDefault=true)
Allow all types or not on construction.
void setStep(T step)
Sets the step being used for the validator.
static unsigned short defaultPrecision()
Takes a validator, wraps it, and applies it to an array.
A list of parameters of arbitrary type.
static long unsigned int min()
static unsigned int defaultStep()
ValidStringsList validStringValues() const
bool mustAlreadyExist_
Whether or not the file specified in the parameter should already exist.
static unsigned short defaultPrecision()
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.
static short unsigned int min()
bool allowDouble() const
Allow an double value?
#define TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
TwoDArrayValidator(RCP< const ValidatorType > prototypeValidator)
Constructs a ArrayValidator.
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.
const std::type_info & type() const
Return the type of value being stored.
Abstract interface for an object that can validate a ParameterEntry's value.
const std::string & name() const
The name of this ParameterList.
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.
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.
RCP< const Array< std::string > > ValidStringsList
Default traits class that just returns typeid(T).name().
virtual void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
Class for retrieving a dummy object of type T.
unsigned short precision_
The number of decimal places with which the nubmer will be displayed in a UI. This value is meaningle...
static const std::string & getPrefferedTypeString(EPreferredType enumValue)
Gets the string representation of a given preferred type enum.
std::string typeName() const
Return the name of the type.
bool allowInt() const
Allow an int value?
static std::string upperCase(const std::string s)
Return an upper-case copy of the string s.
const std::string & getDefaultParameterName() const
Get the name of the default parameter for the validator.
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.
ValidStringsList validStringValues_
void validateAndModify(std::string const ¶mName, std::string const &sublistName, ParameterEntry *entry) const
void setValidValues(ArrayView< const std::string > const &strings, ArrayView< const std::string > const *stringsDocs=NULL)
RCP< const ValidatorType > getPrototype() const
Returns the prototype validator for this Array Validator.
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
Class defining the traits of the number type being used in an EnhancedNumberValidator.
TwoDArrayNumberValidator(RCP< const EnhancedNumberValidator< T > > prototypeValidator)
AcceptedTypes & allowDouble(bool _allowDouble)
Set allow a double value or not.
Smart reference counting pointer class for automatic garbage collection.
TwoDArrayStringValidator(RCP< const StringValidator > prototypeValidator)
static long unsigned int max()
T getStep() const
Gets the step being used for the validator.
TwoDArrayFileNameValidator(RCP< const FileNameValidator > prototypeValidator)
#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 ...
RCP< T2 > rcp_const_cast(const RCP< T1 > &p1)
Constant cast of underlying RCP type from T1* to T2*.
T step_
The increment to use when increaseing or decreaseing the value the validator is validating.
Standard implementation of a ParameterEntryValidator that accepts numbers from a number of different ...
T getMin() const
Gets the minimum acceptable value for the validator.
static unsigned int max()
std::string defaultParameterName_
Defines basic traits returning the name of a type in a portable and readable way. ...
Teuchos::any getNumberFromString(const ParameterEntry &entry, const bool activeQuery) const
static short unsigned int max()
bool containsMin
Whether or not a minimum value has been specified for this validator.
void printDoc(std::string const &docString, std::ostream &out) const
Print documentation to the given output string.
#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...
static std::string name()
T maxVal
The maximum value accepted by the validator.
bool hasMin() const
Determines whether or not the validator has a minimum value.
RCP< const ValidatorType > prototypeValidator_
The prototype validator to be applied to each entry in the Array.
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
static unsigned int min()
ArrayNumberValidator(RCP< const EnhancedNumberValidator< T > > prototypeValidator)