annotate libinterp/corefcn/hook-fcn.h @ 29561:ed90a4d75f6d

use shared_ptr to manage data for hook_function class * hook-fcn.h, hook-fcn.cc (class base_hook_function): Delete count data member and all uses. Use default destructor, and copy constructor. Don't declare hook_function as friend class. (class hook_function): Use shared_ptr for rep and nil_rep objects. Use default destructor, copy constructor, and assignment operator. (class hook_function_list): Use default constructor, destructor, and assignment operator.
author John W. Eaton <jwe@octave.org>
date Tue, 27 Apr 2021 13:16:01 -0400
parents 0a5b15007766
children 7513a6aa14ef
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 //
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
3 // Copyright (C) 2013-2021 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
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 class
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 base_hook_function
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 {
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 public:
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43
29561
ed90a4d75f6d use shared_ptr to manage data for hook_function class
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
44 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
45
29561
ed90a4d75f6d use shared_ptr to manage data for hook_function class
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
46 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
47
22868
87e3163f6c87 use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
48 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
49
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
50 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
51
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
52 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
53
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 virtual void eval (const octave_value_list&) { }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 };
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 class
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 hook_function
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 {
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 public:
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 hook_function (void)
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 {
29561
ed90a4d75f6d use shared_ptr to manage data for hook_function class
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
64 static std::shared_ptr<base_hook_function>
ed90a4d75f6d use shared_ptr to manage data for hook_function class
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
65 nil_rep (new base_hook_function ());
ed90a4d75f6d use shared_ptr to manage data for hook_function class
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
66
ed90a4d75f6d use shared_ptr to manage data for hook_function class
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
67 rep = nil_rep;
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 hook_function (const octave_value& f,
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 const octave_value& d = octave_value ());
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72
29561
ed90a4d75f6d use shared_ptr to manage data for hook_function class
John W. Eaton <jwe@octave.org>
parents: 29358
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
29561
ed90a4d75f6d use shared_ptr to manage data for hook_function class
John W. Eaton <jwe@octave.org>
parents: 29358
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
29561
ed90a4d75f6d use shared_ptr to manage data for hook_function class
John W. Eaton <jwe@octave.org>
parents: 29358
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
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
79 std::string id (void) const { return rep->id (); }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
81 bool is_valid (void) const { return rep->is_valid (); }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 void eval (const octave_value_list& initial_args)
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 {
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 rep->eval (initial_args);
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 private:
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89
29561
ed90a4d75f6d use shared_ptr to manage data for hook_function class
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
90 std::shared_ptr<base_hook_function> rep;
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 };
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 class
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 named_hook_function : public base_hook_function
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 {
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 public:
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 named_hook_function (const std::string& n, const octave_value& d)
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 : name (n), data (d)
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 { }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
102 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
103
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
104 std::string id (void) const { return name; }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
106 bool is_valid (void) const { return is_valid_function (name); }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 private:
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 std::string name;
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 octave_value data;
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 };
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 class
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116 fcn_handle_hook_function : public base_hook_function
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 {
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 public:
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 fcn_handle_hook_function (const octave_value& fh_arg, const octave_value& d)
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 : ident (), valid (false), fcn_handle (fh_arg), data (d)
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 {
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 octave_fcn_handle *fh = fcn_handle.fcn_handle_value (true);
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 if (fh)
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 {
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 valid = true;
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 std::ostringstream buf;
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130 buf << fh;
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23473
diff changeset
131 ident = fh->fcn_name () + ':' + buf.str ();
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132 }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
135 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
136
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
137 std::string id (void) const { return ident; }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
139 bool is_valid (void) const { return valid; }
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 private:
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143 std::string ident;
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
145 bool valid;
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 octave_value fcn_handle;
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 octave_value data;
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150 };
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152 class
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153 hook_function_list
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154 {
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 public:
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157 typedef std::map<std::string, hook_function> map_type;
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 typedef map_type::iterator iterator;
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160 typedef map_type::const_iterator const_iterator;
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161
29561
ed90a4d75f6d use shared_ptr to manage data for hook_function class
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
162 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
163
22868
87e3163f6c87 use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
164 ~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
165
29561
ed90a4d75f6d use shared_ptr to manage data for hook_function class
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
166 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
167
29561
ed90a4d75f6d use shared_ptr to manage data for hook_function class
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
168 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
169
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
170 bool empty (void) const { return fcn_map.empty (); }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
171
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172 void clear (void) { fcn_map.clear (); }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
173
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174 void insert (const std::string& id, const hook_function& f)
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175 {
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
176 fcn_map[id] = f;
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
177 }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179 iterator find (const std::string& id)
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180 {
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181 return fcn_map.find (id);
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182 }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184 const_iterator find (const std::string& id) const
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185 {
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186 return fcn_map.find (id);
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
187 }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189 iterator end (void) { return fcn_map.end (); }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191 const_iterator end (void) const { return fcn_map.end (); }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193 void erase (iterator p) { fcn_map.erase (p); }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195 void run (const octave_value_list& initial_args = octave_value_list ())
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196 {
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
197 auto p = fcn_map.begin ();
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
198
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199 while (p != fcn_map.end ())
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200 {
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201 std::string hook_fcn_id = p->first;
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202 hook_function hook_fcn = p->second;
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
204 auto q = p++;
16384
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206 if (hook_fcn.is_valid ())
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207 hook_fcn.eval (initial_args);
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208 else
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209 fcn_map.erase (q);
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210 }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211 }
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
212
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213 private:
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215 map_type fcn_map;
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216 };
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217
a8d9ee3766db * hook-fcn.h: Commit file omitted from previous changeset.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218 #endif