libassa 3.5.1
|
Class CmdLineOpts. More...
#include <CmdLineOpts.h>
Public Types | |
typedef void(* | OPTS_FUNC) (void) |
typedef void(* | OPTS_FUNC_ONE) (const string &) |
typedef vector< Option > | OptionSet |
Public Member Functions | |
CmdLineOpts () | |
Default constructor. | |
virtual | ~CmdLineOpts () |
Do-nothing destructor. | |
bool | add_flag_opt (const char c, const string &s, bool *f) |
Add binary flag option. | |
bool | add_opt (const char c, const string &s, string *str) |
Add an option with STL string argument. | |
bool | add_opt (const char c, const string &s, int *i) |
Add an option with integer argument. | |
bool | add_opt (const char c, const string &s, unsigned int *ui) |
Add an option with unsigned integer argument. | |
bool | add_opt (const char c, const string &s, long *l) |
Add an option with long argument. | |
bool | add_opt (const char c, const string &s, unsigned long *ul) |
Add an option with unsigned long argument. | |
bool | add_opt (const char c, const string &s, double *d) |
Add an option with double argument. | |
bool | add_opt (const char c, const string &s, float *f) |
Add an option with float argument. | |
bool | add_opt (const char c_, const string &s_, OPTS_FUNC f_) |
Add an option with static function argument. | |
bool | add_opt (const char c_, const string &s_, OPTS_FUNC_ONE f_) |
Add an option with static function argument. | |
bool | rm_opt (const char c_, const string &s_) |
Remove option for the option list. | |
bool | parse_args (const char *argv[]) |
Parse command line arguments based on installed options set. | |
int | parse_config_file (IniFile &inifile_) |
Parse configuration parameters found in [options] section of the INI file. | |
const char * | get_opt_error () const |
If previous call to one of member functions returned false, retrieve detailed error message. | |
void | dump () const |
Write options set to the log file. | |
Static Public Member Functions | |
static void | str_to_argv (const string &src_, int &argc_, char **&argv_) |
Static function. | |
static void | free_argv (char **&argv_) |
Free up memory allocated by str_to_argv() function | |
Protected Member Functions | |
bool | is_valid (const char sopt_, const string &lopt_) |
Detect if supplied option is valid. | |
void | set_error_none () |
Reset error message to an empty string. | |
bool | assign (Option *node_, const char *op_) |
Perform value assignment to the node. | |
Option * | find_option (const char *str_) |
Locate option in the options set. | |
Option * | find_option (const char letter_) |
Locate option in the options set. | |
virtual void | pos_arg (const char *arg_) |
Process positional argument arg_. | |
Private Attributes | |
OptionSet | m_opts_set |
Options set. | |
string | m_error |
Last reported error. | |
Class CmdLineOpts.
CmdLineOpts class parsers the command line arguments. It is a base class, and to use it, it has to be inherited from. See "ASSA Library User's Guide" for further details.
Definition at line 113 of file CmdLineOpts.h.
Definition at line 119 of file CmdLineOpts.h.
Definition at line 116 of file CmdLineOpts.h.
Definition at line 117 of file CmdLineOpts.h.
|
inline |
Default constructor.
Definition at line 295 of file CmdLineOpts.h.
References ASSA::CMDLINEOPTS, set_error_none(), and trace_with_mask.
|
inlinevirtual |
Do-nothing destructor.
Definition at line 125 of file CmdLineOpts.h.
References ASSA::CMDLINEOPTS, and trace_with_mask.
Add binary flag option.
c | short name |
s | long name |
f | pointer to bool flag variable |
Definition at line 205 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, ASSA::Option::flag_t, is_valid(), m_opts_set, and trace_with_mask.
Referenced by ASSA::GenServer::GenServer().
Add an option with double argument.
c | short name |
s | long name |
d | pointer to double variable |
Definition at line 289 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, ASSA::Option::double_t, is_valid(), m_opts_set, and trace_with_mask.
Add an option with float argument.
c | short name |
s | long name |
f | pointer to float variable |
Definition at line 303 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, ASSA::Option::float_t, is_valid(), m_opts_set, and trace_with_mask.
Add an option with integer argument.
c | short name |
s | long name |
i | pointer to int variable |
Definition at line 233 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, ASSA::Option::int_t, is_valid(), m_opts_set, and trace_with_mask.
Add an option with long argument.
c | short name |
s | long name |
l | pointer to long variable |
Definition at line 261 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, is_valid(), ASSA::Option::long_t, m_opts_set, and trace_with_mask.
Add an option with STL string argument.
c | short name |
s | long name |
str | pointer to string variable |
Definition at line 219 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, is_valid(), m_opts_set, ASSA::Option::string_t, and trace_with_mask.
Referenced by ASSA::GenServer::GenServer().
Add an option with unsigned integer argument.
c | short name |
s | long name |
ui | pointer to u_int variable |
Definition at line 247 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, is_valid(), m_opts_set, trace_with_mask, and ASSA::Option::uint_t.
Add an option with unsigned long argument.
c | short name |
s | long name |
ul | pointer to unsigned long variable |
Definition at line 275 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, is_valid(), ASSA::Option::long_t, m_opts_set, and trace_with_mask.
Add an option with static function argument.
This void function with no arguments will be called when command line option is processed. An option installed is treated as binary flag option.
c_ | short name |
s_ | long name |
f_ | pointer to the static function |
Definition at line 317 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, ASSA::Option::func_t, is_valid(), m_opts_set, and trace_with_mask.
bool CmdLineOpts::add_opt | ( | const char | c_, |
const string & | s_, | ||
OPTS_FUNC_ONE | f_ | ||
) |
Add an option with static function argument.
This void function with STL string arguments will be called when command line option is processed. The option value is delivered via function's argument.
c_ | short name |
s_ | long name |
f_ | pointer to the static function |
Definition at line 331 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, ASSA::Option::func_one_t, is_valid(), m_opts_set, and trace_with_mask.
Perform value assignment to the node.
Data conversion happens here.
Definition at line 535 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, DL, ASSA::Option::double_t, ASSA::Option::flag_t, ASSA::Option::float_t, ASSA::Option::func_one_t, ASSA::Option::func_t, ASSA::Option::int_t, ASSA::Option::long_t, m_error, ASSA::Option::none_t, ASSA::Option::string_t, trace_with_mask, ASSA::Option::uint_t, and ASSA::Option::ulong_t.
Referenced by parse_args(), and parse_config_file().
void CmdLineOpts::dump | ( | ) | const |
Write options set to the log file.
Definition at line 645 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, DL, m_error, and m_opts_set.
Referenced by ASSA::GenServer::init_internals().
Locate option in the options set.
Definition at line 172 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, m_opts_set, and trace_with_mask.
Referenced by parse_args().
Locate option in the options set.
Definition at line 189 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, m_opts_set, and trace_with_mask.
Free up memory allocated by str_to_argv()
function
Definition at line 692 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, and trace_with_mask.
If previous call to one of member functions returned false, retrieve detailed error message.
Definition at line 309 of file CmdLineOpts.h.
References m_error.
Referenced by ASSA::GenServer::init().
Detect if supplied option is valid.
Definition at line 144 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, m_error, m_opts_set, set_error_none(), and trace_with_mask.
Referenced by add_flag_opt(), add_opt(), add_opt(), add_opt(), add_opt(), add_opt(), add_opt(), add_opt(), add_opt(), and add_opt().
Parse command line arguments based on installed options set.
Definition at line 364 of file CmdLineOpts.cpp.
References assign(), ASSA::CMDLINEOPTS, DL, find_option(), ASSA::Option::flag_t, ASSA::Option::func_t, m_error, pos_arg(), set_error_none(), and trace_with_mask.
Referenced by ASSA::GenServer::init().
Parse configuration parameters found in [options] section of the INI file.
An Option object keeps long names the way they were assigned by the add_opt() call (i.e.
File should be already loaded with load().
inifile_ | The INI file to parse. |
"mac-address"). IniFile has same options in their normalized format (i.e. "mac_address").
Check to see if [options] section is present. Try all possible matches of the section name.
Iterate throught the set of all registered Options. For each in the set, normalize its name and lookup in IniFile's [option] section for the value.
Definition at line 491 of file CmdLineOpts.cpp.
References assign(), ASSA::CMDLINEOPTS, DL, ASSA::Utils::find_and_replace_char(), m_error, m_opts_set, and trace_with_mask.
Process positional argument arg_.
This method must be overloaded by the derived class to take advantage of it.
arg_ | positional argument value |
Definition at line 292 of file CmdLineOpts.h.
Referenced by parse_args().
Remove option for the option list.
c_ | short name |
s_ | long name |
Definition at line 345 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, m_opts_set, and trace_with_mask.
|
inlineprotected |
Reset error message to an empty string.
Definition at line 302 of file CmdLineOpts.h.
References ASSA::CMDLINEOPTS, m_error, and trace_with_mask.
Referenced by CmdLineOpts(), is_valid(), and parse_args().
Static function.
Convert string list of command line options into dynamically allocated argv-like array. The array is terminated with NULL. This memory must be freed after it has been used. Remember that the first parameter is process name.
src_ | command line option string |
argc_ | number of options found in the source string |
argv_ | returns a pointer to the heap-allocated memory |
Definition at line 660 of file CmdLineOpts.cpp.
References ASSA::CMDLINEOPTS, and trace_with_mask.
Referenced by ASSA::Fork::fork_exec().
|
private |
Last reported error.
Definition at line 287 of file CmdLineOpts.h.
Referenced by assign(), dump(), get_opt_error(), is_valid(), parse_args(), parse_config_file(), and set_error_none().
|
private |
Options set.
Definition at line 284 of file CmdLineOpts.h.
Referenced by add_flag_opt(), add_opt(), add_opt(), add_opt(), add_opt(), add_opt(), add_opt(), add_opt(), add_opt(), add_opt(), dump(), find_option(), find_option(), is_valid(), parse_config_file(), and rm_opt().