diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-06-07 19:56:20 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-06-07 19:56:20 +0000 |
commit | 9e8a4944e50fab432012878c66e1bdac20649f76 (patch) | |
tree | 412b0d49ae4086bb330045f9956513397b866807 /src/paramproc.h | |
parent | c2e3879b965d297604804f03271ac71c8c5c81f3 (diff) | |
download | libbu++-9e8a4944e50fab432012878c66e1bdac20649f76.tar.gz libbu++-9e8a4944e50fab432012878c66e1bdac20649f76.tar.bz2 libbu++-9e8a4944e50fab432012878c66e1bdac20649f76.tar.xz libbu++-9e8a4944e50fab432012878c66e1bdac20649f76.zip |
The Stream Filter archetecture is finished, it's actually much cooler than I
had anticipated, and much cleaner. I'll have to add some documentation to it,
because it's not really obvious how any of it fits together from the outset,
although I have to say that the bzip2 test program is the easiest general bzip2
compression program I've ever made...it just goes :)
Decompression in Bu::BZip2 isn't finished yet, but that's ok, it's coming soon.
Diffstat (limited to 'src/paramproc.h')
-rw-r--r-- | src/paramproc.h | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/src/paramproc.h b/src/paramproc.h new file mode 100644 index 0000000..beee4a0 --- /dev/null +++ b/src/paramproc.h | |||
@@ -0,0 +1,156 @@ | |||
1 | #ifndef PARAM_PROC_H | ||
2 | #define PARAM_PROC_H | ||
3 | |||
4 | #include <stdint.h> | ||
5 | #include <string> | ||
6 | #include <list> | ||
7 | #include "bu/fstring.h" | ||
8 | |||
9 | namespace Bu | ||
10 | { | ||
11 | class ParamProc | ||
12 | { | ||
13 | public: | ||
14 | class ParamPtr | ||
15 | { | ||
16 | public: | ||
17 | ParamPtr(); | ||
18 | ParamPtr( std::string *str ); | ||
19 | ParamPtr( uint64_t *uint64 ); | ||
20 | ParamPtr( uint32_t *uint32 ); | ||
21 | ParamPtr( uint16_t *uint16 ); | ||
22 | ParamPtr( uint8_t *uint8 ); | ||
23 | ParamPtr( int64_t *int64 ); | ||
24 | ParamPtr( int32_t *int32 ); | ||
25 | ParamPtr( int16_t *int16 ); | ||
26 | ParamPtr( int8_t *int8 ); | ||
27 | ParamPtr( float *float32 ); | ||
28 | ParamPtr( double *float64 ); | ||
29 | ParamPtr( long double *float96 ); | ||
30 | ParamPtr( bool *bln ); | ||
31 | |||
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 | |||
52 | bool isSet(); | ||
53 | |||
54 | private: | ||
55 | int type; | ||
56 | union | ||
57 | { | ||
58 | std::string *str; | ||
59 | uint64_t *uint64; | ||
60 | uint32_t *uint32; | ||
61 | uint16_t *uint16; | ||
62 | uint8_t *uint8; | ||
63 | int64_t *int64; | ||
64 | int32_t *int32; | ||
65 | int16_t *int16; | ||
66 | int8_t *int8; | ||
67 | float *float32; | ||
68 | double *float64; | ||
69 | long double *float96; | ||
70 | bool *bln; | ||
71 | } val; | ||
72 | }; | ||
73 | |||
74 | typedef int (ParamProc::*Proc)( int, char *[] ); | ||
75 | |||
76 | typedef struct ArgSpec | ||
77 | { | ||
78 | uint8_t nFlags; | ||
79 | Bu::FString sWord; | ||
80 | char cChar; | ||
81 | Proc proc; | ||
82 | ParamProc::ParamPtr val; | ||
83 | Bu::FString sExtra; | ||
84 | Bu::FString sDesc; | ||
85 | Bu::FString sValue; | ||
86 | } ArgSpec; | ||
87 | |||
88 | public: | ||
89 | ParamProc(); | ||
90 | virtual ~ParamProc(); | ||
91 | |||
92 | void addParam( const char *lpWord, char cChar, Proc proc, ParamPtr val, | ||
93 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
94 | const char *lpValue=NULL | ||
95 | ); | ||
96 | void addParam( const char *lpWord, char cChar, Proc proc, | ||
97 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
98 | const char *lpValue=NULL | ||
99 | ); | ||
100 | void addParam( const char *lpWord, char cChar, ParamPtr val, | ||
101 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
102 | const char *lpValue=NULL | ||
103 | ); | ||
104 | |||
105 | void addParam( const char *lpWord, Proc proc, ParamPtr val, | ||
106 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
107 | const char *lpValue=NULL | ||
108 | ); | ||
109 | void addParam( const char *lpWord, Proc proc, | ||
110 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
111 | const char *lpValue=NULL | ||
112 | ); | ||
113 | void addParam( const char *lpWord, ParamPtr val, | ||
114 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
115 | const char *lpValue=NULL | ||
116 | ); | ||
117 | |||
118 | void addParam( char cChar, Proc proc, ParamPtr val, | ||
119 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
120 | const char *lpValue=NULL | ||
121 | ); | ||
122 | void addParam( char cChar, Proc proc, | ||
123 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
124 | const char *lpValue=NULL | ||
125 | ); | ||
126 | void addParam( char cChar, ParamPtr val, | ||
127 | const char *lpDesc=NULL, const char *lpExtra=NULL, | ||
128 | const char *lpValue=NULL | ||
129 | ); | ||
130 | |||
131 | void process( int argc, char *argv[] ); | ||
132 | void addHelpBanner( const char *sHelpBanner ); | ||
133 | |||
134 | private: | ||
135 | ArgSpec *checkWord( const char *arg ); | ||
136 | ArgSpec *checkLetr( const char arg ); | ||
137 | |||
138 | public: | ||
139 | virtual int cmdParam( int argc, char *argv[] ); | ||
140 | virtual int unknownParam( int argc, char *argv[] ); | ||
141 | virtual int help( int argc, char *argv[] ); | ||
142 | |||
143 | private: | ||
144 | typedef struct Banner | ||
145 | { | ||
146 | Bu::FString sBanner; | ||
147 | ArgSpec *pBefore; | ||
148 | } Banner; | ||
149 | std::list<Banner *> lBan; | ||
150 | std::list<ArgSpec *> lArg; | ||
151 | }; | ||
152 | } | ||
153 | |||
154 | #define mkproc( cls ) static_cast<int (Bu::ParamProc::*)( int, char *[])>(&cls) | ||
155 | |||
156 | #endif | ||