ASSA::CmdLineOpts Class Reference

Class CmdLineOpts. More...

#include <CmdLineOpts.h>

Inheritance diagram for ASSA::CmdLineOpts:

ASSA::GenServer

List of all members.

Public Types

typedef void(* OPTS_FUNC )(void)
typedef void(* OPTS_FUNC_ONE )(const string &)
typedef vector< OptionOptionSet

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.
Optionfind_option (const char *str_)
 Locate option in the options set.
Optionfind_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.


Detailed Description

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.


Member Typedef Documentation

typedef void(* ASSA::CmdLineOpts::OPTS_FUNC)(void)

typedef void(* ASSA::CmdLineOpts::OPTS_FUNC_ONE)(const string &)

typedef vector<Option> ASSA::CmdLineOpts::OptionSet

Definition at line 119 of file CmdLineOpts.h.


Constructor & Destructor Documentation

ASSA::CmdLineOpts::CmdLineOpts (  )  [inline]

Default constructor.

Definition at line 295 of file CmdLineOpts.h.

References ASSA::CMDLINEOPTS, set_error_none(), and trace_with_mask.

00295                           : m_opts_set (), m_error ("")
00296 {
00297     trace_with_mask("CmdLineOpts::CmdLineOpts", CMDLINEOPTS);
00298     set_error_none ();
00299 }

virtual ASSA::CmdLineOpts::~CmdLineOpts (  )  [inline, virtual]

Do-nothing destructor.

Definition at line 125 of file CmdLineOpts.h.

References ASSA::CMDLINEOPTS, and trace_with_mask.

00125                             { 
00126         trace_with_mask ("CmdLineOpts::~CmdLineOpts", CMDLINEOPTS); 
00127     }


Member Function Documentation

bool CmdLineOpts::add_flag_opt ( const char  c,
const string &  s,
bool *  f 
)

Add binary flag option.

Parameters:
c short name
s long name
f pointer to bool flag variable
Returns:
true on success, false on error

Definition at line 206 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().

00207 {
00208     trace_with_mask ("CmdLineOpts::add_flag_opt", CMDLINEOPTS);
00209 
00210     if (!is_valid (sopt_, lopt_)) 
00211         return (false);
00212 
00213     Option o (sopt_, lopt_, Option::flag_t, (void*) v_);
00214     m_opts_set.push_back (o);
00215     return (true);
00216 }

bool CmdLineOpts::add_opt ( const char  c,
const string &  s,
string *  str 
)

Add an option with STL string argument.

Parameters:
c short name
s long name
str pointer to string variable
Returns:
true on success, false on error

Definition at line 220 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().

00221 {
00222     trace_with_mask ("CmdLineOpts::add_opt(string*)", CMDLINEOPTS);
00223 
00224     if (!is_valid (sopt_, lopt_)) 
00225         return (false);
00226 
00227     Option o (sopt_, lopt_, Option::string_t, (void*) v_);
00228     m_opts_set.push_back (o);
00229     return (true);
00230 }

bool CmdLineOpts::add_opt ( const char  c,
const string &  s,
int *  i 
)

Add an option with integer argument.

Parameters:
c short name
s long name
i pointer to int variable
Returns:
true on success, false on error

Definition at line 234 of file CmdLineOpts.cpp.

References ASSA::CMDLINEOPTS, ASSA::Option::int_t, is_valid(), m_opts_set, and trace_with_mask.

00235 {
00236     trace_with_mask ("CmdLineOpts::add_opt(int*)", CMDLINEOPTS);
00237 
00238     if (!is_valid (sopt_, lopt_)) {
00239         return (false);
00240     }
00241     Option o (sopt_, lopt_, Option::int_t, (void*) v_);
00242     m_opts_set.push_back (o);
00243     return (true);
00244 }

bool CmdLineOpts::add_opt ( const char  c,
const string &  s,
unsigned int *  ui 
)

Add an option with unsigned integer argument.

Parameters:
c short name
s long name
ui pointer to u_int variable
Returns:
true on success, false on error

Definition at line 248 of file CmdLineOpts.cpp.

References ASSA::CMDLINEOPTS, is_valid(), m_opts_set, trace_with_mask, and ASSA::Option::uint_t.

