Teuchos - Trilinos Tools Package Version of the Day
Teuchos_StandardParameterEntryValidators.cpp
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 #include "Teuchos_as.hpp"
00044 
00045 
00046 std::string Teuchos::getVerbosityLevelParameterValueName(
00047   const EVerbosityLevel verbLevel
00048   )
00049 {
00050   switch(verbLevel) {
00051     case VERB_DEFAULT:
00052       return "default";
00053     case VERB_NONE:
00054       return "none";
00055     case VERB_LOW:
00056       return "low";
00057     case VERB_MEDIUM:
00058       return "medium";
00059     case VERB_HIGH:
00060       return "high";
00061     case VERB_EXTREME:
00062       return "extreme";
00063     default:
00064       TEUCHOS_TEST_FOR_EXCEPT("Should never get here!");
00065   }
00066   return ""; // Never get here!
00067 }
00068 
00069 
00070 Teuchos::RCP<
00071   Teuchos::StringToIntegralParameterEntryValidator<Teuchos::EVerbosityLevel>
00072   >
00073 Teuchos::verbosityLevelParameterEntryValidator(
00074   std::string const& defaultParameterName
00075   )
00076 {
00077   return rcp(
00078     new StringToIntegralParameterEntryValidator<EVerbosityLevel>(
00079       tuple<std::string>(
00080         getVerbosityLevelParameterValueName(VERB_DEFAULT),
00081         getVerbosityLevelParameterValueName(VERB_NONE),
00082         getVerbosityLevelParameterValueName(VERB_LOW),
00083         getVerbosityLevelParameterValueName(VERB_MEDIUM),
00084         getVerbosityLevelParameterValueName(VERB_HIGH),
00085         getVerbosityLevelParameterValueName(VERB_EXTREME)
00086         ),
00087       tuple<std::string>(
00088         "Use level set in code",
00089         "Produce no output",
00090         "Produce minimal output",
00091         "Produce a little more output",
00092         "Produce a higher level of output",
00093         "Produce the highest level of output"
00094         ),
00095       tuple<EVerbosityLevel>(
00096         VERB_DEFAULT,
00097         VERB_NONE,
00098         VERB_LOW,
00099         VERB_MEDIUM,
00100         VERB_HIGH,
00101         VERB_EXTREME
00102         ),
00103       defaultParameterName
00104       )
00105     );
00106 }
00107 
00108 
00109 namespace Teuchos {
00110 
00111 
00112 //
00113 // AnyNumberParameterEntryValidator
00114 //
00115 
00116 
00117 // Constructors
00118 
00119 
00120 AnyNumberParameterEntryValidator::AnyNumberParameterEntryValidator()
00121   : preferredType_(PREFER_DOUBLE), acceptedTypes_(AcceptedTypes())
00122 {
00123   finishInitialization();
00124 }
00125 
00126 
00127 AnyNumberParameterEntryValidator::AnyNumberParameterEntryValidator(
00128   EPreferredType const preferredType, AcceptedTypes const& acceptedTypes
00129   )
00130   : preferredType_(preferredType), acceptedTypes_(acceptedTypes)
00131 {
00132   finishInitialization();
00133 }
00134 
00135 
00136 //  Local non-virtual validated lookup functions
00137 
00138 
00139 int AnyNumberParameterEntryValidator::getInt(
00140   const ParameterEntry &entry, const std::string &paramName,
00141   const std::string &sublistName, const bool activeQuery
00142   ) const
00143 {
00144   const any &anyValue = entry.getAny(activeQuery);
00145   if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
00146     return any_cast<int>(anyValue);
00147   if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
00148     return as<int>(any_cast<double>(anyValue));
00149   if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
00150     return std::atoi(any_cast<std::string>(anyValue).c_str());
00151   throwTypeError(entry,paramName,sublistName);
00152   return 0; // Will never get here!
00153 }
00154 
00155 
00156 double AnyNumberParameterEntryValidator::getDouble(
00157   const ParameterEntry &entry, const std::string &paramName,
00158   const std::string &sublistName, const bool activeQuery
00159   ) const
00160 {
00161   const any &anyValue = entry.getAny(activeQuery);
00162   if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
00163     return as<double>(any_cast<int>(anyValue));
00164   if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
00165     return any_cast<double>(anyValue);
00166   if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
00167     return std::atof(any_cast<std::string>(anyValue).c_str());
00168   throwTypeError(entry,paramName,sublistName);
00169   return 0.0; // Will never get here!
00170 }
00171 
00172 
00173 std::string AnyNumberParameterEntryValidator::getString(
00174   const ParameterEntry &entry, const std::string &paramName,
00175   const std::string &sublistName, const bool activeQuery
00176   ) const
00177 {
00178   const any &anyValue = entry.getAny(activeQuery);
00179   if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
00180     return Utils::toString(any_cast<int>(anyValue));
00181   if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
00182     return Utils::toString(any_cast<double>(anyValue));
00183   if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
00184     return any_cast<std::string>(anyValue);
00185   throwTypeError(entry,paramName,sublistName);
00186   return ""; // Will never get here!
00187 }
00188 
00189 
00190 int AnyNumberParameterEntryValidator::getInt(
00191   ParameterList &paramList, const std::string &paramName,
00192   const int defaultValue
00193   ) const
00194 {
00195   const ParameterEntry *entry = paramList.getEntryPtr(paramName);
00196   if(entry) return getInt(*entry,paramName,paramList.name(),true);
00197   return paramList.get(paramName,defaultValue);
00198 }
00199 
00200 
00201 double AnyNumberParameterEntryValidator::getDouble(
00202   ParameterList &paramList, const std::string &paramName,
00203   const double defaultValue
00204   ) const
00205 {
00206   const ParameterEntry *entry = paramList.getEntryPtr(paramName);
00207   if(entry) return getDouble(*entry,paramName,paramList.name(),true);
00208   return paramList.get(paramName,defaultValue);
00209 }
00210 
00211 
00212 std::string AnyNumberParameterEntryValidator::getString(
00213   ParameterList &paramList, const std::string &paramName,
00214   const std::string &defaultValue
00215   ) const
00216 {
00217   const ParameterEntry *entry = paramList.getEntryPtr(paramName);
00218   if(entry) return getString(*entry,paramName,paramList.name(),true);
00219   return paramList.get(paramName,defaultValue);
00220 }
00221 
00222 
00223 bool AnyNumberParameterEntryValidator::isDoubleAllowed() const
00224 {
00225   return acceptedTypes_.allowDouble();
00226 }
00227 
00228 
00229 bool AnyNumberParameterEntryValidator::isIntAllowed() const
00230 {
00231   return acceptedTypes_.allowInt();
00232 }
00233 
00234   
00235 bool AnyNumberParameterEntryValidator::isStringAllowed() const
00236 {
00237   return acceptedTypes_.allowString();
00238 }
00239 
00240 
00241 AnyNumberParameterEntryValidator::EPreferredType
00242 AnyNumberParameterEntryValidator::getPreferredType() const
00243 {
00244   return preferredType_;
00245 }
00246 
00247 
00248 // Overridden from ParameterEntryValidator
00249 
00250 
00251 const std::string AnyNumberParameterEntryValidator::getXMLTypeName() const
00252 {
00253   return "anynumberValidator";
00254 }
00255 
00256 
00257 void AnyNumberParameterEntryValidator::printDoc(
00258   std::string  const & docString,
00259   std::ostream & out
00260   ) const
00261 {
00262   StrUtils::printLines(out,"# ",docString);
00263   out << "#  Accepted types: " << acceptedTypesString_ << ".\n";
00264 }
00265 
00266 
00267 ParameterEntryValidator::ValidStringsList
00268 AnyNumberParameterEntryValidator::validStringValues() const
00269 {
00270   return null;
00271 }
00272 
00273 
00274 void AnyNumberParameterEntryValidator::validate(
00275   ParameterEntry const& entry,
00276   std::string const& paramName,
00277   std::string const& sublistName
00278   ) const
00279 {
00280   // Validate that the parameter exists and can be converted to a double.
00281   // NOTE: Even if the target type will be an 'int', we don't know that here
00282   // so it will be better to assert that a 'double' can be created.  The type
00283   // 'double' has a very large exponent range and, subject to digit
00284   // truncation, a 'double' can represent every 'int' value.
00285   getDouble(entry, paramName, sublistName, false);
00286 }
00287 
00288 
00289 void AnyNumberParameterEntryValidator::validateAndModify(
00290   std::string const& paramName,
00291   std::string const& sublistName,
00292   ParameterEntry * entry
00293   ) const
00294 {
00295   TEUCHOS_TEST_FOR_EXCEPT(0==entry);
00296   switch(preferredType_) {
00297     case PREFER_INT:
00298       entry->setValue(
00299         getInt(*entry,paramName,sublistName,false),
00300         false // isDefault
00301         );
00302       break;
00303     case PREFER_DOUBLE:
00304       entry->setValue(
00305         getDouble(*entry,paramName,sublistName,false),
00306         false // isDefault
00307         );
00308       break;
00309     case PREFER_STRING:
00310       entry->setValue(
00311         getString(*entry,paramName,sublistName,false),
00312         false // isDefault
00313         );
00314       break;
00315     default:
00316       TEUCHOS_TEST_FOR_EXCEPT("Error, Invalid EPreferredType value!");
00317   }
00318 }
00319 
00320 
00321 // private
00322 
00323 
00324 void AnyNumberParameterEntryValidator::finishInitialization()
00325 {
00326 
00327   std::ostringstream oss;
00328   bool addedType = false;
00329   if(acceptedTypes_.allowInt()) {
00330     oss << "\"int\"";
00331     addedType = true;
00332   }
00333   if(acceptedTypes_.allowDouble()) {
00334     if(addedType) oss << ", ";
00335     oss << "\"double\"";
00336     addedType = true;
00337   }
00338   if(acceptedTypes_.allowString()) {
00339     if(addedType) oss << ", ";
00340     oss << "\"string\"";
00341     addedType = true;
00342   }
00343   acceptedTypesString_ = oss.str();
00344 }
00345 
00346 
00347 void AnyNumberParameterEntryValidator::throwTypeError(
00348   ParameterEntry const& entry,
00349   std::string const& paramName,
00350   std::string const& sublistName
00351   ) const
00352 {
00353   const std::string &entryName = entry.getAny(false).typeName();
00354   TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(
00355     true, Exceptions::InvalidParameterType
00356     ,"Error, the parameter {paramName=\""<<paramName<<"\""
00357     ",type=\""<<entryName<<"\"}"
00358     << "\nin the sublist \"" << sublistName << "\""
00359     << "\nhas the wrong type."
00360     << "\n\nThe accepted types are: " << acceptedTypesString_ << "!";
00361     );
00362 }
00363 
00364 
00365 RCP<AnyNumberParameterEntryValidator> 
00366   DummyObjectGetter<AnyNumberParameterEntryValidator>::getDummyObject()
00367 {
00368   return anyNumberParameterEntryValidator(
00369     AnyNumberParameterEntryValidator::PREFER_INT, 
00370     AnyNumberParameterEntryValidator::AcceptedTypes());
00371 }
00372 
00373 
00374 FileNameValidator::FileNameValidator(bool mustAlreadyExist)
00375   : ParameterEntryValidator(), mustAlreadyExist_(mustAlreadyExist)
00376 {}
00377 
00378 
00379 bool FileNameValidator::fileMustExist() const
00380 {
00381   return mustAlreadyExist_;
00382 }
00383 
00384 
00385 bool FileNameValidator::setFileMustExist(bool shouldFileExist)
00386 {
00387   this->mustAlreadyExist_ = shouldFileExist;
00388   return mustAlreadyExist_;
00389 }
00390 
00391 
00392 ParameterEntryValidator::ValidStringsList
00393   FileNameValidator::validStringValues() const
00394 {
00395   return null;
00396 }
00397 
00398 
00399 void FileNameValidator::validate(ParameterEntry const &entry, std::string const &paramName,
00400   std::string const &sublistName) const
00401 {
00402   const std::string &entryName = entry.getAny(false).typeName();
00403   any anyValue = entry.getAny(true);
00404   TEUCHOS_TEST_FOR_EXCEPTION(!(anyValue.type() == typeid(std::string) ),
00405     Exceptions::InvalidParameterType,
00406     "Aww shoot! Sorry bud, but it looks like the \"" << paramName << "\"" <<
00407     " parameter in the \"" << sublistName << 
00408     "\" sublist didn't quite work out." << std::endl << std::endl <<
00409     "No need to fret though. I'm sure it's just a small mistake. "
00410     "Maybe the information below "
00411     "can help you figure out what went wrong." << std::endl << std::endl <<
00412     "Error: The value that you entered was the wrong type." << std::endl <<
00413     "Parameter: " << paramName << std::endl << 
00414     "Type specified: " << entryName << std::endl <<
00415     "Type accepted: " << typeid(std::string).name() << 
00416     std::endl << std::endl);
00417   if(mustAlreadyExist_){
00418     std::string fileName = getValue<std::string>(entry);
00419     TEUCHOS_TEST_FOR_EXCEPTION(!std::ifstream(fileName.c_str()),
00420       Exceptions::InvalidParameterValue,
00421       "Aww shoot! Sorry bud, but it looks like the \"" 
00422       << paramName << "\"" <<
00423       " parameter in the \"" << sublistName << 
00424       "\" sublist didn't quite work out." << std::endl << 
00425       "No need to fret though. I'm sure it's just a small mistake. " <<
00426       "Maybe the information below "<<
00427       "can help you figure out what went wrong." << 
00428       std::endl << std::endl <<
00429       "Error: The file must already exists. The value you entered does " <<
00430       "not corresspond to an existing file name." << std::endl <<
00431       "Parameter: " << paramName << std::endl <<
00432       "File name specified: " << fileName << std::endl << std::endl);
00433   }
00434 }
00435 
00436 
00437 const std::string FileNameValidator::getXMLTypeName() const
00438 {
00439   return "FilenameValidator";
00440 }
00441 
00442 
00443 void FileNameValidator::printDoc(
00444   std::string const &docString, std::ostream &out) const
00445 {
00446   StrUtils::printLines(out,"# ",docString);
00447   out << "#  Validator Used: " << std::endl;
00448   out << "#  FileName Validator" << std::endl;
00449 }
00450 
00451 
00452 RCP<FileNameValidator> DummyObjectGetter<FileNameValidator>::getDummyObject(){
00453   return rcp(new FileNameValidator(true));
00454 }
00455 
00456 
00457 StringValidator::StringValidator()
00458   : ParameterEntryValidator(), validStrings_(NULL)
00459 {}
00460 
00461 
00462 StringValidator::StringValidator(const Array<std::string>& validStrings):
00463   ParameterEntryValidator(),
00464   validStrings_(rcp(new Array<std::string>(validStrings)))
00465 {}
00466 
00467 
00468 ParameterEntryValidator::ValidStringsList
00469 StringValidator::setValidStrings(const Array<std::string>& validStrings)
00470 {
00471   validStrings_ = rcp(new Array<std::string>(validStrings));
00472   return validStrings_;
00473 }
00474 
00475 
00476 ParameterEntryValidator::ValidStringsList
00477 StringValidator::validStringValues() const
00478 {
00479   return validStrings_;
00480 }
00481 
00482 
00483 void StringValidator::validate(
00484   ParameterEntry const &entry, std::string const &paramName,
00485   std::string const &sublistName) const
00486 {
00487   any anyValue = entry.getAny(true);
00488   const std::string &entryName = entry.getAny(false).typeName();
00489   TEUCHOS_TEST_FOR_EXCEPTION(!(anyValue.type() == typeid(std::string)) ,
00490     Exceptions::InvalidParameterType,
00491     "Aww shoot! Sorry bud, but it looks like the \"" << paramName << "\"" <<
00492     " parameter in the \"" << sublistName << 
00493     "\" sublist didn't quite work out." << std::endl <<
00494     "No need to fret though. I'm sure it's just a small mistake. " <<
00495     "Maybe the information below "<<
00496     "can help you figure out what went wrong." << std::endl << std::endl <<
00497     "Error: The value that you entered was the wrong type." <<
00498     "Parameter: " << paramName << std::endl <<
00499     "Type specified: " << entryName << std::endl <<
00500     "Type accepted: " << Teuchos::TypeNameTraits<std::string>::name() <<
00501     std::endl);
00502   if(!validStrings_.is_null()){
00503     Array<std::string>::const_iterator
00504       it = std::find(validStrings_->begin(),
00505       validStrings_->end(), getValue<std::string>(entry));
00506     TEUCHOS_TEST_FOR_EXCEPTION(it == validStrings_->end(),
00507       Exceptions::InvalidParameterValue,
00508       "Aww shoot! Sorry bud, but it looks like the \""
00509       << paramName << "\"" <<
00510       " parameter in the \"" << sublistName << 
00511       "\" sublist didn't quite work out." << std::endl <<
00512       "No need to fret though. I'm sure it's just a small mistake. "
00513       "Maybe the information below "
00514       "can help you figure out what went wrong." <<
00515       std::endl << std::endl <<
00516       "Error: The value that was entered doesn't fall with in "
00517       "the range set by the validator." <<
00518       "Parameter: " << paramName << std::endl <<
00519       "Acceptable Values: " << validStrings_ << std::endl <<
00520       "Value entered: " << getValue<std::string>(entry) << std::endl <<
00521       std::endl);
00522   }
00523 }
00524 
00525 
00526 const std::string StringValidator::getXMLTypeName() const
00527 {
00528   return "StringValidator";
00529 }
00530 
00531 
00532 void StringValidator::printDoc(std::string const &docString,
00533   std::ostream &out) const
00534 {
00535   Teuchos::StrUtils::printLines(out,"# ",docString);
00536   out << "#  Validator Used: " << std::endl;
00537   out << "#  String Validator" << std::endl;
00538   if (validStrings_.get() && validStrings_->size()){
00539     out << "#  Acceptable Values: " << *validStrings_ << std::endl;
00540   }
00541 }
00542 
00543 
00544 RCP<StringValidator> DummyObjectGetter<StringValidator>::getDummyObject(){
00545   return rcp(new StringValidator(tuple<std::string>("")));
00546 }
00547 
00548 
00549 } // namespace Teuchos
00550 
00551 
00552 // Nonmmeber helper functions
00553 
00554 
00555 Teuchos::RCP<Teuchos::AnyNumberParameterEntryValidator>
00556 Teuchos::anyNumberParameterEntryValidator()
00557 {
00558   return rcp(new AnyNumberParameterEntryValidator());
00559 }
00560 
00561 
00562 Teuchos::RCP<Teuchos::AnyNumberParameterEntryValidator>
00563 Teuchos::anyNumberParameterEntryValidator(
00564   AnyNumberParameterEntryValidator::EPreferredType const preferredType,
00565   AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
00566   )
00567 {
00568   return rcp(
00569     new AnyNumberParameterEntryValidator(
00570       preferredType, acceptedTypes
00571       )
00572     );
00573 }
00574 
00575 void Teuchos::setIntParameter(
00576   std::string const& paramName,
00577   int const value, std::string const& docString,
00578   ParameterList *paramList,
00579   AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
00580   )
00581 {
00582   TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
00583   const RCP<const ParameterEntryValidator> paramEntryValidator =  
00584     anyNumberParameterEntryValidator(
00585       AnyNumberParameterEntryValidator::PREFER_INT, acceptedTypes
00586       );
00587   paramList->set(paramName, value, docString, paramEntryValidator);
00588 }
00589 
00590 
00591 void Teuchos::setDoubleParameter(
00592   std::string const& paramName,
00593   double const& value, std::string const& docString,
00594   ParameterList *paramList,
00595   AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
00596   )
00597 {
00598   TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
00599   const RCP<const ParameterEntryValidator> paramEntryValidator =  
00600     anyNumberParameterEntryValidator(
00601       AnyNumberParameterEntryValidator::PREFER_DOUBLE, acceptedTypes
00602       );
00603   paramList->set(paramName, value, docString, paramEntryValidator);
00604 }
00605 
00606 
00607 void Teuchos::setNumericStringParameter(
00608   std::string const& paramName,
00609   std::string const& value, std::string const& docString,
00610   ParameterList *paramList,
00611   AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
00612   )
00613 {
00614   TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
00615   const RCP<const ParameterEntryValidator> paramEntryValidator =  
00616     anyNumberParameterEntryValidator(
00617       AnyNumberParameterEntryValidator::PREFER_STRING, acceptedTypes
00618       );
00619   paramList->set(paramName, value, docString, paramEntryValidator);
00620 }
00621 
00622 
00623 int Teuchos::getIntParameter(
00624   ParameterList const& paramList,
00625   std::string const& paramName
00626   )
00627 {
00628   const ParameterEntry &entry = paramList.getEntry(paramName);
00629   RCP<const AnyNumberParameterEntryValidator>
00630     anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
00631       entry.validator()
00632       );
00633   if ( !is_null(anyNumValidator) )
00634     return anyNumValidator->getInt(entry,paramName,paramList.name());
00635   if ( typeid(int) == entry.getAny().type() )
00636     return any_cast<int>(entry.getAny());
00637   // Try the do the conversion which might fail!
00638   const AnyNumberParameterEntryValidator myAnyNumValidator;
00639   return myAnyNumValidator.getInt(entry,paramName,paramList.name());
00640 }
00641 
00642 
00643 double Teuchos::getDoubleParameter(
00644   ParameterList const& paramList,
00645   std::string const& paramName
00646   )
00647 {
00648   const ParameterEntry &entry = paramList.getEntry(paramName);
00649   RCP<const AnyNumberParameterEntryValidator>
00650     anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
00651       entry.validator()
00652       );
00653   if ( !is_null(anyNumValidator) )
00654     return anyNumValidator->getDouble(entry,paramName,paramList.name());
00655   if ( typeid(double) == entry.getAny().type() )
00656     return any_cast<double>(entry.getAny());
00657   // Try the do the conversion which might fail!
00658   const AnyNumberParameterEntryValidator myAnyNumValidator;
00659   return myAnyNumValidator.getDouble(entry,paramName,paramList.name());
00660 }
00661 
00662 
00663 std::string Teuchos::getNumericStringParameter(
00664   ParameterList const& paramList,
00665   std::string const& paramName
00666   )
00667 {
00668   const ParameterEntry &entry = paramList.getEntry(paramName);
00669   RCP<const AnyNumberParameterEntryValidator>
00670     anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
00671       entry.validator()
00672       );
00673   if ( !is_null(anyNumValidator) )
00674     return anyNumValidator->getString(entry,paramName,paramList.name());
00675   if ( typeid(std::string) == entry.getAny().type() )
00676     return any_cast<std::string>(entry.getAny());
00677   // Try the do the conversion which might fail!
00678   const AnyNumberParameterEntryValidator myAnyNumValidator;
00679   return myAnyNumValidator.getString(entry,paramName,paramList.name());
00680 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines