22 #ifndef KALDI_UTIL_PARSE_OPTIONS_H_ 23 #define KALDI_UTIL_PARSE_OPTIONS_H_ 41 #if !defined(_MSC_VER) && !defined(__CYGWIN__) // This is just a convenient place to set the stderr to line 43 #endif // This helps ensure different programs' output is not mixed up. 45 "option may be repeated)");
47 "Print the command line arguments (to stderr)");
50 "Verbose level (higher->more logging)");
74 void Register(
const std::string &name,
75 bool *ptr,
const std::string &doc);
76 void Register(
const std::string &name,
77 int32 *ptr,
const std::string &doc);
78 void Register(
const std::string &name,
79 uint32 *ptr,
const std::string &doc);
80 void Register(
const std::string &name,
81 float *ptr,
const std::string &doc);
82 void Register(
const std::string &name,
83 double *ptr,
const std::string &doc);
84 void Register(
const std::string &name,
85 std::string *ptr,
const std::string &doc);
95 T *ptr,
const std::string &doc);
107 int Read(
int argc,
const char *
const *argv);
110 void PrintUsage(
bool print_command_line =
false);
125 std::string
GetArg(
int param)
const;
134 static std::string
Escape(
const std::string &str);
140 void RegisterTmpl(
const std::string &name, T *ptr,
const std::string &doc);
145 bool *b,
const std::string &doc,
bool is_standard);
148 int32 *
i,
const std::string &doc,
bool is_standard);
152 const std::string &doc,
bool is_standard);
155 float *f,
const std::string &doc,
bool is_standard);
158 double *f,
const std::string &doc,
bool is_standard);
161 std::string *s,
const std::string &doc,
169 T *ptr,
const std::string &doc,
bool is_standard);
174 bool SetOption(
const std::string &key,
const std::string &value,
175 bool has_equal_sign);
177 bool ToBool(std::string str);
179 uint32
ToUint(
const std::string &str);
180 float ToFloat(
const std::string &str);
181 double ToDouble(
const std::string &str);
196 DocInfo(
const std::string &name,
const std::string &usemsg)
198 DocInfo(
const std::string &name,
const std::string &usemsg,
226 void SplitLongArg(
const std::string &in, std::string *key,
227 std::string *value,
bool *has_equal_sign);
239 std::ostringstream usage_str;
240 usage_str <<
"Parsing config from " 241 <<
"from '" << config_filename <<
"'";
244 po.ReadConfigFile(config_filename);
251 std::ostringstream usage_str;
252 usage_str <<
"Parsing config from " 253 <<
"from '" << conf <<
"'";
257 po.ReadConfigFile(conf);
264 #endif // KALDI_UTIL_PARSE_OPTIONS_H_ void DisableOption(const std::string &name)
If called after registering an option and before calling Read(), disables that option from being used...
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void ReadConfigFromFile(const std::string &config_filename, C *c)
This template is provided for convenience in reading config classes from files; this is not the stand...
bool print_args_
variable for the implicit –print-args parameter
std::map< std::string, uint32 * > uint_map_
std::string config_
variable for the implicit –config parameter
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
static std::string Escape(const std::string &str)
The following function will return a possibly quoted and escaped version of "str", according to the current shell.
uint32 ToUint(const std::string &str)
void PrintConfig(std::ostream &os)
Prints the actual configuration of all the registered variables.
DocMapType doc_map_
map for the documentation
std::map< std::string, bool * > bool_map_
void SplitLongArg(const std::string &in, std::string *key, std::string *value, bool *has_equal_sign)
SplitLongArg parses an argument of the form –a=b, –a=, or –a,.
void RegisterCommon(const std::string &name, T *ptr, const std::string &doc, bool is_standard)
Does the actual job for both kinds of parameters Does the common part of the job for all datatypes...
void Register(const std::string &name, bool *ptr, const std::string &doc)
std::vector< std::string > positional_args_
double ToDouble(const std::string &str)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Structure for options' documentation.
void NormalizeArgName(std::string *str)
bool ToBool(std::string str)
std::map< std::string, float * > float_map_
float ToFloat(const std::string &str)
bool SetOption(const std::string &key, const std::string &value, bool has_equal_sign)
Set option with name "key" to "value"; will crash if can't do it.
std::map< std::string, std::string * > string_map_
ParseOptions(const char *usage)
void ReadConfigFile(const std::string &filename)
Reads the options values from a config file.
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
std::map< std::string, DocInfo > DocMapType
bool help_
variable for the implicit –help parameter
void RegisterSpecific(const std::string &name, const std::string &idx, bool *b, const std::string &doc, bool is_standard)
Register boolean variable.
void RegisterTmpl(const std::string &name, T *ptr, const std::string &doc)
Template to register various variable types, used for program-specific parameters.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
const char *const * argv_
DocInfo(const std::string &name, const std::string &usemsg, bool is_standard)
std::map< std::string, int32 * > int_map_
void ReadConfigsFromFile(const std::string &conf, C1 *c1, C2 *c2)
This variant of the template ReadConfigFromFile is for if you need to read two config classes from th...
int32 g_kaldi_verbose_level
This is set by util/parse-options.
DocInfo(const std::string &name, const std::string &usemsg)
std::map< std::string, double * > double_map_
int32 ToInt(const std::string &str)
std::string GetOptArg(int param) const
void RegisterStandard(const std::string &name, T *ptr, const std::string &doc)
This one is used for registering standard parameters of all the programs.
OptionsItf * other_parser_
std::string prefix_
These members are not normally used.