diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-06-29 02:50:56 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-06-29 02:50:56 +0000 |
commit | 5e386890b41fe043e2639b25b613831ef8362e7b (patch) | |
tree | 60da93a6ade1db5ed2620fbe47b472291459a1a1 /src/paramproc.h | |
parent | ac98da8eacbf1147d69e378db62432db05e8c73e (diff) | |
download | libbu++-5e386890b41fe043e2639b25b613831ef8362e7b.tar.gz libbu++-5e386890b41fe043e2639b25b613831ef8362e7b.tar.bz2 libbu++-5e386890b41fe043e2639b25b613831ef8362e7b.tar.xz libbu++-5e386890b41fe043e2639b25b613831ef8362e7b.zip |
Completely removed the old, crappy pproc and replaced it with the new, shiny
ParamProc class...it's soooo much better it makes me wanna' throw things...
Diffstat (limited to 'src/paramproc.h')
-rw-r--r-- | src/paramproc.h | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/src/paramproc.h b/src/paramproc.h new file mode 100644 index 0000000..b7450b7 --- /dev/null +++ b/src/paramproc.h | |||
@@ -0,0 +1,139 @@ | |||
1 | #ifndef PARAM_PROC_H | ||
2 | #define PARAM_PROC_H | ||
3 | |||
4 | #include <stdint.h> | ||
5 | #include <string> | ||
6 | #include <list> | ||
7 | #include "staticstring.h" | ||
8 | |||
9 | class ParamProc | ||
10 | { | ||
11 | public: | ||
12 | class ParamPtr | ||
13 | { | ||
14 | public: | ||
15 | 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 | { | ||
32 | vtunset, | ||
33 | vtstr, | ||
34 | vtuint64, | ||
35 | vtuint32, | ||
36 | vtuint16, | ||
37 | vtuint8, | ||
38 | vtint64, | ||
39 | vtint32, | ||
40 | vtint16, | ||
41 | vtint8, | ||
42 | vtfloat32, | ||
43 | vtfloat64, | ||
44 | vtfloat96, | ||
45 | vtbln, | ||
46 | }; | ||
47 | ParamPtr &operator=( ParamPtr &ptr ); | ||
48 | ParamPtr &operator=( const char *str ); | ||
49 | |||
50 | bool isSet(); | ||
51 | |||
52 | private: | ||
53 | int type; | ||
54 | union | ||
55 | { | ||
56 | std::string *str; | ||
57 | uint64_t *uint64; | ||
58 | uint32_t *uint32; | ||
59 | uint16_t *uint16; | ||
60 | uint8_t *uint8; | ||
61 | int64_t *int64; | ||
62 | int32_t *int32; | ||
63 | int16_t *int16; | ||
64 | int8_t *int8; | ||
65 | float *float32; | ||
66 | double *float64; | ||
67 | long double *float96; | ||
68 | bool *bln; | ||
69 | } val; | ||
70 | }; | ||
71 | |||
72 | typedef int (ParamProc::*Proc)( int, char *[] ); | ||
73 | |||
74 | typedef struct ArgSpec | ||
75 | { | ||
76 | uint8_t nFlags; | ||
77 | StaticString sWord; | ||
78 | char cChar; | ||
79 | Proc proc; | ||
80 | ParamProc::ParamPtr val; | ||
81 | StaticString sExtra; | ||
82 | StaticString sDesc; | ||
83 | StaticString sValue; | ||
84 | } ArgSpec; | ||
85 | |||
86 | public: | ||
87 | ParamProc(); | ||
88 | virtual ~ParamProc(); | ||
89 | |||
90 | void addParam( const char *lpWord, char cChar, Proc proc, ParamPtr val, | ||
91 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
92 | const char *lpValue=NULL | ||
93 | ); | ||
94 | void addParam( const char *lpWord, char cChar, Proc proc, | ||
95 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
96 | const char *lpValue=NULL | ||
97 | ); | ||
98 | void addParam( const char *lpWord, char cChar, ParamPtr val, | ||
99 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
100 | const char *lpValue=NULL | ||
101 | ); | ||
102 | |||
103 | void addParam( const char *lpWord, Proc proc, ParamPtr val, | ||
104 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
105 | const char *lpValue=NULL | ||
106 | ); | ||
107 | void addParam( const char *lpWord, Proc proc, | ||
108 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
109 | const char *lpValue=NULL | ||
110 | ); | ||
111 | void addParam( const char *lpWord, ParamPtr val, | ||
112 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
113 | const char *lpValue=NULL | ||
114 | ); | ||
115 | |||
116 | void addParam( char cChar, Proc proc, ParamPtr val, | ||
117 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
118 | const char *lpValue=NULL | ||
119 | ); | ||
120 | void addParam( char cChar, Proc proc, | ||
121 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
122 | const char *lpValue=NULL | ||
123 | ); | ||
124 | void addParam( char cChar, ParamPtr val, | ||
125 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
126 | const char *lpValue=NULL | ||
127 | ); | ||
128 | |||
129 | void process( int argc, char *argv[] ); | ||
130 | ArgSpec *checkWord( const char *arg ); | ||
131 | ArgSpec *checkLetr( const char arg ); | ||
132 | |||
133 | private: | ||
134 | std::list<ArgSpec *> lArg; | ||
135 | }; | ||
136 | |||
137 | #define mkproc( cls ) static_cast<int (ParamProc::*)( int, char *[])>(&cls) | ||
138 | |||
139 | #endif | ||