Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

teestream.h

Go to the documentation of this file.
00001 #ifndef DV_UTIL_TEESTREAM_H 00002 #define DV_UTIL_TEESTREAM_H 00003 // $Id: teestream.h,v 1.3 2002/10/18 09:50:14 dvermeir Exp $ 00004 00005 #include <iostream> 00006 #include "filterstreambuf.h" 00007 00008 /** \file 00009 * This files defines a class teestream, named after 00010 * the ``tee'' command, which illustrates the use 00011 * of Dv::Util::filterstreambuf. 00012 */ 00013 #include <list> 00014 00015 namespace Dv { 00016 namespace Util { 00017 00018 /** 00019 * A teestream object extends the unix ``tee'' command. 00020 * It is derived from ostream and initialized with 00021 * a list of ostream pointers. Anything written to 00022 * a teestream is written to all the underlying ostreams. 00023 */ 00024 class teestream: public std::ostream { 00025 private: 00026 /** 00027 * Implements Filter interface for filterstreambuf 00028 */ 00029 class Tee { 00030 public: 00031 Tee(std::ostream& os1, std::ostream& os2); 00032 Tee(const std::list<std::ostream*>& streams); 00033 ~Tee(); 00034 int put(int c); 00035 int get() { return EOF; } 00036 int sync(); 00037 void close() {} 00038 std::ios::iostate state() const; 00039 private: 00040 std::list<std::ostream*> streams_; 00041 }; 00042 public: 00043 /** 00044 * Special constructor for common case of 2 ostreams. 00045 * \param os1 first ostream to which output to teestream will be copied 00046 * \param os2 second ostream to which output to teestream will be copied 00047 */ 00048 teestream(std::ostream& os1, std::ostream& os2); 00049 /** 00050 * General constructor takes a list of ostream pointers. 00051 * \param streams list of ostreams to which output to teestream will be 00052 * copied 00053 */ 00054 teestream(const std::list<std::ostream*>& streams); 00055 private: 00056 Tee tee_; 00057 }; 00058 00059 }} 00060 #endif

dvutil-0.13.15 [30 December, 2004]