Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tee.h
Go to the documentation of this file.
1 /*! \file xstream/tee.h
2  *
3  * \brief C++ streambuf to fork output
4  * data written to it is also written to several other streambufs
5  *
6  */
7 
8 #ifndef __XSTREAM_TEE_H
9 #define __XSTREAM_TEE_H
10 
11 #include <xstream/config.h>
12 
13 #include <xstream/common.h>
14 #include <streambuf>
15 #include <set>
16 
17 namespace xstream{
18 
19 /*!
20  * \brief tee related ostreambuf objects
21  *
22  */
23 namespace tee{
24 
25 /*!
26  * \brief fork output stream class
27  *
28  * when data is written to it, it writes it to several other streambufs
29  * error handling is as follows:
30  * \arg if writting to a streambuf returns an error, that streambuf is removed from the internal list and no more data is written to it
31  * \arg when there is no streambuf left to write to \c eof is returned
32  *
33  * \note doesn't catch any exceptions, so let's the io library decide if they should be propagated
34  *
35  */
37 {
38  private:
39 
40  std::set<std::streambuf*> destinations; /*!< set of streambufs to write to */
41 
42  /*!
43  * \brief flush as much data as possible (overloaded from streambuf)
44  *
45  * */
46  int sync();
47 
48  /*!
49  * \brief write a character that supasses buffer end (overloaded from streambuf)
50  *
51  */
52  int overflow(int c);
53 
54  /*!
55  * \brief write an entire buffer (overloaded from streambuf)
56  *
57  */
58  std::streamsize xsputn(const char *buffer, std::streamsize n);
59 
60  public:
61  /*!
62  * \brief construct \c NOP object
63  */
65  {};
66 
67  /*!
68  * \brief add an output streembuf to write to
69  */
70  void add(std::streambuf* sb);
71 
72  /*!
73  * \brief remove a streambuf to write to
74  *
75  */
76  void remove(std::streambuf* sb);
77 
78  /*!
79  * \brief add an output ostream to write to
80  *
81  * higher level syntatic sugar for the streambuf version
82  */
83  void add(std::ostream& os);
84 
85  /*!
86  * \brief remove an output ostream to write to
87  *
88  * higher level syntatic sugar for the streambuf version
89  */
90  void remove(std::ostream& os);
91 
92  /*!
93  * \brief closes the streambuf stream
94  *
95  */
96  ~ostreambuf();
97 
98 };
99 
100  /*!
101  * \example n_tee.cpp
102  *
103  * shows how to write the content of standard input to several files using the xstream::tee::ostreambuf class
104  *
105  */
106 
107 
108 }//namespace fork
109 }//namespace xstream
110 
111 #endif
std::set< std::streambuf * > destinations
Definition: tee.h:40
fork output stream class
Definition: tee.h:36
#define c
int sync()
flush as much data as possible (overloaded from streambuf)
Definition: tee.cpp:35
~ostreambuf()
closes the streambuf stream
Definition: tee.cpp:130
void add(std::streambuf *sb)
add an output streembuf to write to
Definition: tee.cpp:15
std::streamsize xsputn(const char *buffer, std::streamsize n)
write an entire buffer (overloaded from streambuf)
Definition: tee.cpp:98
ostreambuf()
construct NOP object
Definition: tee.h:64
buffer management
Definition: common.h:46
common objects
int overflow(int c)
write a character that supasses buffer end (overloaded from streambuf)
Definition: tee.cpp:66