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.cpp | |
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.cpp')
-rw-r--r-- | src/formatter.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/formatter.cpp b/src/formatter.cpp index 5ab1b3f..14f70ed 100644 --- a/src/formatter.cpp +++ b/src/formatter.cpp | |||
@@ -111,6 +111,11 @@ void Bu::Formatter::writeAligned( const char *sStr, int iLen ) | |||
111 | usedFormat(); | 111 | usedFormat(); |
112 | } | 112 | } |
113 | 113 | ||
114 | void Bu::Formatter::read( void *sStr, int iLen ) | ||
115 | { | ||
116 | rStream.read( sStr, iLen ); | ||
117 | } | ||
118 | |||
114 | Bu::FString Bu::Formatter::readToken() | 119 | Bu::FString Bu::Formatter::readToken() |
115 | { | 120 | { |
116 | Bu::FString sRet; | 121 | Bu::FString sRet; |
@@ -362,3 +367,101 @@ Bu::Formatter &Bu::operator>>( Bu::Formatter &f, Bu::FString &sStr ) | |||
362 | return f; | 367 | return f; |
363 | } | 368 | } |
364 | 369 | ||
370 | Bu::Formatter &Bu::operator>>( Bu::Formatter &f, signed char &c ) | ||
371 | { | ||
372 | f.read( &c, 1 ); | ||
373 | return f; | ||
374 | } | ||
375 | |||
376 | Bu::Formatter &Bu::operator>>( Bu::Formatter &f, char &c ) | ||
377 | { | ||
378 | f.read( &c, 1 ); | ||
379 | return f; | ||
380 | } | ||
381 | |||
382 | Bu::Formatter &Bu::operator>>( Bu::Formatter &f, unsigned char &c ) | ||
383 | { | ||
384 | f.read( &c, 1 ); | ||
385 | return f; | ||
386 | } | ||
387 | |||
388 | Bu::Formatter &Bu::operator>>( Bu::Formatter &f, signed short &i ) | ||
389 | { | ||
390 | f.iparse( i, f.readToken() ); | ||
391 | return f; | ||
392 | } | ||
393 | |||
394 | Bu::Formatter &Bu::operator>>( Bu::Formatter &f, unsigned short &i ) | ||
395 | { | ||
396 | f.uparse( i, f.readToken() ); | ||
397 | return f; | ||
398 | } | ||
399 | |||
400 | Bu::Formatter &Bu::operator>>( Bu::Formatter &f, signed int &i ) | ||
401 | { | ||
402 | f.iparse( i, f.readToken() ); | ||
403 | return f; | ||
404 | } | ||
405 | |||
406 | Bu::Formatter &Bu::operator>>( Bu::Formatter &f, unsigned int &i ) | ||
407 | { | ||
408 | f.uparse( i, f.readToken() ); | ||
409 | return f; | ||
410 | } | ||
411 | |||
412 | Bu::Formatter &Bu::operator>>( Bu::Formatter &f, signed long &i ) | ||
413 | { | ||
414 | f.iparse( i, f.readToken() ); | ||
415 | return f; | ||
416 | } | ||
417 | |||
418 | Bu::Formatter &Bu::operator>>( Bu::Formatter &f, unsigned long &i ) | ||
419 | { | ||
420 | f.uparse( i, f.readToken() ); | ||
421 | return f; | ||
422 | } | ||
423 | |||
424 | Bu::Formatter &Bu::operator>>( Bu::Formatter &f, signed long long &i ) | ||
425 | { | ||
426 | f.iparse( i, f.readToken() ); | ||
427 | return f; | ||
428 | } | ||
429 | |||
430 | Bu::Formatter &Bu::operator>>( Bu::Formatter &f, unsigned long long &i ) | ||
431 | { | ||
432 | f.uparse( i, f.readToken() ); | ||
433 | return f; | ||
434 | } | ||
435 | |||
436 | Bu::Formatter &Bu::operator>>( Bu::Formatter &f, float &flt ) | ||
437 | { | ||
438 | f.fparse( flt, f.readToken() ); | ||
439 | return f; | ||
440 | } | ||
441 | |||
442 | Bu::Formatter &Bu::operator>>( Bu::Formatter &f, double &flt ) | ||
443 | { | ||
444 | f.fparse( flt, f.readToken() ); | ||
445 | return f; | ||
446 | } | ||
447 | |||
448 | Bu::Formatter &Bu::operator>>( Bu::Formatter &f, long double &flt ) | ||
449 | { | ||
450 | f.fparse( flt, f.readToken() ); | ||
451 | return f; | ||
452 | } | ||
453 | |||
454 | Bu::Formatter &Bu::operator>>( Bu::Formatter &f, bool &b ) | ||
455 | { | ||
456 | Bu::FString sStr = f.readToken(); | ||
457 | if( !sStr ) | ||
458 | return f; | ||
459 | char c = *sStr.begin(); | ||
460 | if( c == 'y' || c == 'Y' || c == 't' || c == 'T' ) | ||
461 | b = true; | ||
462 | else if( c == 'n' || c == 'N' || c == 'f' || c == 'F' ) | ||
463 | b = false; | ||
464 | |||
465 | return f; | ||
466 | } | ||
467 | |||