Mercurial > jwe > qt-gui-with-push-parser
diff interpreter.h @ 7:04867eba6428
function objects and signals/slots for errors and results
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 23 May 2019 09:27:09 -0400 |
parents | 1b575145197e |
children | 894be158b32d |
line wrap: on
line diff
--- a/interpreter.h Thu May 23 07:41:18 2019 -0400 +++ b/interpreter.h Thu May 23 09:27:09 2019 -0400 @@ -1,6 +1,8 @@ #if ! defined (calc_interpreter_h) #define calc_interpreter_h 1 +#include <functional> + namespace calc { class interpreter @@ -19,11 +21,30 @@ int parse_and_execute (const std::string& line); + std::function<void (const char *)> + set_error_handler (const std::function<void (const char *)>& error_handler) + { + std::function<void (const char *)> tmp = m_error_handler; + m_error_handler = error_handler; + return tmp; + } + + std::function<void (double)> + set_result_handler (const std::function<void (double)>& result_handler) + { + std::function<void (double)> tmp = m_result_handler; + m_result_handler = result_handler; + return tmp; + } + void emit_error (const char *msg); void emit_result (double value); private: + + std::function<void (const char *)> m_error_handler; + std::function<void (double)> m_result_handler; }; }