From 50b89841463d7724e7e20dad19da8bd61d49a06c Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 5 Sep 2012 21:23:44 +0000 Subject: Bu::StdStream can be set to print to stderror now, and sio.h now declares serr and serrRaw. Also, they are now StreamStacks, which means you can change what type of stream they read/write to, and also add filters. --- src/stable/sio.cpp | 6 +++++- src/stable/sio.h | 7 +++++-- src/stable/stdstream.cpp | 7 ++++--- src/stable/stdstream.h | 12 ++++++++++-- src/tests/print.cpp | 2 ++ 5 files changed, 26 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/stable/sio.cpp b/src/stable/sio.cpp index 66db152..8ecb4ad 100644 --- a/src/stable/sio.cpp +++ b/src/stable/sio.cpp @@ -6,9 +6,13 @@ */ #include "bu/sio.h" +#include "bu/streamstack.h" +#include "bu/stdstream.h" -Bu::StdStream Bu::sioRaw; +Bu::StreamStack Bu::sioRaw( new Bu::StdStream() ); Bu::Formatter Bu::sio( Bu::sioRaw ); +Bu::StreamStack Bu::serrRaw( new Bu::StdStream( Bu::StdStream::StdError ) ); +Bu::Formatter Bu::serr( Bu::serrRaw ); class PrintEndAction : public Bu::String::FormatProxyEndAction { diff --git a/src/stable/sio.h b/src/stable/sio.h index d9761b2..2d4a104 100644 --- a/src/stable/sio.h +++ b/src/stable/sio.h @@ -8,13 +8,16 @@ #ifndef BU_SIO_H #define BU_SIO_H -#include "bu/stdstream.h" #include "bu/formatter.h" namespace Bu { - extern Bu::StdStream sioRaw; + class StreamStack; + + extern Bu::StreamStack sioRaw; extern Bu::Formatter sio; + extern Bu::StreamStack serrRaw; + extern Bu::Formatter serr; Bu::String::FormatProxy print( Bu::Stream &s, const Bu::String &str ); Bu::String::FormatProxy print( const Bu::String &str ); diff --git a/src/stable/stdstream.cpp b/src/stable/stdstream.cpp index 9bc22f2..25ad8d4 100644 --- a/src/stable/stdstream.cpp +++ b/src/stable/stdstream.cpp @@ -8,7 +8,8 @@ #include #include "bu/stdstream.h" -Bu::StdStream::StdStream() +Bu::StdStream::StdStream( OutMode eOut ) : + eOut( eOut ) { } @@ -27,7 +28,7 @@ Bu::size Bu::StdStream::read( void *pBuf, Bu::size nBytes ) Bu::size Bu::StdStream::write( const void *pBuf, Bu::size nBytes ) { - return fwrite( pBuf, 1, nBytes, stdout ); + return fwrite( pBuf, 1, nBytes, eOut==StdOut?stdout:stderr ); } Bu::size Bu::StdStream::tell() @@ -59,7 +60,7 @@ bool Bu::StdStream::isOpen() void Bu::StdStream::flush() { - fflush( stdout ); + fflush( eOut==StdOut?stdout:stderr ); } bool Bu::StdStream::canRead() diff --git a/src/stable/stdstream.h b/src/stable/stdstream.h index c3ab153..d71d95d 100644 --- a/src/stable/stdstream.h +++ b/src/stable/stdstream.h @@ -19,7 +19,12 @@ namespace Bu class StdStream : public Stream { public: - StdStream(); + enum OutMode + { + StdOut, + StdError + }; + StdStream( OutMode eOut=StdOut ); virtual ~StdStream(); virtual void close(); @@ -43,7 +48,10 @@ namespace Bu virtual void setSize( size iSize ); virtual size getSize() const; virtual size getBlockSize() const; - virtual Bu::String getLocation() const; + virtual Bu::String getLocation() const; + + private: + OutMode eOut; }; } diff --git a/src/tests/print.cpp b/src/tests/print.cpp index 7d55554..7a2fab2 100644 --- a/src/tests/print.cpp +++ b/src/tests/print.cpp @@ -8,6 +8,8 @@ int main() arg("totally").arg( 47.2 ); Bu::println("This is unsubstituted?"); + Bu::serr << "This is error text." << Bu::serr.nl; + return 0; } -- cgit v1.2.3