31 if (buffers.size() < 1) {
32 std::ostringstream msg;
33 msg << __FILE__ <<
":" << __LINE__ <<
"\n\t";
34 msg <<
"Buffer must be initialized with at least one streambuf!";
35 throw std::invalid_argument(msg.str().c_str());
40 SplitStreamBuf::~SplitStreamBuf() {
46 char const cchar = traits_type::to_char_type(c);
47 for (
unsigned int i=0; i <
_buffers.size(); i++)
48 over = over || (
_buffers[i]->sputc(cchar) == EOF);
52 return traits_type::not_eof(c);
56 std::streamsize min = std::numeric_limits<std::streamsize>::max();
57 for(
unsigned int i=0; i <
_buffers.size(); i++) {
58 std::streamsize temp =
_buffers[i]->sputn(str, size);
67 for (
unsigned int i=0; i<
_buffers.size(); i++) {
68 bool temp = (
_buffers[i]->pubsync() == -1 );
79 std::ostream(std::cout.rdbuf()),
81 std::ostream(std::_Uninitialized()),
88 std::ostream(stream.rdbuf()) {
93 assert(rdbuf() == _buffer);
97 std::ostream(std::cout.rdbuf()) {
103 assert(rdbuf() == _buffer);
107 std::ostream(std::cout.rdbuf()) {
108 for(
unsigned int i=0; i<streamList.size();i++)
109 _buffers.push_back(streamList[i]->rdbuf());
110 assert(
_buffers.size() == streamList.size());
113 assert(rdbuf() == _buffer);
132 void SplitStream::assign(std::ostream& stream){
134 init(stream.rdbuf());
139 void SplitStream::assign(std::ostream& stream1, std::ostream &stream2){
141 init(stream1.rdbuf());
142 _buffers.push_back(stream1.rdbuf());
143 _buffers.push_back(stream2.rdbuf());
148 void SplitStream::assign(std::vector<std::ostream*>& streamList){
150 if (streamList.size() < 1) {
151 std::ostringstream msg;
152 msg << __FILE__ <<
":" << __LINE__ <<
"\n\t";
153 msg <<
"You have to assign at least one output stream!";
154 throw std::invalid_argument(msg.str().c_str());
156 init(streamList[0]->rdbuf());
157 for(
unsigned int i=0; i<streamList.size();i++)
158 _buffers.push_back(streamList[i]->rdbuf());
159 assert(
_buffers.size() == streamList.size());
SplitStreamBuf * _buffer
pointer to output stream buffer
This class wraps a list of output streams and pipes output made to a splitstream instance to all of t...
virtual ~SplitStream()
Default destructor.
SplitStream sout
Dummy instance for usage in other files (for interface too).
int sync()
Sync stream buffers.
void charon_core_LOCAL updateBuf(std::vector< std::streambuf * > buffers)
Set new buffers.
Buffer to split output on several streams.
charon_core_LOCAL SplitStreamBuf(const SplitStreamBuf &)
forbid copying
SplitStream()
Default constructor.
std::streamsize xsputn(char const *str, std::streamsize size)
Write sequence of characters.
int overflow(int c)
Write character in the case of overflow.
std::vector< std::streambuf * > _buffers
pointer to stream buffers
Declaration of class SplitStream.
std::vector< std::streambuf * > _buffers
buffer array