|
Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
|
Go to the documentation of this file.
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> >
359 std::string
const& defaultParameterName
367 template<
class IntegralType>
371 std::string
const& defaultParameterName,
372 const bool caseSensitive
380 template<
class IntegralType>
385 std::string
const& defaultParameterName
393 template<
class IntegralType>
398 std::string
const& defaultParameterName,
399 const bool caseSensitive
407 template<
class IntegralType>
413 std::string
const& defaultParameterName
421 template<
class IntegralType>
427 std::string
const& defaultParameterName,
428 const bool caseSensitive
442 template<
class IntegralType>
444 std::string
const& paramName,
445 std::string
const& defaultValue,
446 std::string
const& docString,
463 template<
class IntegralType>
465 std::string
const& paramName,
466 std::string
const& defaultValue,
467 std::string
const& docString,
485 template<
class IntegralType>
487 std::string
const& paramName,
488 std::string
const& defaultValue,
489 std::string
const& docString,
507 template<
class IntegralType>
524 template<
class IntegralType>
535 template<
class IntegralType>
539 std::string
const& paramName
548 std::string getVerbosityLevelParameterValueName(
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
718 enum EPreferredType { PREFER_INT, PREFER_LONG_LONG, PREFER_DOUBLE, PREFER_STRING };
726 :allowInt_(allowAllTypesByDefault)
727 ,allowLongLong_(allowAllTypesByDefault)
728 ,allowDouble_(allowAllTypesByDefault)
729 ,allowString_(allowAllTypesByDefault)
733 { allowInt_ = _allowInt;
return *
this; }
736 { allowLongLong_ = _allowLongLong;
return *
this; }
739 { allowDouble_ = _allowDouble;
return *
this; }
742 { allowString_ = _allowString;
return *
this; }
795 const std::string &sublistName =
"",
const bool activeQuery =
true
803 long long getLongLong(
805 const std::string &sublistName =
"",
const bool activeQuery =
true
813 const std::string &sublistName =
"",
const bool activeQuery =
true
817 std::string getString(
819 const std::string &sublistName =
"",
const bool activeQuery =
true
827 const int defaultValue
833 long long getLongLong(
835 const long long defaultValue
843 const double defaultValue
849 std::string getString(
851 const std::string &defaultValue
856 bool isIntAllowed()
const;
860 bool isLongLongAllowed()
const;
864 bool isDoubleAllowed()
const;
868 bool isStringAllowed()
const;
879 return getIntEnumString ();
880 case PREFER_LONG_LONG:
881 return getLongLongEnumString ();
883 return getDoubleEnumString ();
885 return getStringEnumString ();
887 const std::string typeString (
toString (enumValue));
888 throw std::runtime_error(
"Cannot convert enumValue: " + typeString +
" to a string");
895 if (enumString == getIntEnumString ()) {
898 else if (enumString == getLongLongEnumString ()) {
899 return PREFER_LONG_LONG;
901 else if (enumString == getDoubleEnumString ()) {
902 return PREFER_DOUBLE;
904 else if (enumString == getStringEnumString ()) {
905 return PREFER_STRING;
908 throw std::runtime_error (
"Cannot convert enumString: " + enumString +
" to an enum");
918 const std::string getXMLTypeName()
const;
922 std::string
const& docString,
928 validStringValues()
const;
933 std::string
const& paramName,
934 std::string
const& sublistName
938 void validateAndModify(
939 std::string
const& paramName,
940 std::string
const& sublistName,
957 #pragma warning(push)
958 #pragma warning(disable:4251)
971 return intEnumString_;
977 return longLongEnumString_;
983 return doubleEnumString_;
989 return stringEnumString_;
993 void finishInitialization();
997 std::string
const& paramName,
998 std::string
const& sublistName
1031 std::string
const& paramName,
1032 int const value, std::string
const& docString,
1045 std::string
const& paramName,
1046 long long const value, std::string
const& docString,
1058 std::string
const& paramName,
1059 double const& value, std::string
const& docString,
1072 std::string
const& paramName,
1073 std::string
const& value, std::string
const& docString,
1095 ParameterList const& paramList, std::string
const& paramName
1114 ParameterList const& paramList, std::string
const& paramName
1133 std::string
const& paramName
1154 std::string
const& paramName
1188 return T::this_type_is_missing_a_specialization();
1241 static inline short int min() {
return std::numeric_limits<short int>::min(); }
1242 static inline short int max() {
return std::numeric_limits<short int>::max(); }
1251 static inline short unsigned int min() {
return std::numeric_limits<short unsigned int>::min(); }
1252 static inline short unsigned int max() {
return std::numeric_limits<short unsigned int>::max(); }
1261 static inline int min() {
return std::numeric_limits<int>::min(); }
1262 static inline int max() {
return std::numeric_limits<int>::max(); }
1271 static inline unsigned int min() {
return std::numeric_limits<unsigned int>::min(); }
1272 static inline unsigned int max() {
return std::numeric_limits<unsigned int>::max(); }
1281 static inline long int min() {
return std::numeric_limits<long int>::min(); }
1282 static inline long int max() {
return std::numeric_limits<long int>::max(); }
1291 static inline long unsigned int min() {
return std::numeric_limits<long unsigned int>::min(); }
1292 static inline long unsigned int max() {
return std::numeric_limits<long unsigned int>::max(); }
1301 static inline long long int min() {
return std::numeric_limits<long long int>::min(); }
1302 static inline long long int max() {
return std::numeric_limits<long long int>::max(); }
1311 static inline long long unsigned int min() {
return std::numeric_limits<long long unsigned int>::min(); }
1312 static inline long long unsigned int max() {
return std::numeric_limits<long long unsigned int>::max(); }
1318 #ifdef HAVE_TEUCHOSCORE_QUADMATH
1320 class EnhancedNumberTraits<__float128>{
1322 static inline __float128
min() {
return -std::numeric_limits<__float128>::max(); }
1323 static inline __float128
max() {
return std::numeric_limits<__float128>::max(); }
1324 static inline __float128
defaultStep() {
return 1; }
1327 #endif // HAVE_TEUCHOSCORE_QUADMATH
1332 static inline double min() {
return -std::numeric_limits<double>::max(); }
1333 static inline double max() {
return std::numeric_limits<double>::max(); }
1341 static inline float min() {
return -std::numeric_limits<float>::max(); }
1342 static inline float max() {
return std::numeric_limits<float>::max(); }
1504 std::string
const &sublistName)
const;
1512 const bool activeQuery)
const;
1520 void printDoc(std::string
const &docString, std::ostream &out)
const{
1522 out <<
"#\tValidator Used: " << std::endl;
1523 out <<
"#\t\tNumber Validator" << std::endl;
1526 out <<
"#\t\tMin (inclusive): " <<
minVal << std::endl;
1527 out <<
"#\t\tMax (inclusive): " <<
maxVal << std::endl;
1578 std::string
const& paramName,
1579 std::string
const& sublistName,
1587 if( anyValue.
type() ==
typeid(std::string) ) {
1588 anyValue = getNumberFromString(*entry,
false);
1590 any_cast<T>(anyValue),
1597 paramName, sublistName, entry);
1609 if(
typeid(T) ==
typeid(
char))
return true;
1610 if(
typeid(T) ==
typeid(
unsigned char))
return true;
1611 if(
typeid(T) ==
typeid(
int))
return true;
1612 if(
typeid(T) ==
typeid(
unsigned int))
return true;
1613 if(
typeid(T) ==
typeid(
short))
return true;
1614 if(
typeid(T) ==
typeid(
unsigned short))
return true;
1615 if(
typeid(T) ==
typeid(
long))
return true;
1616 if(
typeid(T) ==
typeid(
unsigned long))
return true;
1617 if(
typeid(T) ==
typeid(
long long))
return true;
1618 if(
typeid(T) ==
typeid(
unsigned long long))
return true;
1635 const any &anyValue = entry.
getAny(activeQuery);
1636 if(useIntConversions()) {
1637 return any((T)convertStringToInt(any_cast<std::string>(anyValue)));
1640 return any((T)convertStringToDouble(any_cast<std::string>(anyValue)));
1646 std::string
const &sublistName)
const
1654 if( anyValue.
type() ==
typeid(std::string) ) {
1656 anyValue = getNumberFromString(entry,
false);
1662 "The \"" << paramName <<
"\"" <<
1663 " parameter in the \"" << sublistName <<
1664 "\" sublist is has an error." << std::endl << std::endl <<
1665 "Error: The value that you entered was the wrong type." << std::endl <<
1666 "Parameter: " << paramName << std::endl <<
1667 "Type specified: " << entryName << std::endl <<
1670 bool isValueInRange;
1671 any_cast<T>(anyValue) >= minVal && any_cast<T>(anyValue) <= maxVal
1672 ? isValueInRange = true : isValueInRange=
false;
1675 "The \"" << paramName <<
"\"" <<
1676 " parameter in the \"" << sublistName <<
1677 "\" sublist is has an error." << std::endl << std::endl <<
1678 "Error: The value that was entered doesn't fall with in " <<
1679 "the range set by the validator" << std::endl <<
1680 "Parameter: " << paramName << std::endl <<
1681 "Min: " << minVal << std::endl <<
1682 "Max: " << maxVal << std::endl <<
1683 "Value entered: " <<
1684 (any_cast<T>(anyValue)) << std::endl << std::endl);
1756 bool fileMustExist()
const;
1771 bool fileEmptyNameOK()
const;
1786 bool setFileMustExist(
bool shouldFileExist);
1796 bool setFileEmptyNameOK(
bool isEmptyNameOK);
1804 ValidStringsList validStringValues()
const;
1809 std::string
const ¶mName,
1810 std::string
const &sublistName)
const;
1813 const std::string getXMLTypeName()
const;
1816 void printDoc(std::string
const &docString, std::ostream &out)
const;
1905 void validate(
ParameterEntry const &entry, std::string
const ¶mName,
1906 std::string
const &sublistName)
const;
1909 const std::string getXMLTypeName()
const;
1912 void printDoc(std::string
const &docString, std::ostream &out)
const;
1955 template<
class Val
idatorType,
class EntryType>
2023 template<
class Val
idatorType,
class EntryType>
2045 std::string
const &sublistName)
const;
2049 return "TwoDArrayValidator(" +
2055 virtual void printDoc(std::string
const &docString, std::ostream &out)
const
2058 std::string toPrint;
2059 toPrint +=
"TwoDArrayValidator:\n";
2060 toPrint +=
"Prototype Validator:\n";
2068 template<
class Val
idatorType,
class EntryType>
2070 std::string
const &sublistName)
const
2076 "The \"" << paramName <<
"\"" <<
2077 " parameter in the \"" << sublistName <<
2078 "\" sublist is has an error." << std::endl << std::endl <<
2079 "Error: The value you entered was the wrong type." << std::endl <<
2080 "Parameter: " << paramName << std::endl <<
2081 "Type specified: " << entryName << std::endl <<
2083 std::endl << std::endl);
2086 getValue<Teuchos::TwoDArray<EntryType> >(entry);
2088 for(
int i = 0; i<extracted.
getNumRows(); ++i){
2089 for(
int j = 0; j<extracted.
getNumCols(); ++j){
2091 dummyParameter.
setValue(extracted(i,j));
2093 prototype->validate(
2094 dummyParameter, paramName, sublistName);
2097 std::stringstream oss;
2098 oss <<
"TwoDArray Validator Exception:" << std::endl <<
2099 "Bad Index: (" << i <<
"," << j <<
")" << std::endl << e.what();
2112 template<
class Val
idatorType,
class EntryType>
2129 template<
class Val
idatorType,
class EntryType>
2208 template<
class Val
idatorType,
class EntryType>
2231 std::string
const &sublistName)
const;
2235 return "ArrayValidator(" +
2241 virtual void printDoc(std::string
const &docString, std::ostream &out)
const
2244 std::string toPrint;
2245 toPrint +=
"ArrayValidator:\n";
2246 toPrint +=
"Prototype Validator:\n";
2254 template<
class Val
idatorType,
class EntryType>
2256 std::string
const &sublistName)
const
2262 "The \"" << paramName <<
"\"" <<
2263 " parameter in the \"" << sublistName <<
2264 "\" sublist is has an error." << std::endl << std::endl <<
2265 "Error: The value you entered was the wrong type." << std::endl <<
2266 "Parameter: " << paramName << std::endl <<
2267 "Type specified: " << entryName << std::endl <<
2269 std::endl << std::endl);
2272 getValue<Teuchos::Array<EntryType> >(entry);
2274 for(
int i = 0; i<extracted.
size(); ++i){
2276 dummyParameter.
setValue(extracted[i]);
2278 prototype->validate(
2279 dummyParameter, paramName, sublistName);
2282 std::stringstream oss;
2283 oss <<
"Array Validator Exception:" << std::endl <<
2284 "Bad Index: " << i << std::endl << e.what();
2295 template<
class Val
idatorType,
class EntryType>
2312 template<
class Val
idatorType,
class EntryType>
2406 template<
class IntegralType>
2409 std::string
const& defaultParameterName,
2410 const bool caseSensitive) :
2412 defaultParameterName_ (defaultParameterName),
2413 caseSensitive_ (caseSensitive)
2415 typedef typename map_t::value_type val_t;
2416 for (
int i = 0; i < static_cast<int> (strings.
size ()); ++i) {
2418 map_.insert (val_t (strings[i],
static_cast<IntegralType
> (i))).second :
2419 map_.insert (val_t (
upperCase (strings[i]),
static_cast<IntegralType
> (i))).second;
2421 ! unique, std::logic_error,
2423 "strings[" << i <<
"] = \"" << strings[i] <<
"\" is a duplicate.");
2429 template<
class IntegralType>
2433 std::string
const& defaultParameterName,
2434 const bool caseSensitive) :
2436 defaultParameterName_ (defaultParameterName),
2437 caseSensitive_ (caseSensitive)
2439 #ifdef TEUCHOS_DEBUG
2443 strings.
size() != integralValues.
size(),
2445 "The input arrays strings and integralValues must have the same length.");
2447 typedef typename map_t::value_type val_t;
2448 for (
int i = 0; i < static_cast<int> (strings.
size ()); ++i) {
2450 map_.insert (val_t (strings[i], integralValues[i])).second :
2451 map_.insert (val_t (
upperCase (strings[i]), integralValues[i])).second;
2454 ! unique, std::logic_error,
2456 "strings[" << i <<
"] = \"" << strings[i] <<
"\" is a duplicate.");
2461 template<
class IntegralType>
2466 std::string
const& defaultParameterName,
2467 const bool caseSensitive) :
2469 defaultParameterName_ (defaultParameterName),
2470 caseSensitive_ (caseSensitive)
2472 #ifdef TEUCHOS_DEBUG
2478 strings.
size() != integralValues.
size(),
2480 "The input arrays strings and integralValues must have the same length.");
2483 strings.
size() != stringsDocs.
size(),
2485 "The input arrays strings and stringsDocs must have the same length.");
2487 typedef typename map_t::value_type val_t;
2488 for (
int i = 0; i < static_cast<int> (strings.
size ()); ++i) {
2490 map_.insert (val_t (strings[i], integralValues[i])).second :
2491 map_.insert (val_t (
upperCase (strings[i]), integralValues[i])).second;
2493 ! unique, std::logic_error,
2495 "strings[" << i <<
"] = \"" << strings[i] <<
"\" is a duplicate.");
2503 template<
class IntegralType>
2506 const std::string &str,
const std::string ¶mName
2507 ,
const std::string &sublistName
2510 typename map_t::const_iterator itr = map_.find (caseSensitive_ ? str : upperCase (str));
2513 ,
"Error, the value \"" << str <<
"\" is not recognized for the parameter \""
2514 << ( paramName.length() ? paramName : defaultParameterName_ ) <<
"\""
2515 <<
"\nin the sublist \"" << sublistName <<
"\"."
2516 <<
"\n\nValid values include:"
2521 return (*itr).second;
2525 template<
class IntegralType>
2529 ,
const std::string &sublistName,
const bool activeQuery
2532 const bool validType = ( entry.
getAny(activeQuery).
type() ==
typeid(std::string) );
2535 ,
"Error, the parameter {paramName=\""<<(paramName.length()?paramName:defaultParameterName_)
2537 <<
"\nin the sublist \"" << sublistName <<
"\""
2538 <<
"\nhas the wrong type."
2539 <<
"\n\nThe correct type is \"string\"!"
2542 &strValue = any_cast<std::string>(entry.
getAny(activeQuery));
2543 return getIntegralValue(strValue,paramName,sublistName);
2547 template<
class IntegralType>
2551 ,
const std::string &sublistName,
const bool activeQuery
2555 this->getIntegralValue(entry,paramName,sublistName,activeQuery);
2557 return any_cast<std::string>(entry.
getAny(activeQuery));
2561 template<
class IntegralType>
2565 ,
const std::string &defaultValue
2568 const std::string& strValue =
2569 paramList.
get (paramName,
2570 caseSensitive_ ? defaultValue : upperCase (defaultValue));
2571 return getIntegralValue (strValue, paramName, paramList.
name ());
2575 template<
class IntegralType>
2579 ,
const std::string &defaultValue
2582 const std::string& strValue =
2583 paramList.
get (paramName,
2584 caseSensitive_ ? defaultValue : upperCase (defaultValue));
2585 getIntegralValue(strValue,paramName,paramList.
name());
2589 template<
class IntegralType>
2593 return validStringValuesDocs_;
2596 template<
class IntegralType>
2600 return defaultParameterName_;
2603 template<
class IntegralType>
2606 const std::string &str,
const std::string ¶mName
2607 ,
const std::string &sublistName
2610 getIntegralValue (caseSensitive_ ? str : upperCase (str),
2619 template<
class IntegralType>
2625 template<
class IntegralType>
2627 std::string
const& docString
2632 out <<
"# Valid std::string values:\n";
2634 if(validStringValuesDocs_.get()) {
2635 for(
int i = 0; i < static_cast<int>(validStringValues_->size()); ++i ) {
2636 out <<
"# \"" << (*validStringValues_)[i] <<
"\"\n";
2649 template<
class IntegralType>
2653 return validStringValues_;
2657 template<
class IntegralType>
2660 ,std::string
const& paramName
2661 ,std::string
const& sublistName
2664 this->getIntegralValue (entry, paramName, sublistName,
false);
2670 template<
class IntegralType>
2676 if (caseSensitive_) {
2682 (*vals)[i] = upperCase (strings[i]);
2684 validStringValues_ = rcp_const_cast<const Array<std::string> > (vals);
2691 std::ostringstream oss;
2692 for (
int i = 0; i < static_cast<int> (strings.
size()); ++i) {
2693 oss <<
" \"" << strings[i] <<
"\"\n";
2696 validValues_ = oss.str();
2708 template<
class IntegralType>
2711 Teuchos::stringToIntegralParameterEntryValidator(
2712 ArrayView<const std::string>
const& strings,
2713 std::string
const& defaultParameterName
2717 new StringToIntegralParameterEntryValidator<IntegralType>(
2718 strings, defaultParameterName
2724 template<
class IntegralType>
2727 Teuchos::stringToIntegralParameterEntryValidator(
2728 ArrayView<const std::string>
const& strings,
2729 std::string
const& defaultParameterName,
2730 const bool caseSensitive
2733 typedef StringToIntegralParameterEntryValidator<IntegralType> ret_type;
2734 return rcp (
new ret_type (strings, defaultParameterName, caseSensitive));
2739 template<
class IntegralType>
2742 Teuchos::stringToIntegralParameterEntryValidator(
2743 ArrayView<const std::string>
const& strings,
2744 ArrayView<const IntegralType>
const& integralValues,
2745 std::string
const& defaultParameterName
2749 new StringToIntegralParameterEntryValidator<IntegralType>(
2750 strings, integralValues, defaultParameterName
2756 template<
class IntegralType>
2759 Teuchos::stringToIntegralParameterEntryValidator(
2760 ArrayView<const std::string>
const& strings,
2761 ArrayView<const IntegralType>
const& integralValues,
2762 std::string
const& defaultParameterName,
2763 const bool caseSensitive)
2765 typedef StringToIntegralParameterEntryValidator<IntegralType> ret_type;
2766 return rcp (
new ret_type (strings, integralValues,
2767 defaultParameterName, caseSensitive));
2771 template<
class IntegralType>
2774 Teuchos::stringToIntegralParameterEntryValidator(
2775 ArrayView<const std::string>
const& strings,
2776 ArrayView<const std::string>
const& stringsDocs,
2777 ArrayView<const IntegralType>
const& integralValues,
2778 std::string
const& defaultParameterName
2782 new StringToIntegralParameterEntryValidator<IntegralType>(
2783 strings, stringsDocs, integralValues, defaultParameterName
2789 template<
class IntegralType>
2792 Teuchos::stringToIntegralParameterEntryValidator(
2793 ArrayView<const std::string>
const& strings,
2794 ArrayView<const std::string>
const& stringsDocs,
2795 ArrayView<const IntegralType>
const& integralValues,
2796 std::string
const& defaultParameterName,
2797 const bool caseSensitive)
2799 typedef StringToIntegralParameterEntryValidator<IntegralType> ret_type;
2800 return rcp (
new ret_type (strings, stringsDocs, integralValues,
2801 defaultParameterName, caseSensitive));
2805 template<
class IntegralType>
2806 void Teuchos::setStringToIntegralParameter(
2807 std::string
const& paramName,
2808 std::string
const& defaultValue,
2809 std::string
const& docString,
2810 ArrayView<const std::string>
const& strings,
2811 ParameterList * paramList
2814 typedef ParameterEntryValidator PEV;
2817 paramName, defaultValue, docString,
2818 rcp_implicit_cast<const PEV>(
2819 stringToIntegralParameterEntryValidator<IntegralType>(
2827 template<
class IntegralType>
2828 void Teuchos::setStringToIntegralParameter(
2829 std::string
const& paramName,
2830 std::string
const& defaultValue,
2831 std::string
const& docString,
2832 ArrayView<const std::string>
const& strings,
2833 ArrayView<const IntegralType>
const& integralValues,
2834 ParameterList * paramList
2837 typedef ParameterEntryValidator PEV;
2840 paramName, defaultValue, docString,
2841 rcp_implicit_cast<const PEV>(
2842 stringToIntegralParameterEntryValidator<IntegralType>(
2843 strings, integralValues, paramName
2850 template<
class IntegralType>
2851 void Teuchos::setStringToIntegralParameter(
2852 std::string
const& paramName,
2853 std::string
const& defaultValue,
2854 std::string
const& docString,
2855 ArrayView<const std::string>
const& strings,
2856 ArrayView<const std::string>
const& stringsDocs,
2857 ArrayView<const IntegralType>
const& integralValues,
2858 ParameterList * paramList
2862 typedef ParameterEntryValidator PEV;
2865 paramName, defaultValue, docString,
2866 rcp_implicit_cast<const PEV>(
2867 stringToIntegralParameterEntryValidator<IntegralType>(
2868 strings, stringsDocs, integralValues, paramName
2875 template<
class IntegralType>
2876 IntegralType Teuchos::getIntegralValue(
2877 ParameterList
const& paramList, std::string
const& paramName
2880 const ParameterEntry &entry = paramList.getEntry(paramName);
2881 RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
2882 integralValidator = getStringToIntegralParameterEntryValidator<IntegralType>(
2883 entry, paramList, paramName
2885 return integralValidator->getIntegralValue(
2886 entry, paramName, paramList.name(),
true );
2890 template<
class IntegralType>
2891 std::string Teuchos::getStringValue(
2892 ParameterList
const& paramList, std::string
const& paramName
2895 const ParameterEntry &entry = paramList.getEntry(paramName);
2896 RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
2897 integralValidator = getStringToIntegralParameterEntryValidator<IntegralType>(
2898 entry, paramList, paramName
2900 return integralValidator->getStringValue(
2901 entry, paramName, paramList.name(),
true
2906 template<
class IntegralType>
2909 ParameterEntry
const& entry, ParameterList
const& paramList,
2910 std::string
const& paramName
2913 const RCP<const ParameterEntryValidator> validator = entry.validator();
2915 is_null(validator), Exceptions::InvalidParameterType,
2916 "Error! The parameter \""<<paramName<<
"\" exists\n"
2917 "in the parameter (sub)list \""<<paramList.name()<<
"\"\n"
2918 "but it does not contain any validator needed to extract\n"
2919 "an integral value of type \""<<TypeNameTraits<IntegralType>::name()<<
"\"!"
2921 const RCP<const StringToIntegralParameterEntryValidator<IntegralType> > integralValidator =
2922 rcp_dynamic_cast<const StringToIntegralParameterEntryValidator<IntegralType> >(
2926 is_null(integralValidator), Exceptions::InvalidParameterType,
2927 "Error! The parameter \""<<paramName<<
"\" exists\n"
2928 "in the parameter (sub)list \""<<paramList.name()<<
"\"\n"
2929 "but it contains the wrong type of validator. The expected validator type\n"
2930 "is \""<<TypeNameTraits<StringToIntegralParameterEntryValidator<IntegralType> >::name()<<
"\"\n"
2931 "but the contained validator type is \""<<
typeName(*validator)<<
"\"!"
2933 return integralValidator;
2937 #endif // TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H
TwoDArrayStringValidator(RCP< const StringValidator > prototypeValidator)
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
static std::string name()
#define TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
Templated Parameter List class.
EVerbosityLevel
Verbosity level.
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.
virtual void validateAndModify(std::string const ¶mName, std::string const &sublistName, ParameterEntry *entry) const
Validate and perhaps modify a parameter entry's value.
static unsigned short defaultPrecision()
virtual void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
T minVal
The minimum value accepted by the validator.
ArrayValidator(RCP< const ValidatorType > prototypeValidator)
Constructs a ArrayValidator.
Teuchos::any getNumberFromString(const ParameterEntry &entry, const bool activeQuery) const
AcceptedTypes & allowInt(bool _allowInt)
Set allow an int value or not.
A thin wrapper around the Array class which causes it to be interpreted as a 2D Array.
T getStep() const
Gets the step being used for the validator.
static const std::string & getStringEnumString()
#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.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT double getDoubleParameter(ParameterList const ¶mList, std::string const ¶mName)
Get double integer parameter.
EnhancedNumberValidator()
Constructs a EnhancedNumberValidator without an explicit minimum or maximum.
RCP< StringToIntegralParameterEntryValidator< IntegralType > > stringToIntegralParameterEntryValidator(ArrayView< const std::string > const &strings, std::string const &defaultParameterName)
Nonmember constructor (see implementation).
Standard implementation of a BoolParameterEntryValidator that accepts bool values (true/false) or str...
A std::string utilities class for Teuchos.
const std::string getXMLTypeName() const
Default structure used by EnhancedNumberTraits<T> to produce a compile time error when the specializa...
static long int defaultStep()
T getMin() const
Gets the minimum acceptable value for the validator.
RCP< StringToIntegralParameterEntryValidator< IntegralType > > stringToIntegralParameterEntryValidator(ArrayView< const std::string > const &strings, std::string const &defaultParameterName, const bool caseSensitive)
Nonmember constructor (see implementation).
bool allowString() const
Allow an std::string value?
bool useIntConversions() const
Convience class for StringValidators that are to be applied to arrays.
static unsigned int defaultStep()
static long long unsigned int min()
void setStringToIntegralParameter(std::string const ¶mName, std::string const &defaultValue, std::string const &docString, ArrayView< const std::string > const &strings, ParameterList *paramList)
Set up a std::string parameter that will use an embedded validator to allow the extraction of an inte...
static const std::string & getPrefferedTypeString(EPreferredType enumValue)
Gets the string representation of a given preferred type enum.
static short unsigned int defaultStep()
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
RCP< StringToIntegralParameterEntryValidator< IntegralType > > stringToIntegralParameterEntryValidator(ArrayView< const std::string > const &strings, ArrayView< const std::string > const &stringsDocs, ArrayView< const IntegralType > const &integralValues, std::string const &defaultParameterName, const bool caseSensitive)
Nonmember constructor (see implementation).
virtual void printDoc(std::string const &docString, std::ostream &out) const
static unsigned short defaultPrecision()
bool is_null(const ArrayRCP< T > &p)
Returns true if p.get()==NULL.
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.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void setIntParameter(std::string const ¶mName, int const value, std::string const &docString, ParameterList *paramList, AnyNumberParameterEntryValidator::AcceptedTypes const &acceptedTypes=AnyNumberParameterEntryValidator::AcceptedTypes())
Set an integer parameter that allows for (nearly) any input parameter type that is convertible to an ...
size_type getNumRows() const
returns the number of rows in the TwoDArray.
A simple validator that only allows certain string values to be choosen or simply enforces that a par...
static unsigned short defaultPrecision()
static const std::string & getDoubleEnumString()
Abstract interface for an object that can validate a ParameterEntry's value.
static T defaultStep()
gets default amount a value of the number type should be incremented by when being utilizied in a UI.
static unsigned short defaultPrecision()
bool allowInt() const
Allow an int value?
bool allowLongLong() const
Allow an long long value?
Convience class for EnhancedNumberValidators that are to be applied to arrays.
static EPreferredType getPrefferedTypeStringEnum(const std::string &enumString)
Gets the preferred type enum associated with a give string.
static short unsigned int min()
AcceptedTypes(bool allowAllTypesByDefault=true)
Allow all types or not on construction.
RCP< const Array< std::string > > ValidStringsList
Default traits class that just returns typeid(T).name().
StringToIntegralParameterEntryValidator(const ArrayView< const std::string > &strings, const std::string &defaultParameterName, const bool caseSensitive=true)
Construct with a mapping from strings to the enum or integer values .
T & get(const std::string &name, T def_value)
Return the parameter's value, or the default value if it is not there.
bool mustAlreadyExist_
Whether or not the file specified in the parameter should already exist.
Convience class for EnhancedNumberValidators that are to be applied to TwoDArray.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
ValidStringsList validStrings_
An array containing a list of all the valid string values.
RCP< StringToIntegralParameterEntryValidator< IntegralType > > stringToIntegralParameterEntryValidator(ArrayView< const std::string > const &strings, ArrayView< const std::string > const &stringsDocs, ArrayView< const IntegralType > const &integralValues, std::string const &defaultParameterName)
Nonmember constructor (see implementation).
static unsigned int min()
static long long unsigned int max()
ValidStringsList validStringValues() const
Convience class for FileNameValidators that are to be applied to arrays.
EnhancedNumberValidator(T min, T max, T step=EnhancedNumberTraits< T >::defaultStep(), unsigned short precision=EnhancedNumberTraits< T >::defaultPrecision())
Constructs a EnhancedNumberValidator.
RCP< const ValidatorType > prototypeValidator_
The prototype validator to be applied to each entry in the Array.
static unsigned short defaultPrecision()
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void setDoubleParameter(std::string const ¶mName, double const &value, std::string const &docString, ParameterList *paramList, AnyNumberParameterEntryValidator::AcceptedTypes const &acceptedTypes=AnyNumberParameterEntryValidator::AcceptedTypes())
Set an double parameter that allows for (nearly) any input parameter type that is convertible to a do...
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT std::string getNumericStringParameter(ParameterList const ¶mList, std::string const ¶mName)
Get std::string numeric parameter.
IntegralType getIntegralValue(const ParameterEntry &entry, const std::string ¶mName="", const std::string &sublistName="", const bool activeQuery=true) const
Find the enum or integer value for the given ParameterEntry.
static bool mustAlreadyExistDefault()
The default value of the mustAlreadyExist parameter in the constructor.
StringToIntegralParameterEntryValidator(const ArrayView< const std::string > &strings, const ArrayView< const IntegralType > &integralValues, std::string const &defaultParameterName, const bool caseSensitive=true)
Construct with a mapping from strings to specified enum or integer values.
const std::type_info & type() const
Return the type of value being stored.
static unsigned short defaultPrecision()
const bool caseSensitive_
Convience class for FileNameValidators that are to be applied to TwoDArrays.
Smart reference counting pointer class for automatic garbage collection.
std::string getStringValue(ParameterList const ¶mList, std::string const ¶mName)
Get a std::string value for a parameter that is assumed to already be set.
An abstract base class for all ArrayValidators.
ValidStringsList validStringValuesDocs_
bool containsMax
Whetehr or not a maximum value has been specified for this validator.
#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 ...
Convience class for StringValidators that are to be applied to TwoDArrays.
void setStringToIntegralParameter(std::string const ¶mName, std::string const &defaultValue, std::string const &docString, ArrayView< const std::string > const &strings, ArrayView< const std::string > const &stringsDocs, ArrayView< const IntegralType > const &integralValues, ParameterList *paramList)
Set up a std::string parameter with documentation strings for each valid value that will use an embed...
std::string defaultParameterName_
AcceptedTypes & allowLongLong(bool _allowLongLong)
Set allow an long long value or not.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void setNumericStringParameter(std::string const ¶mName, std::string const &value, std::string const &docString, ParameterList *paramList, AnyNumberParameterEntryValidator::AcceptedTypes const &acceptedTypes=AnyNumberParameterEntryValidator::AcceptedTypes())
Set an numeric parameter preferred as a std::string that allows for (nearly) any input parameter type...
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.
Standard implementation of a ParameterEntryValidator that accepts numbers from a number of different ...
static T max()
Gets the maximum possible value the number type can take on.
static unsigned short defaultPrecision()
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT RCP< AnyNumberParameterEntryValidator > anyNumberParameterEntryValidator(AnyNumberParameterEntryValidator::EPreferredType const preferredType, AnyNumberParameterEntryValidator::AcceptedTypes const &acceptedTypes)
Nonmember constructor AnyNumberParameterEntryValidator.
EPreferredType preferredType_
std::string toString(const HashSet< Key > &h)
void setStep(T step)
Sets the step being used for the validator.
const std::string getXMLTypeName() const
StringToIntegralParameterEntryValidator(const ArrayView< const std::string > &strings, const ArrayView< const std::string > &stringsDocs, const ArrayView< const IntegralType > &integralValues, const std::string &defaultParameterName, const bool caseSensitive=true)
Construct with a mapping from strings (with documentation) to specified enum or integer values,...
T getMax() const
Gets the maximum acceptable value for the validator.
IntegralType getIntegralValue(ParameterList ¶mList, const std::string ¶mName, const std::string &defaultValue) const
Get the integer enum value for the given parameter.
AbstractArrayValidator(RCP< const ValidatorType > prototypeValidator)
Constructs an AbstractArrayValidator.
ValidStringsList validStringValues() const
static T notDefined()
This function should not compile if there is an attempt to instantiate!
static long long int max()
ArrayNumberValidator(RCP< const EnhancedNumberValidator< T > > prototypeValidator)
ValidStringsList validStringValues_
static unsigned short defaultPrecision()
size_type size() const
The total number of items in the managed array.
any & getAny(bool activeQry=true)
Direct access to the Teuchos::any data value underlying this object. The bool argument activeQry (def...
void setMin(T min)
Sets the minimum acceptable value for the validator.
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
Validate the given ParameterEntry.
void setValidValues(ArrayView< const std::string > const &strings, ArrayView< const std::string > const *stringsDocs=NULL)
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void setLongLongParameter(std::string const ¶mName, long long const value, std::string const &docString, ParameterList *paramList, AnyNumberParameterEntryValidator::AcceptedTypes const &acceptedTypes=AnyNumberParameterEntryValidator::AcceptedTypes())
Set an integer parameter that allows for (nearly) any input parameter type that is convertible to an ...
RCP< StringToIntegralParameterEntryValidator< IntegralType > > stringToIntegralParameterEntryValidator(ArrayView< const std::string > const &strings, ArrayView< const IntegralType > const &integralValues, std::string const &defaultParameterName, const bool caseSensitive)
Nonmember constructor (see implementation).
static float defaultStep()
Class uesd to validate a particular type of number.
const std::string getXMLTypeName() const
Class for retrieving a dummy object of type T.
static std::ostream & printLines(std::ostream &os, const std::string &linePrefix, const std::string &lines)
Print lines with prefix first.
static short int defaultStep()
virtual void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
Defines basic traits returning the name of a type in a portable and readable way.
static unsigned int max()
IntegralType getIntegralValue(ParameterList const ¶mList, std::string const ¶mName)
Get an integral value for a parameter that is assumed to already be set.
static long unsigned int defaultStep()
static const std::string & getLongLongEnumString()
std::string getStringValue(ParameterList ¶mList, const std::string ¶mName, const std::string &defaultValue) const
Lookup a parameter from a parameter list, validate the std::string value, and return the std::string ...
unsigned short getPrecision() const
Gets the precision specified for the validator.
static const std::string & getIntEnumString()
bool hasMax() const
Determines whether or not the validator has a maximum value.
std::string validateString(const std::string &str, const std::string ¶mName="", const std::string &sublistName="") const
Validate the std::string and pass it on.
virtual void printDoc(std::string const &docString, std::ostream &out) const
static std::string upperCase(const std::string s)
Return an upper-case copy of the string s.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT int getIntParameter(ParameterList const ¶mList, std::string const ¶mName)
Get an integer parameter.
ValidStringsList validStringValues() const
const AcceptedTypes acceptedTypes_
static unsigned short defaultPrecision()
size_type getNumCols() const
returns the number of columns in the TwoDArray.
Standard implementation of a ParameterEntryValidator that maps from a list of strings to an enum or i...
TwoDArrayValidator(RCP< const ValidatorType > prototypeValidator)
Constructs a ArrayValidator.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT long long getLongLongParameter(ParameterList const ¶mList, std::string const ¶mName)
Get a long long parameter.
void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const
std::string acceptedTypesString_
Validate a file name entry.
ArrayFileNameValidator(RCP< const FileNameValidator > prototypeValidator)
static long long int min()
std::string typeName() const
Return the name of the type.
static T min()
Gets the minimum possible value the number type can take on.
bool isCaseSensitive() const
Whether this validator is case sensitive.
bool containsMin
Whether or not a minimum value has been specified for this validator.
const std::string & getDefaultParameterName() const
Get the name of the default parameter for the validator.
void printDoc(std::string const &docString, std::ostream &out) const
Print documentation to the given output string.
static unsigned short defaultPrecision()
Gets the default precision with which the number type should be displayed.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT RCP< BoolParameterEntryValidator > boolParameterEntryValidator()
Nonmember constructor BoolParameterEntryValidator.
T step_
The increment to use when increaseing or decreaseing the value the validator is validating.
void printDoc(std::string const &docString, std::ostream &out) const
ArrayStringValidator(RCP< const StringValidator > prototypeValidator)
const std::string & name() const
The name of this ParameterList.
bool allowDouble() const
Allow an double value?
Takes a validator, wraps it, and applies it to a TwoDArray.
TwoDArrayFileNameValidator(RCP< const FileNameValidator > prototypeValidator)
void validateAndModify(std::string const ¶mName, std::string const &sublistName, ParameterEntry *entry) const
A list of parameters of arbitrary type.
A thin wrapper around the Teuchos Array class that allows for 2 dimensional arrays.
AcceptedTypes & allowDouble(bool _allowDouble)
Set allow a double value or not.
unsigned short precision_
The number of decimal places with which the nubmer will be displayed in a UI. This value is meaningle...
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT RCP< AnyNumberParameterEntryValidator > anyNumberParameterEntryValidator()
Nonmember constructor AnyNumberParameterEntryValidator.
RCP< StringToIntegralParameterEntryValidator< IntegralType > > stringToIntegralParameterEntryValidator(ArrayView< const std::string > const &strings, ArrayView< const IntegralType > const &integralValues, std::string const &defaultParameterName)
Nonmember constructor (see implementation).
Takes a validator, wraps it, and applies it to an array.
StringToIntegralParameterEntryValidator()
static unsigned short defaultPrecision()
void setStringToIntegralParameter(std::string const ¶mName, std::string const &defaultValue, std::string const &docString, ArrayView< const std::string > const &strings, ArrayView< const IntegralType > const &integralValues, ParameterList *paramList)
Set up a std::string parameter that will use an embedded validator to allow the extraction of an inte...
static short unsigned int max()
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.
bool hasMin() const
Determines whether or not the validator has a minimum value.
Class defining the traits of the number type being used in an EnhancedNumberValidator.
static long long int defaultStep()
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
This object is held as the "value" in the Teuchos::ParameterList std::map.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
EPreferredType
Determines what type is the preferred type.
void setPrecision(unsigned short precision)
Sets the precision specified for the validator.
T maxVal
The maximum value accepted by the validator.
static double defaultStep()
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.
AcceptedTypes & allowString(bool _allowString)
Set allow an std::string value or not.
static long unsigned int max()
std::string acceptedTypesString_
ValidStringsList getStringDocs() const
Get a pointer to the array containing all the documentation strings.
RCP< const ValidatorType > getPrototype() const
Returns the prototype validator for this Array Validator.
TwoDArrayNumberValidator(RCP< const EnhancedNumberValidator< T > > prototypeValidator)
static long unsigned int min()
std::map< std::string, IntegralType > map_t
void setMax(T max)
Sets the maximum acceptable value for the validator.
Modified boost::any class, which is a container for a templated value.
const std::string getXMLTypeName() const
Determines the types that are accepted.
static long long unsigned int defaultStep()