00249 {
00250     trace_with_mask ("CmdLineOpts::add_opt(u_int*)", CMDLINEOPTS);
00251 
00252     if (!is_valid (sopt_, lopt_)) {
00253         return (false);
00254     }
00255     Option o (sopt_, lopt_, Option::uint_t, (void*) v_);
00256     m_opts_set.push_back (o);
00257     return (true);
00258 }

bool CmdLineOpts::add_opt ( const char  c,
const string &  s,
long *  l 
)

Add an option with long argument.

Parameters:
c short name
s long name
l pointer to long variable
Returns:
true on success, false on error

Definition at line 262 of file CmdLineOpts.cpp.

References ASSA::CMDLINEOPTS, is_valid(), ASSA::Option::long_t, m_opts_set, and trace_with_mask.

00263 {
00264     trace_with_mask ("CmdLineOpts::add_opt(long*)", CMDLINEOPTS);
00265 
00266     if (!is_valid (sopt_, lopt_)) {
00267         return (false);
00268     }
00269     Option o (sopt_, lopt_, Option::long_t, (void*) v_);
00270     m_opts_set.push_back (o);
00271     return (true);
00272 }

bool CmdLineOpts::add_opt ( const char  c,
const string &  s,
unsigned long *  ul 
)

Add an option with unsigned long argument.

Parameters:
c short name
s long name
ul pointer to unsigned long variable
Returns:
true on success, false on error

Definition at line 276 of file CmdLineOpts.cpp.

References ASSA::CMDLINEOPTS, is_valid(), ASSA::Option::long_t, m_opts_set, and trace_with_mask.

00277 {
00278     trace_with_mask ("CmdLineOpts::add_opt(u_long*)", CMDLINEOPTS);
00279 
00280     if (!is_valid (sopt_, lopt_)) {
00281         return (false);
00282     }
00283     Option o (sopt_, lopt_, Option::long_t, (void*) v_);
00284     m_opts_set.push_back (o);
00285     return (true);
00286 }

bool CmdLineOpts::add_opt ( const char  c,
const string &  s,
double *  d 
)

Add an option with double argument.

Parameters:
c short name
s long name
d pointer to double variable
Returns:
true on success, false on error

Definition at line 290 of file CmdLineOpts.cpp.

References ASSA::CMDLINEOPTS, ASSA::Option::double_t, is_valid(), m_opts_set, and trace_with_mask.

00291 {
00292     trace_with_mask ("CmdLineOpts::add_opt(double*)", CMDLINEOPTS);
00293 
00294     if (!is_valid (sopt_, lopt_)) {
00295         return (false);
00296     }
00297     Option o (sopt_, lopt_, Option::double_t, (void*) v_);
00298     m_opts_set.push_back (o);
00299     return (true);
00300 }

bool CmdLineOpts::add_opt ( const char  c,
const string &  s,
float *  f 
)

Add an option with float argument.

Parameters:
c short name
s long name
f pointer to float variable
Returns:
true on success, false on error

Definition at line 304 of file CmdLineOpts.cpp.

References ASSA::CMDLINEOPTS, ASSA::Option::float_t, is_valid(), m_opts_set, and trace_with_mask.

00305 {
00306     trace_with_mask ("CmdLineOpts::add_opt(float*)", CMDLINEOPTS);
00307 
00308     if (!is_valid (sopt_, lopt_)) {
00309         return (false);
00310     }
00311     Option o (sopt_, lopt_, Option::float_t, (void*) v_);
00312     m_opts_set.push_back (o);
00313     return (true);
00314 }

bool CmdLineOpts::add_opt ( const char  c_,
const string &  s_,
OPTS_FUNC  f_ 
)

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.

Parameters:
c_ short name
s_ long name
f_ pointer to the static function
Returns:
true on success, false on error

Definition at line 318 of file CmdLineOpts.cpp.

References ASSA::CMDLINEOPTS, ASSA::Option::func_t, is_valid(), m_opts_set, and trace_with_mask.

00319 {
00320     trace_with_mask ("CmdLineOpts::add_opt(OPTS_FUNC)", CMDLINEOPTS);
00321 
00322     if (!is_valid (sopt_, lopt_)) {
00323         return (false);
00324     }
00325     Option o (sopt_, lopt_, Option::func_t, (void*) v_);
00326     m_opts_set.push_back (o);
00327     return (true);
00328 }

