1
/* This file is part of Charon.
3
Charon is free software: you can redistribute it and/or modify
4
it under the terms of the GNU Lesser General Public License as published by
5
the Free Software Foundation, either version 3 of the License, or
6
(at your option) any later version.
8
Charon is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU Lesser General Public License for more details.
13
You should have received a copy of the GNU Lesser General Public License
14
along with Charon. If not, see <http://www.gnu.org/licenses/>.
16
/** @file SplitStream.h
17
* Declaration of class SplitStream.
18
* @author <a href="mailto:jmgottfried@web.de">Jens-Malte Gottfried</a>
20
* @remark Used Interface from SplitStream Class of Daniel Kondermann
23
#ifndef _SPLIT_STREAM_H_
24
#define _SPLIT_STREAM_H_
31
#define DLLEX __declspec(dllexport)
32
#else // CREATE_SHARED
33
#define DLLEX __declspec(dllimport)
34
#endif // CREATE_SHARED
42
/** Buffer to split output on several streams.
44
class DLLEX SplitStreamBuf : public std::streambuf {
46
/// pointer to stream buffers
47
std::vector<std::streambuf*> buffers_;
49
SplitStreamBuf(SplitStreamBuf const &);
51
void operator= (SplitStreamBuf const &);
54
/// Constructor initializing the buffers array
55
SplitStreamBuf(const std::vector<std::streambuf*>& buffers);
56
virtual ~SplitStreamBuf();
58
/** Write character in the case of overflow.
59
* @param c char value to check
60
* @return EOF if overflow occured
64
/** Write sequence of characters.
65
* @param str char array to put
66
* @param size number of characters
67
* @return number of written characters
69
std::streamsize xsputn(char const * str, std::streamsize size);
71
/** Sync stream buffers.
72
* @return EOF on failure
77
/** This class wraps a list of output streams and
78
* pipes output made to a splitstream instance to
79
* all of these output streams.
81
class DLLEX SplitStream : public std::ostream {
83
/// Default constructor
84
/** Use no output stream.<br>
85
* Make sure you call assign() before using this SplitStream.
89
/** Assign one stream to output list.
90
* @param stream stream to pipe output to
92
SplitStream(std::ostream& stream);
94
/** Assign two streams to output list.
95
* @param stream1 fist output stream to assign
96
* @param stream2 second stream to assign
98
SplitStream(std::ostream& stream1, std::ostream& stream2);
100
/** Assing a whole list of streams.
101
* @param streamList list of streams to assign
103
SplitStream(std::vector<std::ostream*>& streamList);
105
/// Default destructor
106
virtual ~SplitStream();
108
///@name Stream assignment (see constructors for details)
110
void assign(std::ostream& stream = std::cout);
111
void assign(std::ostream& stream1, std::ostream &stream2);
112
void assign(std::vector<std::ostream*>& streamsList);
115
/** Dummy function to fulfill interface
116
* \deprecated This function is not used in current plugins,
117
* check if it's still needed.
118
* \return always true
123
std::vector<std::streambuf*> buffers_; ///< buffer array
124
SplitStreamBuf* buffer_; ///< pointer to output stream buffer
127
* @param buffers new buffers to set
129
void updateBuf(std::vector<std::streambuf*> buffers);
132
/// Dummy instance for usage in other files (for interface too).
133
extern DLLEX SplitStream sout;
135
#endif /* _SPLIT_STREAM_H_ */