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     "The \"" << paramName << "\"" <<
00407     " parameter in the \"" << sublistName << 
00408     "\" sublist is has an error." << std::endl << std::endl <<
00409     "Error: The value that you entered was the wrong type." << std::endl <<
00410     "Parameter: " << paramName << std::endl << 
00411     "Type specified: " << entryName << std::endl <<
00412     "Type accepted: " << typeid(std::string).name() << 
00413     std::endl << std::endl);
00414   if(mustAlreadyExist_){
00415     std::string fileName = getValue<std::string>(entry);
00416     TEUCHOS_TEST_FOR_EXCEPTION(!std::ifstream(fileName.c_str()),
00417       Exceptions::InvalidParameterValue,
00418       "The \"" << paramName << "\"" <<
00419       " parameter in the \"" << sublistName << 
00420       "\" sublist is has an error." << std::endl << std::endl <<
00421       "Error: The file must already exists. The value you entered does " <<
00422       "not corresspond to an existing file name." << std::endl <<
00423       "Parameter: " << paramName << std::endl <<
00424       "File name specified: " << fileName << std::endl << std::endl);
00425   }
00426 }
00427 
00428 
00429 const std::string FileNameValidator::getXMLTypeName() const
00430 {
00431   return "FilenameValidator";
00432 }
00433 
00434 
00435 void FileNameValidator::printDoc(
00436   std::string const &docString, std::ostream &out) const
00437 {
00438   StrUtils::printLines(out,"# ",docString);
00439   out << "#  Validator Used: " << std::endl;
00440   out << "#  FileName Validator" << std::endl;
00441 }
00442 
00443 
00444 RCP<FileNameValidator> DummyObjectGetter<FileNameValidator>::getDummyObject(){
00445   return rcp(new FileNameValidator(true));
00446 }
00447 
00448 
00449 StringValidator::StringValidator()
00450   : ParameterEntryValidator(), validStrings_(NULL)
00451 {}
00452 
00453 
00454 StringValidator::StringValidator(const Array<std::string>& validStrings):
00455   ParameterEntryValidator(),
00456   validStrings_(rcp(new Array<std::string>(validStrings)))
00457 {}
00458 
00459 
00460 ParameterEntryValidator::ValidStringsList
00461 StringValidator::setValidStrings(const Array<std::string>& validStrings)
00462 {
00463   validStrings_ = rcp(new Array<std::string>(validStrings));
00464   return validStrings_;
00465 }
00466 
00467 
00468 ParameterEntryValidator::ValidStringsList
00469 StringValidator::validStringValues() const
00470 {
00471   return validStrings_;
00472 }
00473 
00474 
00475 void StringValidator::validate(
00476   ParameterEntry const &entry, std::string const &paramName,
00477   std::string const &sublistName) const
00478 {
00479   any anyValue = entry.getAny(true);
00480   const std::string &entryName = entry.getAny(false).typeName();
00481   TEUCHOS_TEST_FOR_EXCEPTION(!(anyValue.type() == typeid(std::string)) ,
00482     Exceptions::InvalidParameterType,
00483     "The \"" << paramName << "\"" <<
00484     " parameter in the \"" << sublistName << 
00485     "\" sublist is has an error." << std::endl << std::endl <<
00486     "Error: The value that you entered was the wrong type." <<
00487     "Parameter: " << paramName << std::endl <<
00488     "Type specified: " << entryName << std::endl <<
00489     "Type accepted: " << Teuchos::TypeNameTraits<std::string>::name() <<
00490     std::endl);
00491   if(!validStrings_.is_null()){
00492     Array<std::string>::const_iterator
00493       it = std::find(validStrings_->begin(),
00494       validStrings_->end(), getValue<std::string>(entry));
00495     TEUCHOS_TEST_FOR_EXCEPTION(it == validStrings_->end(),
00496       Exceptions::InvalidParameterValue,
00497       "The \"" << paramName << "\"" <<
00498       " parameter in the \"" << sublistName << 
00499       "\" sublist is has an error." << std::endl << std::endl <<
00500       "Error: The value that was entered doesn't fall with in "
00501       "the range set by the validator." <<
00502       "Parameter: " << paramName << std::endl <<
00503       "Acceptable Values: " << *validStrings_ << std::endl <<
00504       "Value entered: " << getValue<std::string>(entry) << std::endl <<
00505       std::endl);
00506   }
00507 }
00508 
00509 
00510 const std::string StringValidator::getXMLTypeName() const
00511 {
00512   return "StringValidator";
00513 }
00514 
00515 
00516 void StringValidator::printDoc(std::string const &docString,
00517   std::ostream &out) const
00518 {
00519   Teuchos::StrUtils::printLines(out,"# ",docString);
00520   out << "#  Validator Used: " << std::endl;
00521   out << "#  String Validator" << std::endl;
00522   if (validStrings_.get() && validStrings_->size()){
00523     out << "#  Acceptable Values: " << *validStrings_ << std::endl;
00524   }
00525 }
00526 
00527 
00528 RCP<StringValidator> DummyObjectGetter<StringValidator>::getDummyObject(){
00529   return rcp(new StringValidator(tuple<std::string>("")));
00530 }
00531 
00532 
00533 } // namespace Teuchos
00534 
00535 
00536 // Nonmmeber helper functions
00537 
00538 
00539 Teuchos::RCP<Teuchos::AnyNumberParameterEntryValidator>
00540 Teuchos::anyNumberParameterEntryValidator()
00541 {
00542   return rcp(new AnyNumberParameterEntryValidator());
00543 }
00544 
00545 
00546 Teuchos::RCP<Teuchos::AnyNumberParameterEntryValidator>
00547 Teuchos::anyNumberParameterEntryValidator(
00548   AnyNumberParameterEntryValidator::EPreferredType const preferredType,
00549   AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
00550   )
00551 {
00552   return rcp(
00553     new AnyNumberParameterEntryValidator(
00554       preferredType, acceptedTypes
00555       )
00556     );
00557 }
00558 
00559 void Teuchos::setIntParameter(
00560   std::string const& paramName,
00561   int const value, std::string const& docString,
00562   ParameterList *paramList,
00563   AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
00564   )
00565 {
00566   TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
00567   const RCP<const ParameterEntryValidator> paramEntryValidator =  
00568     anyNumberParameterEntryValidator(
00569       AnyNumberParameterEntryValidator::PREFER_INT, acceptedTypes
00570       );
00571   paramList->set(paramName, value, docString, paramEntryValidator);
00572 }
00573 
00574 
00575 void Teuchos::setDoubleParameter(
00576   std::string const& paramName,
00577   double 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_DOUBLE, acceptedTypes
00586       );
00587   paramList->set(paramName, value, docString, paramEntryValidator);
00588 }
00589 
00590 
00591 void Teuchos::setNumericStringParameter(
00592   std::string const& paramName,
00593   std::string 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_STRING, acceptedTypes
00602       );
00603   paramList->set(paramName, value, docString, paramEntryValidator);
00604 }
00605 
00606 
00607 int Teuchos::getIntParameter(
00608   ParameterList const& paramList,
00609   std::string const& paramName
00610   )
00611 {
00612   const ParameterEntry &entry = paramList.getEntry(paramName);
00613   RCP<const AnyNumberParameterEntryValidator>
00614     anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
00615       entry.validator()
00616       );
00617   if ( !is_null(anyNumValidator) )
00618     return anyNumValidator->getInt(entry,paramName,paramList.name());
00619   if ( typeid(int) == entry.getAny().type() )
00620     return any_cast<int>(entry.getAny());
00621   // Try the do the conversion which might fail!
00622   const AnyNumberParameterEntryValidator myAnyNumValidator;
00623   return myAnyNumValidator.getInt(entry,paramName,paramList.name());
00624 }
00625 
00626 
00627 double Teuchos::getDoubleParameter(
00628   ParameterList const& paramList,
00629   std::string const& paramName
00630   )
00631 {
00632   const ParameterEntry &entry = paramList.getEntry(paramName);
00633   RCP<const AnyNumberParameterEntryValidator>
00634     anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
00635       entry.validator()
00636       );
00637   if ( !is_null(anyNumValidator) )
00638     return anyNumValidator->getDouble(entry,paramName,paramList.name());
00639   if ( typeid(double) == entry.getAny().type() )
00640     return any_cast<double>(entry.getAny());
00641   // Try the do the conversion which might fail!
00642   const AnyNumberParameterEntryValidator myAnyNumValidator;
00643   return myAnyNumValidator.getDouble(entry,paramName,paramList.name());
00644 }
00645 
00646 
00647 std::string Teuchos::getNumericStringParameter(
00648   ParameterList const& paramList,
00649   std::string const& paramName
00650   )
00651 {
00652   const ParameterEntry &entry = paramList.getEntry(paramName);
00653   RCP<const AnyNumberParameterEntryValidator>
00654     anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
00655       entry.validator()
00656       );
00657   if ( !is_null(anyNumValidator) )
00658     return anyNumValidator->getString(entry,paramName,paramList.name());
00659   if ( typeid(std::string) == entry.getAny().type() )
00660     return any_cast<std::string>(entry.getAny());
00661   // Try the do the conversion which might fail!
00662   const AnyNumberParameterEntryValidator myAnyNumValidator;
00663   return myAnyNumValidator.getString(entry,paramName,paramList.name());
00664 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines