AbstractLinAlgPack_BasisSystemTesterSetOptions.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) 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 Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include <assert.h>
00030 #include <math.h>
00031 
00032 #include "AbstractLinAlgPack_BasisSystemTesterSetOptions.hpp"
00033 #include "OptionsFromStreamPack_StringToBool.hpp"
00034 #include "Teuchos_TestForException.hpp"
00035 
00036 // Define the options
00037 namespace {
00038 
00039   const int local_num_options = 6;
00040 
00041   enum local_EOptions {
00042     PRINT_TESTS
00043     ,DUMP_ALL
00044     ,TEST_FOR_EXCEPTION
00045     ,NUM_RANDOM_TESTS
00046     ,WARNING_TOL
00047     ,ERROR_TOL
00048   };
00049 
00050   const char* local_SOptions[local_num_options] = {
00051     "print_tests"
00052     ,"dump_all"
00053     ,"throw_exception"
00054     ,"num_random_tests"
00055     ,"warning_tol"
00056     ,"error_tol"
00057   };
00058 
00059 }
00060 
00061 namespace AbstractLinAlgPack {
00062 
00063 BasisSystemTesterSetOptions::BasisSystemTesterSetOptions(
00064         BasisSystemTester* target
00065       , const char opt_grp_name[] )
00066   : OptionsFromStreamPack::SetOptionsFromStreamNode(
00067         opt_grp_name, local_num_options, local_SOptions )
00068     , OptionsFromStreamPack::SetOptionsToTargetBase<
00069       BasisSystemTester >( target )
00070 {}
00071 
00072 void BasisSystemTesterSetOptions::setOption(
00073   int option_num, const std::string& option_value )
00074 {
00075   using OptionsFromStreamPack::StringToBool;
00076   typedef BasisSystemTester target_t;
00077   switch( (local_EOptions)option_num ) {
00078     case PRINT_TESTS:
00079     {
00080       const std::string &option = option_value.c_str();
00081       if( option == "PRINT_NONE" )
00082         target().print_tests( target_t::PRINT_NONE );
00083         else if( option == "PRINT_BASIC" )
00084         target().print_tests( target_t::PRINT_BASIC );
00085         else if( option == "PRINT_MORE" )
00086         target().print_tests( target_t::PRINT_MORE );
00087         else if( option == "PRINT_ALL" )
00088         target().print_tests( target_t::PRINT_ALL );
00089       else
00090         TEST_FOR_EXCEPTION(
00091           true, std::invalid_argument
00092           ,"Error, incorrect value for "
00093           "\"print_tests\".  Only the options "
00094           "PRINT_NONE, PRINT_BASIS, PRINT_MORE and PRINT_ALL are allowed" );
00095       break;
00096     }
00097     case DUMP_ALL:
00098       target().dump_all(
00099         StringToBool( "dump_all", option_value.c_str() )
00100         );
00101       break;
00102     case TEST_FOR_EXCEPTION:
00103       target().throw_exception(
00104         StringToBool( "throw_exception", option_value.c_str() )
00105         );
00106       break;
00107       case NUM_RANDOM_TESTS:
00108       target().num_random_tests(::abs(::atoi(option_value.c_str())));
00109       break;
00110       case WARNING_TOL:
00111       target().warning_tol(::fabs(::atof(option_value.c_str())));
00112       break;
00113       case ERROR_TOL:
00114       target().error_tol(::fabs(::atof(option_value.c_str())));
00115       break;
00116     default:
00117       TEST_FOR_EXCEPT(true);  // Local error only?
00118   }
00119 }
00120 
00121 } // end namespace AbstractLinAlgPack

Generated on Thu Sep 18 12:35:10 2008 for MOOCHO (Single Doxygen Collection) by doxygen 1.3.9.1