Last active
March 3, 2016 15:43
-
-
Save ArthurSonzogni/60ac2ecf42f16195f82e to your computer and use it in GitHub Desktop.
qdebug() like object that avoid interleaving issues in a multiprocess / multithread environment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* --------------------------------------------------------------------------- | |
* ** This software is in the public domain, furnished "as is", without technical | |
* ** support, and with no warranty, express or implied, as to its usefulness for | |
* ** any purpose. | |
* ** | |
* ** The file provide a way to avoid interleaved printing in a multithreaded | |
* ** environment. It works like qDebug() for the Qt framework | |
* ** | |
* ** Usage : | |
* ** Print() << " The debug value = " << 42; | |
* ** Print() << " The debug value = " << 56; | |
* ** | |
* ** Author: Arthur Sonzogni | |
* ** -------------------------------------------------------------------------*/ | |
#ifndef PRINT_HEADER_GUARD_823 | |
#define PRINT_HEADER_GUARD_823 | |
#include <iostream> | |
#include <sstream> | |
class Print | |
{ | |
public: | |
template<typename T> Print& operator<<(const T& x) | |
{ | |
ss << x; | |
return *this; | |
} | |
~Print() | |
{ | |
std::cerr << ss.rdbuf() << std::endl; | |
} | |
private: | |
std::stringstream ss; | |
}; | |
#endif /* end of include guard: PRINT_HEADER_GUARD_823 */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment