00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H
00030 #define TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H
00031
00032 #include "Teuchos_ParameterEntryValidator.hpp"
00033 #include "Teuchos_ParameterList.hpp"
00034 #include "Teuchos_ParameterListExceptions.hpp"
00035 #include "Teuchos_VerbosityLevel.hpp"
00036 #include "Teuchos_Array.hpp"
00037 #include "Teuchos_StrUtils.hpp"
00038 #include "Teuchos_TypeNameTraits.hpp"
00039
00040
00041 namespace Teuchos {
00042
00043
00053 template<class IntegralType>
00054 class StringToIntegralParameterEntryValidator : public ParameterEntryValidator {
00055 public:
00056
00059
00068 StringToIntegralParameterEntryValidator(
00069 ArrayView<const std::string> const& strings,
00070 std::string const& defaultParameterName
00071 );
00072
00088 StringToIntegralParameterEntryValidator(
00089 ArrayView<const std::string> const& strings,
00090 ArrayView<const IntegralType> const& integralValues,
00091 std::string const& defaultParameterName
00092 );
00093
00112 StringToIntegralParameterEntryValidator(
00113 ArrayView<const std::string> const& strings,
00114 ArrayView<const std::string> const& stringsDocs,
00115 ArrayView<const IntegralType> const& integralValues,
00116 std::string const& defaultParameterName
00117 );
00118
00120
00123
00134 IntegralType getIntegralValue(
00135 const std::string &str, const std::string ¶mName = "",
00136 const std::string &sublistName = ""
00137 ) const;
00138
00152 IntegralType getIntegralValue(
00153 const ParameterEntry &entry, const std::string ¶mName = "",
00154 const std::string &sublistName = "", const bool activeQuery = true
00155 ) const;
00156
00171 std::string getStringValue(
00172 const ParameterEntry &entry, const std::string ¶mName = "",
00173 const std::string &sublistName = "", const bool activeQuery = true
00174 ) const;
00175
00180 IntegralType getIntegralValue(
00181 ParameterList ¶mList, const std::string ¶mName,
00182 const std::string &defaultValue
00183 ) const;
00184
00188 std::string getStringValue(
00189 ParameterList ¶mList, const std::string ¶mName,
00190 const std::string &defaultValue
00191 ) const;
00192
00202 std::string validateString(
00203 const std::string &str, const std::string ¶mName = "",
00204 const std::string &sublistName = ""
00205 ) const;
00206
00208
00211
00213 void printDoc(
00214 std::string const& docString,
00215 std::ostream & out
00216 ) const;
00217
00219 Teuchos::RCP<const Array<std::string> >
00220 validStringValues() const;
00221
00223 void validate(
00224 ParameterEntry const& entry,
00225 std::string const& paramName,
00226 std::string const& sublistName
00227 ) const;
00228
00230
00231 private:
00232
00233 typedef std::map<std::string,IntegralType> map_t;
00234 std::string defaultParameterName_;
00235 std::string validValues_;
00236 RCP<const Array<std::string> > validStringValues_;
00237 RCP<const Array<std::string> > validStringValuesDocs_;
00238 map_t map_;
00239
00240 void setValidValues(
00241 ArrayView<const std::string> const& strings,
00242 ArrayView<const std::string> const* stringsDocs = NULL
00243 );
00244
00245
00246 StringToIntegralParameterEntryValidator();
00247
00248 };
00249
00250
00255 template<class IntegralType>
00256 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
00257 stringToIntegralParameterEntryValidator(
00258 ArrayView<const std::string> const& strings,
00259 std::string const& defaultParameterName
00260 );
00261
00262
00267 template<class IntegralType>
00268 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
00269 stringToIntegralParameterEntryValidator(
00270 ArrayView<const std::string> const& strings,
00271 ArrayView<const IntegralType> const& integralValues,
00272 std::string const& defaultParameterName
00273 );
00274
00275
00280 template<class IntegralType>
00281 RCP<StringToIntegralParameterEntryValidator<IntegralType> >
00282 stringToIntegralParameterEntryValidator(
00283 ArrayView<const std::string> const& strings,
00284 ArrayView<const std::string> const& stringsDocs,
00285 ArrayView<const IntegralType> const& integralValues,
00286 std::string const& defaultParameterName
00287 );
00288
00289
00300 template<class IntegralType>
00301 void setStringToIntegralParameter(
00302 std::string const& paramName,
00303 std::string const& defaultValue,
00304 std::string const& docString,
00305 ArrayView<const std::string> const& strings,
00306 ParameterList * paramList
00307 );
00308
00309
00320 template<class IntegralType>
00321 void setStringToIntegralParameter(
00322 std::string const& paramName,
00323 std::string const& defaultValue,
00324 std::string const& docString,
00325 ArrayView<const std::string> const& strings,
00326 ArrayView<const IntegralType> const& integralValues,
00327 ParameterList * paramList
00328 );
00329
00330
00342 template<class IntegralType>
00343 void setStringToIntegralParameter(
00344 std::string const& paramName,
00345 std::string const& defaultValue,
00346 std::string const& docString,
00347 ArrayView<const std::string> const& strings,
00348 ArrayView<const std::string> const& stringsDocs,
00349 ArrayView<const IntegralType> const& integralValues,
00350 ParameterList * paramList
00351 );
00352
00353
00363 template<class IntegralType>
00364 IntegralType getIntegralValue(
00365 ParameterList const& paramList, std::string const& paramName
00366 );
00367
00368
00379 template<class IntegralType>
00380 std::string getStringValue(
00381 ParameterList const& paramList, std::string const& paramName
00382 );
00383
00384
00390 template<class IntegralType>
00391 RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
00392 getStringToIntegralParameterEntryValidator(
00393 ParameterEntry const& entry, ParameterList const& paramList,
00394 std::string const& paramName
00395 );
00396
00397
00403 std::string getVerbosityLevelParameterValueName(
00404 const EVerbosityLevel verbLevel
00405 );
00406
00407
00412 RCP<StringToIntegralParameterEntryValidator<EVerbosityLevel> >
00413 verbosityLevelParameterEntryValidator(std::string const& defaultParameterName);
00414
00415
00426 class AnyNumberParameterEntryValidator : public ParameterEntryValidator {
00427 public:
00428
00431
00433 enum EPreferredType { PREFER_INT, PREFER_DOUBLE, PREFER_STRING };
00434
00435
00437 class AcceptedTypes {
00438 public:
00440 AcceptedTypes( bool allowAllTypesByDefault = true )
00441 :allowInt_(allowAllTypesByDefault),allowDouble_(allowAllTypesByDefault),
00442 allowString_(allowAllTypesByDefault)
00443 {}
00445 AcceptedTypes& allowInt( bool _allowInt )
00446 { allowInt_ = _allowInt; return *this; }
00448 AcceptedTypes& allowDouble( bool _allowDouble )
00449 { allowDouble_ = _allowDouble; return *this; }
00451 AcceptedTypes& allowString( bool _allowString )
00452 { allowString_ = _allowString; return *this; }
00454 bool allowInt() const { return allowInt_; }
00456 bool allowDouble() const { return allowDouble_; }
00458 bool allowString() const { return allowString_; }
00459 private:
00460 bool allowInt_;
00461 bool allowDouble_;
00462 bool allowString_;
00463 };
00464
00465
00466
00468
00471
00475 AnyNumberParameterEntryValidator();
00476
00486 AnyNumberParameterEntryValidator(
00487 EPreferredType const preferredType,
00488 AcceptedTypes const& acceptedTypes
00489 );
00490
00492
00495
00497 int getInt(
00498 const ParameterEntry &entry, const std::string ¶mName = "",
00499 const std::string &sublistName = "", const bool activeQuery = true
00500 ) const;
00501
00503 double getDouble(
00504 const ParameterEntry &entry, const std::string ¶mName = "",
00505 const std::string &sublistName = "", const bool activeQuery = true
00506 ) const;
00507
00509 std::string getString(
00510 const ParameterEntry &entry, const std::string ¶mName = "",
00511 const std::string &sublistName = "", const bool activeQuery = true
00512 ) const;
00513
00517 int getInt(
00518 ParameterList ¶mList, const std::string ¶mName,
00519 const int defaultValue
00520 ) const;
00521
00525 double getDouble(
00526 ParameterList ¶mList, const std::string ¶mName,
00527 const double defaultValue
00528 ) const;
00529
00533 std::string getString(
00534 ParameterList ¶mList, const std::string ¶mName,
00535 const std::string &defaultValue
00536 ) const;
00537
00539
00542
00544 void printDoc(
00545 std::string const& docString,
00546 std::ostream & out
00547 ) const;
00548
00550 Teuchos::RCP<const Array<std::string> >
00551 validStringValues() const;
00552
00554 void validate(
00555 ParameterEntry const& entry,
00556 std::string const& paramName,
00557 std::string const& sublistName
00558 ) const;
00559
00561 void validateAndModify(
00562 std::string const& paramName,
00563 std::string const& sublistName,
00564 ParameterEntry * entry
00565 ) const;
00566
00568
00569 private:
00570
00571
00572
00573
00574 EPreferredType preferredType_;
00575 const AcceptedTypes acceptedTypes_;
00576 std::string acceptedTypesString_;
00577
00578
00579
00580
00581 void finishInitialization();
00582
00583 void throwTypeError(
00584 ParameterEntry const& entry,
00585 std::string const& paramName,
00586 std::string const& sublistName
00587 ) const;
00588
00589 };
00590
00591
00592
00593
00594
00599 RCP<AnyNumberParameterEntryValidator>
00600 anyNumberParameterEntryValidator(
00601 AnyNumberParameterEntryValidator::EPreferredType const preferredType,
00602 AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
00603 );
00604
00605
00611 void setIntParameter(
00612 std::string const& paramName,
00613 int const value, std::string const& docString,
00614 ParameterList *paramList,
00615 AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
00616 = AnyNumberParameterEntryValidator::AcceptedTypes()
00617 );
00618
00619
00625 void setDoubleParameter(
00626 std::string const& paramName,
00627 double const& value, std::string const& docString,
00628 ParameterList *paramList,
00629 AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
00630 = AnyNumberParameterEntryValidator::AcceptedTypes()
00631 );
00632
00633
00639 void setNumericStringParameter(
00640 std::string const& paramName,
00641 std::string const& value, std::string const& docString,
00642 ParameterList *paramList,
00643 AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
00644 = AnyNumberParameterEntryValidator::AcceptedTypes()
00645 );
00646
00647
00662 int getIntParameter(
00663 ParameterList const& paramList, std::string const& paramName
00664 );
00665
00666
00681 double getDoubleParameter(
00682 ParameterList const& paramList,
00683 std::string const& paramName
00684 );
00685
00686
00701 std::string getNumericStringParameter(
00702 ParameterList const& paramList,
00703 std::string const& paramName
00704 );
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719 template<class IntegralType>
00720 StringToIntegralParameterEntryValidator<IntegralType>::StringToIntegralParameterEntryValidator(
00721 ArrayView<const std::string> const& strings, std::string const& defaultParameterName
00722 )
00723 :defaultParameterName_(defaultParameterName)
00724 {
00725 typedef typename map_t::value_type val_t;
00726 for( int i = 0; i < static_cast<int>(strings.size()); ++i ) {
00727 const bool unique = map_.insert( val_t( strings[i], i ) ).second;
00728 TEST_FOR_EXCEPTION(
00729 !unique, std::logic_error
00730 ,"Error, the std::string \"" << strings[i] << "\" is a duplicate for parameter \""
00731 << defaultParameterName_ << "\"."
00732 );
00733 }
00734 setValidValues(strings);
00735 }
00736
00737
00738 template<class IntegralType>
00739 StringToIntegralParameterEntryValidator<IntegralType>::StringToIntegralParameterEntryValidator(
00740 ArrayView<const std::string> const& strings, ArrayView<const IntegralType> const& integralValues
00741 ,std::string const& defaultParameterName
00742 )
00743 :defaultParameterName_(defaultParameterName)
00744 {
00745 #ifdef TEUCHOS_DEBUG
00746 TEST_FOR_EXCEPT( strings.size() != integralValues.size() );
00747 #endif
00748 typedef typename map_t::value_type val_t;
00749 for( int i = 0; i < static_cast<int>(strings.size()); ++i ) {
00750 const bool unique = map_.insert( val_t( strings[i], integralValues[i] ) ).second;
00751 TEST_FOR_EXCEPTION(
00752 !unique, std::logic_error
00753 ,"Error, the std::string \"" << strings[i] << "\" is a duplicate for parameter \""
00754 << defaultParameterName_ << "\""
00755 );
00756 }
00757 setValidValues(strings);
00758 }
00759
00760
00761 template<class IntegralType>
00762 StringToIntegralParameterEntryValidator<IntegralType>::StringToIntegralParameterEntryValidator(
00763 ArrayView<const std::string> const& strings
00764 ,ArrayView<const std::string> const& stringsDocs
00765 ,ArrayView<const IntegralType> const& integralValues
00766 ,std::string const& defaultParameterName
00767 )
00768 :defaultParameterName_(defaultParameterName)
00769 {
00770 #ifdef TEUCHOS_DEBUG
00771 TEST_FOR_EXCEPT( strings.size() != stringsDocs.size() );
00772 TEST_FOR_EXCEPT( strings.size() != integralValues.size() );
00773 #endif
00774 typedef typename map_t::value_type val_t;
00775 for( int i = 0; i < static_cast<int>(strings.size()); ++i ) {
00776 const bool unique = map_.insert( val_t( strings[i], integralValues[i] ) ).second;
00777 TEST_FOR_EXCEPTION(
00778 !unique, std::logic_error
00779 ,"Error, the std::string \"" << strings[i] << "\" is a duplicate for parameter \""
00780 << defaultParameterName_ << "\""
00781 );
00782 }
00783 setValidValues(strings,&stringsDocs);
00784 }
00785
00786
00787
00788
00789
00790 template<class IntegralType>
00791 IntegralType
00792 StringToIntegralParameterEntryValidator<IntegralType>::getIntegralValue(
00793 const std::string &str, const std::string ¶mName
00794 ,const std::string &sublistName
00795 ) const
00796 {
00797 typename map_t::const_iterator itr = map_.find(str);
00798 TEST_FOR_EXCEPTION_PURE_MSG(
00799 itr == map_.end(), Exceptions::InvalidParameterValue
00800 ,"Error, the value \"" << str << "\" is not recognized for the parameter \""
00801 << ( paramName.length() ? paramName : defaultParameterName_ ) << "\""
00802 << "\nin the sublist \"" << sublistName << "\"."
00803 << "\n\nValid values include:"
00804 << "\n {\n"
00805 << validValues_
00806 << " }"
00807 );
00808 return (*itr).second;
00809 }
00810
00811
00812 template<class IntegralType>
00813 IntegralType
00814 StringToIntegralParameterEntryValidator<IntegralType>::getIntegralValue(
00815 const ParameterEntry &entry, const std::string ¶mName
00816 ,const std::string &sublistName, const bool activeQuery
00817 ) const
00818 {
00819 const bool validType = ( entry.getAny(activeQuery).type() == typeid(std::string) );
00820 TEST_FOR_EXCEPTION_PURE_MSG(
00821 !validType, Exceptions::InvalidParameterType
00822 ,"Error, the parameter {paramName=\""<<(paramName.length()?paramName:defaultParameterName_)
00823 << "\",type=\""<<entry.getAny(activeQuery).typeName()<<"\"}"
00824 << "\nin the sublist \"" << sublistName << "\""
00825 << "\nhas the wrong type."
00826 << "\n\nThe correct type is \"string\"!"
00827 );
00828 const std::string
00829 &strValue = any_cast<std::string>(entry.getAny(activeQuery));
00830 return getIntegralValue(strValue,paramName,sublistName);
00831 }
00832
00833
00834 template<class IntegralType>
00835 std::string
00836 StringToIntegralParameterEntryValidator<IntegralType>::getStringValue(
00837 const ParameterEntry &entry, const std::string ¶mName
00838 ,const std::string &sublistName, const bool activeQuery
00839 ) const
00840 {
00841
00842 this->getIntegralValue(entry,paramName,sublistName,activeQuery);
00843
00844 return any_cast<std::string>(entry.getAny(activeQuery));
00845 }
00846
00847
00848 template<class IntegralType>
00849 IntegralType
00850 StringToIntegralParameterEntryValidator<IntegralType>::getIntegralValue(
00851 ParameterList ¶mList, const std::string ¶mName
00852 ,const std::string &defaultValue
00853 ) const
00854 {
00855 const std::string
00856 &strValue = paramList.get(paramName,defaultValue);
00857 return getIntegralValue(strValue,paramName,paramList.name());
00858 }
00859
00860
00861 template<class IntegralType>
00862 std::string
00863 StringToIntegralParameterEntryValidator<IntegralType>::getStringValue(
00864 ParameterList ¶mList, const std::string ¶mName
00865 ,const std::string &defaultValue
00866 ) const
00867 {
00868 const std::string
00869 &strValue = paramList.get(paramName,defaultValue);
00870 getIntegralValue(strValue,paramName,paramList.name());
00871 return strValue;
00872 }
00873
00874
00875 template<class IntegralType>
00876 std::string
00877 StringToIntegralParameterEntryValidator<IntegralType>::validateString(
00878 const std::string &str, const std::string ¶mName
00879 ,const std::string &sublistName
00880 ) const
00881 {
00882 getIntegralValue(str,paramName,sublistName);
00883 return str;
00884 }
00885
00886
00887
00888
00889
00890 template<class IntegralType>
00891 void StringToIntegralParameterEntryValidator<IntegralType>::printDoc(
00892 std::string const& docString
00893 ,std::ostream & out
00894 ) const
00895 {
00896 StrUtils::printLines(out,"# ",docString);
00897 out << "# Valid std::string values:\n";
00898 out << "# {\n";
00899 if(validStringValuesDocs_.get()) {
00900 for( int i = 0; i < static_cast<int>(validStringValues_->size()); ++i ) {
00901 out << "# \"" << (*validStringValues_)[i] << "\"\n";
00902 StrUtils::printLines(out,"# ",(*validStringValuesDocs_)[i] );
00903 }
00904 }
00905 else {
00906 StrUtils::printLines(out,"# ",validValues_);
00907
00908
00909 }
00910 out << "# }\n";
00911 }
00912
00913
00914 template<class IntegralType>
00915 Teuchos::RCP<const Array<std::string> >
00916 StringToIntegralParameterEntryValidator<IntegralType>::validStringValues() const
00917 {
00918 return validStringValues_;
00919 }
00920
00921
00922 template<class IntegralType>
00923 void StringToIntegralParameterEntryValidator<IntegralType>::validate(
00924 ParameterEntry const& entry
00925 ,std::string const& paramName
00926 ,std::string const& sublistName
00927 ) const
00928 {
00929 this->getIntegralValue(entry,paramName,sublistName,false);
00930 }
00931
00932
00933
00934
00935
00936 template<class IntegralType>
00937 void StringToIntegralParameterEntryValidator<IntegralType>::setValidValues(
00938 ArrayView<const std::string> const& strings
00939 ,ArrayView<const std::string> const* stringsDocs
00940 )
00941 {
00942 validStringValues_ = rcp(new Array<std::string>(strings));
00943 if(stringsDocs)
00944 validStringValuesDocs_ = rcp(new Array<std::string>(*stringsDocs));
00945
00946
00947 std::ostringstream oss;
00948 typename map_t::const_iterator itr = map_.begin();
00949 for( int i = 0; i < static_cast<int>(strings.size()); ++i ) {
00950 oss << " \""<<strings[i]<<"\"\n";
00951 }
00952
00953 validValues_ = oss.str();
00954 }
00955
00956
00957 }
00958
00959
00960
00961
00962
00963
00964
00965 template<class IntegralType>
00966 inline
00967 Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<IntegralType> >
00968 Teuchos::stringToIntegralParameterEntryValidator(
00969 ArrayView<const std::string> const& strings,
00970 std::string const& defaultParameterName
00971 )
00972 {
00973 return rcp(
00974 new StringToIntegralParameterEntryValidator<IntegralType>(
00975 strings, defaultParameterName
00976 )
00977 );
00978 }
00979
00980
00981 template<class IntegralType>
00982 inline
00983 Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<IntegralType> >
00984 Teuchos::stringToIntegralParameterEntryValidator(
00985 ArrayView<const std::string> const& strings,
00986 ArrayView<const IntegralType> const& integralValues,
00987 std::string const& defaultParameterName
00988 )
00989 {
00990 return rcp(
00991 new StringToIntegralParameterEntryValidator<IntegralType>(
00992 strings, integralValues, defaultParameterName
00993 )
00994 );
00995 }
00996
00997
00998 template<class IntegralType>
00999 inline
01000 Teuchos::RCP< Teuchos::StringToIntegralParameterEntryValidator<IntegralType> >
01001 Teuchos::stringToIntegralParameterEntryValidator(
01002 ArrayView<const std::string> const& strings,
01003 ArrayView<const std::string> const& stringsDocs,
01004 ArrayView<const IntegralType> const& integralValues,
01005 std::string const& defaultParameterName
01006 )
01007 {
01008 return rcp(
01009 new StringToIntegralParameterEntryValidator<IntegralType>(
01010 strings, stringsDocs, integralValues, defaultParameterName
01011 )
01012 );
01013 }
01014
01015
01016 template<class IntegralType>
01017 void Teuchos::setStringToIntegralParameter(
01018 std::string const& paramName,
01019 std::string const& defaultValue,
01020 std::string const& docString,
01021 ArrayView<const std::string> const& strings,
01022 ParameterList * paramList
01023 )
01024 {
01025 TEST_FOR_EXCEPT(0==paramList);
01026 paramList->set(
01027 paramName, defaultValue, docString,
01028 stringToIntegralParameterEntryValidator<IntegralType>(
01029 strings, paramName
01030 )
01031 );
01032 }
01033
01034
01035 template<class IntegralType>
01036 void Teuchos::setStringToIntegralParameter(
01037 std::string const& paramName,
01038 std::string const& defaultValue,
01039 std::string const& docString,
01040 ArrayView<const std::string> const& strings,
01041 ArrayView<const IntegralType> const& integralValues,
01042 ParameterList * paramList
01043 )
01044 {
01045 TEST_FOR_EXCEPT(0==paramList);
01046 paramList->set(
01047 paramName, defaultValue, docString,
01048 stringToIntegralParameterEntryValidator<IntegralType>(
01049 strings, integralValues, paramName
01050 )
01051 );
01052 }
01053
01054
01055 template<class IntegralType>
01056 void Teuchos::setStringToIntegralParameter(
01057 std::string const& paramName,
01058 std::string const& defaultValue,
01059 std::string const& docString,
01060 ArrayView<const std::string> const& strings,
01061 ArrayView<const std::string> const& stringsDocs,
01062 ArrayView<const IntegralType> const& integralValues,
01063 ParameterList * paramList
01064 )
01065
01066 {
01067 TEST_FOR_EXCEPT(0==paramList);
01068 paramList->set(
01069 paramName, defaultValue, docString,
01070 stringToIntegralParameterEntryValidator<IntegralType>(
01071 strings, stringsDocs, integralValues, paramName
01072 )
01073 );
01074 }
01075
01076
01077 template<class IntegralType>
01078 IntegralType Teuchos::getIntegralValue(
01079 ParameterList const& paramList, std::string const& paramName
01080 )
01081 {
01082 const ParameterEntry &entry = paramList.getEntry(paramName);
01083 RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
01084 integralValidator = getStringToIntegralParameterEntryValidator<IntegralType>(
01085 entry, paramList, paramName
01086 );
01087 return integralValidator->getIntegralValue(
01088 entry, paramName, paramList.name(), true
01089 );
01090 }
01091
01092
01093 template<class IntegralType>
01094 std::string Teuchos::getStringValue(
01095 ParameterList const& paramList, std::string const& paramName
01096 )
01097 {
01098 const ParameterEntry &entry = paramList.getEntry(paramName);
01099 RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
01100 integralValidator = getStringToIntegralParameterEntryValidator<IntegralType>(
01101 entry, paramList, paramName
01102 );
01103 return integralValidator->getStringValue(
01104 entry, paramName, paramList.name(), true
01105 );
01106 }
01107
01108
01109 template<class IntegralType>
01110 Teuchos::RCP<const Teuchos::StringToIntegralParameterEntryValidator<IntegralType> >
01111 Teuchos::getStringToIntegralParameterEntryValidator(
01112 ParameterEntry const& entry, ParameterList const& paramList,
01113 std::string const& paramName
01114 )
01115 {
01116 RCP<const ParameterEntryValidator>
01117 validator = entry.validator();
01118 TEST_FOR_EXCEPTION_PURE_MSG(
01119 is_null(validator), Exceptions::InvalidParameterType,
01120 "Error! The parameter \""<<paramName<<"\" exists\n"
01121 "in the parameter (sub)list \""<<paramList.name()<<"\"\n"
01122 "but it does not contain any validator needed to extract\n"
01123 "an integral value of type \""<<TypeNameTraits<IntegralType>::name()<<"\"!"
01124 );
01125 RCP<const StringToIntegralParameterEntryValidator<IntegralType> >
01126 integralValidator
01127 =
01128 rcp_dynamic_cast<const StringToIntegralParameterEntryValidator<IntegralType> >(
01129 validator
01130 );
01131 TEST_FOR_EXCEPTION_PURE_MSG(
01132 is_null(integralValidator), Exceptions::InvalidParameterType,
01133 "Error! The parameter \""<<paramName<<"\" exists\n"
01134 "in the parameter (sub)list \""<<paramList.name()<<"\"\n"
01135 "but it contains the wrong type of validator. The expected validator type\n"
01136 "is \""<<TypeNameTraits<StringToIntegralParameterEntryValidator<IntegralType> >::name()<<"\"\n"
01137 "but the contained validator type is \""<<typeName(*validator)<<"\"!"
01138 );
01139 return integralValidator;
01140 }
01141
01142
01143 #endif // TEUCHOS_STANDARD_PARAMETER_ENTRY_VALIDATORS_H