bool ASSA::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.

Parameters:
c_ short name
s_ long name
f_ pointer to the static function
Returns:
true on success, false on error

bool CmdLineOpts::rm_opt ( const char  c_,
const string &  s_ 
)

Remove option for the option list.

Parameters:
c_ short name
s_ long name
Returns:
true if found, false if not

Definition at line 346 of file CmdLineOpts.cpp.

References ASSA::CMDLINEOPTS, m_opts_set, and trace_with_mask.

00347 {
00348     trace_with_mask ("CmdLineOpts::rm_opt(string&)", CMDLINEOPTS);
00349 
00350     OptionSet::iterator i;
00351 
00352     for (i = m_opts_set.begin (); i != m_opts_set.end (); i++) 
00353     {
00354         if (i->m_short_name == sopt_ || i->m_long_name == lopt_) 
00355         {
00356             m_opts_set.erase (i);
00357             return (true);
00358         }
00359     }
00360     return (false);
00361 }

bool CmdLineOpts::parse_args ( const char *  argv[]  ) 

Parse command line arguments based on installed options set.

Returns:
true on success, false on error.

Definition at line 365 of file CmdLineOpts.cpp.

References assign(), ASSA::CMDLINEOPTS, DL, find_option(), ASSA::Option::flag_t, ASSA::Option::func_t, m_error, ASSA::Option::m_type, pos_arg(), set_error_none(), and trace_with_mask.

Referenced by ASSA::GenServer::init().

00366 {
00367     trace_with_mask ("CmdLineOpts::parse_args", CMDLINEOPTS);
00368 
00369     register int skip = 1;
00370     bool pos_args_started = false;
00371     string param ("");
00372     string token ("");
00373     set_error_none ();
00374     Option* node = (Option*) NULL;
00375 
00376     for (argv_++; argv_[0]; argv_ += skip) {
00377         if (skip != 0) {
00378             token = argv_[0];
00379         }
00380 
00381         DL((CMDLINEOPTS, "token: \"%s\"\n", token.c_str()));
00382 
00383         if (pos_args_started) {
00384             DL((CMDLINEOPTS,"pos_args_started = true\n"));
00385 
00386             if (token[0] == '-' && token.size () != 1) {
00387                 m_error = "Invalid order of arguments: '";
00388                 m_error += token + "'.";
00389                 goto done;
00390             }
00391             pos_arg (token.c_str ());
00392             continue;
00393         }
00394         skip = 1;
00395 
00396         if (token[0] == '-' && token.size () > 1 && token[1] != '-') {
00397             if (token.size () == 1 && !pos_args_started) {
00398                 pos_arg (token.c_str ());
00399                 pos_args_started = true;
00400                 continue;
00401             }
00402                 
00403             if ((node = find_option (token[1])) != NULL) {
00404                 if (token.size () > 2) {
00405                     if (node->m_type == Option::flag_t ||
00406                         node->m_type == Option::func_t) 
00407                     {
00408                         token.erase (1, 1);
00409                         skip = 0;
00410                     }
00411                     else {
00412                         param = token.substr (2);
00413                     } 
00414                 } // if (token.size()>2)
00415             } // if ((node = find_option ())
00416         } 
00417         else {  
00418             if (token.size () > 1 && token[1] == '-') {
00419                 string op = token.substr (2);
00420                 size_t pos;
00421 
00422                 if ((pos = op.find ("=")) != (size_t)-1) {
00423                     param = op.substr (pos+1, op.length ());
00424                     op.replace (pos, op.length() - pos, "");
00425                 }
00426                 node = find_option (op.c_str ());
00427             }
00428             else {  
00429                 pos_arg (token.c_str ());
00430                 pos_args_started = true;
00431                 continue;
00432             } 
00433         } // if (token[0] == '-' && token[1] != '-') 
00434 
00435         if (!node) {
00436             m_error = "Invalid option '" + token + "'.";
00437             goto done;
00438         }
00439 
00440         if (node->m_type != Option::flag_t &&
00441             node->m_type != Option::func_t) 
00442         {
00443             if (param.empty ()) {
00444                 if (!argv_[1]) {
00445                     m_error = "Expecting parameter after '"
00446                         + string (argv_[0]) + "'.";
00447                     goto done;
00448                 }
00449                 param = argv_[1];
00450                 skip = 2;
00451             }
00452         }
00453         /*--- 
00454          * if positional arguments only 
00455          ---*/
00456         if (!node) {
00457             goto done;
00458         }
00459 
00460         if (param.empty ()) {
00461             if (!assign (node, argv_[1])) {
00462                 return (false);
00463             }
00464         }
00465         else {
00466             const char* str = param.c_str ();
00467             if (!assign (node, str)) {
00468                 return (false);
00469             }
00470             param = "";
00471         }
00472     } // for (argv_++; argv_[0]; argv_ += skip) 
00473 
00474  done:
00475     return !m_error.empty () ? false : true;
00476 }

