42 #ifndef TEUCHOS_COMMAND_LINE_PROCESSOR_HPP 43 #define TEUCHOS_COMMAND_LINE_PROCESSOR_HPP 56 #include "Teuchos_Ptr.hpp" 83 {
public:
ParseError(
const std::string& what_arg) : std::logic_error(what_arg) {}};
99 ,PARSE_HELP_PRINTED = 1
100 ,PARSE_UNRECOGNIZED_OPTION = 2
125 bool throwExceptions =
true 126 ,
bool recogniseAllOptions =
true 127 ,
bool addOutputSetupOptions =
false 140 void throwExceptions(
const bool & throwExceptions );
143 bool throwExceptions()
const;
146 void recogniseAllOptions(
const bool & recogniseAllOptions );
149 bool recogniseAllOptions()
const;
152 void addOutputSetupOptions(
const bool &addOutputSetupOptions );
155 bool addOutputSetupOptions()
const;
164 void setDocString(
const char doc_string[] );
179 const char option_true[]
180 ,
const char option_false[]
182 ,
const char documentation[] = NULL
196 const char option_name[]
198 ,
const char documentation[] = NULL
199 ,
const bool required =
false 213 const char option_name[]
214 ,
long int *option_val
215 ,
const char documentation[] = NULL
216 ,
const bool required =
false 230 const char option_name[]
232 ,
const char documentation[] = NULL
233 ,
const bool required =
false 235 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 247 const char option_name[]
248 ,
long long int *option_val
249 ,
const char documentation[] = NULL
250 ,
const bool required =
false 265 const char option_name[]
267 ,
const char documentation[] = NULL
268 ,
const bool required =
false 282 const char option_name[]
283 ,std::string *option_val
284 ,
const char documentation[] = NULL
285 ,
const bool required =
false 316 template <
class EType>
318 const char enum_option_name[]
319 ,
EType *enum_option_val
320 ,
const int num_enum_opt_values
321 ,
const EType enum_opt_values[]
322 ,
const char* enum_opt_names[]
323 ,
const char documentation[] = NULL
324 ,
const bool required =
false 391 EParseCommandLineReturn parse(
394 ,std::ostream *errout = &std::cerr
410 void printHelpMessage(
const char program_name[], std::ostream &out )
const;
423 enum EOptType { OPT_NONE, OPT_BOOL_TRUE, OPT_BOOL_FALSE, OPT_INT, OPT_LONG_INT, OPT_SIZE_T,
424 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 427 OPT_DOUBLE, OPT_STRING, OPT_ENUM_INT };
444 struct opt_val_val_t {
450 opt_val_val_t( EOptType opt_type_in,
const any& opt_val_in,
bool required_in )
451 :opt_type(opt_type_in),opt_val(opt_val_in),required(required_in),was_read(false)
460 typedef Teuchos::map<std::string,opt_val_val_t> options_list_t;
467 opt_doc_t(EOptType opt_type_in,
const std::string& opt_name_in,
const std::string& opt_name_false_in
468 ,
const std::string &documentation_in,
const any &default_val_in )
469 :opt_type(opt_type_in),opt_name(opt_name_in),opt_name_false(opt_name_false_in)
470 ,documentation(documentation_in),default_val(default_val_in)
473 std::string opt_name;
474 std::string opt_name_false;
475 std::string documentation;
480 typedef std::vector<opt_doc_t> options_documentation_list_t;
483 struct enum_opt_data_t {
485 :enum_option_val(NULL), num_enum_opt_values(0)
488 int *_enum_option_val
489 ,
const int _num_enum_opt_values
490 ,
const int _enum_opt_values[]
491 ,
const char* _enum_opt_names[]
493 :enum_option_val(_enum_option_val)
494 ,num_enum_opt_values(_num_enum_opt_values)
495 ,enum_opt_values(_enum_opt_values,_enum_opt_values+_num_enum_opt_values)
497 for(
int k = 0; k < num_enum_opt_values; ++k )
498 enum_opt_names.push_back(std::string(_enum_opt_names[k]));
500 int *enum_option_val;
501 int num_enum_opt_values;
502 std::vector<int> enum_opt_values;
503 std::vector<std::string> enum_opt_names;
507 typedef std::vector<enum_opt_data_t> enum_opt_data_list_t;
512 bool throwExceptions_;
513 bool recogniseAllOptions_;
514 bool addOutputSetupOptions_;
515 std::string doc_string_;
519 #pragma warning(push) 520 #pragma warning(disable:4251) 522 mutable options_list_t options_list_;
523 options_documentation_list_t options_documentation_list_;
524 enum_opt_data_list_t enum_opt_data_list_;
529 bool output_all_front_matter_;
530 bool output_show_line_prefix_;
531 bool output_show_tab_count_;
532 bool output_show_proc_rank_;
533 int output_to_root_rank_only_;
534 bool print_rcpnode_statistics_on_exit_;
535 bool show_timer_summary_on_exit_;
537 bool printed_timer_summary_;
539 bool added_extra_output_setup_options_;
540 bool in_add_extra_output_setup_options_;
542 static const bool output_all_front_matter_default_;
543 static const bool output_show_line_prefix_default_;
544 static const bool output_show_tab_count_default_;
545 static const bool output_show_proc_rank_default_;
546 static const int output_to_root_rank_only_default_;
547 static const bool print_rcpnode_statistics_on_exit_default_;
548 static const bool show_timer_summary_on_exit_default_;
554 void add_extra_output_setup_options()
const;
558 const char enum_option_name[]
559 ,
int *enum_option_val
560 ,
const int num_enum_opt_values
561 ,
const int enum_opt_values[]
562 ,
const char* enum_opt_names[]
563 ,
const char documentation[]
571 ,
const std::string &enum_opt_name
573 ,
const std::string &enum_str_val
574 ,std::ostream *errout
578 void print_enum_opt_names(
584 std::string enum_opt_default_val_name(
585 const std::string &enum_name
587 ,std::ostream *errout
591 int find_enum_opt_index(
592 const std::string &enum_opt_name
594 ,
const enum_opt_data_t &enum_data
595 ,std::ostream *errout
602 ,std::string *opt_name
603 ,std::string *opt_val_str
607 std::string opt_type_str( EOptType )
const;
613 ,std::ostream *errout
657 virtual void summarize(std::ostream &out=std::cout) = 0;
680 { throwExceptions_ = throwExceptions_in; }
685 {
return throwExceptions_; }
690 { recogniseAllOptions_ = recogniseAllOptions_in; }
695 {
return recogniseAllOptions_; }
700 { addOutputSetupOptions_ = addOutputSetupOptions_in; }
705 {
return addOutputSetupOptions_; }
708 template <
class EType>
711 const char enum_option_name[]
712 ,
EType *enum_option_val
713 ,
const int num_enum_opt_values
714 ,
const EType enum_opt_values[]
715 ,
const char* enum_opt_names[]
716 ,
const char documentation[]
731 ,reinterpret_cast<int*>(enum_option_val)
733 ,reinterpret_cast<const int*>(enum_opt_values)
742 std::string CommandLineProcessor::opt_type_str( EOptType opt_type )
const 758 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 759 case OPT_LONG_LONG_INT:
760 str =
"long long int";
782 #endif // TEUCHOS_COMMAND_LINE_PROCESSOR_HPP Modified boost::any class for holding a templated value.
Thrown if –help was specified and throwExceptions==true.
Template classes for testing assertions at compile time.
bool recogniseAllOptions() const
Returns true if all options must be recognized by the parser.
virtual ~TimeMonitorSurrogate()
! brief.
Thrown if an unrecognized option was found and throwExceptions==true.
bool addOutputSetupOptions() const
Returns true options will be automatically added to setup Teuchos::VerboseObjectBase::getDefaultOStre...
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
Set a boolean option.
Interface by which CommandLineProcessor may use TimeMonitor.
Provides std::map class for deficient platforms.
EParseCommandLineReturn
Return value for CommandLineProcessor::parse(). Note: These enums are all given non-negative values s...
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
bool throwExceptions() const
Returns true if an std::exception is thrown, there is a parse error, or help is printed.
Smart reference counting pointer class for automatic garbage collection.
If instantiated (for Test!=0) then this should not compile!
Thrown if a parse std::exception occurs and throwExceptions==true.
Class that helps parse command line input arguments from (argc,argv[]) and set options.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...