GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
hook-fcn.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2013-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include "hook-fcn.h"
31 #include "parse.h"
32 
34 
36 {
37  if (f.is_string ())
38  {
39  std::string name = f.string_value ();
40 
41  m_rep = std::shared_ptr<base_hook_function> (new named_hook_function (name, d));
42  }
43  else if (f.is_function_handle ())
44  {
45  m_rep = std::shared_ptr<base_hook_function> (new fcn_handle_hook_function (f, d));
46  }
47  else
48  error ("invalid hook function");
49 }
50 
51 void named_hook_function::eval (const octave_value_list& initial_args)
52 {
53  octave_value_list args = initial_args;
54 
55  if (m_data.is_defined ())
56  args.append (m_data);
57 
58  feval (m_name, args, 0);
59 }
60 
62 {
63  octave_value_list args = initial_args;
64 
65  if (m_data.is_defined ())
66  args.append (m_data);
67 
68  feval (m_fcn_handle, args, 0);
69 }
70 
OCTAVE_END_NAMESPACE(octave)
octave_value m_data
Definition: hook-fcn.h:147
void eval(const octave_value_list &initial_args)
Definition: hook-fcn.cc:61
octave_value m_fcn_handle
Definition: hook-fcn.h:145
void eval(const octave_value_list &initial_args)
Definition: hook-fcn.cc:51
octave_value m_data
Definition: hook-fcn.h:111
std::string m_name
Definition: hook-fcn.h:109
octave_value_list & append(const octave_value &val)
Definition: ovl.cc:98
bool is_defined(void) const
Definition: ov.h:637
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition: error.cc:979
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE const F77_DBLE * f
octave_value_list feval(const char *name, const octave_value_list &args, int nargout)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
Definition: oct-parse.cc:10370