libassa  3.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Private Member Functions | Private Attributes | Friends
ASSA::Option Class Reference

Option class. More...

#include <CmdLineOpts.h>

List of all members.

Public Types

enum  type_t {
  string_t = 0, int_t, uint_t, long_t,
  ulong_t, double_t, float_t, flag_t,
  func_t, func_one_t, none_t
}
 Option type. More...

Private Member Functions

 Option ()
 Private default constructor.
 Option (char shopt_, const string &lopt_, type_t type_, void *val_)
 Private constructor.
void dump () const
 Write object state to the log file.
const char * type_c_str ()
 Return the type of the Option object.

Private Attributes

char m_short_name
 One-letter option name.
string m_long_name
 Long option name.
type_t m_type
 Option type.
void * m_val
 Pointer to the option value.

Friends

class CmdLineOpts

Detailed Description

Option class.

This class is a helper class of CmdLineOpts class. It is not used by any other class and cannot be instantiated.

Definition at line 39 of file CmdLineOpts.h.


Member Enumeration Documentation

Option type.

Each option, except for flags has a value following it on the command line. Following types are supported:

Enumerator:
string_t 

Convert argument to STL string.

int_t 

Convert argument to int.

uint_t 

Convert argument to unsigned int.

long_t 

Convert argument to long.

ulong_t 

Convert argument to unsinged long.

double_t 

Convert argument to double.

float_t 

Convert argument to float.

flag_t 

No argument; bool value is flipped.

func_t 

Convert argument to function.

func_one_t 

Convert argument to function with one argument.

none_t 

Definition at line 47 of file CmdLineOpts.h.


Constructor & Destructor Documentation

ASSA::Option::Option ( )
inlineprivate

Private default constructor.

Definition at line 89 of file CmdLineOpts.h.

:
m_short_name (' '), m_long_name (""), m_type (none_t), m_val (NULL)
{
/* empty */
}
ASSA::Option::Option ( char  shopt_,
const string &  lopt_,
type_t  type_,
void *  val_ 
)
inlineprivate

Private constructor.

Definition at line 96 of file CmdLineOpts.h.

References ASSA::CMDLINEOPTS, and trace_with_mask.

:
m_short_name (shopt_), m_long_name (lopt_),
m_type (type_), m_val (val_)
{
trace_with_mask("Option::Option", CMDLINEOPTS);
}

Member Function Documentation

void Option::dump ( ) const
private

Write object state to the log file.

Definition at line 30 of file CmdLineOpts.cpp.

References ASSA::CMDLINEOPTS, DL, double_t, ASSA::ends(), flag_t, float_t, func_one_t, func_t, int_t, long_t, m_long_name, m_short_name, m_type, m_val, none_t, string_t, uint_t, and ulong_t.

{
std::ostringstream msg;
if (m_short_name != 0) {
msg << "-" << m_short_name << ", ";
}
else {
msg << " ";
}
if (m_long_name.size ()) {
msg << "--" << std::setiosflags (std::ios::left)
<< std::setw(14) << m_long_name.c_str () << ' ';
}
else {
msg << std::setiosflags (std::ios::left) << std::setw (14) << " ";
}
msg << '[';
switch (m_type)
{
msg << std::setiosflags (std::ios::left) << std::setw(7) << "string";
msg << "] = '" << *(string*) m_val << "'";
break;
msg << std::setiosflags(std::ios::left) << std::setw(7) << "int";
msg << "] = " << *(int*) m_val;
break;
msg << std::setiosflags(std::ios::left) << std::setw(7) << "u_int";
msg << "] = " << *(int*) m_val;
break;
msg << std::setiosflags(std::ios::left) << std::setw(7) << "long";
msg << "] = " << *(long*) m_val;
break;
msg << std::setiosflags(std::ios::left) << std::setw(7) << "u_long";
msg << "] = " << *(long*) m_val;
break;
msg << std::setiosflags(std::ios::left) << std::setw(7) << "double";
msg << "] = " << *(double*) m_val;
break;
msg << std::setiosflags(std::ios::left) << std::setw(7) << "float";
msg << "] = " << *(float*) m_val;
break;
msg << std::setiosflags(std::ios::left) << std::setw(7) << "bool";
msg << "] = " << *(bool*) m_val ? "true" : "false";
break;
msg << std::setiosflags(std::ios::left)
<< std::setw(7) << "function ()";
msg << ']';
break;
msg << std::setiosflags(std::ios::left)
<< std::setw(7) << "function (opt)";
msg << ']';
break;
msg << std::setiosflags(std::ios::left) << std::setw(7) << "none";
msg << ']';
break;
default:
msg << std::setiosflags(std::ios::left)
<< std::setw(7) << "--undef--";
msg << ']';
}
msg << std::ends;
DL((CMDLINEOPTS,"%s\n", msg.str ().c_str ()));
}
const char * Option::type_c_str ( )
private

Return the type of the Option object.

Definition at line 120 of file CmdLineOpts.cpp.

References double_t, flag_t, float_t, func_one_t, func_t, int_t, long_t, m_type, none_t, string_t, uint_t, and ulong_t.

Referenced by ASSA::CmdLineOpts::assign().

{
const char* ret;
switch (m_type)
{
case Option::string_t: ret = "string"; break;
case Option::int_t: ret = "int"; break;
case Option::uint_t: ret = "u_int"; break;
case Option::long_t: ret = "long"; break;
case Option::ulong_t: ret = "u_long"; break;
case Option::double_t: ret = "double"; break;
case Option::float_t: ret = "float"; break;
case Option::flag_t: ret = "bool"; break;
case Option::func_t: ret = "func()"; break;
case Option::func_one_t: ret = "func(opt)"; break;
case Option::none_t: ret = "none"; break;
default: ret = "--undef--";
}
return (ret);
}

Friends And Related Function Documentation

friend class CmdLineOpts
friend

Definition at line 41 of file CmdLineOpts.h.


Member Data Documentation

string ASSA::Option::m_long_name
private

Long option name.

Definition at line 79 of file CmdLineOpts.h.

Referenced by ASSA::CmdLineOpts::assign(), and dump().

char ASSA::Option::m_short_name
private

One-letter option name.

Definition at line 76 of file CmdLineOpts.h.

Referenced by ASSA::CmdLineOpts::assign(), and dump().

type_t ASSA::Option::m_type
private

Option type.

Definition at line 82 of file CmdLineOpts.h.

Referenced by ASSA::CmdLineOpts::assign(), dump(), ASSA::CmdLineOpts::parse_args(), and type_c_str().

void* ASSA::Option::m_val
private

Pointer to the option value.

Definition at line 85 of file CmdLineOpts.h.

Referenced by ASSA::CmdLineOpts::assign(), and dump().


The documentation for this class was generated from the following files: