annotate libinterp/corefcn/hook-fcn.h @ 31606:dfa5d9c3ae72

maint: merge stable to default
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 14:28:07 -0800
parents 2aa5bcaba504 e88a07dec498
children 23664317f0d3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
3 // Copyright (C) 2013-2022 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
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
41 class base_hook_function
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 {
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
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
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
45 base_hook_function (void) = default;
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
47 base_hook_function (const 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
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
49 virtual ~base_hook_function (void) = default;
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
51 virtual std::string id (void) const { return ""; }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
53 virtual bool is_valid (void) const { return false; }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
55 virtual void eval (const octave_value_list&) { }
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
56 };
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
58 class hook_function
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 {
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
60 public:
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
62 hook_function (void)
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
63 {
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
64 static std::shared_ptr<base_hook_function>
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
65 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
66
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
67 m_rep = nil_rep;
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
68 }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
70 hook_function (const octave_value& f,
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
71 const octave_value& d = octave_value ());
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
72
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
73 ~hook_function (void) = default;
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
75 hook_function (const hook_function& hf) = default;
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
77 hook_function& operator = (const hook_function& hf) = default;
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
79 std::string id (void) const { return m_rep->id (); }
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
80
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
81 bool is_valid (void) 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
82
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
83 void eval (const octave_value_list& initial_args)
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
84 {
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
85 m_rep->eval (initial_args);
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
86 }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
88 private:
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
90 std::shared_ptr<base_hook_function> m_rep;
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
91 };
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
93 class named_hook_function : public base_hook_function
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 {
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
95 public:
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
97 named_hook_function (const std::string& n, const octave_value& d)
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
98 : m_name (n), m_data (d)
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
99 { }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
101 void eval (const octave_value_list& initial_args);
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
102
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
103 std::string id (void) 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
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
105 bool is_valid (void) const { return is_valid_function (m_name); }
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
106
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
107 private:
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
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
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
111 octave_value m_data;
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
112 };
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
114 class fcn_handle_hook_function : public base_hook_function
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
115 {
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
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
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
118 fcn_handle_hook_function (const octave_value& fh_arg, const octave_value& d)
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
119 : m_ident (), m_valid (false), m_fcn_handle (fh_arg), m_data (d)
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
120 {
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
121 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
122
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
123 if (fh)
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
124 {
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
125 m_valid = true;
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
127 std::ostringstream buf;
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
128 buf << fh;
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
129 m_ident = fh->fcn_name () + ':' + buf.str ();
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
130 }
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
131 }
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
132
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
133 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
134
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
135 std::string id (void) const { return m_ident; }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
137 bool is_valid (void) const { return m_valid; }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
139 private:
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
141 std::string m_ident;
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
143 bool m_valid;
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
145 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
146
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
147 octave_value m_data;
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
148 };
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
150 class hook_function_list
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151 {
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
152 public:
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
154 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
155
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
156 typedef map_type::iterator iterator;
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
157 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
158
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
159 hook_function_list (void) = default;
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
161 ~hook_function_list (void) = default;
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
162
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
163 hook_function_list (const hook_function_list& lst) = default;
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
164
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
165 hook_function_list& operator = (const hook_function_list& lst) = default;
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
167 bool empty (void) 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
168
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
169 void clear (void) { m_fcn_map.clear (); }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
170
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
171 void insert (const std::string& id, const hook_function& f)
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
172 {
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
173 m_fcn_map[id] = f;
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
174 }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
176 iterator find (const std::string& id)
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
177 {
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
178 return m_fcn_map.find (id);
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
179 }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
181 const_iterator find (const std::string& id) const
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
182 {
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
183 return m_fcn_map.find (id);
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
184 }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
186 iterator end (void) { return m_fcn_map.end (); }
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
187
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
188 const_iterator end (void) 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
189
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
190 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
191
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
192 void run (const octave_value_list& initial_args = octave_value_list ())
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
193 {
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
194 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
195
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
196 while (p != m_fcn_map.end ())
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
197 {
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
198 std::string hook_fcn_id = p->first;
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
199 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
200
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
201 auto q = p++;
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
203 if (hook_fcn.is_valid ())
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
204 hook_fcn.eval (initial_args);
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
205 else
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
206 m_fcn_map.erase (q);
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
207 }
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
208 }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
210 private:
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211
29563
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
212 map_type m_fcn_map;
8a296f1351a4 move hook function classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29562
diff changeset
213 };
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
214
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
215 OCTAVE_END_NAMESPACE(octave)
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216
29954
4c88a452519c rename OCTAVE_USE_DEPRECATED_FUNCTIONS macro and attempt to make it work
John W. Eaton <jwe@octave.org>
parents: 29657
diff changeset
217 #endif