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