int CmdLineOpts::parse_config_file ( IniFile inifile_  ) 

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().

Parameters:
inifile_ The INI file to parse.
Returns:
The number of options parsed or -1 if [options] section is missing
"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 492 of file CmdLineOpts.cpp.

References assign(), ASSA::CMDLINEOPTS, DL, ASSA::Utils::find_and_replace_char(), ASSA::IniFile::find_section(), ASSA::IniFile::get_value(), m_error, m_opts_set, ASSA::IniFile::sect_end(), and trace_with_mask.

00493 {
00494     trace_with_mask ("CmdLineOpts::parse_config_file", CMDLINEOPTS);
00495 
00496     unsigned int count = 0;
00497     string v;
00498     string s;
00499     string optsect_name ("options");
00500     OptionSet::iterator pos = m_opts_set.begin ();
00501 
00502     if (inifile_.find_section (optsect_name) == inifile_.sect_end ()) 
00503     {
00504         optsect_name = "Options";
00505         if (inifile_.find_section (optsect_name) == inifile_.sect_end ()) 
00506         {
00507             optsect_name = "OPTIONS";
00508             if (inifile_.find_section (optsect_name) == inifile_.sect_end ()) 
00509             {
00510                 m_error = "Missing [options] section in INI file!";
00511                 return -1;
00512             }
00513         }
00514     }
00515 
00516     while (pos != m_opts_set.end ()) {
00517         if (pos->m_long_name.size ()) {
00518             s = pos->m_long_name;
00519             ASSA::Utils::find_and_replace_char (s, '-', '_');
00520             DL ((CMDLINEOPTS, "trying option \"%s\"\n", s.c_str ()));
00521             v = inifile_.get_value (optsect_name, s);
00522             if (v.size ()) {
00523                 if (assign (&(*pos), v.c_str ())) {
00524                     count++;
00525                 }
00526             }
00527         }
00528         pos++;
00529     }
00530 
00531     return (count);
00532 }

const char * ASSA::CmdLineOpts::get_opt_error (  )  const [inline]

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().

00310 {
00311     return (m_error.c_str ());
00312 }

void CmdLineOpts::str_to_argv ( const string &  src_,
int &  argc_,
char **&  argv_ 
) [static]

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.

Parameters:
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 661 of file CmdLineOpts.cpp.

References ASSA::CMDLINEOPTS, and trace_with_mask.

Referenced by ASSA::Fork::fork_exec().

00662 {
00663     trace_with_mask ("CmdLineOpts::str_to_argv", CMDLINEOPTS);
00664 
00665     std::vector<string> vs;
00666     std::istringstream input (src_);
00667     std::string token;
00668 
00669     while (input >> token) {
00670         vs.push_back (token);
00671         token = "";
00672     }
00673     int i = 0;
00674     char* p;
00675 
00676     if (vs.size ()) {
00677         argv_ = new char* [vs.size() + 1];
00678         std::vector<string>::iterator it;
00679 
00680         for (it = vs.begin (); it != vs.end (); it++, i++) {
00681             p = new char [it->size() + 1];
00682             strcpy (p, it->c_str ());
00683             p[it->size()] = '\0';
00684             argv_[i] = p;
00685         }
00686         argv_[i] = NULL;
00687     }
00688     argc_ = i;
00689 }

void CmdLineOpts::free_argv ( char **&  argv_  )  [static]

Free up memory allocated by str_to_argv() function.

Definition at line 693 of file CmdLineOpts.cpp.

References ASSA::CMDLINEOPTS, and trace_with_mask.

