diff options
Diffstat (limited to 'paludis/util/tee_output_stream.cc')
-rw-r--r-- | paludis/util/tee_output_stream.cc | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/paludis/util/tee_output_stream.cc b/paludis/util/tee_output_stream.cc index b0b74e56f..00cb71f47 100644 --- a/paludis/util/tee_output_stream.cc +++ b/paludis/util/tee_output_stream.cc @@ -1,7 +1,7 @@ /* vim: set sw=4 sts=4 et foldmethod=syntax : */ /* - * Copyright (c) 2008 Ciaran McCreesh + * Copyright (c) 2008, 2009 Ciaran McCreesh * * This file is part of the Paludis package manager. Paludis is free software; * you can redistribute it and/or modify it under the terms of the GNU General @@ -18,6 +18,63 @@ */ #include <paludis/util/tee_output_stream.hh> +#include <paludis/util/private_implementation_pattern-impl.hh> +#include <list> using namespace paludis; +namespace paludis +{ + template <> + struct Implementation<TeeOutputStreamBuf> + { + std::list<std::ostream *> streams; + }; +} + +TeeOutputStreamBuf::TeeOutputStreamBuf() : + PrivateImplementationPattern<TeeOutputStreamBuf>(new Implementation<TeeOutputStreamBuf>) +{ +} + +TeeOutputStreamBuf::~TeeOutputStreamBuf() +{ +} + +TeeOutputStreamBuf::int_type +TeeOutputStreamBuf::overflow(int_type c) +{ + for (std::list<std::ostream *>::iterator i(_imp->streams.begin()), i_end(_imp->streams.end()) ; + i != i_end ; ++i) + (*i)->put(c); + return c; +} + +std::streamsize +TeeOutputStreamBuf::xsputn(const char * s, std::streamsize num) +{ + for (std::list<std::ostream *>::iterator i(_imp->streams.begin()), i_end(_imp->streams.end()) ; + i != i_end ; ++i) + (*i)->write(s, num); + return num; +} + +void +TeeOutputStreamBuf::add_stream(std::ostream * const s) +{ + _imp->streams.push_back(s); +} + +TeeOutputStream::TeeOutputStream() : + std::ostream(&buf) +{ +} + +void +TeeOutputStream::add_stream(std::ostream * const s) +{ + buf.add_stream(s); +} + +template class PrivateImplementationPattern<TeeOutputStreamBuf>; + |