Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Teuchos_StandardParameterEntryValidators.cpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #include "Teuchos_StandardParameterEntryValidators.hpp"
00043 
00044 std::string Teuchos::getVerbosityLevelParameterValueName(
00045   const EVerbosityLevel verbLevel
00046   )
00047 {
00048   switch(verbLevel) {
00049     case VERB_DEFAULT:
00050       return "default";
00051     case VERB_NONE:
00052       return "none";
00053     case VERB_LOW:
00054       return "low";
00055     case VERB_MEDIUM:
00056       return "medium";
00057     case VERB_HIGH:
00058       return "high";
00059     case VERB_EXTREME:
00060       return "extreme";
00061     default:
00062       TEST_FOR_EXCEPT("Should never get here!");
00063   }
00064   return ""; // Never get here!
00065 }
00066 
00067 
00068 Teuchos::RCP<
00069   Teuchos::StringToIntegralParameterEntryValidator<Teuchos::EVerbosityLevel>
00070   >
00071 Teuchos::verbosityLevelParameterEntryValidator(
00072   std::string const& defaultParameterName
00073   )
00074 {
00075   return rcp(
00076     new StringToIntegralParameterEntryValidator<EVerbosityLevel>(
00077       tuple<std::string>(
00078         getVerbosityLevelParameterValueName(VERB_DEFAULT),
00079         getVerbosityLevelParameterValueName(VERB_NONE),
00080         getVerbosityLevelParameterValueName(VERB_LOW),
00081         getVerbosityLevelParameterValueName(VERB_MEDIUM),
00082         getVerbosityLevelParameterValueName(VERB_HIGH),
00083         getVerbosityLevelParameterValueName(VERB_EXTREME)
00084         ),
00085       tuple<std::string>(
00086         "Use level set in code",
00087         "Produce no output",
00088         "Produce minimal output",
00089         "Produce a little more output",
00090         "Produce a higher level of output",
00091         "Produce the highest level of output"
00092         ),
00093       tuple<EVerbosityLevel>(
00094         VERB_DEFAULT,
00095         VERB_NONE,
00096         VERB_LOW,
00097         VERB_MEDIUM,
00098         VERB_HIGH,
00099         VERB_EXTREME
00100         ),
00101       defaultParameterName
00102       )
00103     );
00104 }
00105 
00106 
00107 namespace Teuchos {
00108 
00109 
00110 //
00111 // AnyNumberParameterEntryValidator
00112 //
00113 
00114 
00115 // Constructors
00116 
00117 
00118 AnyNumberParameterEntryValidator::AnyNumberParameterEntryValidator()
00119   : preferredType_(PREFER_DOUBLE), acceptedTypes_(AcceptedTypes())
00120 {
00121   finishInitialization();
00122 }
00123 
00124 
00125 AnyNumberParameterEntryValidator::AnyNumberParameterEntryValidator(
00126   EPreferredType const preferredType, AcceptedTypes const& acceptedTypes
00127   )
00128   : preferredType_(preferredType), acceptedTypes_(acceptedTypes)
00129 {
00130   finishInitialization();
00131 }
00132 
00133 //  Local non-virtual validated lookup functions
00134 
00135 
00136 int AnyNumberParameterEntryValidator::getInt(
00137   const ParameterEntry &entry, const std::string &paramName,
00138   const std::string &sublistName, const bool activeQuery
00139   ) const
00140 {
00141   const any &anyValue = entry.getAny(activeQuery);
00142   if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
00143     return any_cast<int>(anyValue);
00144   if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
00145     return static_cast<int>(any_cast<double>(anyValue));
00146   if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
00147     return std::atoi(any_cast<std::string>(anyValue).c_str());
00148   throwTypeError(entry,paramName,sublistName);
00149   return 0; // Will never get here!
00150 }
00151 
00152 
00153 double AnyNumberParameterEntryValidator::getDouble(
00154   const ParameterEntry &entry, const std::string &paramName,
00155   const std::string &sublistName, const bool activeQuery
00156   ) const
00157 {
00158   const any &anyValue = entry.getAny(activeQuery);
00159   if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
00160     return static_cast<double>(any_cast<int>(anyValue));
00161   if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
00162     return any_cast<double>(anyValue);
00163   if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
00164     return std::atof(any_cast<std::string>(anyValue).c_str());
00165   throwTypeError(entry,paramName,sublistName);
00166   return 0.0; // Will never get here!
00167 }
00168 
00169 
00170 std::string AnyNumberParameterEntryValidator::getString(
00171   const ParameterEntry &entry, const std::string &paramName,
00172   const std::string &sublistName, const bool activeQuery
00173   ) const
00174 {
00175   const any &anyValue = entry.getAny(activeQuery);
00176   if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
00177     return Utils::toString(any_cast<int>(anyValue));
00178   if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
00179     return Utils::toString(any_cast<double>(anyValue));
00180   if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
00181     return any_cast<std::string>(anyValue);
00182   throwTypeError(entry,paramName,sublistName);
00183   return ""; // Will never get here!
00184 }
00185 
00186 
00187 int AnyNumberParameterEntryValidator::getInt(
00188   ParameterList &paramList, const std::string &paramName,
00189   const int defaultValue
00190   ) const
00191 {
00192   const ParameterEntry *entry = paramList.getEntryPtr(paramName);
00193   if(entry) return getInt(*entry,paramName,paramList.name(),true);
00194   return paramList.get(paramName,defaultValue);
00195 }
00196 
00197 
00198 double AnyNumberParameterEntryValidator::getDouble(
00199   ParameterList &paramList, const std::string &paramName,
00200   const double defaultValue
00201   ) const
00202 {
00203   const ParameterEntry *entry = paramList.getEntryPtr(paramName);
00204   if(entry) return getDouble(*entry,paramName,paramList.name(),true);
00205   return paramList.get(paramName,defaultValue);
00206 }
00207 
00208 
00209 std::string AnyNumberParameterEntryValidator::getString(
00210   ParameterList &paramList, const std::string &paramName,
00211   const std::string &defaultValue
00212   ) const
00213 {
00214   const ParameterEntry *entry = paramList.getEntryPtr(paramName);
00215   if(entry) return getString(*entry,paramName,paramList.name(),true);
00216   return paramList.get(paramName,defaultValue);
00217 }
00218 
00219 
00220 bool AnyNumberParameterEntryValidator::isDoubleAllowed() const
00221 {
00222   return acceptedTypes_.allowDouble();
00223 }
00224 
00225 
00226 bool AnyNumberParameterEntryValidator::isIntAllowed() const
00227 {
00228   return acceptedTypes_.allowInt();
00229 }
00230 
00231   
00232 bool AnyNumberParameterEntryValidator::isStringAllowed() const
00233 {
00234   return acceptedTypes_.allowString();
00235 }
00236 
00237 
00238 AnyNumberParameterEntryValidator::EPreferredType
00239 AnyNumberParameterEntryValidator::getPreferredType() const
00240 {
00241   return preferredType_;
00242 }
00243 
00244 
00245 // Overridden from ParameterEntryValidator
00246 
00247 
00248 const std::string AnyNumberParameterEntryValidator::getXMLTypeName() const
00249 {
00250   return "anynumberValidator";
00251 }
00252 
00253 
00254 void AnyNumberParameterEntryValidator::printDoc(
00255   std::string  const & docString,
00256   std::ostream & out
00257   ) const
00258 {
00259   StrUtils::printLines(out,"# ",docString);
00260   out << "#  Accepted types: " << acceptedTypesString_ << ".\n";
00261 }
00262 
00263 
00264 ParameterEntryValidator::ValidStringsList
00265 AnyNumberParameterEntryValidator::validStringValues() const
00266 {
00267   return null;
00268 }
00269 
00270 
00271 void AnyNumberParameterEntryValidator::validate(
00272   ParameterEntry const& entry,
00273   std::string const& paramName,
00274   std::string const& sublistName
00275   ) const
00276 {
00277   // Validate (any of the get functions will do!)
00278   getInt(entry,paramName,sublistName,false);
00279 }
00280 
00281 
00282 void AnyNumberParameterEntryValidator::validateAndModify(
00283   std::string const& paramName,
00284   std::string const& sublistName,
00285   ParameterEntry * entry
00286   ) const
00287 {
00288   TEST_FOR_EXCEPT(0==entry);
00289   switch(preferredType_) {
00290     case PREFER_INT:
00291       entry->setValue(
00292         getInt(*entry,paramName,sublistName,false),
00293         false // isDefault
00294         );
00295       break;
00296     case PREFER_DOUBLE:
00297       entry->setValue(
00298         getDouble(*entry,paramName,sublistName,false),
00299         false // isDefault
00300         );
00301       break;
00302     case PREFER_STRING:
00303       entry->setValue(
00304         getString(*entry,paramName,sublistName,false),
00305         false // isDefault
00306         );
00307       break;
00308     default:
00309       TEST_FOR_EXCEPT("Error, Invalid EPreferredType value!");
00310   }
00311 }
00312 
00313 
00314 // private
00315 
00316 
00317 void AnyNumberParameterEntryValidator::finishInitialization()
00318 {
00319 
00320   std::ostringstream oss;
00321   bool addedType = false;
00322   if(acceptedTypes_.allowInt()) {
00323     oss << "\"int\"";
00324     addedType = true;
00325   }
00326   if(acceptedTypes_.allowDouble()) {
00327     if(addedType) oss << ", ";
00328     oss << "\"double\"";
00329     addedType = true;
00330   }
00331   if(acceptedTypes_.allowString()) {
00332     if(addedType) oss << ", ";
00333     oss << "\"string\"";
00334     addedType = true;
00335   }
00336   acceptedTypesString_ = oss.str();
00337 }
00338 
00339 
00340 void AnyNumberParameterEntryValidator::throwTypeError(
00341   ParameterEntry const& entry,
00342   std::string const& paramName,
00343   std::string const& sublistName
00344   ) const
00345 {
00346   const std::string &entryName = entry.getAny(false).typeName();
00347   TEST_FOR_EXCEPTION_PURE_MSG(
00348     true, Exceptions::InvalidParameterType
00349     ,"Error, the parameter {paramName=\""<<paramName<<"\""
00350     ",type=\""<<entryName<<"\"}"
00351     << "\nin the sublist \"" << sublistName << "\""
00352     << "\nhas the wrong type."
00353     << "\n\nThe accepted types are: " << acceptedTypesString_ << "!";
00354     );
00355 }
00356 
00357 RCP<AnyNumberParameterEntryValidator> 
00358   DummyObjectGetter<AnyNumberParameterEntryValidator>::getDummyObject()
00359 {
00360   return anyNumberParameterEntryValidator(
00361     AnyNumberParameterEntryValidator::PREFER_INT, 
00362     AnyNumberParameterEntryValidator::AcceptedTypes());
00363 }
00364 
00365 FileNameValidator::FileNameValidator(bool mustAlreadyExist)
00366   : ParameterEntryValidator(), mustAlreadyExist_(mustAlreadyExist)
00367 {}
00368 
00369 bool FileNameValidator::fileMustExist() const
00370 {
00371   return mustAlreadyExist_;
00372 }
00373 
00374 
00375 bool FileNameValidator::setFileMustExist(bool shouldFileExist)
00376 {
00377   this->mustAlreadyExist_ = shouldFileExist;
00378   return mustAlreadyExist_;
00379 }
00380 
00381 
00382 ParameterEntryValidator::ValidStringsList
00383   FileNameValidator::validStringValues() const
00384 {
00385   return null;
00386 }
00387 
00388 
00389 void FileNameValidator::validate(ParameterEntry const &entry, std::string const &paramName,
00390   std::string const &sublistName) const
00391 {
00392   const std::string &entryName = entry.getAny(false).typeName();
00393   any anyValue = entry.getAny(true);
00394   TEST_FOR_EXCEPTION(!(anyValue.type() == typeid(std::string) ),
00395     Exceptions::InvalidParameterType,
00396     "Aww shoot! Sorry bud, but it looks like the \"" << paramName << "\"" <<
00397     " parameter in the \"" << sublistName << 
00398     "\" sublist didn't quite work out." << std::endl << std::endl <<
00399     "No need to fret though. I'm sure it's just a small mistake. "
00400     "Maybe the information below "
00401     "can help you figure out what went wrong." << std::endl << std::endl <<
00402     "Error: The value that you entered was the wrong type." << std::endl <<
00403     "Parameter: " << paramName << std::endl << 
00404     "Type specified: " << entryName << std::endl <<
00405     "Type accepted: " << typeid(std::string).name() << 
00406     std::endl << std::endl);
00407   if(mustAlreadyExist_){
00408     std::string fileName = getValue<std::string>(entry);
00409     TEST_FOR_EXCEPTION(!std::ifstream(fileName.c_str()),
00410       Exceptions::InvalidParameterValue,
00411       "Aww shoot! Sorry bud, but it looks like the \"" 
00412       << paramName << "\"" <<
00413       " parameter in the \"" << sublistName << 
00414       "\" sublist didn't quite work out." << std::endl << 
00415       "No need to fret though. I'm sure it's just a small mistake. " <<
00416       "Maybe the information below "<<
00417       "can help you figure out what went wrong." << 
00418       std::endl << std::endl <<
00419       "Error: The file must already exists. The value you entered does " <<
00420       "not corresspond to an existing file name." << std::endl <<
00421       "Parameter: " << paramName << std::endl <<
00422       "File name specified: " << fileName << std::endl << std::endl);
00423   }
00424 }
00425 
00426 
00427 const std::string FileNameValidator::getXMLTypeName() const
00428 {
00429   return "FilenameValidator";
00430 }
00431 
00432 
00433 void FileNameValidator::printDoc(
00434   std::string const &docString, std::ostream &out) const
00435 {
00436   StrUtils::printLines(out,"# ",docString);
00437   out << "#  Validator Used: " << std::endl;
00438   out << "#  FileName Validator" << std::endl;
00439 }
00440 
00441 RCP<FileNameValidator> DummyObjectGetter<FileNameValidator>::getDummyObject(){
00442   return rcp(new FileNameValidator(true));
00443 }
00444 
00445 StringValidator::StringValidator()
00446   : ParameterEntryValidator(), validStrings_(NULL)
00447 {}
00448 
00449 StringValidator::StringValidator(const Array<std::string>& validStrings):
00450   ParameterEntryValidator(),
00451   validStrings_(rcp(new Array<std::string>(validStrings)))
00452 {}
00453 
00454 ParameterEntryValidator::ValidStringsList
00455 StringValidator::setValidStrings(const Array<std::string>& validStrings)
00456 {
00457   validStrings_ = rcp(new Array<std::string>(validStrings));
00458   return validStrings_;
00459 }
00460 
00461 
00462 ParameterEntryValidator::ValidStringsList
00463 StringValidator::validStringValues() const
00464 {
00465   return validStrings_;
00466 }
00467 
00468 
00469 void StringValidator::validate(
00470   ParameterEntry const &entry, std::string const &paramName,
00471   std::string const &sublistName) const
00472 {
00473   any anyValue = entry.getAny(true);
00474   const std::string &entryName = entry.getAny(false).typeName();
00475   TEST_FOR_EXCEPTION(!(anyValue.type() == typeid(std::string)) ,
00476     Exceptions::InvalidParameterType,
00477     "Aww shoot! Sorry bud, but it looks like the \"" << paramName << "\"" <<
00478     " parameter in the \"" << sublistName << 
00479     "\" sublist didn't quite work out." << std::endl <<
00480     "No need to fret though. I'm sure it's just a small mistake. " <<
00481     "Maybe the information below "<<
00482     "can help you figure out what went wrong." << std::endl << std::endl <<
00483     "Error: The value that you entered was the wrong type." <<
00484     "Parameter: " << paramName << std::endl <<
00485     "Type specified: " << entryName << std::endl <<
00486     "Type accepted: " << Teuchos::TypeNameTraits<std::string>::name() <<
00487     std::endl);
00488   if(!validStrings_.is_null()){
00489     Array<std::string>::const_iterator
00490       it = std::find(validStrings_->begin(),
00491       validStrings_->end(), getValue<std::string>(entry));
00492     TEST_FOR_EXCEPTION(it == validStrings_->end(),
00493       Exceptions::InvalidParameterValue,
00494       "Aww shoot! Sorry bud, but it looks like the \""
00495       << paramName << "\"" <<
00496       " parameter in the \"" << sublistName << 
00497       "\" sublist didn't quite work out." << std::endl <<
00498       "No need to fret though. I'm sure it's just a small mistake. "
00499       "Maybe the information below "
00500       "can help you figure out what went wrong." <<
00501       std::endl << std::endl <<
00502       "Error: The value that was entered doesn't fall with in "
00503       "the range set by the validator." <<
00504       "Parameter: " << paramName << std::endl <<
00505       "Acceptable Values: " << validStrings_ << std::endl <<
00506       "Value entered: " << getValue<std::string>(entry) << std::endl <<
00507       std::endl);
00508   }
00509 }
00510 
00511 
00512 const std::string StringValidator::getXMLTypeName() const
00513 {
00514   return "StringValidator";
00515 }
00516 
00517 
00518 void StringValidator::printDoc(std::string const &docString,
00519   std::ostream &out) const
00520 {
00521   Teuchos::StrUtils::printLines(out,"# ",docString);
00522   out << "#  Validator Used: " << std::endl;
00523   out << "#  String Validator" << std::endl;
00524 }
00525 
00526 RCP<StringValidator> DummyObjectGetter<StringValidator>::getDummyObject(){
00527   return rcp(new StringValidator(tuple<std::string>("")));
00528 }
00529 
00530 
00531 } // namespace Teuchos
00532 
00533 
00534 // Nonmmeber helper functions
00535 
00536 Teuchos::RCP<Teuchos::AnyNumberParameterEntryValidator>
00537 Teuchos::anyNumberParameterEntryValidator()
00538 {
00539   return rcp(new AnyNumberParameterEntryValidator());
00540 }
00541 
00542 
00543 Teuchos::RCP<Teuchos::AnyNumberParameterEntryValidator>
00544 Teuchos::anyNumberParameterEntryValidator(
00545   AnyNumberParameterEntryValidator::EPreferredType const preferredType,
00546   AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
00547   )
00548 {
00549   return rcp(
00550     new AnyNumberParameterEntryValidator(
00551       preferredType, acceptedTypes
00552       )
00553     );
00554 }
00555 
00556 void Teuchos::setIntParameter(
00557   std::string const& paramName,
00558   int const value, std::string const& docString,
00559   ParameterList *paramList,
00560   AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
00561   )
00562 {
00563   TEST_FOR_EXCEPT(0==paramList);
00564   const RCP<const ParameterEntryValidator> paramEntryValidator =  
00565     anyNumberParameterEntryValidator(
00566       AnyNumberParameterEntryValidator::PREFER_INT, acceptedTypes
00567       );
00568   paramList->set(paramName, value, docString, paramEntryValidator);
00569 }
00570 
00571 
00572 void Teuchos::setDoubleParameter(
00573   std::string const& paramName,
00574   double const& value, std::string const& docString,
00575   ParameterList *paramList,
00576   AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
00577   )
00578 {
00579   TEST_FOR_EXCEPT(0==paramList);
00580   const RCP<const ParameterEntryValidator> paramEntryValidator =  
00581     anyNumberParameterEntryValidator(
00582       AnyNumberParameterEntryValidator::PREFER_DOUBLE, acceptedTypes
00583       );
00584   paramList->set(paramName, value, docString, paramEntryValidator);
00585 }
00586 
00587 
00588 void Teuchos::setNumericStringParameter(
00589   std::string const& paramName,
00590   std::string const& value, std::string const& docString,
00591   ParameterList *paramList,
00592   AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
00593   )
00594 {
00595   TEST_FOR_EXCEPT(0==paramList);
00596   const RCP<const ParameterEntryValidator> paramEntryValidator =  
00597     anyNumberParameterEntryValidator(
00598       AnyNumberParameterEntryValidator::PREFER_STRING, acceptedTypes
00599       );
00600   paramList->set(paramName, value, docString, paramEntryValidator);
00601 }
00602 
00603 
00604 int Teuchos::getIntParameter(
00605   ParameterList const& paramList,
00606   std::string const& paramName
00607   )
00608 {
00609   const ParameterEntry &entry = paramList.getEntry(paramName);
00610   RCP<const AnyNumberParameterEntryValidator>
00611     anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
00612       entry.validator()
00613       );
00614   if ( !is_null(anyNumValidator) )
00615     return anyNumValidator->getInt(entry,paramName,paramList.name());
00616   if ( typeid(int) == entry.getAny().type() )
00617     return any_cast<int>(entry.getAny());
00618   // Try the do the conversion which might fail!
00619   const AnyNumberParameterEntryValidator myAnyNumValidator;
00620   return myAnyNumValidator.getInt(entry,paramName,paramList.name());
00621 }
00622 
00623 
00624 double Teuchos::getDoubleParameter(
00625   ParameterList const& paramList,
00626   std::string const& paramName
00627   )
00628 {
00629   const ParameterEntry &entry = paramList.getEntry(paramName);
00630   RCP<const AnyNumberParameterEntryValidator>
00631     anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
00632       entry.validator()
00633       );
00634   if ( !is_null(anyNumValidator) )
00635     return anyNumValidator->getDouble(entry,paramName,paramList.name());
00636   if ( typeid(double) == entry.getAny().type() )
00637     return any_cast<double>(entry.getAny());
00638   // Try the do the conversion which might fail!
00639   const AnyNumberParameterEntryValidator myAnyNumValidator;
00640   return myAnyNumValidator.getDouble(entry,paramName,paramList.name());
00641 }
00642 
00643 
00644 std::string Teuchos::getNumericStringParameter(
00645   ParameterList const& paramList,
00646   std::string const& paramName
00647   )
00648 {
00649   const ParameterEntry &entry = paramList.getEntry(paramName);
00650   RCP<const AnyNumberParameterEntryValidator>
00651     anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
00652       entry.validator()
00653       );
00654   if ( !is_null(anyNumValidator) )
00655     return anyNumValidator->getString(entry,paramName,paramList.name());
00656   if ( typeid(std::string) == entry.getAny().type() )
00657     return any_cast<std::string>(entry.getAny());
00658   // Try the do the conversion which might fail!
00659   const AnyNumberParameterEntryValidator myAnyNumValidator;
00660   return myAnyNumValidator.getString(entry,paramName,paramList.name());
00661 }
00662 
00663 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines