42 #include "OptionsFromStreamPack_CommandLineOptionsFromStreamProcessor.hpp"
47 namespace OptionsFromStreamPack {
50 const std::string &options_file_name_opt_name
51 ,
const std::string &options_file_name_opt_doc
52 ,
const std::string &options_file_name
53 ,
const std::string &extra_options_str_opt_name
54 ,
const std::string &extra_options_str_opt_doc
55 ,
const std::string &extra_options_str
57 :options_file_name_opt_name_(options_file_name_opt_name)
58 ,options_file_name_opt_doc_(options_file_name_opt_doc)
59 ,options_file_name_(options_file_name)
60 ,extra_options_str_opt_name_(extra_options_str_opt_name)
61 ,extra_options_str_opt_doc_(extra_options_str_opt_doc)
62 ,extra_options_str_(extra_options_str)
82 clp->
setOption(options_file_name_opt_name().c_str(),&options_file_name_,options_file_name_opt_doc().c_str());
83 clp->
setOption(extra_options_str_opt_name().c_str(),&extra_options_str_,extra_options_str_opt_doc().c_str());
89 if(options_file_name_.length()) {
90 std::ifstream options_in(options_file_name_.c_str());
94 options_->read_options(options_in);
98 const int len = extra_options_str_.length();
102 const char colon =
':';
104 std::ostringstream ooptsstream;
105 ooptsstream <<
"\nbegin_options\n\n";
108 last_i = extra_options_str_.find(colon,start_i);
109 std::string optgroup = extra_options_str_.substr(start_i,last_i-start_i);
110 #ifdef PRINT_COMMAND_LINE_OPTIONS_FROM_STREAM_PROCESSOR_TRACE
111 std::cout <<
"\nstart_i = " << start_i;
112 std::cout <<
"\nlast_i = " << last_i;
113 std::cout <<
"\noptgroup (before replacement) = \""<<optgroup<<
"\"\n";
115 std::replace( optgroup.begin(), optgroup.end(),
',',
';' );
116 #ifdef PRINT_COMMAND_LINE_OPTIONS_FROM_STREAM_PROCESSOR_TRACE
117 std::cout <<
"\noptgroup (after replacement) = \""<<optgroup<<
"\"\n";
119 ooptsstream <<
"options_group " << optgroup <<
"\n";
120 if(last_i == npos)
break;
121 start_i = last_i + 1;
123 ooptsstream <<
"\nend_options\n";
124 const std::string options_str = ooptsstream.str();
125 #ifdef PRINT_COMMAND_LINE_OPTIONS_FROM_STREAM_PROCESSOR_TRACE
126 std::cout <<
"options_str:\n" << options_str;
128 std::istringstream ioptsstream(options_str);
129 options_->read_options(ioptsstream);
Extracts options from a text stream and then allows convenient access to them.
void setup_commandline_processor(Teuchos::CommandLineProcessor *clp)
Setup a comandline processor before it processes commandline options or reads form a file...
Teuchos::RCP< OptionsFromStream > get_options() const
Just return the OptionsFromStream object in its current state.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
size_t size_type
Size type.
void set_options(Teuchos::RCP< OptionsFromStream > const &options)
Set the OptionsFromStream object that will be used to fill options in to.
void process_options()
Read the options file and/or process the commandline options.
Teuchos::RCP< OptionsFromStream > process_and_get_options()
Calls process_options() and returns get_options()
CommandLineOptionsFromStreamProcessor(const std::string &options_file_name_opt_name="ofs-options-file", const std::string &options_file_name_opt_doc="The name of the file containing input options for OptionsFromStream object.", const std::string &options_file_name="", const std::string &extra_options_str_opt_name="ofs-extra-options", const std::string &extra_options_str_opt_doc="Extra options in format \"OptGrp1{name1=val1,...,namen=valn}:OptGr2{name1=val1,...,namen=valn}:...\"", const std::string &extra_options_str="")
Construct with default values for the options file name and extra options.