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.
		
		
		
		
		
			
		
			
				
	
	
		
			46 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
| /*! \file
 | |
|  *  \brief \ref NullStream is a stream discarding everything
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| #include "../object/outputstream.h"
 | |
| #include "../types.h"
 | |
| 
 | |
| /*! \brief Ignore all data passed by the stream operator
 | |
|  *  \ingroup io
 | |
|  *
 | |
|  * Can be used instead of the \ref OutputStream if (for debugging reasons) all
 | |
|  * output should be ignored, e.g. for \ref DBG_VERBOSE
 | |
|  *
 | |
|  * By using template programming, a single generic methods is sufficient
 | |
|  * (which simply discard everything).
 | |
|  */
 | |
| class NullStream {
 | |
|   /*! \brief Check if type is supported by output stream
 | |
|    */
 | |
|   template <typename T>
 | |
|   auto check(T v, OutputStream* p = nullptr) -> decltype(*p << v, void()) {}
 | |
| 
 | |
|  public:
 | |
|   /*! \brief Empty default constructor
 | |
|    */
 | |
|   NullStream() {}
 | |
| 
 | |
|   /*! \brief Generic stream operator for any data type
 | |
|    *
 | |
|    * Uses template meta programming for a generic & short solution
 | |
|    *
 | |
|    * \tparam T Type of data to ignore
 | |
|    * \param value data to be ignore
 | |
|    * \return Reference to the \ref NullStream object allowing concatenation of
 | |
|    * operators
 | |
|    */
 | |
|   template <typename T>
 | |
|   NullStream& operator<<(T value) {
 | |
|     check(value);
 | |
|     return *this;
 | |
|   }
 | |
| };
 | |
| 
 | |
| extern NullStream nullstream;
 |