Handout
This commit is contained in:
45
debug/nullstream.h
Normal file
45
debug/nullstream.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*! \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;
|
||||
Reference in New Issue
Block a user