libwreport 3.40
notes.h
1#ifndef WREPORT_NOTES_H
2#define WREPORT_NOTES_H
3
4#include <iosfwd>
5
6#ifndef WREPORT_PRINTF_ATTRS
7#define WREPORT_PRINTF_ATTRS(a, b) __attribute__((format(printf, a, b)))
8#endif
9
10namespace wreport {
11
18namespace notes {
19
21void set_target(std::ostream& out);
22
24std::ostream* get_target();
25
27bool logs() throw();
28
30std::ostream& log() throw();
31
33void logf(const char* fmt, ...) WREPORT_PRINTF_ATTRS(1, 2);
34
41struct Collect
42{
46 std::ostream* old;
47
49 Collect(std::ostream& out)
50 {
51 old = get_target();
52 set_target(out);
53 }
54 ~Collect() { set_target(*old); }
55};
56
57} // namespace notes
58} // namespace wreport
59
60#endif
std::ostream & log()
Output stream to send notes to.
std::ostream * get_target()
Get the current target stream for notes.
void set_target(std::ostream &out)
Set the target stream where the notes are sent.
void logf(const char *fmt,...) WREPORT_PRINTF_ATTRS(1
printf-style logging
bool logs()
Return true if there is any target to which notes are sent.
String functions.
Definition benchmark.h:13
RAII way to temporarily set a notes target.
Definition notes.h:42
std::ostream * old
Old target stream to be restored whemn the object goes out of scope.
Definition notes.h:46
Collect(std::ostream &out)
Direct notes to out for the lifetime of the object.
Definition notes.h:49