00694 {
00695     trace_with_mask ("CmdLineOpts::free_argv", CMDLINEOPTS);
00696 
00697     /* If argument is empty (which should never be the case),
00698      * then freeing the memory would core dump application.
00699      */
00700     if (argv_ == NULL) {
00701         return;
00702     }
00703 
00704     for (int i = 0; argv_[i]; i++) {
00705         delete [] argv_[i];
00706     }
00707     delete [] argv_;
00708     argv_ = NULL;
00709 }

void CmdLineOpts::dump (  )  const

Write options set to the log file.

Definition at line 646 of file CmdLineOpts.cpp.

References ASSA::CMDLINEOPTS, DL, m_error, and m_opts_set.

Referenced by ASSA::GenServer::init_internals().

00647 {
00648     OptionSet::const_iterator i;
00649 
00650     for (i = m_opts_set.begin (); i != m_opts_set.end (); i++) {
00651         i->dump ();
00652     }
00653 
00654     if (!m_error.empty ()) {
00655         DL((CMDLINEOPTS, "Last error: '%s'\n", m_error.c_str ()));
00656     }
00657 }

bool CmdLineOpts::is_valid ( const char  sopt_,
const string &  lopt_ 
) [protected]

Detect if supplied option is valid.

Definition at line 145 of file CmdLineOpts.cpp.

References ASSA::CMDLINEOPTS, m_error, m_opts_set, set_error_none(), and trace_with_mask.

Referenced by add_flag_opt(), and add_opt().

00146 {
00147     trace_with_mask ("CmdLineOpts::is_valid", CMDLINEOPTS);
00148 
00149     set_error_none ();
00150     OptionSet::const_iterator i;
00151 
00152     for (i = m_opts_set.begin (); i != m_opts_set.end (); i++) {
00153         if (sopt_ == '\0' && lopt_.empty ()) {
00154             m_error = "Ignore empty option";
00155             return (false);
00156         }
00157         else if (sopt_ != '\0' && i->m_short_name == sopt_) {
00158             m_error = "Ignored multiple option '-";
00159             m_error += sopt_ + string ("'");
00160             return (false);
00161         }
00162         else if (!lopt_.empty () && i->m_long_name == lopt_) {
00163             m_error = "Ignore multiple option '--";
00164             m_error += lopt_ + string ("'");
00165             return (false);
00166         }
00167     }
00168     return (true);
00169 }

void ASSA::CmdLineOpts::set_error_none (  )  [inline, protected]

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().

00303 {
00304     trace_with_mask("CmdLineOpts::set_error_none", CMDLINEOPTS);
00305     m_error = "";
00306 }

bool CmdLineOpts::assign ( Option node_,
const char *  op_ 
) [protected]

Perform value assignment to the node.

Data conversion happens here.

Definition at line 536 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::m_long_name, ASSA::Option::m_short_name, ASSA::Option::m_type, ASSA::Option::m_val, ASSA::Option::none_t, ASSA::Option::string_t, trace_with_mask, ASSA::Option::type_c_str(), ASSA::Option::uint_t, and ASSA::Option::ulong_t.

Referenced by parse_args(), and parse_config_file().

