aboutsummaryrefslogtreecommitdiff
path: root/paludis/util/tee_output_stream.cc
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-12 01:26:20 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-12 01:26:20 +0000
commit5522cc551aaee176591b08546f368bb417c32f9e (patch)
tree975aa3b7325c820b51e35d1af4ee9dfc1bf7e2e4 /paludis/util/tee_output_stream.cc
parentb85660f6da793d06a304bf6d511c6b00344f20e2 (diff)
downloadpaludis-5522cc551aaee176591b08546f368bb417c32f9e.tar.gz
paludis-5522cc551aaee176591b08546f368bb417c32f9e.tar.xz
Add tee output manager
Diffstat (limited to 'paludis/util/tee_output_stream.cc')
-rw-r--r--paludis/util/tee_output_stream.cc59
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>;
+