From e5f2e1ce7faeb8fb4609f7291e77d5b682685057 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 5 Sep 2012 20:44:55 +0000 Subject: This'll make *everything* rebuild. String formatters now support the end() call, which will force substitution and return a string. They now also support ending actions, which let us do great stuff like printing stuff out after formatting finished...and other stuff. --- src/stable/sio.cpp | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'src/stable/sio.cpp') diff --git a/src/stable/sio.cpp b/src/stable/sio.cpp index 02ba631..e7f7565 100644 --- a/src/stable/sio.cpp +++ b/src/stable/sio.cpp @@ -10,25 +10,45 @@ Bu::StdStream Bu::sioRaw; Bu::Formatter Bu::sio( Bu::sioRaw ); -Bu::size Bu::print( Bu::Stream &s, const Bu::String &str ) +class PrintEndAction : public Bu::String::FormatProxyEndAction { - return s.write( str.getStr(), str.getSize() ); +public: + PrintEndAction( Bu::Stream &s, bool bEndLn ) : + s( s ), + bEndLn( bEndLn ) + { + } + + virtual void operator()( const Bu::String &sFinal ) + { + s.write( sFinal.getStr(), sFinal.getSize() ); + if( bEndLn ) + { + s.write("\n", 1); + s.flush(); + } + } + + Bu::Stream &s; + bool bEndLn; +}; + +Bu::String::FormatProxy Bu::print( Bu::Stream &s, const Bu::String &str ) +{ + return str.format( new PrintEndAction( s, false ) ); } -Bu::size Bu::print( const Bu::String &str ) +Bu::String::FormatProxy Bu::print( const Bu::String &str ) { return print( sioRaw, str ); } -Bu::size Bu::println( Bu::Stream &s, const Bu::String &str ) +Bu::String::FormatProxy Bu::println( Bu::Stream &s, const Bu::String &str ) { - Bu::size sRet = s.write( str.getStr(), str.getSize() ); - sRet += s.write("\n", 1 ); - s.flush(); - return sRet; + return str.format( new PrintEndAction( s, true ) ); } -Bu::size Bu::println( const Bu::String &str ) +Bu::String::FormatProxy Bu::println( const Bu::String &str ) { return println( sioRaw, str ); } -- cgit v1.2.3