comparison 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
comparison
equal deleted inserted replaced
6:1b575145197e 7:04867eba6428
1 #if ! defined (calc_interpreter_h) 1 #if ! defined (calc_interpreter_h)
2 #define calc_interpreter_h 1 2 #define calc_interpreter_h 1
3
4 #include <functional>
3 5
4 namespace calc 6 namespace calc
5 { 7 {
6 class interpreter 8 class interpreter
7 { 9 {
17 19
18 ~interpreter (void); 20 ~interpreter (void);
19 21
20 int parse_and_execute (const std::string& line); 22 int parse_and_execute (const std::string& line);
21 23
24 std::function<void (const char *)>
25 set_error_handler (const std::function<void (const char *)>& error_handler)
26 {
27 std::function<void (const char *)> tmp = m_error_handler;
28 m_error_handler = error_handler;
29 return tmp;
30 }
31
32 std::function<void (double)>
33 set_result_handler (const std::function<void (double)>& result_handler)
34 {
35 std::function<void (double)> tmp = m_result_handler;
36 m_result_handler = result_handler;
37 return tmp;
38 }
39
22 void emit_error (const char *msg); 40 void emit_error (const char *msg);
23 41
24 void emit_result (double value); 42 void emit_result (double value);
25 43
26 private: 44 private:
45
46 std::function<void (const char *)> m_error_handler;
47 std::function<void (double)> m_result_handler;
27 }; 48 };
28 } 49 }
29 50
30 #endif 51 #endif