32 std::ostringstream
msg;
42 msg <<
"--" << std::setiosflags (std::ios::left)
46 msg << std::setiosflags (std::ios::left) << std::setw (14) <<
" ";
53 msg << std::setiosflags (std::ios::left) << std::setw(7) <<
"string";
54 msg <<
"] = '" << *(
string*)
m_val <<
"'";
58 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"int";
63 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"u_int";
68 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"long";
73 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"u_long";
78 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"double";
83 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"float";
88 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"bool";
89 msg <<
"] = " << *(
bool*)
m_val ?
"true" :
"false";
93 msg << std::setiosflags(std::ios::left)
94 << std::setw(7) <<
"function ()";
99 msg << std::setiosflags(std::ios::left)
100 << std::setw(7) <<
"function (opt)";
105 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"none";
110 msg << std::setiosflags(std::ios::left)
111 << std::setw(7) <<
"--undef--";
137 default:
ret =
"--undef--";
150 OptionSet::const_iterator
i;
154 m_error =
"Ignore empty option";
157 else if (
sopt_ !=
'\0' &&
i->m_short_name ==
sopt_) {
158 m_error =
"Ignored multiple option '-";
162 else if (!
lopt_.empty () &&
i->m_long_name ==
lopt_) {
163 m_error =
"Ignore multiple option '--";
177 OptionSet::iterator
i;
181 if (
i->m_long_name ==
str_) {
194 OptionSet::iterator
i;
350 OptionSet::iterator
i;
354 if (
i->m_short_name ==
sopt_ ||
i->m_long_name ==
lopt_)
369 register int skip = 1;
387 m_error =
"Invalid order of arguments: '";
404 if (
token.size () > 2) {
419 string op =
token.substr (2);
422 if ((
pos = op.find (
"=")) != (
size_t)-1) {
423 param = op.substr (
pos+1, op.length ());
424 op.replace (
pos, op.length() -
pos,
"");
443 if (
param.empty ()) {
445 m_error =
"Expecting parameter after '"
446 + string (
argv_[0]) +
"'.";
460 if (
param.empty ()) {
466 const char* str =
param.c_str ();
496 unsigned int count = 0;
510 m_error =
"Missing [options] section in INI file!";
517 if (
pos->m_long_name.size ()) {
518 s =
pos->m_long_name;
546 node_->type_c_str ()));
558 switch (
node_->m_type) {
570 m_error +=
" in converting to integer from '";
579 *(
long*)
node_->m_val =
l;
590 m_error +=
" in converting to unsigned integer from '";
599 *(
unsigned long*)
node_->m_val =
l;
610 m_error +=
" in converting to double/float from '";
616 *(
double*)
node_->m_val =
d;
624 *(
bool*)
node_->m_val =
true;
637 m_error =
"Undefined type for option '"+string (
op_)+
"'.";
648 OptionSet::const_iterator
i;
665 std::vector<string>
vs;
677 argv_ =
new char* [
vs.size() + 1];
678 std::vector<string>::iterator
it;
680 for (
it =
vs.begin ();
it !=
vs.end ();
it++,
i++) {
681 p =
new char [
it->size() + 1];
683 p[
it->size()] =
'\0';
Class to handle processing command-line options.
A Windows-style INI configuration file management class.
An abstraction to message logging facility.
#define DL(X)
A macro for writing debug message to the Logger.
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
A wrapper class to provide AutoPtr with reference semantics.
Option * find_option(const char *str_)
Locate option in the options set.
string m_error
Last reported error.
bool parse_args(const char *argv[])
Parse command line arguments based on installed options set.
void(* OPTS_FUNC_ONE)(const string &)
void set_error_none()
Reset error message to an empty string.
bool add_opt(const char c, const string &s, string *str)
Add an option with STL string argument.
bool rm_opt(const char c_, const string &s_)
Remove option for the option list.
OptionSet m_opts_set
Options set.
bool add_flag_opt(const char c, const string &s, bool *f)
Add binary flag option.
bool assign(Option *node_, const char *op_)
Perform value assignment to the node.
int parse_config_file(IniFile &inifile_)
Parse configuration parameters found in [options] section of the INI file.
virtual void pos_arg(const char *arg_)
Process positional argument arg_.
static void str_to_argv(const string &src_, int &argc_, char **&argv_)
Static function.
void dump() const
Write options set to the log file.
static void free_argv(char **&argv_)
Free up memory allocated by str_to_argv() function
bool is_valid(const char sopt_, const string &lopt_)
Detect if supplied option is valid.
@ func_one_t
Convert argument to function with one argument
@ func_t
Convert argument to function
@ string_t
Convert argument to STL string
@ ulong_t
Convert argument to unsigned long
@ float_t
Convert argument to float
@ long_t
Convert argument to long
@ double_t
Convert argument to double
@ flag_t
No argument; bool value is flipped.
@ int_t
Convert argument to int
@ uint_t
Convert argument to unsigned int
type_t m_type
Option type.
string m_long_name
Long option name.
void * m_val
Pointer to the option value.
void dump() const
Write object state to the log file.
const char * type_c_str()
Return the type of the Option object.
char m_short_name
One-letter option name.
void find_and_replace_char(std::string &text_, char src_, char dest_)
Find and relpace all instances of src_ character with dest_ character in a string text_.
@ CMDLINEOPTS
Class CmdLineOpts messages