1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
/*
* Copyright (C) 2007-2010 Xagasoft, All rights reserved.
*
* This file is part of the libbu++ library and is released under the
* terms of the license contained in the file LICENSE.
*/
#ifndef BU_PARAM_PROC_H
#define BU_PARAM_PROC_H
#include <stdint.h>
#include "bu/list.h"
#include "bu/fstring.h"
namespace Bu
{
class ParamProc
{
public:
class ParamPtr
{
public:
ParamPtr();
ParamPtr( Bu::FString *str );
ParamPtr( uint64_t *uint64 );
ParamPtr( uint32_t *uint32 );
ParamPtr( uint16_t *uint16 );
ParamPtr( uint8_t *uint8 );
ParamPtr( int64_t *int64 );
ParamPtr( int32_t *int32 );
ParamPtr( int16_t *int16 );
ParamPtr( int8_t *int8 );
ParamPtr( float *float32 );
ParamPtr( double *float64 );
ParamPtr( long double *float96 );
ParamPtr( bool *bln );
enum
{
vtunset,
vtstr,
vtuint64,
vtuint32,
vtuint16,
vtuint8,
vtint64,
vtint32,
vtint16,
vtint8,
vtfloat32,
vtfloat64,
vtfloat96,
vtbln,
};
ParamPtr &operator=( ParamPtr &ptr );
ParamPtr &operator=( const char *str );
bool isSet();
private:
int type;
union
{
Bu::FString *str;
uint64_t *uint64;
uint32_t *uint32;
uint16_t *uint16;
uint8_t *uint8;
int64_t *int64;
int32_t *int32;
int16_t *int16;
int8_t *int8;
float *float32;
double *float64;
long double *float96;
bool *bln;
} val;
};
typedef int (ParamProc::*Proc)( int, char *[] );
typedef struct ArgSpec
{
uint8_t nFlags;
Bu::FString sWord;
char cChar;
Proc proc;
ParamProc::ParamPtr val;
Bu::FString sExtra;
Bu::FString sDesc;
Bu::FString sValue;
} ArgSpec;
public:
DEPRECATED
ParamProc();
virtual ~ParamProc();
void addParam( const char *lpWord, char cChar, Proc proc, ParamPtr val,
const char *lpDesc=NULL, const char *lpExtra=NULL,
const char *lpValue=NULL
);
void addParam( const char *lpWord, char cChar, Proc proc,
const char *lpDesc=NULL, const char *lpExtra=NULL,
const char *lpValue=NULL
);
void addParam( const char *lpWord, char cChar, ParamPtr val,
const char *lpDesc=NULL, const char *lpExtra=NULL,
const char *lpValue=NULL
);
void addParam( const char *lpWord, Proc proc, ParamPtr val,
const char *lpDesc=NULL, const char *lpExtra=NULL,
const char *lpValue=NULL
);
void addParam( const char *lpWord, Proc proc,
const char *lpDesc=NULL, const char *lpExtra=NULL,
const char *lpValue=NULL
);
void addParam( const char *lpWord, ParamPtr val,
const char *lpDesc=NULL, const char *lpExtra=NULL,
const char *lpValue=NULL
);
void addParam( char cChar, Proc proc, ParamPtr val,
const char *lpDesc=NULL, const char *lpExtra=NULL,
const char *lpValue=NULL
);
void addParam( char cChar, Proc proc,
const char *lpDesc=NULL, const char *lpExtra=NULL,
const char *lpValue=NULL
);
void addParam( char cChar, ParamPtr val,
const char *lpDesc=NULL, const char *lpExtra=NULL,
const char *lpValue=NULL
);
void process( int argc, char *argv[] );
void addHelpBanner( const char *sHelpBanner );
private:
ArgSpec *checkWord( const char *arg );
ArgSpec *checkLetr( const char arg );
public:
virtual int cmdParam( int argc, char *argv[] );
virtual int unknownParam( int argc, char *argv[] );
virtual int help( int argc, char *argv[] );
private:
typedef struct Banner
{
Bu::FString sBanner;
ArgSpec *pBefore;
} Banner;
Bu::List<Banner *> lBan;
Bu::List<ArgSpec *> lArg;
};
}
#define mkproc( cls ) static_cast<int (Bu::ParamProc::*)( int, char *[])>(&cls)
#endif
|