diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2009-12-18 15:32:37 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2009-12-18 15:32:37 +0000 |
| commit | 038815ae3a019ac56fa1c62e18c5861166d3a975 (patch) | |
| tree | 816352148be5593f43c746062657849212bdc55e /src/formatter.h | |
| parent | 146930268a695dcc0432599d625ec3eb7e74025e (diff) | |
| download | libbu++-038815ae3a019ac56fa1c62e18c5861166d3a975.tar.gz libbu++-038815ae3a019ac56fa1c62e18c5861166d3a975.tar.bz2 libbu++-038815ae3a019ac56fa1c62e18c5861166d3a975.tar.xz libbu++-038815ae3a019ac56fa1c62e18c5861166d3a975.zip | |
Wow, cool, Bu::Formatter can read all the basic types now, (int, float, bool,
char, etc.) and OptParser totally works. I have one last change to make to it,
which is using the return value of signal type options to determine weather or
not the option took a parameter at all, especially in the case of short options.
Diffstat (limited to 'src/formatter.h')
| -rw-r--r-- | src/formatter.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/formatter.h b/src/formatter.h index aec5c5d..3f51e8e 100644 --- a/src/formatter.h +++ b/src/formatter.h | |||
| @@ -103,6 +103,7 @@ namespace Bu | |||
| 103 | void writeAligned( const Bu::FString &sStr ); | 103 | void writeAligned( const Bu::FString &sStr ); |
| 104 | void writeAligned( const char *sStr, int iLen ); | 104 | void writeAligned( const char *sStr, int iLen ); |
| 105 | 105 | ||
| 106 | void read( void *sStr, int iLen ); | ||
| 106 | Bu::FString readToken(); | 107 | Bu::FString readToken(); |
| 107 | 108 | ||
| 108 | void incIndent(); | 109 | void incIndent(); |
| @@ -199,6 +200,63 @@ namespace Bu | |||
| 199 | writeAligned( fTmp ); | 200 | writeAligned( fTmp ); |
| 200 | usedFormat(); | 201 | usedFormat(); |
| 201 | } | 202 | } |
| 203 | |||
| 204 | template<typename type> | ||
| 205 | void iparse( type &i, const Bu::FString &sBuf ) | ||
| 206 | { | ||
| 207 | if( !sBuf ) | ||
| 208 | return; | ||
| 209 | if( sBuf[0] != '+' && sBuf[0] != '-' && | ||
| 210 | (sBuf[0] < '0' && sBuf[0] > '9') ) | ||
| 211 | return; | ||
| 212 | int j = 1; | ||
| 213 | int iMax = sBuf.getSize(); | ||
| 214 | for(; j < iMax && (sBuf[j] >= '0' && sBuf[j] <= '9'); j++ ) { } | ||
| 215 | i = 0; | ||
| 216 | type iPos = 1; | ||
| 217 | for(j--; j >= 0; j-- ) | ||
| 218 | { | ||
| 219 | if( sBuf[j] == '+' || sBuf[j] == '-' ) | ||
| 220 | continue; | ||
| 221 | i += (sBuf[j]-'0')*iPos; | ||
| 222 | iPos *= fLast.uRadix; | ||
| 223 | } | ||
| 224 | if( sBuf[0] == '-' ) | ||
| 225 | i = -i; | ||
| 226 | |||
| 227 | usedFormat(); | ||
| 228 | } | ||
| 229 | |||
| 230 | template<typename type> | ||
| 231 | void uparse( type &i, const Bu::FString &sBuf ) | ||
| 232 | { | ||
| 233 | if( !sBuf ) | ||
| 234 | return; | ||
| 235 | if( sBuf[0] != '+' && | ||
| 236 | (sBuf[0] < '0' && sBuf[0] > '9') ) | ||
| 237 | return; | ||
| 238 | int j = 1; | ||
| 239 | int iMax = sBuf.getSize(); | ||
| 240 | for(; j < iMax && (sBuf[j] >= '0' && sBuf[j] <= '9'); j++ ) { } | ||
| 241 | i = 0; | ||
| 242 | type iPos = 1; | ||
| 243 | for(j--; j >= 0; j-- ) | ||
| 244 | { | ||
| 245 | if( sBuf[j] == '+' ) | ||
| 246 | continue; | ||
| 247 | i += (sBuf[j]-'0')*iPos; | ||
| 248 | iPos *= fLast.uRadix; | ||
| 249 | } | ||
| 250 | |||
| 251 | usedFormat(); | ||
| 252 | } | ||
| 253 | |||
| 254 | template<typename type> | ||
| 255 | void fparse( type &f, const Bu::FString &sBuf ) | ||
| 256 | { | ||
| 257 | sscanf( sBuf.getStr(), "%f", &f ); | ||
| 258 | usedFormat(); | ||
| 259 | } | ||
| 202 | 260 | ||
| 203 | enum Special | 261 | enum Special |
| 204 | { | 262 | { |
| @@ -243,6 +301,21 @@ namespace Bu | |||
| 243 | Formatter &operator<<( Formatter &f, bool b ); | 301 | Formatter &operator<<( Formatter &f, bool b ); |
| 244 | 302 | ||
| 245 | Formatter &operator>>( Formatter &f, Bu::FString &sStr ); | 303 | Formatter &operator>>( Formatter &f, Bu::FString &sStr ); |
| 304 | Formatter &operator>>( Formatter &f, signed char &c ); | ||
| 305 | Formatter &operator>>( Formatter &f, char &c ); | ||
| 306 | Formatter &operator>>( Formatter &f, unsigned char &c ); | ||
| 307 | Formatter &operator>>( Formatter &f, signed short &i ); | ||
| 308 | Formatter &operator>>( Formatter &f, unsigned short &i ); | ||
| 309 | Formatter &operator>>( Formatter &f, signed int &i ); | ||
| 310 | Formatter &operator>>( Formatter &f, unsigned int &i ); | ||
| 311 | Formatter &operator>>( Formatter &f, signed long &i ); | ||
| 312 | Formatter &operator>>( Formatter &f, unsigned long &i ); | ||
| 313 | Formatter &operator>>( Formatter &f, signed long long &i ); | ||
| 314 | Formatter &operator>>( Formatter &f, unsigned long long &i ); | ||
| 315 | Formatter &operator>>( Formatter &f, float &flt ); | ||
| 316 | Formatter &operator>>( Formatter &f, double &flt ); | ||
| 317 | Formatter &operator>>( Formatter &f, long double &flt ); | ||
| 318 | Formatter &operator>>( Formatter &f, bool &b ); | ||
| 246 | 319 | ||
| 247 | template<typename type> | 320 | template<typename type> |
| 248 | Formatter &operator<<( Formatter &f, const type *p ) | 321 | Formatter &operator<<( Formatter &f, const type *p ) |