00537 {
00538     trace_with_mask ("CmdLineOpts::assign", CMDLINEOPTS);
00539 
00540     long l;
00541     double d;
00542 
00543     if (node_ && op_) {
00544         DL ((CMDLINEOPTS, "Assign '%s' to {-%c, --%s, t=%s}\n", 
00545              op_, node_->m_short_name, node_->m_long_name.c_str (),
00546              node_->type_c_str ()));
00547     }
00548 
00549     /*---
00550       From strtol(3C) man page:
00551 
00552       "Because 0 is returned on error and is also a valid return on
00553       success, an application wishing to check for error situations 
00554       should set 'errno' to 0, then call strtol(3C), then check 'errno'
00555       and if it is non-zero, assume an error has occured."
00556       ---*/
00557       
00558     switch (node_->m_type) {
00559     case Option::string_t:
00560         *(string*) node_->m_val = op_;
00561         break;
00562 
00563     case Option::int_t:
00564     case Option::long_t:
00565         errno = 0;
00566         l = strtol (op_, NULL, 0);
00567 
00568         if (errno != 0) {
00569             m_error = "Error: '" + string (strerror (errno)) + "',";
00570             m_error += " in converting to integer from '";
00571             m_error += string (op_) + "'.";
00572             return (false);
00573         }
00574 
00575         if (node_->m_type == Option::int_t) {
00576             *(int*) node_->m_val = int (l);
00577         }
00578         else {
00579             *(long*) node_->m_val = l;
00580         }
00581         break;
00582 
00583     case Option::uint_t:
00584     case Option::ulong_t:
00585         errno = 0;
00586         l = strtol (op_, NULL, 0);
00587 
00588         if (errno != 0) {
00589             m_error = "Error: '" + string (strerror (errno)) + "',";
00590             m_error += " in converting to unsinged integer from '";
00591             m_error += string (op_) + "'.";
00592             return (false);
00593         }
00594 
00595         if (node_->m_type == Option::uint_t) {
00596             *(unsigned int*) node_->m_val = int (l);
00597         }
00598         else {
00599             *(unsigned long*) node_->m_val = l;
00600         }
00601         break;
00602 
00603     case Option::double_t:
00604     case Option::float_t:
00605         errno = 0;
00606         d = strtod (op_, NULL);
00607 
00608         if (errno != 0) {
00609             m_error = "Error: '" + string (strerror (errno)) + "',";
00610             m_error += " in converting to double/float from '";
00611             m_error += string (op_) + "'.";
00612             return (false);
00613         }
00614 
00615         if (node_->m_type == Option::double_t) {
00616             *(double*) node_->m_val = d;
00617         }
00618         else {
00619             *(float*) node_->m_val = float (d);
00620         }
00621         break;
00622 
00623     case Option::flag_t:
00624         *(bool*) node_->m_val = true; // no more flipping!
00625         break;
00626         
00627     case Option::func_t:
00628         (*(OPTS_FUNC)(node_->m_val)) ();
00629         break;
00630 
00631     case Option::func_one_t:
00632         (*(OPTS_FUNC_ONE)(node_->m_val)) (op_);
00633         break;
00634 
00635     case Option::none_t:
00636     default:
00637         m_error = "Undefined type for option '"+string (op_)+"'.";
00638         return (false);
00639     } /*-- switch () --*/
00640 
00641     return (true);
00642 }

Option * CmdLineOpts::find_option ( const char *  str_  )  [protected]

Locate option in the options set.

Definition at line 173 of file CmdLineOpts.cpp.

References ASSA::CMDLINEOPTS, m_opts_set, and trace_with_mask.

Referenced by parse_args().

00174 {
00175     trace_with_mask ("CmdLineOpts::find_option(char*)", CMDLINEOPTS);
00176 
00177     OptionSet::iterator i;
00178 
00179     for ( i = m_opts_set.begin (); i != m_opts_set.end (); i++) 
00180     {
00181         if (i->m_long_name == str_) {
00182             return &(*i);
00183         }
00184     }
00185     return (NULL);
00186 }

Option * CmdLineOpts::find_option ( const char  letter_  )  [protected]

Locate option in the options set.

Definition at line 190 of file CmdLineOpts.cpp.

References ASSA::CMDLINEOPTS, m_opts_set, and trace_with_mask.

00191 {
00192     trace_with_mask ("CmdLineOpts::find_option(char)", CMDLINEOPTS);
00193 
00194     OptionSet::iterator i;
00195 
00196     for (i = m_opts_set.begin (); i != m_opts_set.end (); i++) 
00197     {
00198         if (i->m_short_name == letter_) 
00199             return &(*i);
00200     }
00201     return (NULL);
00202 }

void ASSA::CmdLineOpts::pos_arg ( const char *  arg_  )  [inline, protected, virtual]

Process positional argument arg_.

This method must be overloaded by the derived class to take advantage of it.

Parameters:
arg_ positional argument value

Definition at line 292 of file CmdLineOpts.h.

Referenced by parse_args().

00292 { /* no-opt*/ }


Member Data Documentation

OptionSet ASSA::CmdLineOpts::m_opts_set [private]

Options set.

Definition at line 284 of file CmdLineOpts.h.

Referenced by add_flag_opt(), add_opt(), dump(), find_option(), is_valid(), parse_config_file(), and rm_opt().

string ASSA::CmdLineOpts::m_error [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().


The documentation for this class was generated from the following files:
Generated on Sun Feb 10 11:43:09 2008 for libassa by  doxygen 1.5.4