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