Loading...
Searching...
No Matches
ASSA::Option Class Reference

Option class. More...

`#include <CmdLineOpts.h>`

## 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

## type_t

enum ASSA::Option::type_t

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 unsigned 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.

{
string_t=0,
int_t,
uint_t,
long_t,
ulong_t,
double_t,
float_t,
flag_t,
func_t,
func_one_t,
none_t
};
ASSA::Option::func_one_t
@ func_one_t
Convert argument to function with one argument.
Definition CmdLineOpts.h:57
ASSA::Option::func_t
@ func_t
Convert argument to function.
Definition CmdLineOpts.h:56
ASSA::Option::string_t
@ string_t
Convert argument to STL string.
Definition CmdLineOpts.h:48
ASSA::Option::ulong_t
@ ulong_t
Convert argument to unsigned long.
Definition CmdLineOpts.h:52
ASSA::Option::float_t
@ float_t
Convert argument to float.
Definition CmdLineOpts.h:54
ASSA::Option::long_t
@ long_t
Convert argument to long.
Definition CmdLineOpts.h:51
ASSA::Option::double_t
@ double_t
Convert argument to double.
Definition CmdLineOpts.h:53
ASSA::Option::flag_t
@ flag_t
No argument; bool value is flipped.
Definition CmdLineOpts.h:55
ASSA::Option::int_t
@ int_t
Convert argument to int.
Definition CmdLineOpts.h:49
ASSA::Option::uint_t
@ uint_t
Convert argument to unsigned int.
Definition CmdLineOpts.h:50
ASSA::Option::none_t
@ none_t
Definition CmdLineOpts.h:58

## Constructor & Destructor Documentation

## Option() [1/2]

ASSA::Option::Option | ( |  | ) |

inline private

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::m_type
type_t m_type
Option type.
Definition CmdLineOpts.h:82
ASSA::Option::m_long_name
string m_long_name
Long option name.
Definition CmdLineOpts.h:79
ASSA::Option::m_val
void * m_val
Pointer to the option value.
Definition CmdLineOpts.h:85
ASSA::Option::m_short_name
char m_short_name
One-letter option name.
Definition CmdLineOpts.h:76

References m_long_name, m_short_name, m_type, m_val, and none_t.

## Option() [2/2]

ASSA::Option::Option | ( | char | shopt_,
|  | const string & | lopt_,
|  | type_t | type_,
|  | void * | val_ )

inline private

Private constructor.

Definition at line 96 of file CmdLineOpts.h.

:
m_short_name (shopt_), m_long_name (lopt_),
m_type (type_), m_val (val_)
{
trace_with_mask("Option::Option", CMDLINEOPTS);
}
trace_with_mask
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition Logger.h:437
ASSA::CMDLINEOPTS
@ CMDLINEOPTS
Class CmdLineOpts messages.
Definition LogMask.h:36

References ASSA::CMDLINEOPTS, m_long_name, m_short_name, m_type, m_val, and trace_with_mask.

## Member Function Documentation

## dump()

void Option::dump | ( |  | ) | const

private

Write object state to the log file.

Definition at line 29 of file CmdLineOpts.cpp.

{
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)
{
case Option::string_t:
msg << std::setiosflags (std::ios::left) << std::setw(7) << "string";
msg << "] = '" << *(string*) m_val << "'";
break;
case Option::int_t:
msg << std::setiosflags(std::ios::left) << std::setw(7) << "int";
msg << "] = " << *(int*) m_val;
break;
case Option::uint_t:
msg << std::setiosflags(std::ios::left) << std::setw(7) << "u_int";
msg << "] = " << *(int*) m_val;
break;
case Option::long_t:
msg << std::setiosflags(std::ios::left) << std::setw(7) << "long";
msg << "] = " << *(long*) m_val;
break;
case Option::ulong_t:
msg << std::setiosflags(std::ios::left) << std::setw(7) << "u_long";
msg << "] = " << *(long*) m_val;
break;
case Option::double_t:
msg << std::setiosflags(std::ios::left) << std::setw(7) << "double";
msg << "] = " << *(double*) m_val;
break;
case Option::float_t:
msg << std::setiosflags(std::ios::left) << std::setw(7) << "float";
msg << "] = " << *(float*) m_val;
break;
case Option::flag_t:
msg << std::setiosflags(std::ios::left) << std::setw(7) << "bool";
msg << "] = " << *(bool*) m_val ? "true" : "false";
break;
case Option::func_t:
msg << std::setiosflags(std::ios::left)
<< std::setw(7) << "function ()";
msg << ']';
break;
case Option::func_one_t:
msg << std::setiosflags(std::ios::left)
<< std::setw(7) << "function (opt)";
msg << ']';
break;
case Option::none_t:
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 ()));
}
DL
#define DL(X)
A macro for writing debug message to the Logger.
Definition Logger.h:273

References ASSA::CMDLINEOPTS, DL, double_t, 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.

## type_c_str()

const char * Option::type_c_str | ( |  | ) |

private

Return the type of the Option object.

Definition at line 119 of file CmdLineOpts.cpp.

{
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);
}

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

## Friends And Related Symbol Documentation

## CmdLineOpts

friend class CmdLineOpts

friend

Definition at line 41 of file CmdLineOpts.h.

References CmdLineOpts.

Referenced by CmdLineOpts.

## Member Data Documentation

## m_long_name

string ASSA::Option::m_long_name

private

Long option name.

Definition at line 79 of file CmdLineOpts.h.

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

## m_short_name

char ASSA::Option::m_short_name

private

One-letter option name.

Definition at line 76 of file CmdLineOpts.h.

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

## m_type

type_t ASSA::Option::m_type

private

Option type.

Definition at line 82 of file CmdLineOpts.h.

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

## m_val

void* ASSA::Option::m_val

private

Pointer to the option value.

Definition at line 85 of file CmdLineOpts.h.

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

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

- CmdLineOpts.h
- CmdLineOpts.cpp