46 #include "OptionsFromStreamPack_OptionsFromStream.hpp"
47 #include "InputStreamHelperPack_EatInputComment.hpp"
48 #include "Teuchos_Assert.hpp"
57 void clip_ws( std::string* str ) {
60 std::string::iterator itr;
61 for( itr = str->begin(); itr != str->end(); ++itr )
62 if( *itr !=
' ' )
break;
63 str->erase( str->begin(), itr );
67 std::string::iterator itr;
68 for( itr = str->end() - 1; itr > str->begin() - 1; --itr )
69 if( *itr !=
' ' )
break;
70 str->erase( itr + 1, str->end() );
76 namespace OptionsFromStreamPack {
78 namespace OptionsFromStreamUtilityPack {
82 std::string OptionsGroup::option_does_not_exist_;
91 options_group_map_t::iterator itr = options_group_map_.find( options_group_name );
92 if( itr != options_group_map_.end() ) {
93 (*itr).second.second.set(
true);
102 options_group_map_t::const_iterator itr = options_group_map_.find( options_group_name );
103 if( itr != options_group_map_.end() ) {
104 const_cast<false_bool_t&
>((*itr).second.second).set(
true);
105 return options_group_t(const_cast<option_to_value_map_t*>(&(*itr).second.first));
113 (*og_itr).second.second.set(
false);
120 for( ; og_itr !=
end(); ++og_itr ) {
121 if( (*og_itr).second.second ==
false )
122 out <<
"options_group " << options_group_name( og_itr ) <<
" {}\n";
130 using InputStreamHelperPack::eat_comment_lines;
132 std::string curr_word;
137 #ifdef PRINT_OPTIONS_FROM_STREAM_TRACE
138 std::cout <<
"\n*** Entering OptionsFromStream::read_options(...)!\n\n";
142 while( curr_word !=
"begin_options" && !in.eof() )
144 #ifdef PRINT_OPTIONS_FROM_STREAM_TRACE
145 std::cout <<
"Found begin_options, start parsing options!\n";
149 eat_comment_lines(in,
'*');
152 #ifdef PRINT_OPTIONS_FROM_STREAM_TRACE
153 std::cout <<
"\ncurr_word = \""<<curr_word<<
"\"\n";
155 if( curr_word ==
"}" ) {
156 #ifdef PRINT_OPTIONS_FROM_STREAM_TRACE
157 std::cout <<
"Found \'}\', Moving on to the next options group or the end!\n";
161 if( curr_word ==
"end_options" ) {
162 #ifdef PRINT_OPTIONS_FROM_STREAM_TRACE
163 std::cout <<
"Found \'end_options\', stoping parsing options!\n";
169 ,
"OptionsFromStream::read_options(...) : "
170 "Error, curr_word = \'" << curr_word <<
" != \'options_group\'" );
172 std::getline(in,curr_word,
'{');
173 clip_ws( &curr_word );
174 const std::string optgroup_name = curr_word;
175 #ifdef PRINT_OPTIONS_FROM_STREAM_TRACE
176 std::cout <<
"\noptgroup_name = \"" << optgroup_name <<
"\"\n";
179 option_to_value_map_t& optval = options_group_map_[optgroup_name].first;
181 eat_comment_lines(in,
'*');
182 std::string optgroup_options;
183 getline(in,optgroup_options,
'}');
184 #ifdef PRINT_OPTIONS_FROM_STREAM_TRACE
185 std::cout <<
"optgroup_options = \"" << optgroup_options <<
"\"\n";
187 std::istringstream optgroup_options_in(optgroup_options);
190 eat_comment_lines(optgroup_options_in,
'*');
192 std::string option_and_value;
193 getline(optgroup_options_in,option_and_value,
';');
199 clip_ws(&option_and_value);
200 #ifdef PRINT_OPTIONS_FROM_STREAM_TRACE
201 std::cout <<
" option_and_value = \"" << option_and_value <<
"\"\n";
203 if(!option_and_value.length())
208 equal_idx==std::string::npos, std::logic_error,
209 "Error, for the option group \"" << optgroup_name <<
"\""
210 <<
" the option value string \"" << option_and_value <<
"\" is missing the \"=\" separator!"
212 std::string option = option_and_value.substr(0,equal_idx);
213 std::string value = option_and_value.substr(equal_idx+1);
216 #ifdef PRINT_OPTIONS_FROM_STREAM_TRACE
217 std::cout <<
" option = \"" << option <<
"\"\n";
218 std::cout <<
" value = \"" << value <<
"\"\n";
220 optval[option] = value;
223 #ifdef PRINT_OPTIONS_FROM_STREAM_TRACE
224 std::cout <<
"\n*** Leaving OptionsFromStream::read_options(...)!\n\n";
229 out <<
"\nbegin_options\n";
231 for( ; og_itr !=
end(); ++og_itr ) {
232 const options_group_t optgrp = OptionsFromStreamPack::options_group( og_itr );
234 if(itr == optgrp.
end())
continue;
235 out <<
"\noptions_group " << options_group_name( og_itr ) <<
" {\n";
236 for( ; itr != optgrp.
end(); ++itr ) {
238 &name = option_name(itr),
239 &value = option_value(itr);
240 out <<
" " << name <<
" = " << value <<
";\n";
244 out <<
"\nend_options\n\n";
option_to_value_map_t::const_iterator const_iterator
void print_options(std::ostream &out) const
Print the options to an output stream.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
OptionsFromStreamUtilityPack::options_group_map_t::const_iterator const_iterator
non-const iterator through options group access options
OptionsFromStreamUtilityPack::OptionsGroup options_group_t
{OptionsGroup} typedef
void read_options(std::istream &in)
Add / modify options read in from a text stream.
size_t size_type
Size type.
Class used to encapsulate options belonging an options group.
void reset_unaccessed_options_groups()
Reset the flags to false for if the options groups was accessed.
options_group_t options_group(const std::string &options_group_name)
void print_unaccessed_options_groups(std::ostream &out) const
Print a list of options groups never accessed (accessed flag is falsed).
OptionsFromStreamUtilityPack::options_group_map_t::iterator iterator
const iterator through options group access options