Mercurial > jwe > qt-gui-with-push-parser
annotate 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 |
rev | line source |
---|---|
4
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 #if ! defined (calc_interpreter_h) |
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 #define calc_interpreter_h 1 |
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
3 |
7
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
4 #include <functional> |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
5 |
6
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
6 namespace calc |
4
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 { |
6
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
8 class interpreter |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
9 { |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
10 public: |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
11 |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
12 static interpreter *the_interpreter; |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
13 |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
14 interpreter (void); |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
15 |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
16 interpreter (const interpreter&) = delete; |
4
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 |
6
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
18 interpreter& operator = (const interpreter&) = delete; |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
19 |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
20 ~interpreter (void); |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
21 |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
22 int parse_and_execute (const std::string& line); |
4
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 |
7
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
24 std::function<void (const char *)> |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
25 set_error_handler (const std::function<void (const char *)>& error_handler) |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
26 { |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
27 std::function<void (const char *)> tmp = m_error_handler; |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
28 m_error_handler = error_handler; |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
29 return tmp; |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
30 } |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
31 |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
32 std::function<void (double)> |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
33 set_result_handler (const std::function<void (double)>& result_handler) |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
34 { |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
35 std::function<void (double)> tmp = m_result_handler; |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
36 m_result_handler = result_handler; |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
37 return tmp; |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
38 } |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
39 |
6
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
40 void emit_error (const char *msg); |
4
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 |
6
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
42 void emit_result (double value); |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
43 |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
44 private: |
7
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
45 |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
46 std::function<void (const char *)> m_error_handler; |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
47 std::function<void (double)> m_result_handler; |
6
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
48 }; |
4
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 } |
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 |
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 #endif |