aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-09-05 21:23:44 +0000
committerMike Buland <eichlan@xagasoft.com>2012-09-05 21:23:44 +0000
commit50b89841463d7724e7e20dad19da8bd61d49a06c (patch)
tree14259e9596fd741d922b881bc8e3df0d647f4281 /src
parente62311adb3ad71a4a04521544fb12070336f17d2 (diff)
downloadlibbu++-50b89841463d7724e7e20dad19da8bd61d49a06c.tar.gz
libbu++-50b89841463d7724e7e20dad19da8bd61d49a06c.tar.bz2
libbu++-50b89841463d7724e7e20dad19da8bd61d49a06c.tar.xz
libbu++-50b89841463d7724e7e20dad19da8bd61d49a06c.zip
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.
Diffstat (limited to '')
-rw-r--r--src/stable/sio.cpp6
-rw-r--r--src/stable/sio.h7
-rw-r--r--src/stable/stdstream.cpp7
-rw-r--r--src/stable/stdstream.h12
-rw-r--r--src/tests/print.cpp2
5 files changed, 26 insertions, 8 deletions
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 @@
6 */ 6 */
7 7
8#include "bu/sio.h" 8#include "bu/sio.h"
9#include "bu/streamstack.h"
10#include "bu/stdstream.h"
9 11
10Bu::StdStream Bu::sioRaw; 12Bu::StreamStack Bu::sioRaw( new Bu::StdStream() );
11Bu::Formatter Bu::sio( Bu::sioRaw ); 13Bu::Formatter Bu::sio( Bu::sioRaw );
14Bu::StreamStack Bu::serrRaw( new Bu::StdStream( Bu::StdStream::StdError ) );
15Bu::Formatter Bu::serr( Bu::serrRaw );
12 16
13class PrintEndAction : public Bu::String::FormatProxyEndAction 17class PrintEndAction : public Bu::String::FormatProxyEndAction
14{ 18{
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 @@
8#ifndef BU_SIO_H 8#ifndef BU_SIO_H
9#define BU_SIO_H 9#define BU_SIO_H
10 10
11#include "bu/stdstream.h"
12#include "bu/formatter.h" 11#include "bu/formatter.h"
13 12
14namespace Bu 13namespace Bu
15{ 14{
16 extern Bu::StdStream sioRaw; 15 class StreamStack;
16
17 extern Bu::StreamStack sioRaw;
17 extern Bu::Formatter sio; 18 extern Bu::Formatter sio;
19 extern Bu::StreamStack serrRaw;
20 extern Bu::Formatter serr;
18 21
19 Bu::String::FormatProxy print( Bu::Stream &s, const Bu::String &str ); 22 Bu::String::FormatProxy print( Bu::Stream &s, const Bu::String &str );
20 Bu::String::FormatProxy print( const Bu::String &str ); 23 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 @@
8#include <stdio.h> 8#include <stdio.h>
9#include "bu/stdstream.h" 9#include "bu/stdstream.h"
10 10
11Bu::StdStream::StdStream() 11Bu::StdStream::StdStream( OutMode eOut ) :
12 eOut( eOut )
12{ 13{
13} 14}
14 15
@@ -27,7 +28,7 @@ Bu::size Bu::StdStream::read( void *pBuf, Bu::size nBytes )
27 28
28Bu::size Bu::StdStream::write( const void *pBuf, Bu::size nBytes ) 29Bu::size Bu::StdStream::write( const void *pBuf, Bu::size nBytes )
29{ 30{
30 return fwrite( pBuf, 1, nBytes, stdout ); 31 return fwrite( pBuf, 1, nBytes, eOut==StdOut?stdout:stderr );
31} 32}
32 33
33Bu::size Bu::StdStream::tell() 34Bu::size Bu::StdStream::tell()
@@ -59,7 +60,7 @@ bool Bu::StdStream::isOpen()
59 60
60void Bu::StdStream::flush() 61void Bu::StdStream::flush()
61{ 62{
62 fflush( stdout ); 63 fflush( eOut==StdOut?stdout:stderr );
63} 64}
64 65
65bool Bu::StdStream::canRead() 66bool 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
19 class StdStream : public Stream 19 class StdStream : public Stream
20 { 20 {
21 public: 21 public:
22 StdStream(); 22 enum OutMode
23 {
24 StdOut,
25 StdError
26 };
27 StdStream( OutMode eOut=StdOut );
23 virtual ~StdStream(); 28 virtual ~StdStream();
24 29
25 virtual void close(); 30 virtual void close();
@@ -43,7 +48,10 @@ namespace Bu
43 virtual void setSize( size iSize ); 48 virtual void setSize( size iSize );
44 virtual size getSize() const; 49 virtual size getSize() const;
45 virtual size getBlockSize() const; 50 virtual size getBlockSize() const;
46 virtual Bu::String getLocation() const; 51 virtual Bu::String getLocation() const;
52
53 private:
54 OutMode eOut;
47 }; 55 };
48} 56}
49 57
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()
8 arg("totally").arg( 47.2 ); 8 arg("totally").arg( 47.2 );
9 Bu::println("This is unsubstituted?"); 9 Bu::println("This is unsubstituted?");
10 10
11 Bu::serr << "This is error text." << Bu::serr.nl;
12
11 return 0; 13 return 0;
12} 14}
13 15