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.

00047                 { 
00048         string_t=0, 
00049         int_t,      
00050         uint_t,     
00051         long_t,     
00052         ulong_t,    
00053         double_t,   
00054         float_t,    
00055         flag_t,     
00056         func_t,     
00057         func_one_t, 
00058         none_t                  
00059     };


Constructor & Destructor Documentation

ASSA::Option::Option (  )  [inline, private]

Private default constructor.

Definition at line 89 of file CmdLineOpts.h.

00089                 :
00090     m_short_name (' '), m_long_name (""), m_type (none_t), m_val (NULL) 
00091 {
00092     /* empty */
00093 }

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.

References ASSA::CMDLINEOPTS, and trace_with_mask.

00096                                                                           : 
00097     m_short_name (shopt_),  m_long_name (lopt_),
00098     m_type (type_), m_val (val_) 
00099 {
00100     trace_with_mask("Option::Option", CMDLINEOPTS);
00101 }


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.

00031 {
00032     std::ostringstream msg;
00033 
00034     if (m_short_name != 0) {
00035         msg << "-" << m_short_name << ", ";
00036     }
00037     else {
00038         msg << "    ";
00039     }
00040 
00041     if (m_long_name.size ()) { 
00042         msg << "--" << std::setiosflags (std::ios::left)
00043             << std::setw(14) << m_long_name.c_str () << ' ';
00044     }
00045     else {
00046         msg << std::setiosflags (std::ios::left) << std::setw (14) << "    ";
00047     }
00048     msg << '[';
00049 
00050     switch (m_type) 
00051     {
00052     case Option::string_t: 
00053         msg << std::setiosflags (std::ios::left) << std::setw(7) << "string";
00054         msg << "] = '" << *(string*) m_val << "'";
00055         break;
00056 
00057     case Option::int_t: 
00058         msg << std::setiosflags(std::ios::left) << std::setw(7) << "int";
00059         msg << "] = " << *(int*) m_val; 
00060         break;
00061 
00062     case Option::uint_t: 
00063         msg << std::setiosflags(std::ios::left) << std::setw(7) << "u_int";
00064         msg << "] = " << *(int*) m_val; 
00065         break;
00066 
00067     case Option::long_t: 
00068         msg << std::setiosflags(std::ios::left) << std::setw(7) << "long";
00069         msg << "] = " << *(long*) m_val; 
00070         break;
00071 
00072     case Option::ulong_t: 
00073         msg << std::setiosflags(std::ios::left) << std::setw(7) << "u_long";
00074         msg << "] = " << *(long*) m_val; 
00075         break;
00076 
00077     case Option::double_t: 
00078         msg << std::setiosflags(std::ios::left) << std::setw(7) << "double";
00079         msg << "] = " << *(double*) m_val;
00080         break;
00081 
00082     case Option::float_t: 
00083         msg << std::setiosflags(std::ios::left) << std::setw(7) << "float";
00084         msg << "] = " << *(float*) m_val;
00085         break;
00086 
00087     case Option::flag_t: 
00088         msg << std::setiosflags(std::ios::left) << std::setw(7) << "bool";
00089         msg << "] = " << *(bool*) m_val ? "true" : "false"; 
00090         break;
00091 
00092     case Option::func_t: 
00093         msg << std::setiosflags(std::ios::left) 
00094             << std::setw(7) << "function ()"; 
00095         msg << ']';
00096         break;
00097 
00098     case Option::func_one_t: 
00099         msg << std::setiosflags(std::ios::left) 
00100             << std::setw(7) << "function (opt)";
00101         msg << ']';
00102         break;
00103 
00104     case Option::none_t: 
00105         msg << std::setiosflags(std::ios::left) << std::setw(7) << "none"; 
00106         msg << ']';
00107         break;
00108 
00109     default: 
00110         msg << std::setiosflags(std::ios::left) 
00111         << std::setw(7) << "--undef--";
00112         msg << ']';
00113     }
00114     msg << std::ends;
00115     DL((CMDLINEOPTS,"%s\n", msg.str ().c_str ()));
00116 }

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

00121 {
00122     const char* ret;
00123 
00124     switch (m_type) 
00125     {
00126     case Option::string_t:   ret = "string";    break;
00127     case Option::int_t:      ret = "int";       break;
00128     case Option::uint_t:     ret = "u_int";     break;
00129     case Option::long_t:     ret = "long";      break;
00130     case Option::ulong_t:    ret = "u_long";    break;
00131     case Option::double_t:   ret = "double";    break;
00132     case Option::float_t:    ret = "float";     break;
00133     case Option::flag_t:     ret = "bool";      break;
00134     case Option::func_t:     ret = "func()";    break;
00135     case Option::func_one_t: ret = "func(opt)"; break;
00136     case Option::none_t:     ret = "none";      break;
00137     default:                 ret = "--undef--"; 
00138     }
00139     return (ret);
00140 }


Friends And Related Function Documentation

friend class CmdLineOpts [friend]

Definition at line 41 of file CmdLineOpts.h.


Member Data Documentation

One-letter option name.

Definition at line 76 of file CmdLineOpts.h.

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

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

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:

Generated on Sun Mar 2 15:15:45 2008 for libassa by  doxygen 1.5.5