IGSTK
igstkMultipleOutput.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Image Guided Surgery Software Toolkit
4  Module: $RCSfile: igstkMultipleOutput.h,v $
5  Language: C++
6  Date: $Date: 2008-02-11 01:41:51 $
7  Version: $Revision: 1.10 $
8 
9  Copyright (c) ISC Insight Software Consortium. All rights reserved.
10  See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 
18 #ifndef __igstkMultipleOutput_h
19 #define __igstkMultipleOutput_h
20 
21 
22 #include <iostream>
23 #include <fstream>
24 #include <set>
25 
26 namespace igstk
27 {
28 
34 class MultipleOutput : virtual public std::streambuf
35 {
36 
37 public:
38 
39  typedef std::ostream StreamType;
40 
41 
42 public:
43 
46 
49 
50 
54  void AddOutputStream( StreamType & output );
55 
56 
58  void Flush();
59 
62  template <class T>
64  {
65  ContainerType::iterator itr = m_Output.begin();
66  ContainerType::iterator end = m_Output.end();
67  while( itr != end )
68  {
69  *(*itr) << tt;
70  ++itr;
71  }
72  return *this;
73  }
74 
75 
76 private:
77 
78  typedef std::set< StreamType * > ContainerType;
79 
80  ContainerType m_Output;
81 
82 };
83 
84 }
85 
86 #endif //__igstk_MultipleOutput_h_
MultipleOutput()
Constructor.
void AddOutputStream(StreamType &output)
Register a additional output stream into the list of ostreams to write to.
void Flush()
Broadcast a flush operation to all the output streams.
Class MultipleOutput allows writing simultaneously to multiple streams.
MultipleOutput & operator<<(T tt)
Operator that will receive different input types and will forward them to the multiple outputs...
~MultipleOutput()
Destructor.