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