1 #ifndef __PRINTSTREAM_HPP_ 2 #define __PRINTSTREAM_HPP_ 13 #include "utils/PVAssert.hpp" 14 #include "utils/PVLog.hpp" 20 PrintStream(std::ostream &stream) { setOutStream(stream); }
23 int printf(
const char *fmt, ...) {
26 va_copy(args2, args1);
28 int chars_needed = vsnprintf(&c, 1, fmt, args1);
30 char output_string[chars_needed];
31 int chars_printed = vsnprintf(output_string, chars_needed, fmt, args2);
32 pvAssert(chars_printed + 1 == chars_needed);
33 (*mOutStream) << std::string(output_string);
39 void flush() { mOutStream->flush(); }
47 PrintStream &operator<<(std::ostream &(*f)(std::ostream &)) {
51 PrintStream &operator<<(std::ostream &(*f)(std::ios &)) {
55 PrintStream &operator<<(std::ostream &(*f)(std::ios_base &)) {
62 void setOutStream(std::ostream &stream) { mOutStream = &stream; }
65 std::ostream *mOutStream =
nullptr;