50#ifndef YASK_DEPRECATED
51#define YASK_DEPRECATED
56#define YASK_INT64_T long int
59#ifndef YASK_DEPRECATED
60#define YASK_DEPRECATED [[deprecated]]
64#define YASK_NORETURN [[noreturn]]
67#define YASK_INT64_T std::int64_t
134 _msg(
"YASK error") { };
145 virtual const char*
what() const noexcept;
164 #define THROW_YASK_EXCEPTION(message) do { \
165 auto msg = std::string("YASK error: ") + message; \
166 yask_exception e(msg); \
175 #define FORMAT_AND_THROW_YASK_EXCEPTION(message) do { \
176 std::stringstream err; \
178 THROW_YASK_EXCEPTION(err.str()); \
296 int accuracy_order );
308 int accuracy_order );
320 const std::vector<double> sample_points );
347 std::string _help_leader;
348 std::string _current_value_str;
354 const std::string& display_name,
363 const std::string& str)
const;
392 const std::string& help_msg,
393 const std::string& current_value_prefix = std::string(
"Current value = "),
394 const std::string& help_line_prefix = std::string(
" ")) :
395 _name(name), _help(help_msg),
396 _help_leader(help_line_prefix),
397 _current_value_str(current_value_prefix)
414 _print_help(os, _name, width);
438 const std::string& help_msg,
444 int width)
const override;
447 virtual std::ostream&
print_value(std::ostream& os)
const override {
448 os << (_val ?
"true" :
"false");
463 const std::string& help_msg,
469 int width)
const override;
472 virtual std::ostream&
print_value(std::ostream& os)
const override {
488 const std::string& help_msg,
494 int width)
const override;
497 virtual std::ostream&
print_value(std::ostream& os)
const override {
513 const std::string& help_msg,
519 int width)
const override;
522 virtual std::ostream&
print_value(std::ostream& os)
const override {
538 const std::string& help_msg,
544 int width)
const override;
547 virtual std::ostream&
print_value(std::ostream& os)
const override {
548 os <<
"'" << _val <<
"'";
562 std::set<std::string> _allowed_strs;
568 const std::string& help_msg,
575 const std::string& help_msg,
576 const std::set<std::string>& allowed_strs,
579 _allowed_strs(allowed_strs),
584 int width)
const override;
587 virtual std::ostream&
print_value(std::ostream& os)
const override {
589 for (
auto& v : _val) {
603 std::map<std::string, option_ptr> _opts;
629 _opts[opt->get_name()] = opt;
650 const std::string& arg_string) {
651 auto args = set_args(arg_string);
652 return parse_args(pgm_name, args);
658 std::string pgm_name = argv[0];
660 for (
int i = 1; i < argc; i++)
661 args.push_back(argv[i]);
662 return parse_args(pgm_name, args);
676 std::string invocation_leader =
"invocation: ");
A boolean option.
Definition yask_common_api.hpp:432
virtual void print_help(std::ostream &os, int width) const override
Print help message for a boolean option.
bool_option(const std::string &name, const std::string &help_msg, bool &val)
Constructor.
Definition yask_common_api.hpp:437
virtual std::ostream & print_value(std::ostream &os) const override
Print current value of the boolean.
Definition yask_common_api.hpp:447
virtual bool check_arg(const string_vec &args, int &argi) override
Check for a boolean option (set or unset variants).
A double option.
Definition yask_common_api.hpp:482
virtual std::ostream & print_value(std::ostream &os) const override
Print the current value of the double.
Definition yask_common_api.hpp:497
virtual bool check_arg(const string_vec &args, int &argi) override
Check for the option and its double argument.
virtual void print_help(std::ostream &os, int width) const override
Print help message for a double option.
double_option(const std::string &name, const std::string &help_msg, double &val)
Constructor.
Definition yask_common_api.hpp:487
An idx_t option.
Definition yask_common_api.hpp:507
virtual std::ostream & print_value(std::ostream &os) const override
Print the current value of the int_t.
Definition yask_common_api.hpp:522
virtual void print_help(std::ostream &os, int width) const override
Print help message for an int_t option.
virtual bool check_arg(const string_vec &args, int &argi) override
Check for the option and its int_t argument.
idx_option(const std::string &name, const std::string &help_msg, idx_t &val)
Constructor.
Definition yask_common_api.hpp:512
An integer option.
Definition yask_common_api.hpp:457
virtual void print_help(std::ostream &os, int width) const override
Print help message for an int option.
virtual bool check_arg(const string_vec &args, int &argi) override
Check for the option and its integer argument.
virtual std::ostream & print_value(std::ostream &os) const override
Print the current value of the int.
Definition yask_common_api.hpp:472
int_option(const std::string &name, const std::string &help_msg, int &val)
Constructor.
Definition yask_common_api.hpp:462
Base class for a command-line option.
Definition yask_common_api.hpp:342
virtual double _double_val(const string_vec &args, int &argi)
Get one double value from args[argi++].
virtual std::ostream & print_value(std::ostream &os) const =0
Print current value of this option.
virtual const std::string & get_name() const
Get the current option name.
Definition yask_common_api.hpp:402
virtual std::string _string_val(const string_vec &args, int &argi)
Get one string value from args[argi++].
virtual void print_help(std::ostream &os, int width) const
Print help on this option.
Definition yask_common_api.hpp:412
virtual idx_t _idx_val(const string_vec &args, int &argi)
Get one idx_t value from args[argi++].
virtual bool _is_opt(const string_vec &args, int &argi, const std::string &str) const
Check for matching option to str at args[argi].
virtual bool check_arg(const string_vec &args, int &argi)=0
Check for matching option and any needed args at args[argi].
virtual const std::string & get_help() const
Get the unformatted help string.
Definition yask_common_api.hpp:407
option_base(const std::string &name, const std::string &help_msg, const std::string ¤t_value_prefix=std::string("Current value = "), const std::string &help_line_prefix=std::string(" "))
Constructor.
Definition yask_common_api.hpp:391
virtual void _print_help(std::ostream &os, const std::string &display_name, int width) const
Format and print help for option named display_name to os.
A list-of-strings option.
Definition yask_common_api.hpp:561
virtual bool check_arg(const string_vec &args, int &argi) override
Check for the option and its string-list argument.
virtual std::ostream & print_value(std::ostream &os) const override
Print the current value of the strings.
Definition yask_common_api.hpp:587
string_list_option(const std::string &name, const std::string &help_msg, const std::set< std::string > &allowed_strs, string_vec &val)
Constructor with set of allowed strings.
Definition yask_common_api.hpp:574
virtual void print_help(std::ostream &os, int width) const override
Print help message for a list-of-strings option.
string_list_option(const std::string &name, const std::string &help_msg, string_vec &val)
Constructor allowing any strings.
Definition yask_common_api.hpp:567
A string option.
Definition yask_common_api.hpp:532
string_option(const std::string &name, const std::string &help_msg, std::string &val)
Constructor.
Definition yask_common_api.hpp:537
virtual bool check_arg(const string_vec &args, int &argi) override
Check for the option and its string argument.
virtual std::ostream & print_value(std::ostream &os) const override
Print the current value of the string.
Definition yask_common_api.hpp:547
virtual void print_help(std::ostream &os, int width) const override
Print help message for a string option.
A class to parse command-line arguments.
Definition yask_common_api.hpp:334
virtual int get_width() const
Get help width.
Definition yask_common_api.hpp:623
virtual void set_width(int width)
Set help width.
Definition yask_common_api.hpp:618
virtual ~command_line_parser()
Destructor.
Definition yask_common_api.hpp:612
virtual std::string parse_args(int argc, char **argv)
Same as parse_args(), but pgm_name is populated from argv[0] and rest of argv is parsed.
Definition yask_common_api.hpp:657
virtual void add_option(option_ptr opt)
Add an allowed option to the parser.
Definition yask_common_api.hpp:628
virtual void print_values(std::ostream &os) const
Print current settings of all options to os.
virtual std::string parse_args(const std::string &pgm_name, const string_vec &args)
Parse options from 'args' and set corresponding vars.
static string_vec set_args(const std::string &arg_string)
Convenience funcion to tokenize args from a string.
virtual void print_help(std::ostream &os) const
Print help info on all options to os.
command_line_parser()
Constructor.
Definition yask_common_api.hpp:609
std::shared_ptr< option_base > option_ptr
Pointer to an option handler.
Definition yask_common_api.hpp:429
virtual std::string parse_args(const std::string &pgm_name, const std::string &arg_string)
Same as parse_args(), but splits 'arg_string' into tokens.
Definition yask_common_api.hpp:649
Exception from YASK framework.
Definition yask_common_api.hpp:125
yask_exception()
Construct a YASK exception with default message.
Definition yask_common_api.hpp:133
yask_exception(const std::string &message)
Construct a YASK exception with message.
Definition yask_common_api.hpp:137
virtual const char * what() const noexcept
Get description.
virtual const char * get_message() const
Get description.
virtual void add_message(const std::string &message)
Append message to description of this exception.
File output.
Definition yask_common_api.hpp:235
virtual std::string get_filename() const =0
Get the filename.
virtual void close()=0
Close file.
Null output.
Definition yask_common_api.hpp:269
Factory to create output objects.
Definition yask_common_api.hpp:184
virtual yask_file_output_ptr new_file_output(const std::string &file_name) const
Create a file output object.
virtual yask_null_output_ptr new_null_output() const
Create a null output object.
virtual yask_string_output_ptr new_string_output() const
Create a string output object.
virtual yask_stdout_output_ptr new_stdout_output() const
Create a stdout output object.
Base interface for output.
Definition yask_common_api.hpp:225
virtual std::ostream & get_ostream()=0
Access underlying C++ ostream object.
Stdout output.
Definition yask_common_api.hpp:262
String output.
Definition yask_common_api.hpp:248
virtual void discard()=0
Discard contents of current buffer.
virtual std::string get_string() const =0
Get the output.
YASK_INT64_T idx_t
Type to use for indexing grids.
Definition yask_common_api.hpp:86
std::vector< double > get_backward_fd_coefficients(int derivative_order, int accuracy_order)
Create finite-difference (FD) coefficients for the standard backward form.
std::shared_ptr< yask_string_output > yask_string_output_ptr
Shared pointer to yask_string_output.
Definition yask_common_api.hpp:113
std::vector< double > get_center_fd_coefficients(int derivative_order, int radius)
Create finite-difference (FD) coefficients for the standard center form.
std::shared_ptr< yask_file_output > yask_file_output_ptr
Shared pointer to yask_file_output.
Definition yask_common_api.hpp:109
std::vector< std::string > string_vec
Vector of strings.
Definition yask_common_api.hpp:99
std::shared_ptr< yask_output > yask_output_ptr
Shared pointer to yask_output.
Definition yask_common_api.hpp:105
std::vector< double > get_arbitrary_fd_coefficients(int derivative_order, double eval_point, const std::vector< double > sample_points)
Create finite-difference (FD) coefficients at arbitrary evaluation and sample points.
std::shared_ptr< yask_null_output > yask_null_output_ptr
Shared pointer to yask_null_output.
Definition yask_common_api.hpp:121
std::string yask_get_version_string()
Version information.
std::initializer_list< idx_t > idx_t_init_list
Initializer list of indices.
Definition yask_common_api.hpp:96
std::vector< idx_t > idx_t_vec
Vector of indices.
Definition yask_common_api.hpp:89
std::vector< double > get_forward_fd_coefficients(int derivative_order, int accuracy_order)
Create finite-difference (FD) coefficients for the standard forward form.
std::shared_ptr< yask_stdout_output > yask_stdout_output_ptr
Shared pointer to yask_stdout_output.
Definition yask_common_api.hpp:117
void yask_print_splash(std::ostream &os, int argc, char **argv, std::string invocation_leader="invocation: ")
Print a YASK spash message to os.
#define YASK_INT64_T
Signed 64-bit int.
Definition yask_common_api.hpp:67