OptionsFromStreamPack_SetOptionsFromStreamNode.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 <sstream>
00030 
00031 #include "OptionsFromStreamPack_SetOptionsFromStreamNode.hpp"
00032 #include "OptionsFromStreamPack_OptionsFromStream.hpp"
00033 #include "Teuchos_TestForException.hpp"
00034 
00035 namespace OptionsFromStreamPack {
00036 
00037 SetOptionsFromStreamNode::SetOptionsFromStreamNode( const std::string& options_group
00038     , int num_options, const char* option_names[], bool exists_optional )
00039   : name_map_( options_group, num_options, option_names )
00040     , exists_optional_(exists_optional)
00041 {}
00042 
00043 void SetOptionsFromStreamNode::set_options( const OptionsFromStream& options )
00044 {
00045   OptionsFromStream::options_group_t optgrp = options.options_group( name_map_.name() );
00046   if( !OptionsFromStream::options_group_exists( optgrp ) ) {
00047     TEST_FOR_EXCEPTION(
00048       !exists_optional_, std::invalid_argument
00049       ,"SetOptionsFromStreamNode::set_options(...) : "
00050       << "Error, The options group " << name_map_.name()
00051       << " does not exist" );
00052     if(exists_optional_)
00053       return;
00054   }
00055     
00056   OptionsFromStream::options_group_t::const_iterator itr = optgrp.begin();
00057   for( ; itr != optgrp.end(); ++itr ) {
00058     setOption( name_map_( option_name(itr) ), option_value(itr).c_str() );
00059   }
00060 }
00061 
00062 } // end namespace OptionsFromStreamPack

Generated on Wed May 12 21:52:32 2010 for MOOCHO (Single Doxygen Collection) by  doxygen 1.4.7