From 038815ae3a019ac56fa1c62e18c5861166d3a975 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 18 Dec 2009 15:32:37 +0000 Subject: 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. --- src/formatter.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) (limited to 'src/formatter.cpp') 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 ) usedFormat(); } +void Bu::Formatter::read( void *sStr, int iLen ) +{ + rStream.read( sStr, iLen ); +} + Bu::FString Bu::Formatter::readToken() { Bu::FString sRet; @@ -362,3 +367,101 @@ Bu::Formatter &Bu::operator>>( Bu::Formatter &f, Bu::FString &sStr ) return f; } +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, signed char &c ) +{ + f.read( &c, 1 ); + return f; +} + +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, char &c ) +{ + f.read( &c, 1 ); + return f; +} + +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, unsigned char &c ) +{ + f.read( &c, 1 ); + return f; +} + +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, signed short &i ) +{ + f.iparse( i, f.readToken() ); + return f; +} + +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, unsigned short &i ) +{ + f.uparse( i, f.readToken() ); + return f; +} + +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, signed int &i ) +{ + f.iparse( i, f.readToken() ); + return f; +} + +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, unsigned int &i ) +{ + f.uparse( i, f.readToken() ); + return f; +} + +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, signed long &i ) +{ + f.iparse( i, f.readToken() ); + return f; +} + +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, unsigned long &i ) +{ + f.uparse( i, f.readToken() ); + return f; +} + +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, signed long long &i ) +{ + f.iparse( i, f.readToken() ); + return f; +} + +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, unsigned long long &i ) +{ + f.uparse( i, f.readToken() ); + return f; +} + +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, float &flt ) +{ + f.fparse( flt, f.readToken() ); + return f; +} + +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, double &flt ) +{ + f.fparse( flt, f.readToken() ); + return f; +} + +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, long double &flt ) +{ + f.fparse( flt, f.readToken() ); + return f; +} + +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, bool &b ) +{ + Bu::FString sStr = f.readToken(); + if( !sStr ) + return f; + char c = *sStr.begin(); + if( c == 'y' || c == 'Y' || c == 't' || c == 'T' ) + b = true; + else if( c == 'n' || c == 'N' || c == 'f' || c == 'F' ) + b = false; + + return f; +} + -- cgit v1.2.3