charon-core  0.3.1
SplitStream.h
Go to the documentation of this file.
1 /* This file is part of Charon.
2 
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.
7 
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.
12 
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/>.
15 */
23 #ifndef _SPLIT_STREAM_H_
24 #define _SPLIT_STREAM_H_
25 
26 #include <iostream>
27 #include <vector>
28 #include "DllEx.h"
29 
32 class charon_core_DLL_PUBLIC SplitStreamBuf : public std::streambuf {
33 private:
35  std::vector<std::streambuf*> _buffers;
39  void charon_core_LOCAL operator= (const SplitStreamBuf&);
40 
41 public:
43  SplitStreamBuf(const std::vector<std::streambuf*>& buffers);
44  virtual ~SplitStreamBuf();
45 
50  int overflow(int c);
51 
57  std::streamsize xsputn(char const* str, std::streamsize size);
58 
62  int sync();
63 };
64 
69 class charon_core_DLL_PUBLIC SplitStream : public std::ostream {
70 public:
72 
75  SplitStream();
76 
80  SplitStream(std::ostream& stream);
81 
86  SplitStream(std::ostream& stream1, std::ostream& stream2);
87 
91  SplitStream(std::vector<std::ostream*>& streamList);
92 
94  virtual ~SplitStream();
95 
97  // \{
98  void assign(std::ostream& stream = std::cout);
99  void assign(std::ostream& stream1, std::ostream &stream2);
100  void assign(std::vector<std::ostream*>& streamsList);
101  // \}
102 
103 private:
104  std::vector<std::streambuf*> _buffers;
106 
110  void charon_core_LOCAL updateBuf(std::vector<std::streambuf*> buffers);
111 };
112 
115 
116 #endif /* _SPLIT_STREAM_H_ */
117 
SplitStreamBuf * _buffer
pointer to output stream buffer
Definition: SplitStream.h:105
This class wraps a list of output streams and pipes output made to a splitstream instance to all of t...
Definition: SplitStream.h:69
charon_core_DLL_PUBLIC SplitStream sout
Dummy instance for usage in other files (for interface too).
#define charon_core_LOCAL
Preprocessor macro to define this class/function as hidden, i.e.
Definition: DllEx.h:85
Buffer to split output on several streams.
Definition: SplitStream.h:32
#define charon_core_DLL_PUBLIC
Preprocessor macro to define this class/function as public visible, i.e.
Definition: DllEx.h:82
Dynamic library API import/export prprocessor macros.
std::vector< std::streambuf * > _buffers
pointer to stream buffers
Definition: SplitStream.h:35
std::vector< std::streambuf * > _buffers
buffer array
Definition: SplitStream.h:104