diff options
author | Jan Huwald <jh@sotun.de> | 2014-02-16 19:56:04 (GMT) |
---|---|---|
committer | Jan Huwald <jh@sotun.de> | 2014-02-16 19:56:04 (GMT) |
commit | 7de7b1618c85d21d3f737d0981f8ae3784ac1036 (patch) | |
tree | 6a1cdfe882f7ff764a78c27ac4a18a9cf4865c0d /src/printutils.cc | |
parent | 8f87168174e6c883260d613494082ffe791c767e (diff) |
allow writing to standard output from command line, update output handler to lambda
- cmdline can output to a file or cout
- output handler uses lambda instead of function pointer
- this allows removing Echostream with a one-liner
Diffstat (limited to 'src/printutils.cc')
-rw-r--r-- | src/printutils.cc | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/printutils.cc b/src/printutils.cc index 37092fa..a8192ca 100644 --- a/src/printutils.cc +++ b/src/printutils.cc @@ -3,13 +3,13 @@ #include <stdio.h> std::list<std::string> print_messages_stack; -OutputHandlerFunc *outputhandler = NULL; -void *outputhandler_data = NULL; +std::function<void(std::string)> default_outputhandler = [](std::string msg) { + fprintf(stderr, "%s\n", msg.c_str()); +}; +std::function<void(std::string)> outputhandler = default_outputhandler; -void set_output_handler(OutputHandlerFunc *newhandler, void *userdata) -{ +void set_output_handler(std::function<void(std::string)> newhandler) { outputhandler = newhandler; - outputhandler_data = userdata; } void print_messages_push() @@ -44,11 +44,7 @@ void PRINT(const std::string &msg) void PRINT_NOCACHE(const std::string &msg) { if (msg.empty()) return; - if (!outputhandler) { - fprintf(stderr, "%s\n", msg.c_str()); - } else { - outputhandler(msg, outputhandler_data); - } + outputhandler(msg); } std::string two_digit_exp_format( std::string doublestr ) |