output stream cloning?
Is there any package in Boost (or upcoming in the Boost review queue) that would let me create an output stream that clones its output to one or more underlying output streams? -- Jon Biggar Levanta Inc jon@levanta.com
"Jon Biggar"
Is there any package in Boost (or upcoming in the Boost review queue) that would let me create an output stream that clones its output to one or more underlying output streams?
Depends on what you mean by 'cloning'. If you want to write output to a single stream and have it redirected to one or more other streams, then yes, my iostreams library, currently being reviewed, makes this easy. (See the discussion on the developers list.) Here's an example: struct splitter : boost::io::source { std::ostream& first; std::ostream& second splitter(std::ostream& first, std::ostream& second) : first(first), second(second) { } void write(const char* s, std::streamsize n) { first.write(s, n); second.write(s, n); } }; int main() { std::ostream one; std::ostream two; .... filtering_ostream out(splitter(one, two)); out << "this goes to both streams\n"; } In the above example, filtering_ostream is an existing component from the library, while splitter is a user-defined Sink. There have been many requests for such a component, so I'll probably add it or something similar if the library is accepted. BTW, I encourage you to participate in the review, even if you only have time to look through the documentation. The library is here: http://home.comcast.net/~jturkanis/iostreams/ Best Regards, Jonathan
participants (2)
-
Jon Biggar
-
Jonathan Turkanis