Mercurial > octave
annotate libinterp/corefcn/hook-fcn.h @ 32632:2e484f9f1f18 stable
maint: update Octave Project Developers copyright for the new year
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 22 Dec 2023 12:08:17 -0500 |
parents | 1daf8bfceac3 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31855
diff
changeset
|
3 // Copyright (C) 2013-2024 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
26 #if ! defined (octave_hook_fcn_h) |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 #define octave_hook_fcn_h 1 |
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
29 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
30 |
29561
ed90a4d75f6d
use shared_ptr to manage data for hook_function class
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
31 #include <memory> |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #include <string> |
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
34 #include "ovl.h" |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 #include "ov.h" |
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 #include "ov-fcn-handle.h" |
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 #include "variables.h" |
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
39 OCTAVE_BEGIN_NAMESPACE(octave) |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
40 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
41 class base_hook_function |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
42 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
43 public: |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 |
31855
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
45 OCTAVE_DEFAULT_CONSTRUCT_COPY (base_hook_function) |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31707
diff
changeset
|
47 virtual ~base_hook_function () = default; |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31707
diff
changeset
|
49 virtual std::string id () const { return ""; } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31707
diff
changeset
|
51 virtual bool is_valid () const { return false; } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
53 virtual void eval (const octave_value_list&) { } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
54 }; |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
56 class hook_function |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
57 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
58 public: |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31707
diff
changeset
|
60 hook_function () |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
61 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
62 static std::shared_ptr<base_hook_function> |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
63 nil_rep (new base_hook_function ()); |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
65 m_rep = nil_rep; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
66 } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
68 hook_function (const octave_value& f, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
69 const octave_value& d = octave_value ()); |
29563
8a296f1351a4
move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29562
diff
changeset
|
70 |
31855
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
71 OCTAVE_DEFAULT_COPY (hook_function) |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 |
31855
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
73 ~hook_function () = default; |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31707
diff
changeset
|
75 std::string id () const { return m_rep->id (); } |
29563
8a296f1351a4
move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29562
diff
changeset
|
76 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31707
diff
changeset
|
77 bool is_valid () const { return m_rep->is_valid (); } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
79 void eval (const octave_value_list& initial_args) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
80 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
81 m_rep->eval (initial_args); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
82 } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
84 private: |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
85 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
86 std::shared_ptr<base_hook_function> m_rep; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
87 }; |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
89 class named_hook_function : public base_hook_function |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
90 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
91 public: |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
92 |
31855
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
93 named_hook_function () = delete; |
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
94 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
95 named_hook_function (const std::string& n, const octave_value& d) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
96 : m_name (n), m_data (d) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
97 { } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
98 |
31855
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
99 OCTAVE_DEFAULT_COPY_DELETE (named_hook_function) |
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
100 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
101 void eval (const octave_value_list& initial_args); |
29563
8a296f1351a4
move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29562
diff
changeset
|
102 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31707
diff
changeset
|
103 std::string id () const { return m_name; } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
104 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31707
diff
changeset
|
105 bool is_valid () const { return is_valid_function (m_name); } |
29563
8a296f1351a4
move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29562
diff
changeset
|
106 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
107 private: |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
108 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
109 std::string m_name; |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
110 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
111 octave_value m_data; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
112 }; |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
113 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
114 class fcn_handle_hook_function : public base_hook_function |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
115 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
116 public: |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
117 |
31855
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
118 fcn_handle_hook_function () = delete; |
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
119 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
120 fcn_handle_hook_function (const octave_value& fh_arg, const octave_value& d) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
121 : m_ident (), m_valid (false), m_fcn_handle (fh_arg), m_data (d) |
29563
8a296f1351a4
move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29562
diff
changeset
|
122 { |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
123 octave_fcn_handle *fh = m_fcn_handle.fcn_handle_value (true); |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
124 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
125 if (fh) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
126 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
127 m_valid = true; |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
128 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
129 std::ostringstream buf; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
130 buf << fh; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
131 m_ident = fh->fcn_name () + ':' + buf.str (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
132 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
133 } |
29563
8a296f1351a4
move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29562
diff
changeset
|
134 |
31855
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
135 OCTAVE_DEFAULT_COPY_DELETE (fcn_handle_hook_function) |
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
136 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
137 void eval (const octave_value_list& initial_args); |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
138 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31707
diff
changeset
|
139 std::string id () const { return m_ident; } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
140 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31707
diff
changeset
|
141 bool is_valid () const { return m_valid; } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
142 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
143 private: |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
144 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
145 std::string m_ident; |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
146 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
147 bool m_valid; |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
148 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
149 octave_value m_fcn_handle; |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
150 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
151 octave_value m_data; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
152 }; |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
153 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
154 class hook_function_list |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
155 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
156 public: |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
157 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
158 typedef std::map<std::string, hook_function> map_type; |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
159 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
160 typedef map_type::iterator iterator; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
161 typedef map_type::const_iterator const_iterator; |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
162 |
31855
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
163 OCTAVE_DEFAULT_CONSTRUCT_COPY_DELETE (hook_function_list) |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
164 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31707
diff
changeset
|
165 bool empty () const { return m_fcn_map.empty (); } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
166 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31707
diff
changeset
|
167 void clear () { m_fcn_map.clear (); } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
168 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
169 void insert (const std::string& id, const hook_function& f) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
170 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
171 m_fcn_map[id] = f; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
172 } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
173 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
174 iterator find (const std::string& id) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
175 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
176 return m_fcn_map.find (id); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
177 } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
178 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
179 const_iterator find (const std::string& id) const |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
180 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
181 return m_fcn_map.find (id); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
182 } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
183 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31707
diff
changeset
|
184 iterator end () { return m_fcn_map.end (); } |
29563
8a296f1351a4
move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29562
diff
changeset
|
185 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31707
diff
changeset
|
186 const_iterator end () const { return m_fcn_map.end (); } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
187 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
188 void erase (iterator p) { m_fcn_map.erase (p); } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
189 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
190 void run (const octave_value_list& initial_args = octave_value_list ()) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
191 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
192 auto p = m_fcn_map.begin (); |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
193 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
194 while (p != m_fcn_map.end ()) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
195 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
196 std::string hook_fcn_id = p->first; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
197 hook_function hook_fcn = p->second; |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
198 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
199 auto q = p++; |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
200 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
201 if (hook_fcn.is_valid ()) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
202 hook_fcn.eval (initial_args); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
203 else |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
204 m_fcn_map.erase (q); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
205 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
206 } |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
207 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
208 private: |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
209 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
210 map_type m_fcn_map; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
211 }; |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
212 |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
213 OCTAVE_END_NAMESPACE(octave) |
16384
a8d9ee3766db
* hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
214 |
29954
4c88a452519c
rename OCTAVE_USE_DEPRECATED_FUNCTIONS macro and attempt to make it work
John W. Eaton <jwe@octave.org>
parents:
29657
diff
changeset
|
215 #endif |