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 219 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 231 const char option_name[]
232 ,
long long int *option_val
233 ,
const char documentation[] = NULL
234 ,
const bool required =
false 249 const char option_name[]
251 ,
const char documentation[] = NULL
252 ,
const bool required =
false 266 const char option_name[]
267 ,std::string *option_val
268 ,
const char documentation[] = NULL
269 ,
const bool required =
false 300 template <
class EType>
302 const char enum_option_name[]
303 ,
EType *enum_option_val
304 ,
const int num_enum_opt_values
305 ,
const EType enum_opt_values[]
306 ,
const char* enum_opt_names[]
307 ,
const char documentation[] = NULL
308 ,
const bool required =
false 378 ,std::ostream *errout = &std::cerr
394 void printHelpMessage(
const char program_name[], std::ostream &out )
const;
407 enum EOptType { OPT_NONE, OPT_BOOL_TRUE, OPT_BOOL_FALSE, OPT_INT, OPT_LONG_INT,
408 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 411 OPT_DOUBLE, OPT_STRING, OPT_ENUM_INT };
428 struct opt_val_val_t {
432 opt_val_val_t( EOptType opt_type_in,
const any& opt_val_in,
bool required_in )
433 :opt_type(opt_type_in),opt_val(opt_val_in),required(required_in),was_read(false)
442 typedef Teuchos::map<std::string,opt_val_val_t> options_list_t;
449 opt_doc_t(EOptType opt_type_in,
const std::string& opt_name_in,
const std::string& opt_name_false_in
450 ,
const std::string &documentation_in,
const any &default_val_in )
451 :opt_type(opt_type_in),opt_name(opt_name_in),opt_name_false(opt_name_false_in)
452 ,documentation(documentation_in),default_val(default_val_in)
455 std::string opt_name;
456 std::string opt_name_false;
457 std::string documentation;
462 typedef std::vector<opt_doc_t> options_documentation_list_t;
465 struct enum_opt_data_t {
467 :enum_option_val(NULL), num_enum_opt_values(0)
470 int *_enum_option_val
471 ,
const int _num_enum_opt_values
472 ,
const int _enum_opt_values[]
473 ,
const char* _enum_opt_names[]
475 :enum_option_val(_enum_option_val)
476 ,num_enum_opt_values(_num_enum_opt_values)
477 ,enum_opt_values(_enum_opt_values,_enum_opt_values+_num_enum_opt_values)
479 for(
int k = 0; k < num_enum_opt_values; ++k )
480 enum_opt_names.push_back(std::string(_enum_opt_names[k]));
482 int *enum_option_val;
483 int num_enum_opt_values;
484 std::vector<int> enum_opt_values;
485 std::vector<std::string> enum_opt_names;
489 typedef std::vector<enum_opt_data_t> enum_opt_data_list_t;
494 bool throwExceptions_;
495 bool recogniseAllOptions_;
496 bool addOutputSetupOptions_;
497 std::string doc_string_;
501 #pragma warning(push) 502 #pragma warning(disable:4251) 504 mutable options_list_t options_list_;
505 options_documentation_list_t options_documentation_list_;
506 enum_opt_data_list_t enum_opt_data_list_;
511 bool output_all_front_matter_;
512 bool output_show_line_prefix_;
513 bool output_show_tab_count_;
514 bool output_show_proc_rank_;
515 int output_to_root_rank_only_;
516 bool print_rcpnode_statistics_on_exit_;
517 bool show_timer_summary_on_exit_;
519 bool printed_timer_summary_;
521 bool added_extra_output_setup_options_;
522 bool in_add_extra_output_setup_options_;
524 static const bool output_all_front_matter_default_;
525 static const bool output_show_line_prefix_default_;
526 static const bool output_show_tab_count_default_;
527 static const bool output_show_proc_rank_default_;
528 static const int output_to_root_rank_only_default_;
529 static const bool print_rcpnode_statistics_on_exit_default_;
530 static const bool show_timer_summary_on_exit_default_;
536 void add_extra_output_setup_options()
const;
540 const char enum_option_name[]
541 ,
int *enum_option_val
542 ,
const int num_enum_opt_values
543 ,
const int enum_opt_values[]
544 ,
const char* enum_opt_names[]
545 ,
const char documentation[]
553 ,
const std::string &enum_opt_name
555 ,
const std::string &enum_str_val
556 ,std::ostream *errout
560 void print_enum_opt_names(
566 std::string enum_opt_default_val_name(
567 const std::string &enum_name
569 ,std::ostream *errout
573 int find_enum_opt_index(
574 const std::string &enum_opt_name
576 ,
const enum_opt_data_t &enum_data
577 ,std::ostream *errout
584 ,std::string *opt_name
585 ,std::string *opt_val_str
589 std::string opt_type_str( EOptType )
const;
595 ,std::ostream *errout
639 virtual void summarize(std::ostream &out=std::cout) = 0;
662 { throwExceptions_ = throwExceptions_in; }
667 {
return throwExceptions_; }
672 { recogniseAllOptions_ = recogniseAllOptions_in; }
677 {
return recogniseAllOptions_; }
682 { addOutputSetupOptions_ = addOutputSetupOptions_in; }
687 {
return addOutputSetupOptions_; }
690 template <
class EType>
693 const char enum_option_name[]
694 ,
EType *enum_option_val
695 ,
const int num_enum_opt_values
696 ,
const EType enum_opt_values[]
697 ,
const char* enum_opt_names[]
698 ,
const char documentation[]
713 ,reinterpret_cast<int*>(enum_option_val)
715 ,reinterpret_cast<const int*>(enum_opt_values)
724 std::string CommandLineProcessor::opt_type_str( EOptType opt_type )
const 737 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 738 case OPT_LONG_LONG_INT:
739 str =
"long long int";
761 #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 throwExceptions() const
Returns true if an std::exception is thrown, there is a parse error, or help is printed.
virtual ~TimeMonitorSurrogate()
! brief.
Modified boost::any class, which is a container for a templated value.
Thrown if an unrecognized option was found and throwExceptions==true.
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.
bool addOutputSetupOptions() const
Returns true options will be automatically added to setup Teuchos::VerboseObjectBase::getDefaultOStre...
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 recogniseAllOptions() const
Returns true if all options must be recognized by the parser.
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...