Mercurial > jwe > qt-gui-with-push-parser
annotate interpreter.h @ 12:894be158b32d
define parser as a class and eliminate some global variables
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 23 May 2019 17:57:20 -0400 |
parents | 04867eba6428 |
children | 1e5a1e15fa56 |
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 |
12
894be158b32d
define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
7
diff
changeset
|
6 #include "parser.h" |
894be158b32d
define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
7
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 namespace calc |
4
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 { |
6
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
10 class interpreter |
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 public: |
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 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
|
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 (void); |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
17 |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
18 interpreter (const interpreter&) = delete; |
4
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 |
6
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
20 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
|
21 |
12
894be158b32d
define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
7
diff
changeset
|
22 ~interpreter (void) = default; |
894be158b32d
define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
7
diff
changeset
|
23 |
894be158b32d
define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
7
diff
changeset
|
24 parser& get_parser (void) { return m_parser; } |
6
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
25 |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
26 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
|
27 |
7
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
28 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
|
29 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
|
30 { |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
31 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
|
32 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
|
33 return tmp; |
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 |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
36 std::function<void (double)> |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
37 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
|
38 { |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
39 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
|
40 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
|
41 return tmp; |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
42 } |
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
43 |
12
894be158b32d
define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
7
diff
changeset
|
44 void emit_error (const char *msg) const; |
4
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 |
12
894be158b32d
define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
7
diff
changeset
|
46 void emit_result (double value) const; |
6
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
47 |
1b575145197e
interpreter is now a class instead of a namespace with functions
John W. Eaton <jwe@octave.org>
parents:
4
diff
changeset
|
48 private: |
7
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
49 |
12
894be158b32d
define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
7
diff
changeset
|
50 parser m_parser; |
894be158b32d
define parser as a class and eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
7
diff
changeset
|
51 |
7
04867eba6428
function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents:
6
diff
changeset
|
52 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
|
53 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
|
54 }; |
4
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 } |
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 |
0e154787183d
new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 #endif |