libassa  3.5.1
Public Types | Private Member Functions | Private Attributes | Friends | List of all members
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. More...
 
 Option (char shopt_, const string &lopt_, type_t type_, void *val_)
 Private constructor. More...
 
void dump () const
 Write object state to the log file. More...
 
const char * type_c_str ()
 Return the type of the Option object. More...
 

Private Attributes

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

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

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.

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

Constructor & Destructor Documentation

◆ Option() [1/2]

ASSA::Option::Option ( )
inlineprivate

Private default constructor.

Definition at line 89 of file CmdLineOpts.h.

89  :
90  m_short_name (' '), m_long_name (""), m_type (none_t), m_val (NULL)
91 {
92  /* empty */
93 }
type_t m_type
Option type.
Definition: CmdLineOpts.h:82
string m_long_name
Long option name.
Definition: CmdLineOpts.h:79
void * m_val
Pointer to the option value.
Definition: CmdLineOpts.h:85
char m_short_name
One-letter option name.
Definition: CmdLineOpts.h:76

◆ Option() [2/2]

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

Private constructor.

Definition at line 96 of file CmdLineOpts.h.

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

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

31 {
32  std::ostringstream msg;
33 
34  if (m_short_name != 0) {
35  msg << "-" << m_short_name << ", ";
36  }
37  else {
38  msg << " ";
39  }
40 
41  if (m_long_name.size ()) {
42  msg << "--" << std::setiosflags (std::ios::left)
43  << std::setw(14) << m_long_name.c_str () << ' ';
44  }
45  else {
46  msg << std::setiosflags (std::ios::left) << std::setw (14) << " ";
47  }
48  msg << '[';
49 
50  switch (m_type)
51  {
52  case Option::string_t:
53  msg << std::setiosflags (std::ios::left) << std::setw(7) << "string";
54  msg << "] = '" << *(string*) m_val << "'";
55  break;
56 
57  case Option::int_t:
58  msg << std::setiosflags(std::ios::left) << std::setw(7) << "int";
59  msg << "] = " << *(int*) m_val;
60  break;
61 
62  case Option::uint_t:
63  msg << std::setiosflags(std::ios::left) << std::setw(7) << "u_int";
64  msg << "] = " << *(int*) m_val;
65  break;
66 
67  case Option::long_t:
68  msg << std::setiosflags(std::ios::left) << std::setw(7) << "long";
69  msg << "] = " << *(long*) m_val;
70  break;
71 
72  case Option::ulong_t:
73  msg << std::setiosflags(std::ios::left) << std::setw(7) << "u_long";
74  msg << "] = " << *(long*) m_val;
75  break;
76 
77  case Option::double_t:
78  msg << std::setiosflags(std::ios::left) << std::setw(7) << "double";
79  msg << "] = " << *(double*) m_val;
80  break;
81 
82  case Option::float_t:
83  msg << std::setiosflags(std::ios::left) << std::setw(7) << "float";
84  msg << "] = " << *(float*) m_val;
85  break;
86 
87  case Option::flag_t:
88  msg << std::setiosflags(std::ios::left) << std::setw(7) << "bool";
89  msg << "] = " << *(bool*) m_val ? "true" : "false";
90  break;
91 
92  case Option::func_t:
93  msg << std::setiosflags(std::ios::left)
94  << std::setw(7) << "function ()";
95  msg << ']';
96  break;
97 
98  case Option::func_one_t:
99  msg << std::setiosflags(std::ios::left)
100  << std::setw(7) << "function (opt)";
101  msg << ']';
102  break;
103 
104  case Option::none_t:
105  msg << std::setiosflags(std::ios::left) << std::setw(7) << "none";
106  msg << ']';
107  break;
108 
109  default:
110  msg << std::setiosflags(std::ios::left)
111  << std::setw(7) << "--undef--";
112  msg << ']';
113  }
114  msg << std::ends;
115  DL((CMDLINEOPTS,"%s\n", msg.str ().c_str ()));
116 }
#define DL(X)
A macro for writing debug message to the Logger.
Definition: Logger.h:273
Socket & ends(Socket &os_)
ends manipulator.
Definition: Socket.h:622

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.

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

121 {
122  const char* ret;
123 
124  switch (m_type)
125  {
126  case Option::string_t: ret = "string"; break;
127  case Option::int_t: ret = "int"; break;
128  case Option::uint_t: ret = "u_int"; break;
129  case Option::long_t: ret = "long"; break;
130  case Option::ulong_t: ret = "u_long"; break;
131  case Option::double_t: ret = "double"; break;
132  case Option::float_t: ret = "float"; break;
133  case Option::flag_t: ret = "bool"; break;
134  case Option::func_t: ret = "func()"; break;
135  case Option::func_one_t: ret = "func(opt)"; break;
136  case Option::none_t: ret = "none"; break;
137  default: ret = "--undef--";
138  }
139  return (ret);
140 }

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 Function Documentation

◆ CmdLineOpts

friend class CmdLineOpts
friend

Definition at line 41 of file CmdLineOpts.h.

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(), and dump().

◆ 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(), and dump().

◆ m_type

type_t ASSA::Option::m_type
private

◆ 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(), and dump().


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