|
Teuchos Package Browser (Single Doxygen Collection) Version of the Day
|
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 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #include "Teuchos_VerboseObjectParameterListHelpers.hpp" 00030 #include "Teuchos_StandardParameterEntryValidators.hpp" 00031 00032 00033 namespace { 00034 00035 00036 const std::string VerboseObject_name = "VerboseObject"; 00037 00038 const std::string OutputFile_name = "Output File"; 00039 const std::string OutputFile_default = "none"; 00040 00041 const std::string VerbosityLevel_name = "Verbosity Level"; 00042 const std::string VerbosityLevel_default = "default"; 00043 Teuchos::RCP< 00044 Teuchos::StringToIntegralParameterEntryValidator<Teuchos::EVerbosityLevel> 00045 > 00046 VerbosityLevel_validator; 00047 00048 00049 } // namespace 00050 00051 00052 00053 Teuchos::RCP<const Teuchos::ParameterList> 00054 Teuchos::getValidVerboseObjectSublist() 00055 { 00056 using Teuchos::rcp_implicit_cast; 00057 static RCP<const ParameterList> validParams; 00058 if (is_null(validParams)) { 00059 RCP<ParameterList> 00060 pl = rcp(new ParameterList(VerboseObject_name)); 00061 VerbosityLevel_validator = verbosityLevelParameterEntryValidator(VerbosityLevel_name); 00062 pl->set( 00063 VerbosityLevel_name, VerbosityLevel_default, 00064 "The verbosity level to use to override whatever is set in code.\n" 00065 "The value of \"default\" will allow the level set in code to be used.", 00066 rcp_implicit_cast<const ParameterEntryValidator>(VerbosityLevel_validator) 00067 ); 00068 pl->set( 00069 OutputFile_name, OutputFile_default, 00070 "The file to send output to. If the value \"none\" is used, then\n" 00071 "whatever is set in code will be used. However, any other std::string value\n" 00072 "will be used to create an std::ofstream object to a file with the given name.\n" 00073 "Therefore, any valid file name is a valid std::string value for this parameter." 00074 ); 00075 validParams = pl; 00076 } 00077 return validParams; 00078 } 00079 00080 00081 void Teuchos::setupVerboseObjectSublist( ParameterList* paramList ) 00082 { 00083 TEST_FOR_EXCEPT(0==paramList); 00084 paramList->sublist(VerboseObject_name).setParameters( 00085 *getValidVerboseObjectSublist() 00086 ).disableRecursiveValidation(); 00087 } 00088 00089 00090 void Teuchos::readVerboseObjectSublist( 00091 ParameterList* paramList, 00092 RCP<FancyOStream> *oStream, EVerbosityLevel *verbLevel 00093 ) 00094 { 00095 // Validate input 00096 TEST_FOR_EXCEPT(0==paramList); 00097 TEST_FOR_EXCEPT(0==oStream); 00098 TEST_FOR_EXCEPT(0==verbLevel); 00099 ParameterList 00100 &voSublist = paramList->sublist(VerboseObject_name); 00101 voSublist.validateParameters(*getValidVerboseObjectSublist()); 00102 const std::string 00103 outputFileStr = voSublist.get(OutputFile_name,OutputFile_default); 00104 *verbLevel = VerbosityLevel_validator->getIntegralValue( 00105 voSublist,VerbosityLevel_name,VerbosityLevel_default 00106 ); 00107 if (outputFileStr==OutputFile_default) { 00108 *oStream = null; 00109 } 00110 else { 00111 RCP<std::ofstream> 00112 oFileStream = rcp(new std::ofstream(outputFileStr.c_str())); 00113 TEST_FOR_EXCEPTION_PURE_MSG( 00114 oFileStream->eof(), Exceptions::InvalidParameterValue, 00115 "Error, the file \"" << outputFileStr << "\n given by the parameter\n" 00116 "\'" << OutputFile_name << "\' in the sublist\n" 00117 "\'" << voSublist.name() << "\' count not be opened for output!" 00118 ); 00119 *oStream = fancyOStream(rcp_implicit_cast<std::ostream>(oFileStream)); 00120 } 00121 #ifdef TEUCHOS_DEBUG 00122 voSublist.validateParameters(*getValidVerboseObjectSublist()); 00123 #endif 00124 }
1.7.4