You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
| /*! \file
 | |
|  *  \brief \ref CopyStream duplicates \ref OutputStream "output streams"
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| #include "../object/outputstream.h"
 | |
| #include "../types.h"
 | |
| 
 | |
| /*! \brief Duplicate all data passed by the stream operator to two \ref
 | |
|  * OutputStream "output streams"
 | |
|  *  \ingroup io
 | |
|  *
 | |
|  * Can be used as replacement for any \ref OutputStream -- for example,
 | |
|  * forwarding the \ref DBG output simultaneously to screen (\ref TextStream) and
 | |
|  * serial console (\ref SerialStream).
 | |
|  *
 | |
|  */
 | |
| class CopyStream : public OutputStream {
 | |
|   /*! \brief First recipient
 | |
|    */
 | |
|   OutputStream* first;
 | |
| 
 | |
|   /*! \brief Second recipient
 | |
|    */
 | |
|   OutputStream* second;
 | |
| 
 | |
|  public:
 | |
|   /*! \brief Constructor
 | |
|    *
 | |
|    * \param first First recipient for output passed to this object
 | |
|    * \param second Second recipient for output passed to this object
 | |
|    */
 | |
|   CopyStream(OutputStream* first, OutputStream* second)
 | |
|       : first(first), second(second) {}
 | |
| 
 | |
|   /*! \brief Redirect the buffer to both streams and flush them, too.
 | |
|    */
 | |
|   void flush() override {
 | |
|     buffer[pos] = '\0';  // make sure buffer will only be printed until pos.
 | |
|     *first << buffer << ::flush;
 | |
|     *second << buffer << ::flush;
 | |
|     pos = 0;
 | |
|   }
 | |
| };
 |