42 #ifndef TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H 43 #define TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H 45 #include "Teuchos_ParameterEntryValidator.hpp" 47 #include "Teuchos_ParameterListExceptions.hpp" 50 #include "Teuchos_Assert.hpp" 55 #ifdef HAVE_TEUCHOSCORE_QUADMATH 56 # include <quadmath.h> 57 #endif // HAVE_TEUCHOSCORE_QUADMATH 91 template<
class IntegralType>
115 const std::string& defaultParameterName,
116 const bool caseSensitive =
true);
143 std::string
const& defaultParameterName,
144 const bool caseSensitive =
true);
178 const std::string& defaultParameterName,
179 const bool caseSensitive =
true);
195 const std::string &str,
const std::string ¶mName =
"",
196 const std::string &sublistName =
"" 216 const std::string ¶mName =
"",
217 const std::string &sublistName =
"",
218 const bool activeQuery =
true)
const;
237 const std::string ¶mName =
"",
238 const std::string &sublistName =
"",
239 const bool activeQuery =
true)
const;
249 const std::string& paramName,
250 const std::string& defaultValue)
const;
257 const std::string &defaultValue
285 const std::string &str,
const std::string ¶mName =
"",
286 const std::string &sublistName =
"" 294 return caseSensitive_;
306 std::string
const& docString,
317 std::string
const& paramName,
318 std::string
const& sublistName
324 std::string defaultParameterName_;
325 std::string validValues_;
329 typedef std::map<std::string,IntegralType> map_t;
332 const bool caseSensitive_;
343 static std::string upperCase (
const std::string s) {
344 std::string s_upper = s;
345 std::transform (s_upper.begin (), s_upper.end (), s_upper.begin (), ::toupper);
355 template<
class 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>
443 void setStringToIntegralParameter(
444 std::string
const& paramName,
445 std::string
const& defaultValue,
446 std::string
const& docString,
463 template<
class IntegralType>
464 void setStringToIntegralParameter(
465 std::string
const& paramName,
466 std::string
const& defaultValue,
467 std::string
const& docString,
485 template<
class IntegralType>
486 void setStringToIntegralParameter(
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
642 std::string
const& docString,
653 std::string
const& paramName,
654 std::string
const& sublistName
659 std::string
const& paramName,
660 std::string
const& sublistName,
671 std::string acceptedTypesString_;
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");
890 std::string
const& docString,
901 std::string
const& paramName,
902 std::string
const& sublistName
907 std::string
const& paramName,
908 std::string
const& sublistName,
921 std::string acceptedTypesString_;
925 #pragma warning(push) 926 #pragma warning(disable:4251) 937 static const std::string& getIntEnumString(){
939 return intEnumString_;
943 static const std::string& getDoubleEnumString(){
945 return doubleEnumString_;
949 static const std::string& getStringEnumString(){
951 return stringEnumString_;
955 void finishInitialization();
959 std::string
const& paramName,
960 std::string
const& sublistName
974 anyNumberParameterEntryValidator();
982 anyNumberParameterEntryValidator(
992 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
void setIntParameter(
993 std::string
const& paramName,
994 int const value, std::string
const& docString,
1006 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
void setDoubleParameter(
1007 std::string
const& paramName,
1008 double const& value, std::string
const& docString,
1020 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
void setNumericStringParameter(
1021 std::string
const& paramName,
1022 std::string
const& value, std::string
const& docString,
1043 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
int getIntParameter(
1044 ParameterList const& paramList, std::string
const& paramName
1062 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
double getDoubleParameter(
1064 std::string
const& paramName
1083 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT std::string getNumericStringParameter(
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(); }
1174 static inline short int defaultStep() {
return 1; }
1175 static inline unsigned short defaultPrecision() {
return 0; }
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(); }
1184 static inline short unsigned int defaultStep() {
return 1; }
1185 static inline unsigned short defaultPrecision() {
return 0; }
1192 static inline int min() {
return std::numeric_limits<int>::min(); }
1193 static inline int max() {
return std::numeric_limits<int>::max(); }
1194 static inline int defaultStep() {
return 1; }
1195 static inline unsigned short defaultPrecision() {
return 0; }
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(); }
1204 static inline unsigned int defaultStep() {
return 1; }
1205 static inline unsigned short defaultPrecision() {
return 0; }
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(); }
1214 static inline long int defaultStep() {
return 1; }
1215 static inline unsigned short defaultPrecision() {
return 0; }
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(); }
1224 static inline long unsigned int defaultStep() {
return 1; }
1225 static inline unsigned short defaultPrecision() {
return 0; }
1229 #ifdef HAVE_TEUCHOS_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; }
1238 static inline unsigned short defaultPrecision() {
return 0; }
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; }
1248 static inline unsigned short defaultPrecision() {
return 0; }
1252 #endif // HAVE_TEUCHOS_LONG_LONG_INT 1255 #ifdef HAVE_TEUCHOSCORE_QUADMATH 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; }
1262 static inline unsigned short defaultPrecision() {
return 100; }
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(); }
1271 static inline double defaultStep() {
return 1; }
1272 static inline unsigned short defaultPrecision() {
return 100; }
1278 static inline float min() {
return -std::numeric_limits<float>::max(); }
1279 static inline float max() {
return std::numeric_limits<float>::max(); }
1280 static inline float defaultStep() {
return 1; }
1281 static inline unsigned short defaultPrecision() {
return 100; }
1317 minVal(min), maxVal(max), step_(step), precision_(precision),
1318 containsMin(true), containsMax(true){}
1330 containsMax(false){}
1368 precision_ = precision;
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;
1477 bool useIntConversions()
const;
1499 unsigned short precision_;
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);
1746 std::string
const ¶mName,
1747 std::string
const &sublistName)
const;
1753 void printDoc(std::string
const &docString, std::ostream &out)
const;
1765 bool mustAlreadyExist_;
1843 std::string
const &sublistName)
const;
1849 void printDoc(std::string
const &docString, std::ostream &out)
const;
1892 template<
class Val
idatorType,
class EntryType>
1908 prototypeValidator_(prototypeValidator){}
1917 return prototypeValidator_;
1927 return prototypeValidator_->validStringValues();
1960 template<
class Val
idatorType,
class EntryType>
1982 std::string
const &sublistName)
const;
1986 return "TwoDArrayValidator(" +
1987 this->getPrototype()->getXMLTypeName() +
", " +
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";
1998 this->getPrototype()->printDoc(toPrint, out);
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(" +
2173 this->getPrototype()->getXMLTypeName() +
", " +
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";
2184 this->getPrototype()->printDoc(toPrint, out);
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\"!" 2479 &strValue = any_cast<std::string>(entry.
getAny(activeQuery));
2480 return getIntegralValue(strValue,paramName,sublistName);
2484 template<
class IntegralType>
2488 ,
const std::string &sublistName,
const bool activeQuery
2492 this->getIntegralValue(entry,paramName,sublistName,activeQuery);
2494 return any_cast<std::string>(entry.
getAny(activeQuery));
2498 template<
class IntegralType>
2502 ,
const std::string &defaultValue
2505 const std::string& strValue =
2506 paramList.
get (paramName,
2507 caseSensitive_ ? defaultValue : upperCase (defaultValue));
2508 return getIntegralValue (strValue, paramName, paramList.
name ());
2512 template<
class IntegralType>
2516 ,
const std::string &defaultValue
2519 const std::string& strValue =
2520 paramList.
get (paramName,
2521 caseSensitive_ ? defaultValue : upperCase (defaultValue));
2522 getIntegralValue(strValue,paramName,paramList.
name());
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
2547 getIntegralValue (caseSensitive_ ? str : upperCase (str),
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
2601 this->getIntegralValue (entry, paramName, sublistName,
false);
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(
2650 std::string
const& defaultParameterName
2655 strings, defaultParameterName
2661 template<
class IntegralType>
2664 Teuchos::stringToIntegralParameterEntryValidator(
2666 std::string
const& defaultParameterName,
2667 const bool caseSensitive
2671 return rcp (
new ret_type (strings, defaultParameterName, caseSensitive));
2676 template<
class IntegralType>
2679 Teuchos::stringToIntegralParameterEntryValidator(
2682 std::string
const& defaultParameterName
2687 strings, integralValues, defaultParameterName
2693 template<
class IntegralType>
2696 Teuchos::stringToIntegralParameterEntryValidator(
2699 std::string
const& defaultParameterName,
2700 const bool caseSensitive)
2703 return rcp (
new ret_type (strings, integralValues,
2704 defaultParameterName, caseSensitive));
2708 template<
class IntegralType>
2711 Teuchos::stringToIntegralParameterEntryValidator(
2715 std::string
const& defaultParameterName
2720 strings, stringsDocs, integralValues, defaultParameterName
2726 template<
class IntegralType>
2729 Teuchos::stringToIntegralParameterEntryValidator(
2733 std::string
const& defaultParameterName,
2734 const bool caseSensitive)
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,
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,
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,
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
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
2834 integralValidator = getStringToIntegralParameterEntryValidator<IntegralType>(
2835 entry, paramList, paramName
2837 return integralValidator->getStringValue(
2838 entry, paramName, paramList.name(), true
2843 template<
class IntegralType>
2847 std::string
const& paramName
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" 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" 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< StringToIntegralParameterEntryValidator< IntegralType > > stringToIntegralParameterEntryValidator(ArrayView< const std::string > const &strings, std::string const &defaultParameterName)
Nonmember constructor (see implementation).
const std::string getXMLTypeName() const
EnhancedNumberValidator()
Constructs a EnhancedNumberValidator without an explicit minimum or maximum.
void printDoc(std::string const &docString, std::ostream &out) const
Convience class for StringValidators that are to be applied to TwoDArrays.
bool is_null(const boost::shared_ptr< T > &p)
Returns true if p.get()==NULL.
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.
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.
Convience class for EnhancedNumberValidators that are to be applied to arrays.
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.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Set a parameter whose value has type T.
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
bool hasMax() const
Determines whether or not the validator has a maximum value.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
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
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.
size_type size() const
The total number of items in the managed array.
static std::ostream & printLines(std::ostream &os, const std::string &linePrefix, const std::string &lines)
Print lines with prefix first.
EVerbosityLevel
Verbosity level.
unsigned short getPrecision() const
Gets the precision specified for the validator.
ValidStringsList getStringDocs() const
Get a pointer to the array containing all the documentation strings.
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.
virtual void printDoc(std::string const &docString, std::ostream &out) const
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.
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
A thin wrapper around the Array class which causes it to be interpreted as a 2D Array.
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!
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.
const std::string getXMLTypeName() const
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
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.
Validate a file name entry.
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.
RCP< const ParameterEntryValidator > validator() const
Return the (optional) validator object.
A list of parameters of arbitrary type.
ValidStringsList validStringValues() const
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.
bool allowDouble() const
Allow an double value?
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.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
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?
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.
void validateAndModify(std::string const ¶mName, std::string const &sublistName, ParameterEntry *entry) const
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)
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 ...
Standard implementation of a ParameterEntryValidator that accepts numbers from a number of different ...
T getMin() const
Gets the minimum acceptable value for the validator.
ParameterEntry & getEntry(const std::string &name)
Retrieves an entry with the name name.
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
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()
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
bool hasMin() const
Determines whether or not the validator has a minimum value.
#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)