libassa
3.5.1
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
assa
CmdLineOpts.h
Go to the documentation of this file.
1
// -*- c++ -*-
2
//------------------------------------------------------------------------------
3
// $Id: CmdLineOpts.h,v 1.7 2005/10/12 02:28:58 vlg Exp $
4
//------------------------------------------------------------------------------
5
// CmdLineOpts.h
6
//------------------------------------------------------------------------------
7
// Copyright (C) 2000,2005 Vladislav Grinchenko
8
//
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Library General Public
11
// License as published by the Free Software Foundation; either
12
// version 2 of the License, or (at your option) any later version.
13
//------------------------------------------------------------------------------
14
15
#ifndef CMD_LINE_OPTS_H
16
#define CMD_LINE_OPTS_H
17
18
#include "
assa/Assure.h
"
19
20
#include <string>
21
#include <vector>
22
using
std::string;
23
using
std::vector;
24
25
namespace
ASSA {
26
27
class
CmdLineOpts;
28
39
class
Option
{
40
public
:
41
friend
class
CmdLineOpts
;
42
47
enum
type_t
{
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
};
60
61
private
:
63
Option
();
64
66
Option
(
char
shopt_,
const
string
& lopt_,
type_t
type_,
void
* val_);
67
69
void
dump
()
const
;
70
72
const
char
*
type_c_str
();
73
74
private
:
76
char
m_short_name
;
77
79
string
m_long_name
;
80
82
type_t
m_type
;
83
85
void
*
m_val
;
86
};
87
88
inline
89
Option::Option
() :
90
m_short_name (
' '
), m_long_name (
""
), m_type (none_t), m_val (NULL)
91
{
92
/* empty */
93
}
94
95
inline
96
Option::Option
(
char
shopt_,
const
string
& lopt_,
type_t
type_,
void
* val_) :
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
}
102
103
/*----------------------------------------------------------------------------*/
104
class
IniFile
;
105
113
class
CmdLineOpts
114
{
115
public
:
116
typedef
void (*
OPTS_FUNC
) (void);
117
typedef
void (*
OPTS_FUNC_ONE
) (
const
string
&);
118
119
typedef
vector<Option>
OptionSet
;
120
122
CmdLineOpts
();
123
125
virtual
~CmdLineOpts
() {
126
trace_with_mask
(
"CmdLineOpts::~CmdLineOpts"
,
CMDLINEOPTS
);
127
}
128
135
bool
add_flag_opt
(
const
char
c,
const
string
& s,
bool
* f);
136
143
bool
add_opt
(
const
char
c,
const
string
& s,
string
* str);
144
151
bool
add_opt
(
const
char
c,
const
string
& s,
int
* i);
152
159
bool
add_opt
(
const
char
c,
const
string
& s,
unsigned
int
* ui);
160
167
bool
add_opt
(
const
char
c,
const
string
& s,
long
* l);
168
175
bool
add_opt
(
const
char
c,
const
string
& s,
unsigned
long
* ul);
176
183
bool
add_opt
(
const
char
c,
const
string
& s,
double
* d);
184
191
bool
add_opt
(
const
char
c,
const
string
& s,
float
* f);
192
204
bool
add_opt
(
const
char
c_,
const
string
& s_,
OPTS_FUNC
f_);
205
216
bool
add_opt
(
const
char
c_,
const
string
& s_,
OPTS_FUNC_ONE
f_);
217
223
bool
rm_opt
(
const
char
c_,
const
string
& s_);
224
228
bool
parse_args
(
const
char
* argv[]);
229
237
int
parse_config_file
(
IniFile
& inifile_);
238
242
const
char
*
get_opt_error
()
const
;
243
252
static
void
str_to_argv
(
const
string
& src_,
int
& argc_,
char
**& argv_);
253
255
static
void
free_argv
(
char
**& argv_);
256
258
void
dump
()
const
;
259
260
protected
:
262
bool
is_valid
(
const
char
sopt_,
const
string
& lopt_);
263
265
void
set_error_none
();
266
268
bool
assign
(
Option
* node_,
const
char
* op_);
269
271
Option
*
find_option
(
const
char
* str_);
272
274
Option
*
find_option
(
const
char
letter_);
275
280
virtual
void
pos_arg
(
const
char
* arg_);
281
282
private
:
284
OptionSet
m_opts_set
;
285
287
string
m_error
;
288
};
289
290
291
inline
void
292
CmdLineOpts::pos_arg
(
const
char
*
/*arg_*/
) {
/* no-opt*/
}
293
294
inline
295
CmdLineOpts::CmdLineOpts
() : m_opts_set (), m_error (
""
)
296
{
297
trace_with_mask
(
"CmdLineOpts::CmdLineOpts"
,
CMDLINEOPTS
);
298
set_error_none
();
299
}
300
301
inline
void
302
CmdLineOpts::set_error_none
()
303
{
304
trace_with_mask
(
"CmdLineOpts::set_error_none"
,
CMDLINEOPTS
);
305
m_error
=
""
;
306
}
307
308
inline
const
char
*
309
CmdLineOpts::get_opt_error
()
const
310
{
311
return
(
m_error
.c_str ());
312
}
313
314
315
}
// end namespace ASSA
316
317
#endif
/* CMD_LINE_OPTS_H */
Generated on Tue Jun 19 2012 14:39:39 for libassa by
1.8.1