blob: 6a650ed1a03034dc08a2f38fb7f1c43e65c49323 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/*
* Copyright (C) 2007-2012 Xagasoft, All rights reserved.
*
* This file is part of the libbu++ library and is released under the
* terms of the license contained in the file LICENSE.
*/
#include "bu/sio.h"
#include "bu/streamstack.h"
#include "bu/stdstream.h"
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 );
namespace Bu
{
class PrintEndAction : public Bu::String::FormatProxyEndAction
{
public:
PrintEndAction( Bu::Stream &s, bool bEndLn ) :
s( s ),
bEndLn( bEndLn )
{
}
virtual ~PrintEndAction()
{
}
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 Bu::PrintEndAction( s, false ) );
}
Bu::String::FormatProxy Bu::print( const Bu::String &str )
{
return print( sioRaw, str );
}
Bu::String::FormatProxy Bu::println( Bu::Stream &s, const Bu::String &str )
{
return str.format( new Bu::PrintEndAction( s, true ) );
}
Bu::String::FormatProxy Bu::println( const Bu::String &str )
{
return println( sioRaw, str );
}
|