Boost logo

Boost Users :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-09-06 23:34:39


"Jon Biggar" <jon_at_[hidden]> wrote in message
news:chijmd$q3g$1_at_sea.gmane.org...
> 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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net