timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
|
#include "timemory/utility/argparse.hpp"
Classes | |
struct | arg_result |
struct | argument |
Public Types | |
using | this_type = argument_parser |
using | result_type = arg_result |
using | bool_func_t = std::function< bool(this_type &)> |
using | action_func_t = std::function< void(this_type &)> |
using | action_pair_t = std::pair< bool_func_t, action_func_t > |
using | error_func_t = std::function< void(this_type &, arg_result &)> |
using | known_args_t = std::tuple< arg_result, int, char ** > |
using | strvec_t = std::vector< std::string > |
using | strset_t = std::set< std::string > |
Public Member Functions | |
argument_parser (std::string desc) | |
argument & | add_argument () |
argument & | add_argument (const std::initializer_list< std::string > &_names, const std::string &desc, bool req=false) |
argument & | add_argument (const std::vector< std::string > &_names, const std::string &desc, bool req=false) |
argument & | add_positional_argument (const std::string &_name) |
template<typename Tp > | |
arg_result | get (size_t _idx, Tp &_value) |
template<typename Tp > | |
arg_result | get (const std::string &_name, Tp &_value) |
template<typename BoolFuncT , typename ActionFuncT > | |
this_type & | add_action (BoolFuncT &&_b, ActionFuncT &_act) |
template<typename ActionFuncT > | |
this_type & | add_action (const std::string &_name, ActionFuncT &_act) |
void | print_help (const std::string &_extra="") |
known_args_t | parse_known_args (int argc, char **argv, const std::string &_delim="--", int verbose_level=0) |
Basic variant of parse_known_args which does not replace argc/argv and does not provide an array of strings that it processed. More... | |
arg_result | parse_known_args (int *argc, char ***argv, const std::string &_delim="--", int verbose_level=0) |
This variant calls parse_known_args and replaces argc and argv with the argv[0] + anything after delimiter (if the delimiter is provided). If the delimiter does not exist, argc and argv are unchanged. More... | |
arg_result | parse_known_args (int *argc, char ***argv, strvec_t &_args, const std::string &_delim="--", int verbose_level=0) |
known_args_t | parse_known_args (int argc, char **argv, strvec_t &_args, const std::string &_delim="--", int verbose_level=0) |
Parses all options until argv[argc-1] or delimiter is found. Returns a tuple containing an argument error object (operator bool will return true if there was an error) and the new argc and argv after the known arguments have been processed. This is slightly different from the Python argparse.ArgumentParser.parse_known_args: if the delimiter is not found, it will not remove the arguments that it recognizes. To distinguish this parsers options from user arguments, use the syntax: More... | |
template<typename... Args> | |
arg_result | parse_args (Args &&... args) |
arg_result | parse (int argc, char **argv, int verbose_level=0) |
arg_result | parse (const std::vector< std::string > &_args, int verbose_level=0) |
This is the primary function for parsing the command line arguments. This is where the map of the options is built and the loop over the arguments is performed. More... | |
argument & | enable_help () |
Add a help command. More... | |
bool | exists (const std::string &name) const |
Returns whether or not an option was found in the arguments. Only useful after a call to parse or parse_known_args. More... | |
template<typename T > | |
T | get (const std::string &name) |
Get the value(s) associated with an argument. If option, it should be used in conjunction with exists(name). Only useful after a call to parse or parse_known_args. More... | |
int64_t | get_count (const std::string &name) |
int64_t | get_positional_count () const |
template<typename ErrorFuncT > | |
void | on_error (ErrorFuncT &&_func) |
void | set_help_width (int _v) |
Static Public Member Functions | |
static int64_t | get_count (argument &a) |
Definition at line 323 of file argparse.hpp.
using tim::argparse::argument_parser::action_func_t = std::function<void(this_type&)> |
Definition at line 330 of file argparse.hpp.
using tim::argparse::argument_parser::action_pair_t = std::pair<bool_func_t, action_func_t> |
Definition at line 331 of file argparse.hpp.
using tim::argparse::argument_parser::bool_func_t = std::function<bool(this_type&)> |
Definition at line 329 of file argparse.hpp.
using tim::argparse::argument_parser::error_func_t = std::function<void(this_type&, arg_result&)> |
Definition at line 332 of file argparse.hpp.
using tim::argparse::argument_parser::known_args_t = std::tuple<arg_result, int, char**> |
Definition at line 333 of file argparse.hpp.
Definition at line 328 of file argparse.hpp.
using tim::argparse::argument_parser::strset_t = std::set<std::string> |
Definition at line 335 of file argparse.hpp.
using tim::argparse::argument_parser::strvec_t = std::vector<std::string> |
Definition at line 334 of file argparse.hpp.
Definition at line 327 of file argparse.hpp.
|
inline |
Definition at line 630 of file argparse.hpp.
|
inline |
Definition at line 731 of file argparse.hpp.
|
inline |
|
inline |
Definition at line 636 of file argparse.hpp.
Referenced by tim::tsettings< Tp, Vp >::add_argument(), add_argument(), enable_help(), and tim::for().
|
inline |
Definition at line 645 of file argparse.hpp.
References add_argument(), tim::argparse::argument_parser::argument::description(), tim::argparse::argument_parser::argument::names(), and tim::argparse::argument_parser::argument::required().
|
inline |
Definition at line 653 of file argparse.hpp.
References add_argument(), tim::argparse::argument_parser::argument::description(), tim::argparse::argument_parser::argument::names(), and tim::argparse::argument_parser::argument::required().
|
inline |
Definition at line 661 of file argparse.hpp.
|
inline |
Add a help command.
Definition at line 871 of file argparse.hpp.
References add_argument(), tim::description(), and tim::argparse::argument_parser::argument::names().
|
inline |
Returns whether or not an option was found in the arguments. Only useful after a call to parse or parse_known_args.
Definition at line 912 of file argparse.hpp.
Referenced by add_action(), and parse_known_args().
|
inline |
Definition at line 689 of file argparse.hpp.
References get().
|
inline |
Get the value(s) associated with an argument. If option, it should be used in conjunction with exists(name). Only useful after a call to parse or parse_known_args.
T | Data type to convert the argument into |
[in] | name | An identifier of the option |
Definition at line 950 of file argparse.hpp.
|
inline |
Definition at line 674 of file argparse.hpp.
Referenced by tim::description(), get(), tim::component::network_stats::get_interfaces(), and tim::settings::parse().
|
inlinestatic |
Definition at line 974 of file argparse.hpp.
|
inline |
Definition at line 960 of file argparse.hpp.
|
inline |
Definition at line 970 of file argparse.hpp.
|
inline |
Definition at line 979 of file argparse.hpp.
arg_result tim::argparse::argument_parser::parse | ( | const std::vector< std::string > & | args, |
int | verb = 0 |
||
) |
This is the primary function for parsing the command line arguments. This is where the map of the options is built and the loop over the arguments is performed.
[in] | args | Array of strings (i.e. command-line arguments) |
[in] | verb | Verbosity |
Definition at line 375 of file argparse.cpp.
References tim::_args.
|
inline |
Definition at line 847 of file argparse.hpp.
References tim::_args, tim::argv, and parse().
Referenced by parse(), parse_args(), and parse_known_args().
|
inline |
Definition at line 840 of file argparse.hpp.
References parse().
|
inline |
This variant calls parse_known_args and replaces argc and argv with the argv[0] + anything after delimiter (if the delimiter is provided). If the delimiter does not exist, argc and argv are unchanged.
[in,out] | argc | Pointer to number of arguments (i.e. # of command-line args) |
[in,out] | argv | Pointer to array of strings (i.e. command-line) |
[in] | delim | Delimiter which separates this argparser's opts from user's arguments |
[in] | verb | verbosity |
Definition at line 774 of file argparse.hpp.
References tim::argv, and parse_known_args().
TIMEMORY_UTILITY_INLINE argument_parser::arg_result tim::argparse::argument_parser::parse_known_args | ( | int * | argc, |
char *** | argv, | ||
strvec_t & | _args, | ||
const std::string & | _delim = "--" , |
||
int | verbose_level = 0 |
||
) |
Definition at line 269 of file argparse.cpp.
References tim::_args, tim::argv, exists(), and parse_known_args().
|
inline |
Basic variant of parse_known_args which does not replace argc/argv and does not provide an array of strings that it processed.
[in,out] | argc | Number of arguments (i.e. # of command-line args) |
[in,out] | argv | Array of strings (i.e. command-line) |
[in] | delim | Delimiter which separates this argparser's opts from user's arguments |
[in] | verb | verbosity |
Definition at line 765 of file argparse.hpp.
References tim::_args, tim::argv, and parse_known_args().
Referenced by parse_known_args().
arg_result tim::argparse::argument_parser::parse_known_args | ( | int | argc, |
char ** | argv, | ||
strvec_t & | args, | ||
const std::string & | delim = "--" , |
||
int | verb = 0 |
||
) |
Parses all options until argv[argc-1] or delimiter is found. Returns a tuple containing an argument error object (operator bool will return true if there was an error) and the new argc and argv after the known arguments have been processed. This is slightly different from the Python argparse.ArgumentParser.parse_known_args: if the delimiter is not found, it will not remove the arguments that it recognizes. To distinguish this parsers options from user arguments, use the syntax:
[in,out] | argc | Number of arguments (i.e. # of command-line args) |
[in,out] | argv | Array of strings (i.e. command-line) |
[in,out] | args | Array of strings processed by this parser |
[in] | delim | Delimiter which separates this argparser's opts from user's arguments |
[in] | verb | verbosity |
./<CMD> <PARSER_OPTIONS> – <USER_ARGS>
And std::get<1>(...) on the return value will be the new argc. and std::get<2>(...) on the return value will be the new argv. Other valid usages:
./<CMD> –help (will report this parser's help message) ./<CMD> – –help (will report the applications help message, if supported) ./<CMD> <USER_ARGS> ./<CMD> <PARSER_OPTIONS> ./<CMD> <PARSER_OPTIONS> <USER_ARGS> (intermixed)
will not remove any of the known options. In other words, this will remove all arguments after <CMD> until the first "--" if reached and everything after the "--" will be placed in argv[1:]
Definition at line 316 of file argparse.cpp.
References tim::_args, tim::argv, parse(), and strdup().
TIMEMORY_UTILITY_INLINE void tim::argparse::argument_parser::print_help | ( | const std::string & | _extra = "" | ) |
|
inline |
Definition at line 986 of file argparse.hpp.